From a3d888119e15622640ee473839451defda455d83 Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 2 Jan 2025 12:39:51 -0500 Subject: [PATCH 01/11] Adds ability for users to set their own color palettes for XString objects --- NAMESPACE | 5 +- R/coloring.R | 136 +++++++++++++++++++++++++++++++++++++++++++++++---- R/zzz.R | 11 ++++- 3 files changed, 140 insertions(+), 12 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 7830efa9..974c0c7a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -70,7 +70,10 @@ export( BStringSetList, DNAStringSetList, RNAStringSetList, AAStringSetList, ## xscat.R: - xscat + xscat, + + ## coloring.R: + update_DNA_palette, update_RNA_palette, update_AA_palette, update_B_palette ) exportMethods( diff --git a/R/coloring.R b/R/coloring.R index 05406fed..55442a5d 100644 --- a/R/coloring.R +++ b/R/coloring.R @@ -2,13 +2,9 @@ ### add_colors() ### ------------------------------------------------------------------------- ### -### Nothing in this file is exported. +### Only update_X_palette() methods are exported ### -### Placeholder, initialized in .onLoad() -DNA_AND_RNA_COLORED_LETTERS <- NULL -AA_COLORED_LETTERS <- NULL - ### Return a named character vector where all the names are single letters. ### Colors for A, C, G, and T were inspired by ### https://en.wikipedia.org/wiki/Nucleotide#Structure @@ -41,12 +37,13 @@ make_DNA_AND_RNA_COLORED_LETTERS <- function() { if (!isTRUE(getOption("Biostrings.coloring", default=FALSE))) return(x) + color_palette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=.pkgenv) ans <- vapply(x, function(xi) { xi <- safeExplode(xi) - m <- match(xi, names(DNA_AND_RNA_COLORED_LETTERS)) + m <- match(xi, names(color_palette)) match_idx <- which(!is.na(m)) - xi[match_idx] <- DNA_AND_RNA_COLORED_LETTERS[m[match_idx]] + xi[match_idx] <- color_palette[m[match_idx]] paste0(xi, collapse="") }, character(1), @@ -122,12 +119,37 @@ make_AA_COLORED_LETTERS <- function(){ { if (!isTRUE(getOption("Biostrings.coloring", default=FALSE))) return(x) + color_palette <- get("AA_COLORED_LETTERS", envir=.pkgenv) + ans <- vapply(x, + function(xi) { + xi <- safeExplode(xi) + m <- match(xi, names(color_palette)) + match_idx <- which(!is.na(m)) + xi[match_idx] <- color_palette[m[match_idx]] + paste0(xi, collapse="") + }, + character(1), + USE.NAMES=FALSE + ) + x_names <- names(x) + if (!is.null(x_names)) + names(ans) <- x_names + ans +} + +### BString Colors +### by default, no coloring, but will allow users to set their own palettes +.add_bstring_colors <- function(x) +{ + if (!isTRUE(getOption("Biostrings.coloring", default=FALSE))) + return(x) + color_palette <- get("BSTRING_COLORED_LETTERS", envir=.pkgenv) ans <- vapply(x, function(xi) { xi <- safeExplode(xi) - m <- match(xi, names(AA_COLORED_LETTERS)) + m <- match(xi, names(color_palette)) match_idx <- which(!is.na(m)) - xi[match_idx] <- AA_COLORED_LETTERS[m[match_idx]] + xi[match_idx] <- color_palette[m[match_idx]] paste0(xi, collapse="") }, character(1), @@ -139,7 +161,103 @@ make_AA_COLORED_LETTERS <- function(){ ans } +update_DNA_palette <- function(colors=NULL){ + palette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=.pkgenv) + if(is.null(colors)) + palette <- make_DNA_AND_RNA_COLORED_LETTERS() + if(!is.null(colors)){ + if(!is.list(colors)){ + error("'colors' should be NULL or a list of entries with 'bg' ", + "and optionally 'fg' values.") + } + all_bases <- union(DNA_ALPHABET, RNA_ALPHABET) + if(length(setdiff(names(colors), all_bases)) != 0){ + error("Invalid DNA/RNA codes specified.") + } + + n <- names(colors) + for(i in seq_along(colors)){ + fg <- colors[[i]]$fg + bg <- colors[[i]]$bg + if(is.null(fg) && is.null(bg)){ + palette[n[i]] <- n[i] + } else if(is.null(bg)) { + palette[n[i]] <- make_style(fg)(n[i]) + } else { + if(is.null(fg)) fg <- rgb(1,1,1) + palette[n[i]] <- make_style(bg, bg=TRUE)(make_style(fg)(n[i])) + } + } + } + + assign("DNA_AND_RNA_COLORED_LETTERS", palette, envir=.pkgenv) +} + +update_RNA_palette <- update_DNA_palette + +update_AA_palette <- function(colors=NULL){ + palette <- get("AA_COLORED_LETTERS", envir=.pkgenv) + if(is.null(colors)) + palette <- make_AA_COLORED_LETTERS() + + if(!is.null(colors)){ + if(!is.list(colors)){ + error("'colors' should be NULL or a list of entries with 'bg' ", + "and optionally 'fg' values.") + } + + if(length(setdiff(names(colors), AA_ALPHABET)) != 0){ + error("Invalid AA codes specified.") + } + + n <- names(colors) + for(i in seq_along(colors)){ + fg <- colors[[i]]$fg + bg <- colors[[i]]$bg + if(is.null(fg) && is.null(bg)){ + palette[n[i]] <- n[i] + } else if(is.null(bg)) { + palette[n[i]] <- make_style(fg)(n[i]) + } else { + if(is.null(fg)) fg <- rgb(1,1,1) + palette[n[i]] <- make_style(bg, bg=TRUE)(make_style(fg)(n[i])) + } + } + } + + assign("AA_COLORED_LETTERS", palette, envir=.pkgenv) +} + +update_B_palette <- function(colors=NULL){ + palette <- get("BSTRING_COLORED_LETTERS", envir=.pkgenv) + if(is.null(colors)) + palette <- character(0L) + if(!is.null(colors)){ + if(!is.list(colors)){ + error("'colors' should be NULL or a list of entries with 'bg' ", + "and optionally 'fg' values.") + } + + n <- names(colors) + for(i in seq_along(colors)){ + fg <- colors[[i]]$fg + bg <- colors[[i]]$bg + if(is.null(fg) && is.null(bg)){ + palette[n[i]] <- n[i] + } else if(is.null(bg)) { + palette[n[i]] <- make_style(fg)(n[i]) + } else { + if(is.null(fg)) fg <- rgb(1,1,1) + palette[n[i]] <- make_style(bg, bg=TRUE)(make_style(fg)(n[i])) + } + } + } + + assign("BSTRING_COLORED_LETTERS", palette, envir=.pkgenv) +} + add_colors <- function(x) UseMethod("add_colors") add_colors.default <- identity add_colors.DNA <- add_colors.RNA <- .add_dna_and_rna_colors add_colors.AA <- .add_aa_colors +add_colors.B <- .add_bstring_colors diff --git a/R/zzz.R b/R/zzz.R index 65e22402..5a138000 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,5 +1,7 @@ ### +.pkgenv <- new.env(parent=emptyenv()) + .onLoad <- function(libname, pkgname) { .Call2("init_DNAlkups", @@ -11,8 +13,13 @@ .Call2("init_AAlkups", AA_STRING_CODEC@enc_lkup, AA_STRING_CODEC@dec_lkup, PACKAGE=pkgname) - DNA_AND_RNA_COLORED_LETTERS <<- make_DNA_AND_RNA_COLORED_LETTERS() - AA_COLORED_LETTERS <<- make_AA_COLORED_LETTERS() + #.pkgenv[["DNA_AND_RNA_COLORED_LETTERS"]] <- make_DNA_AND_RNA_COLORED_LETTERS() + #.pkgenv[["AA_COLORED_LETTERS"]] <- make_AA_COLORED_LETTERS() + assign("DNA_AND_RNA_COLORED_LETTERS", make_DNA_AND_RNA_COLORED_LETTERS(), envir=.pkgenv) + assign("AA_COLORED_LETTERS", make_AA_COLORED_LETTERS(), envir=.pkgenv) + assign("BSTRING_COLORED_LETTERS", character(0L), envir=.pkgenv) + #DNA_AND_RNA_COLORED_LETTERS <<- make_DNA_AND_RNA_COLORED_LETTERS() + #AA_COLORED_LETTERS <<- make_AA_COLORED_LETTERS() option_name <- "Biostrings.coloring" if (!(option_name %in% names(.Options))) options(setNames(list(TRUE), option_name)) From f8dc6be8935b73947880422c496766c3e1f23d40 Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 2 Jan 2025 12:55:38 -0500 Subject: [PATCH 02/11] Adds tests for coloring update functions --- tests/testthat/test-miscellaneous.R | 71 +++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/testthat/test-miscellaneous.R b/tests/testthat/test-miscellaneous.R index c7c571eb..9d1ffa65 100644 --- a/tests/testthat/test-miscellaneous.R +++ b/tests/testthat/test-miscellaneous.R @@ -18,6 +18,77 @@ test_that("coloring works for DNA, RNA, and AA", { expect_equal(sort(names(make_AA_COLORED_LETTERS())), sort(aa_expected)) }) +test_that("users can update color palettes", { + colored_letter <- \(letter, fg, bg){ + crayon::make_style(bg, bg=TRUE)(crayon::make_style(fg)(letter)) + } + + dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + + origdna_palette <- Biostrings:::make_DNA_AND_RNA_COLORED_LETTERS() + origaa_palette <- Biostrings:::make_AA_COLORED_LETTERS() + origb_palette <- character(0L) + + ## check initialization + expect_identical(dnapalette, origdna_palette) + expect_identical(aapalette, origaa_palette) + expect_identical(bpalette, origb_palette) + + ## check DNA update + DNA_palette <- list( + A=list(fg="blue",bg="black"), + T=list(fg="red",bg='black'), + G=list(fg='green',bg='black'), + C=list(fg='yellow',bg='black') + ) + update_DNA_palette(DNA_palette) + + dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(dnapalette[c("A","T","G","C")], + c(A=colored_letter("A", "blue", "black"), + T=colored_letter("T", "red", "black"), + G=colored_letter("G", "green", "black"), + C=colored_letter("C", "yellow", "black"))) + update_DNA_palette() + dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(dnapalette, origdna_palette) + + ## Check AA update + AA_palette <- list( + A=list(fg="white", bg="purple"), + B=list(fg=rgb(1,1,1), bg='orange') + ) + update_AA_palette(AA_palette) + aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(aapalette[c("A","B")], + c(A=colored_letter("A","white","purple"), + B=colored_letter("B", rgb(1,1,1), "orange"))) + update_AA_palette() + aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(aapalette, origaa_palette) + + B_palette <- list( + A=list(bg='green'), + B=list(bg="red"), + C=list(bg='blue'), + D=list(fg="orange"), + E=list(fg="yellow") + ) + update_B_palette(B_palette) + bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(bpalette[c("A","B","C","D","E")], + c(A=colored_letter("A", rgb(1,1,1), "green"), + B=colored_letter("B", rgb(1,1,1), "red"), + C=colored_letter("C", rgb(1,1,1), "blue"), + D=crayon::make_style("orange")("D"), + E=crayon::make_style("yellow")("E"))) + update_B_palette() + bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(bpalette, origb_palette) +}) + test_that("utils functions work as they should", { expect_true(Biostrings:::isNumericOrNAs(NA_character_)) expect_true(Biostrings:::isNumericOrNAs(NA_real_)) From 65e5e9470bbf9c61130e6f6d05472dc452ccad85 Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 2 Jan 2025 13:16:21 -0500 Subject: [PATCH 03/11] adds man page for new functions --- man/update_X_palette.Rd | 108 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 man/update_X_palette.Rd diff --git a/man/update_X_palette.Rd b/man/update_X_palette.Rd new file mode 100644 index 00000000..f208bbcd --- /dev/null +++ b/man/update_X_palette.Rd @@ -0,0 +1,108 @@ +\name{update_X_palette} + +\alias{update_DNA_palette} +\alias{update_RNA_palette} +\alias{update_AA_palette} +\alias{update_B_palette} + +\title{Update XString Display Colors} + +\description{ + Functions to set custom user color palettes for displaying \code{XString} objects. +} + +\usage{ +update_DNA_palette(colors=NULL) +update_RNA_palette(colors=NULL) +update_AA_palette(colors=NULL) +update_B_palette(colors=NULL) +} + +\arguments{ + \item{colors}{ + A named list of colors to update, with entries \code{fg} and \code{bg} specifying the foreground and background colors, respectively. Colors can be specified in any way compatible with \code{\link[crayon]{make_style}} from the \code{crayon} package. Defaults to \code{NULL}, which resets the color palette to the default color scheme. See Details and Examples for more information. + } +} + +\details{ + These functions allow users to change the default color scheme of Biostrings. Each function expects a \code{list} with named entries corresponding to the values to update. Each entry can specify \code{'fg'} and \code{'bg'} values, corresponding to the foreground and background colors (respectively). If \code{'fg'} is not specified, it defaults to \code{rgb(1,1,1)} (white). If \code{'bg'} is not specified, it defaults to transparent. + + These functions will only update the values passed, leaving the rest of the colors as-is. For example, calling \code{update_AA_palette(list(A=list(fg="green")))} would update the coloring for \code{A} while leaving all other colors as the default schema. + + To reset all colors to the default palette, call the function with no arguments (\code{NULL}). + + To remove a coloring for a specific value, provide a named entry with no elements. For example, \code{update_AA_palette(list(A=NULL))} will remove the coloring for \code{A}. + + \code{update_DNA_palette} and \code{update_RNA_palette} are identical internally, so either function can be used to update colorings for \code{T,U}. + + See the Examples section for more examples of custom colorings. +} + +\value{ + Invisibly returns the new color mapping, consisting of a named character vector. Calling \code{cat} on the return value will print out all letters with their respective coloring. +} + +\author{Aidan Lakshman } + +\seealso{ + \link{XString-class} +} + +\examples{ +## display default colors +DNAString(paste(DNA_ALPHABET, collapse='')) +AAString(paste(AA_ALPHABET, collapse='')) +BString(paste(LETTERS, collapse='')) + +## create new palettes +DNA_palette <- list( + A=list(fg="blue",bg="black"), + T=list(fg="red",bg='black'), + G=list(fg='green',bg='black'), + C=list(fg='yellow',bg='black') +) +update_DNA_palette(DNA_palette) +DNAString(paste(DNA_ALPHABET, collapse='')) + +## reset to default palette +update_DNA_palette() +DNAString(paste(DNA_ALPHABET, collapse='')) + +## colors can also be specified with `rgb()` +AA_palette <- list( + A=list(fg="white", bg="purple"), + B=list(fg=rgb(1,1,1), bg='orange') +) +update_AA_palette(AA_palette) +AAString(paste(AA_ALPHABET, collapse='')) + +## remove all coloring for QEG +update_AA_palette(list(Q=NULL, E=NULL, G=NULL)) +AAString(paste(AA_ALPHABET, collapse='')) + +## reset to default +update_AA_palette() +AAString(paste(AA_ALPHABET, collapse='')) + +## We can also add colors to BStrings, +## which are normally not colored + +## if 'fg' is not specified, defaults to rgb(1,1,1) +## if 'bg' is not specified, background is transparent +B_palette <- list( + A=list(bg='green'), + B=list(bg="red"), + C=list(bg='blue'), + D=list(fg="orange"), + E=list(fg="yellow") +) +update_B_palette(B_palette) +BString(paste(LETTERS, collapse='')) + +## can also directly view the changes with cat +cat(update_B_palette(B_palette), '\n') + +## reset to default +update_B_palette() +BString(paste(LETTERS, collapse='')) +} From 5827d074cdbb1ea5ccde9bd96ddd01557475d3cc Mon Sep 17 00:00:00 2001 From: ahl27 Date: Mon, 6 Jan 2025 13:11:45 -0500 Subject: [PATCH 04/11] removes some commented lines I forgot about --- R/zzz.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 5a138000..7b263e53 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -13,13 +13,11 @@ .Call2("init_AAlkups", AA_STRING_CODEC@enc_lkup, AA_STRING_CODEC@dec_lkup, PACKAGE=pkgname) - #.pkgenv[["DNA_AND_RNA_COLORED_LETTERS"]] <- make_DNA_AND_RNA_COLORED_LETTERS() - #.pkgenv[["AA_COLORED_LETTERS"]] <- make_AA_COLORED_LETTERS() + assign("DNA_AND_RNA_COLORED_LETTERS", make_DNA_AND_RNA_COLORED_LETTERS(), envir=.pkgenv) assign("AA_COLORED_LETTERS", make_AA_COLORED_LETTERS(), envir=.pkgenv) assign("BSTRING_COLORED_LETTERS", character(0L), envir=.pkgenv) - #DNA_AND_RNA_COLORED_LETTERS <<- make_DNA_AND_RNA_COLORED_LETTERS() - #AA_COLORED_LETTERS <<- make_AA_COLORED_LETTERS() + option_name <- "Biostrings.coloring" if (!(option_name %in% names(.Options))) options(setNames(list(TRUE), option_name)) From 2ac983bd7dfe87d2f312203082f731a1ad09e9cd Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 20 Feb 2025 11:14:30 -0500 Subject: [PATCH 05/11] fixes silly mistake with error messages; makes errors more informative; checks for invalid input in BString; more testing --- R/coloring.R | 17 ++-- man/{update_X_palette.Rd => coloring.Rd} | 5 +- tests/testthat/test-coloring.R | 102 +++++++++++++++++++++++ tests/testthat/test-miscellaneous.R | 87 ------------------- 4 files changed, 117 insertions(+), 94 deletions(-) rename man/{update_X_palette.Rd => coloring.Rd} (95%) create mode 100644 tests/testthat/test-coloring.R diff --git a/R/coloring.R b/R/coloring.R index 55442a5d..7bc158a6 100644 --- a/R/coloring.R +++ b/R/coloring.R @@ -167,12 +167,12 @@ update_DNA_palette <- function(colors=NULL){ palette <- make_DNA_AND_RNA_COLORED_LETTERS() if(!is.null(colors)){ if(!is.list(colors)){ - error("'colors' should be NULL or a list of entries with 'bg' ", + stop("'colors' should be NULL or a named list of entries with 'bg' ", "and optionally 'fg' values.") } all_bases <- union(DNA_ALPHABET, RNA_ALPHABET) if(length(setdiff(names(colors), all_bases)) != 0){ - error("Invalid DNA/RNA codes specified.") + stop("Invalid DNA/RNA codes specified.") } n <- names(colors) @@ -202,12 +202,12 @@ update_AA_palette <- function(colors=NULL){ if(!is.null(colors)){ if(!is.list(colors)){ - error("'colors' should be NULL or a list of entries with 'bg' ", + stop("'colors' should be NULL or a named list of entries with 'bg' ", "and optionally 'fg' values.") } if(length(setdiff(names(colors), AA_ALPHABET)) != 0){ - error("Invalid AA codes specified.") + stop("Invalid AA codes specified.") } n <- names(colors) @@ -234,11 +234,18 @@ update_B_palette <- function(colors=NULL){ palette <- character(0L) if(!is.null(colors)){ if(!is.list(colors)){ - error("'colors' should be NULL or a list of entries with 'bg' ", + stop("'colors' should be NULL or a named list of entries with 'bg' ", "and optionally 'fg' values.") } n <- names(colors) + ## have to use this approach over nchar() because of multibyte chars + ## e.g., 240 -> f0 -> "\xf0" -> 'Error: invalid multibyte string' + ## however, BString supports these values (sort of) + name_nchars <- vapply(n, \(x) length(charToRaw(x)), integer(1L)) + if(!all(name_nchars == 1L)){ + stop("Invalid B codes specified.") + } for(i in seq_along(colors)){ fg <- colors[[i]]$fg bg <- colors[[i]]$bg diff --git a/man/update_X_palette.Rd b/man/coloring.Rd similarity index 95% rename from man/update_X_palette.Rd rename to man/coloring.Rd index f208bbcd..56aa6d39 100644 --- a/man/update_X_palette.Rd +++ b/man/coloring.Rd @@ -1,5 +1,6 @@ -\name{update_X_palette} +\name{coloring} +\alias{update_X_palette} \alias{update_DNA_palette} \alias{update_RNA_palette} \alias{update_AA_palette} @@ -31,7 +32,7 @@ update_B_palette(colors=NULL) To reset all colors to the default palette, call the function with no arguments (\code{NULL}). - To remove a coloring for a specific value, provide a named entry with no elements. For example, \code{update_AA_palette(list(A=NULL))} will remove the coloring for \code{A}. + To remove a coloring for a specific value, provide a named entry with value \code{NULL}. For example, \code{update_AA_palette(list(A=NULL))} will remove the coloring for \code{A}. \code{update_DNA_palette} and \code{update_RNA_palette} are identical internally, so either function can be used to update colorings for \code{T,U}. diff --git a/tests/testthat/test-coloring.R b/tests/testthat/test-coloring.R new file mode 100644 index 00000000..05f4cbde --- /dev/null +++ b/tests/testthat/test-coloring.R @@ -0,0 +1,102 @@ +## Tests for coloring.R +## - make_DNA_AND_RNA_COLORED_LETTERS +## - make_AA_COLORED_LETTERS +## - update_X_palette (X is one of DNA, RNA, AA, B) + +test_that("coloring works for DNA, RNA, and AA", { + ## not a super important test + make_DNA_AND_RNA_COLORED_LETTERS <- + Biostrings:::make_DNA_AND_RNA_COLORED_LETTERS + make_AA_COLORED_LETTERS <- Biostrings:::make_AA_COLORED_LETTERS + + dna_rna_expected <- c(DNA_BASES, "U", DNA_ALPHABET[-c(1:4,16:18)]) + expect_true(!any(duplicated(make_DNA_AND_RNA_COLORED_LETTERS()))) + expect_equal(sort(names(make_DNA_AND_RNA_COLORED_LETTERS())), + sort(dna_rna_expected)) + + aa_expected <- AA_ALPHABET[-c(27:30)] + expect_true(!any(duplicated(make_AA_COLORED_LETTERS()))) + expect_equal(sort(names(make_AA_COLORED_LETTERS())), sort(aa_expected)) +}) + +test_that("users can update color palettes", { + colored_letter <- \(letter, fg, bg){ + crayon::make_style(bg, bg=TRUE)(crayon::make_style(fg)(letter)) + } + + dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + + origdna_palette <- Biostrings:::make_DNA_AND_RNA_COLORED_LETTERS() + origaa_palette <- Biostrings:::make_AA_COLORED_LETTERS() + origb_palette <- character(0L) + + ## check initialization + expect_identical(dnapalette, origdna_palette) + expect_identical(aapalette, origaa_palette) + expect_identical(bpalette, origb_palette) + + ## check DNA update + DNA_palette <- list( + A=list(fg="blue",bg="black"), + T=list(fg="red",bg='black'), + G=list(fg='green',bg='black'), + C=list(fg='yellow',bg='black') + ) + update_DNA_palette(DNA_palette) + + dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(dnapalette[c("A","T","G","C")], + c(A=colored_letter("A", "blue", "black"), + T=colored_letter("T", "red", "black"), + G=colored_letter("G", "green", "black"), + C=colored_letter("C", "yellow", "black"))) + update_DNA_palette() + dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(dnapalette, origdna_palette) + + ## Check AA update + AA_palette <- list( + A=list(fg="white", bg="purple"), + B=list(fg=rgb(1,1,1), bg='orange') + ) + update_AA_palette(AA_palette) + aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(aapalette[c("A","B")], + c(A=colored_letter("A","white","purple"), + B=colored_letter("B", rgb(1,1,1), "orange"))) + update_AA_palette() + aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(aapalette, origaa_palette) + + B_palette <- list( + A=list(bg='green'), + B=list(bg="red"), + C=list(bg='blue'), + D=list(fg="orange"), + E=list(fg="yellow") + ) + update_B_palette(B_palette) + bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(bpalette[c("A","B","C","D","E")], + c(A=colored_letter("A", rgb(1,1,1), "green"), + B=colored_letter("B", rgb(1,1,1), "red"), + C=colored_letter("C", rgb(1,1,1), "blue"), + D=crayon::make_style("orange")("D"), + E=crayon::make_style("yellow")("E"))) + update_B_palette() + bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + expect_identical(bpalette, origb_palette) + + ## sad path testing + expect_error(update_DNA_palette(list(E=list(fg="yellow"))), + "Invalid DNA/RNA codes specified.") + expect_error(update_AA_palette(list(test=list(fg="yellow"))), + "Invalid AA codes specified.") + expect_error(update_B_palette(list(test=list(fg="yellow"))), + "Invalid B codes specified.") + expect_error(update_DNA_palette(10), "should be NULL or a named list") + expect_error(update_AA_palette(10), "should be NULL or a named list") + expect_error(update_B_palette(10), "should be NULL or a named list") +}) \ No newline at end of file diff --git a/tests/testthat/test-miscellaneous.R b/tests/testthat/test-miscellaneous.R index 9d1ffa65..12127b98 100644 --- a/tests/testthat/test-miscellaneous.R +++ b/tests/testthat/test-miscellaneous.R @@ -2,93 +2,6 @@ ## these are all relatively low priority and/or for files with only a few things ## some tests are just for internal functions -test_that("coloring works for DNA, RNA, and AA", { - ## not a super important test - make_DNA_AND_RNA_COLORED_LETTERS <- - Biostrings:::make_DNA_AND_RNA_COLORED_LETTERS - make_AA_COLORED_LETTERS <- Biostrings:::make_AA_COLORED_LETTERS - - dna_rna_expected <- c(DNA_BASES, "U", DNA_ALPHABET[-c(1:4,16:18)]) - expect_true(!any(duplicated(make_DNA_AND_RNA_COLORED_LETTERS()))) - expect_equal(sort(names(make_DNA_AND_RNA_COLORED_LETTERS())), - sort(dna_rna_expected)) - - aa_expected <- AA_ALPHABET[-c(27:30)] - expect_true(!any(duplicated(make_AA_COLORED_LETTERS()))) - expect_equal(sort(names(make_AA_COLORED_LETTERS())), sort(aa_expected)) -}) - -test_that("users can update color palettes", { - colored_letter <- \(letter, fg, bg){ - crayon::make_style(bg, bg=TRUE)(crayon::make_style(fg)(letter)) - } - - dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - - origdna_palette <- Biostrings:::make_DNA_AND_RNA_COLORED_LETTERS() - origaa_palette <- Biostrings:::make_AA_COLORED_LETTERS() - origb_palette <- character(0L) - - ## check initialization - expect_identical(dnapalette, origdna_palette) - expect_identical(aapalette, origaa_palette) - expect_identical(bpalette, origb_palette) - - ## check DNA update - DNA_palette <- list( - A=list(fg="blue",bg="black"), - T=list(fg="red",bg='black'), - G=list(fg='green',bg='black'), - C=list(fg='yellow',bg='black') - ) - update_DNA_palette(DNA_palette) - - dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - expect_identical(dnapalette[c("A","T","G","C")], - c(A=colored_letter("A", "blue", "black"), - T=colored_letter("T", "red", "black"), - G=colored_letter("G", "green", "black"), - C=colored_letter("C", "yellow", "black"))) - update_DNA_palette() - dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - expect_identical(dnapalette, origdna_palette) - - ## Check AA update - AA_palette <- list( - A=list(fg="white", bg="purple"), - B=list(fg=rgb(1,1,1), bg='orange') - ) - update_AA_palette(AA_palette) - aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - expect_identical(aapalette[c("A","B")], - c(A=colored_letter("A","white","purple"), - B=colored_letter("B", rgb(1,1,1), "orange"))) - update_AA_palette() - aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - expect_identical(aapalette, origaa_palette) - - B_palette <- list( - A=list(bg='green'), - B=list(bg="red"), - C=list(bg='blue'), - D=list(fg="orange"), - E=list(fg="yellow") - ) - update_B_palette(B_palette) - bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - expect_identical(bpalette[c("A","B","C","D","E")], - c(A=colored_letter("A", rgb(1,1,1), "green"), - B=colored_letter("B", rgb(1,1,1), "red"), - C=colored_letter("C", rgb(1,1,1), "blue"), - D=crayon::make_style("orange")("D"), - E=crayon::make_style("yellow")("E"))) - update_B_palette() - bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - expect_identical(bpalette, origb_palette) -}) - test_that("utils functions work as they should", { expect_true(Biostrings:::isNumericOrNAs(NA_character_)) expect_true(Biostrings:::isNumericOrNAs(NA_real_)) From 62669be5d83a288142db0c0840f2018cda4838bc Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 20 Feb 2025 11:16:01 -0500 Subject: [PATCH 06/11] add extra newline --- tests/testthat/test-coloring.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-coloring.R b/tests/testthat/test-coloring.R index 05f4cbde..fdf693e6 100644 --- a/tests/testthat/test-coloring.R +++ b/tests/testthat/test-coloring.R @@ -99,4 +99,4 @@ test_that("users can update color palettes", { expect_error(update_DNA_palette(10), "should be NULL or a named list") expect_error(update_AA_palette(10), "should be NULL or a named list") expect_error(update_B_palette(10), "should be NULL or a named list") -}) \ No newline at end of file +}) From 81a320b426a89192d23e19631646f4013929b06e Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 20 Feb 2025 11:36:40 -0500 Subject: [PATCH 07/11] makes man page for coloring more general --- man/coloring.Rd | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/man/coloring.Rd b/man/coloring.Rd index 56aa6d39..a4094e5c 100644 --- a/man/coloring.Rd +++ b/man/coloring.Rd @@ -6,10 +6,10 @@ \alias{update_AA_palette} \alias{update_B_palette} -\title{Update XString Display Colors} +\title{XString Display Colors} \description{ - Functions to set custom user color palettes for displaying \code{XString} objects. + \link{XString} objects support custom coloring for display. Users can also set custom color palettes for XString objects using the \code{update_X_palette} functions. } \usage{ @@ -26,7 +26,15 @@ update_B_palette(colors=NULL) } \details{ - These functions allow users to change the default color scheme of Biostrings. Each function expects a \code{list} with named entries corresponding to the values to update. Each entry can specify \code{'fg'} and \code{'bg'} values, corresponding to the foreground and background colors (respectively). If \code{'fg'} is not specified, it defaults to \code{rgb(1,1,1)} (white). If \code{'bg'} is not specified, it defaults to transparent. + \link{XString} objects support the following default coloring for display. +\itemize{ + \item DNAString: A, C, G, and T are colored red, green, blue, and orange (respectively), N is colored light grey, other ambiguity codes are colored dark grey, and \code{"-+."} have no coloring. + \item RNAString: All bases are colored identically to DNAString. U is colored yellow. + \item AAString: Amino acids are colored according to JalView's Zappo color scheme, representing physicochemical properties. X is colored light grey, other ambiguity codes are colored dark grey, and \code{"*-+."} are not colored. + \item BStrings are not colored. +} + + Users can change the default color scheme of Biostrings with the \code{update_X_palette} family functions. Each function expects a \code{list} with named entries corresponding to the values to update. Each entry can specify \code{'fg'} and \code{'bg'} values, corresponding to the foreground and background colors (respectively). If \code{'fg'} is not specified, it defaults to \code{rgb(1,1,1)} (white). If \code{'bg'} is not specified, it defaults to transparent. These functions will only update the values passed, leaving the rest of the colors as-is. For example, calling \code{update_AA_palette(list(A=list(fg="green")))} would update the coloring for \code{A} while leaving all other colors as the default schema. @@ -40,7 +48,7 @@ update_B_palette(colors=NULL) } \value{ - Invisibly returns the new color mapping, consisting of a named character vector. Calling \code{cat} on the return value will print out all letters with their respective coloring. + For \code{update_X_palette}, Invisibly returns the new color mapping, consisting of a named character vector. Calling \code{cat} on the return value will print out all letters with their respective coloring. } \author{Aidan Lakshman } @@ -52,6 +60,7 @@ update_B_palette(colors=NULL) \examples{ ## display default colors DNAString(paste(DNA_ALPHABET, collapse='')) +RNAString(paste(RNA_ALPHABET, collapse='')) AAString(paste(AA_ALPHABET, collapse='')) BString(paste(LETTERS, collapse='')) From 2e663370a583440d74520184e1d3132d3097261c Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 20 Feb 2025 11:42:32 -0500 Subject: [PATCH 08/11] adds in test to make sure multibyte character checks work correctly in BString palette update --- tests/testthat/test-coloring.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/testthat/test-coloring.R b/tests/testthat/test-coloring.R index fdf693e6..2e5ff65f 100644 --- a/tests/testthat/test-coloring.R +++ b/tests/testthat/test-coloring.R @@ -85,6 +85,11 @@ test_that("users can update color palettes", { C=colored_letter("C", rgb(1,1,1), "blue"), D=crayon::make_style("orange")("D"), E=crayon::make_style("yellow")("E"))) + + multibyte_char_palette <- list() + multibyte_char_palette[[rawToChar(as.raw(239L))]] <- list(fg="red") + expect_no_condition(update_B_palette(multibyte_char_palette)) + update_B_palette() bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) expect_identical(bpalette, origb_palette) From 5c366ecf89b11272c6d866d38bc2d8555863ef82 Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 20 Feb 2025 15:36:46 -0500 Subject: [PATCH 09/11] Refactor to remove lots of duplicated code --- R/coloring.R | 161 ++++++++------------------------- man/coloring.Rd | 1 + tests/testthat/test-coloring.R | 6 +- 3 files changed, 42 insertions(+), 126 deletions(-) diff --git a/R/coloring.R b/R/coloring.R index 7bc158a6..4caf3160 100644 --- a/R/coloring.R +++ b/R/coloring.R @@ -1,5 +1,5 @@ ### ========================================================================= -### add_colors() +### XString Display Colors ### ------------------------------------------------------------------------- ### ### Only update_X_palette() methods are exported @@ -32,29 +32,6 @@ make_DNA_AND_RNA_COLORED_LETTERS <- function() ) } -### 'x' must be a character vector. -.add_dna_and_rna_colors <- function(x) -{ - if (!isTRUE(getOption("Biostrings.coloring", default=FALSE))) - return(x) - color_palette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=.pkgenv) - ans <- vapply(x, - function(xi) { - xi <- safeExplode(xi) - m <- match(xi, names(color_palette)) - match_idx <- which(!is.na(m)) - xi[match_idx] <- color_palette[m[match_idx]] - paste0(xi, collapse="") - }, - character(1), - USE.NAMES=FALSE - ) - x_names <- names(x) - if (!is.null(x_names)) - names(ans) <- x_names - ans -} - ### Return a named character vector where all the names are single letters. ### Colors amino acids by similarity ### Colors groupins by @@ -115,35 +92,12 @@ make_AA_COLORED_LETTERS <- function(){ } ### 'x' must be a character vector. -.add_aa_colors <- function(x) -{ - if (!isTRUE(getOption("Biostrings.coloring", default=FALSE))) - return(x) - color_palette <- get("AA_COLORED_LETTERS", envir=.pkgenv) - ans <- vapply(x, - function(xi) { - xi <- safeExplode(xi) - m <- match(xi, names(color_palette)) - match_idx <- which(!is.na(m)) - xi[match_idx] <- color_palette[m[match_idx]] - paste0(xi, collapse="") - }, - character(1), - USE.NAMES=FALSE - ) - x_names <- names(x) - if (!is.null(x_names)) - names(ans) <- x_names - ans -} - -### BString Colors -### by default, no coloring, but will allow users to set their own palettes -.add_bstring_colors <- function(x) +## env_var_name is the name of the corresponding palette in .pkgenv +.add_xstring_colors <- function(x, env_var_name) { if (!isTRUE(getOption("Biostrings.coloring", default=FALSE))) return(x) - color_palette <- get("BSTRING_COLORED_LETTERS", envir=.pkgenv) + color_palette <- get(env_var_name, envir=.pkgenv) ans <- vapply(x, function(xi) { xi <- safeExplode(xi) @@ -161,21 +115,30 @@ make_AA_COLORED_LETTERS <- function(){ ans } -update_DNA_palette <- function(colors=NULL){ - palette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=.pkgenv) +.update_X_palette <- function(colors=NULL, env_var_name, + alphabet, default_palette_function){ + ## passing default_palette_function as a function pointer so we don't + ## have to evaluate it unless necessary + palette <- get(env_var_name, envir=.pkgenv) if(is.null(colors)) - palette <- make_DNA_AND_RNA_COLORED_LETTERS() + palette <- default_palette_function() if(!is.null(colors)){ if(!is.list(colors)){ stop("'colors' should be NULL or a named list of entries with 'bg' ", "and optionally 'fg' values.") } - all_bases <- union(DNA_ALPHABET, RNA_ALPHABET) - if(length(setdiff(names(colors), all_bases)) != 0){ - stop("Invalid DNA/RNA codes specified.") - } n <- names(colors) + if(!is.null(alphabet) && length(setdiff(n, alphabet)) != 0){ + ## non-BStrings: checking if the characters are valid + stop("Invalid codes specified.") + } else if(is.null(alphabet)){ + ## BStrings: checking for single characters (0:255 in raw) + name_nchars <- vapply(n, \(x) length(charToRaw(x)), integer(1L)) + if(!all(name_nchars == 1L)) + stop("Invalid codes specified.") + } + for(i in seq_along(colors)){ fg <- colors[[i]]$fg bg <- colors[[i]]$bg @@ -190,81 +153,33 @@ update_DNA_palette <- function(colors=NULL){ } } - assign("DNA_AND_RNA_COLORED_LETTERS", palette, envir=.pkgenv) + assign(env_var_name, palette, envir=.pkgenv) +} + +update_DNA_palette <- function(colors=NULL){ + .update_X_palette(colors, "DNA_AND_RNA_COLORED_LETTERS", + union(DNA_ALPHABET, RNA_ALPHABET), + make_DNA_AND_RNA_COLORED_LETTERS) } update_RNA_palette <- update_DNA_palette update_AA_palette <- function(colors=NULL){ - palette <- get("AA_COLORED_LETTERS", envir=.pkgenv) - if(is.null(colors)) - palette <- make_AA_COLORED_LETTERS() - - if(!is.null(colors)){ - if(!is.list(colors)){ - stop("'colors' should be NULL or a named list of entries with 'bg' ", - "and optionally 'fg' values.") - } - - if(length(setdiff(names(colors), AA_ALPHABET)) != 0){ - stop("Invalid AA codes specified.") - } - - n <- names(colors) - for(i in seq_along(colors)){ - fg <- colors[[i]]$fg - bg <- colors[[i]]$bg - if(is.null(fg) && is.null(bg)){ - palette[n[i]] <- n[i] - } else if(is.null(bg)) { - palette[n[i]] <- make_style(fg)(n[i]) - } else { - if(is.null(fg)) fg <- rgb(1,1,1) - palette[n[i]] <- make_style(bg, bg=TRUE)(make_style(fg)(n[i])) - } - } - } - - assign("AA_COLORED_LETTERS", palette, envir=.pkgenv) + .update_X_palette(colors, "AA_COLORED_LETTERS", + AA_ALPHABET, + make_AA_COLORED_LETTERS) } update_B_palette <- function(colors=NULL){ - palette <- get("BSTRING_COLORED_LETTERS", envir=.pkgenv) - if(is.null(colors)) - palette <- character(0L) - if(!is.null(colors)){ - if(!is.list(colors)){ - stop("'colors' should be NULL or a named list of entries with 'bg' ", - "and optionally 'fg' values.") - } - - n <- names(colors) - ## have to use this approach over nchar() because of multibyte chars - ## e.g., 240 -> f0 -> "\xf0" -> 'Error: invalid multibyte string' - ## however, BString supports these values (sort of) - name_nchars <- vapply(n, \(x) length(charToRaw(x)), integer(1L)) - if(!all(name_nchars == 1L)){ - stop("Invalid B codes specified.") - } - for(i in seq_along(colors)){ - fg <- colors[[i]]$fg - bg <- colors[[i]]$bg - if(is.null(fg) && is.null(bg)){ - palette[n[i]] <- n[i] - } else if(is.null(bg)) { - palette[n[i]] <- make_style(fg)(n[i]) - } else { - if(is.null(fg)) fg <- rgb(1,1,1) - palette[n[i]] <- make_style(bg, bg=TRUE)(make_style(fg)(n[i])) - } - } - } - - assign("BSTRING_COLORED_LETTERS", palette, envir=.pkgenv) + ## BStrings don't have a default palette + ## thus their default palette function is just \() return(character(0L)) + .update_X_palette(colors, "BSTRING_COLORED_LETTERS", + NULL, + \(){ character(0L) }) } add_colors <- function(x) UseMethod("add_colors") add_colors.default <- identity -add_colors.DNA <- add_colors.RNA <- .add_dna_and_rna_colors -add_colors.AA <- .add_aa_colors -add_colors.B <- .add_bstring_colors +add_colors.DNA <- add_colors.RNA <- function(x){ .add_xstring_colors(x, "DNA_AND_RNA_COLORED_LETTERS") } +add_colors.AA <- function(x){ .add_xstring_colors(x, "AA_COLORED_LETTERS") } +add_colors.B <- function(x) { .add_xstring_colors(x, "BSTRING_COLORED_LETTERS") } diff --git a/man/coloring.Rd b/man/coloring.Rd index a4094e5c..de5c94b4 100644 --- a/man/coloring.Rd +++ b/man/coloring.Rd @@ -1,5 +1,6 @@ \name{coloring} +\alias{coloring} \alias{update_X_palette} \alias{update_DNA_palette} \alias{update_RNA_palette} diff --git a/tests/testthat/test-coloring.R b/tests/testthat/test-coloring.R index 2e5ff65f..3f32d39d 100644 --- a/tests/testthat/test-coloring.R +++ b/tests/testthat/test-coloring.R @@ -96,11 +96,11 @@ test_that("users can update color palettes", { ## sad path testing expect_error(update_DNA_palette(list(E=list(fg="yellow"))), - "Invalid DNA/RNA codes specified.") + "Invalid codes specified.") expect_error(update_AA_palette(list(test=list(fg="yellow"))), - "Invalid AA codes specified.") + "Invalid codes specified.") expect_error(update_B_palette(list(test=list(fg="yellow"))), - "Invalid B codes specified.") + "Invalid codes specified.") expect_error(update_DNA_palette(10), "should be NULL or a named list") expect_error(update_AA_palette(10), "should be NULL or a named list") expect_error(update_B_palette(10), "should be NULL or a named list") From a37953280e379bd40375d72e0ea73150fd44803e Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 20 Feb 2025 15:40:13 -0500 Subject: [PATCH 10/11] standardize naming of 'X_COLORED_LETTERS' variables --- R/coloring.R | 4 ++-- R/zzz.R | 4 ++-- tests/testthat/test-coloring.R | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/coloring.R b/R/coloring.R index 4caf3160..d3698116 100644 --- a/R/coloring.R +++ b/R/coloring.R @@ -173,7 +173,7 @@ update_AA_palette <- function(colors=NULL){ update_B_palette <- function(colors=NULL){ ## BStrings don't have a default palette ## thus their default palette function is just \() return(character(0L)) - .update_X_palette(colors, "BSTRING_COLORED_LETTERS", + .update_X_palette(colors, "B_COLORED_LETTERS", NULL, \(){ character(0L) }) } @@ -182,4 +182,4 @@ add_colors <- function(x) UseMethod("add_colors") add_colors.default <- identity add_colors.DNA <- add_colors.RNA <- function(x){ .add_xstring_colors(x, "DNA_AND_RNA_COLORED_LETTERS") } add_colors.AA <- function(x){ .add_xstring_colors(x, "AA_COLORED_LETTERS") } -add_colors.B <- function(x) { .add_xstring_colors(x, "BSTRING_COLORED_LETTERS") } +add_colors.B <- function(x) { .add_xstring_colors(x, "B_COLORED_LETTERS") } diff --git a/R/zzz.R b/R/zzz.R index 7b263e53..28cabcb0 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -13,10 +13,10 @@ .Call2("init_AAlkups", AA_STRING_CODEC@enc_lkup, AA_STRING_CODEC@dec_lkup, PACKAGE=pkgname) - + assign("DNA_AND_RNA_COLORED_LETTERS", make_DNA_AND_RNA_COLORED_LETTERS(), envir=.pkgenv) assign("AA_COLORED_LETTERS", make_AA_COLORED_LETTERS(), envir=.pkgenv) - assign("BSTRING_COLORED_LETTERS", character(0L), envir=.pkgenv) + assign("B_COLORED_LETTERS", character(0L), envir=.pkgenv) option_name <- "Biostrings.coloring" if (!(option_name %in% names(.Options))) diff --git a/tests/testthat/test-coloring.R b/tests/testthat/test-coloring.R index 3f32d39d..1788f10d 100644 --- a/tests/testthat/test-coloring.R +++ b/tests/testthat/test-coloring.R @@ -26,7 +26,7 @@ test_that("users can update color palettes", { dnapalette <- get("DNA_AND_RNA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) aapalette <- get("AA_COLORED_LETTERS", envir=Biostrings:::.pkgenv) - bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + bpalette <- get("B_COLORED_LETTERS", envir=Biostrings:::.pkgenv) origdna_palette <- Biostrings:::make_DNA_AND_RNA_COLORED_LETTERS() origaa_palette <- Biostrings:::make_AA_COLORED_LETTERS() @@ -78,7 +78,7 @@ test_that("users can update color palettes", { E=list(fg="yellow") ) update_B_palette(B_palette) - bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + bpalette <- get("B_COLORED_LETTERS", envir=Biostrings:::.pkgenv) expect_identical(bpalette[c("A","B","C","D","E")], c(A=colored_letter("A", rgb(1,1,1), "green"), B=colored_letter("B", rgb(1,1,1), "red"), @@ -91,7 +91,7 @@ test_that("users can update color palettes", { expect_no_condition(update_B_palette(multibyte_char_palette)) update_B_palette() - bpalette <- get("BSTRING_COLORED_LETTERS", envir=Biostrings:::.pkgenv) + bpalette <- get("B_COLORED_LETTERS", envir=Biostrings:::.pkgenv) expect_identical(bpalette, origb_palette) ## sad path testing From e4711ba78d35c31b5e85a91df35e6d4d3f0d82f9 Mon Sep 17 00:00:00 2001 From: ahl27 Date: Thu, 20 Feb 2025 15:43:43 -0500 Subject: [PATCH 11/11] remove a comment line I accidentally left in --- R/coloring.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/R/coloring.R b/R/coloring.R index d3698116..f3a5db3c 100644 --- a/R/coloring.R +++ b/R/coloring.R @@ -1,9 +1,6 @@ ### ========================================================================= ### XString Display Colors ### ------------------------------------------------------------------------- -### -### Only update_X_palette() methods are exported -### ### Return a named character vector where all the names are single letters. ### Colors for A, C, G, and T were inspired by