From be5be0e0354f02c5e3c349822fc466f625fc382b Mon Sep 17 00:00:00 2001 From: lcolladotor Date: Fri, 15 Sep 2023 13:26:09 -0400 Subject: [PATCH] v1.13.6 -- resolve #43 --- DESCRIPTION | 4 ++-- NEWS.md | 8 ++++++++ R/vis_clus.R | 23 ++++++++++++++++++++++- R/vis_clus_p.R | 5 +++-- R/vis_gene.R | 5 ----- R/vis_grid_clus.R | 2 ++ man/run_app.Rd | 6 ++++++ man/vis_clus.Rd | 21 +++++++++++++++++++++ man/vis_clus_p.Rd | 9 ++++++++- man/vis_grid_clus.Rd | 7 +++++++ 10 files changed, 79 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5bf620bf..74e74b51 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: spatialLIBD Title: spatialLIBD: an R/Bioconductor package to visualize spatially-resolved transcriptomics data -Version: 1.13.5 -Date: 2023-09-05 +Version: 1.13.6 +Date: 2023-09-15 Authors@R: c( person("Leonardo", "Collado-Torres", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 1b89419e..72d76cb4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# spatialLIBD 1.13.6 + +NEW FEATURES + +* `vis_clus_p()`, `vis_clus()`, and `vis_grid_clus()` now all use implement the +`na_color` argument that was present in the `vis_gene()` functions. This +resolves https://github.com/LieberInstitute/spatialLIBD/issues/43 by @boyiguo1. + # spatialLIBD 1.13.5 NEW FEATURES diff --git a/R/vis_clus.R b/R/vis_clus.R index a4b006c8..d3f00dc1 100644 --- a/R/vis_clus.R +++ b/R/vis_clus.R @@ -24,6 +24,11 @@ #' @param auto_crop A `logical(1)` indicating whether to automatically crop #' the image / plotting area, which is useful if the Visium capture area is #' not centered on the image and if the image is not a square. +#' @param na_color A `character(1)` specifying a color for the NA values. +#' If you set `alpha = NA` then it's best to set `na_color` to a color that has +#' alpha blending already, which will make non-NA values pop up more and the NA +#' values will show with a lighter color. This behavior is lost when `alpha` is +#' set to a non-`NA` value. #' @param ... Passed to [paste0()][base::paste] for making the title of the #' plot following the `sampleid`. #' @@ -74,6 +79,20 @@ #' spatial = FALSE #' ) #' print(p3) +#' +#' ## With some NA values +#' spe$tmp <- spe$layer_guess_reordered +#' spe$tmp[spe$sample_id == "151673"][seq_len(500)] <- NA +#' p4 <- vis_clus( +#' spe = spe, +#' clustervar = "tmp", +#' sampleid = "151673", +#' colors = libd_layer_colors, +#' na_color = "white", +#' ... = " LIBD Layers" +#' ) +#' print(p4) +#' #' } vis_clus <- function(spe, sampleid = unique(spe$sample_id)[1], @@ -97,6 +116,7 @@ vis_clus <- function(spe, alpha = NA, point_size = 2, auto_crop = TRUE, + na_color = "#CCCCCC40", ...) { spe_sub <- spe[, spe$sample_id == sampleid] d <- as.data.frame(cbind(colData(spe_sub), SpatialExperiment::spatialCoords(spe_sub)), optional = TRUE) @@ -112,6 +132,7 @@ vis_clus <- function(spe, image_id = image_id, alpha = alpha, point_size = point_size, - auto_crop = auto_crop + auto_crop = auto_crop, + na_color = na_color ) } diff --git a/R/vis_clus_p.R b/R/vis_clus_p.R index 34aecaef..a91ce369 100644 --- a/R/vis_clus_p.R +++ b/R/vis_clus_p.R @@ -52,7 +52,8 @@ vis_clus_p <- image_id = "lowres", alpha = NA, point_size = 2, - auto_crop = TRUE) { + auto_crop = TRUE, + na_color = "#CCCCCC40") { ## Some variables pxl_row_in_fullres <- pxl_col_in_fullres <- key <- NULL # stopifnot(all(c("pxl_col_in_fullres", "pxl_row_in_fullres", "key") %in% colnames(d))) @@ -112,7 +113,7 @@ vis_clus_p <- alpha = alpha ) + coord_fixed(expand = FALSE) + - scale_fill_manual(values = colors) + + scale_fill_manual(values = colors, na.value = na_color) + xlim(0, ncol(img)) + ylim(nrow(img), 0) + xlab("") + ylab("") + diff --git a/R/vis_gene.R b/R/vis_gene.R index 712800de..673bb453 100644 --- a/R/vis_gene.R +++ b/R/vis_gene.R @@ -23,11 +23,6 @@ #' dependent on cell density. #' @param cont_colors A `character()` vector of colors that supersedes the #' `viridis` argument. -#' @param na_color A `character(1)` specifying a color for the NA values. -#' If you set `alpha = NA` then it's best to set `na_color` to a color that has -#' alpha blending already, which will make non-NA values pop up more and the NA -#' values will show with a lighter color. This behavior is lost when `alpha` is -#' set to a non-`NA` value. #' #' @return A [ggplot2][ggplot2::ggplot] object. #' @export diff --git a/R/vis_grid_clus.R b/R/vis_grid_clus.R index 6c90221c..40ead6b3 100644 --- a/R/vis_grid_clus.R +++ b/R/vis_grid_clus.R @@ -61,6 +61,7 @@ vis_grid_clus <- sample_order = unique(spe$sample_id), point_size = 2, auto_crop = TRUE, + na_color = "#CCCCCC40", ...) { stopifnot(all(sample_order %in% unique(spe$sample_id))) @@ -79,6 +80,7 @@ vis_grid_clus <- alpha = alpha, point_size = point_size, auto_crop = auto_crop, + na_color = na_color, ... ) }) diff --git a/man/run_app.Rd b/man/run_app.Rd index ec7f0cb3..5b1d6c6a 100644 --- a/man/run_app.Rd +++ b/man/run_app.Rd @@ -23,6 +23,7 @@ run_app( spe_continuous_vars = c("cell_count", "sum_umi", "sum_gene", "expr_chrM", "expr_chrM_ratio"), default_cluster = "spatialLIBD", + auto_crop_default = TRUE, ... ) } @@ -69,6 +70,11 @@ as genes. They will have to be present in \code{colData(sce)}.} (discrete) variable to use. It will have to be present in both \code{colData(spe)} and \code{colData(sce_layer)}.} +\item{auto_crop_default}{A \code{logical(1)} specifying the default value for +automatically cropping the images. Set this to \code{FALSE} if your images do not +follow the Visium grid size expectations, which are key for enabling +auto-cropping.} + \item{...}{Other arguments passed to the list of golem options for running the application.} } diff --git a/man/vis_clus.Rd b/man/vis_clus.Rd index 4bb0c369..ebb948c2 100644 --- a/man/vis_clus.Rd +++ b/man/vis_clus.Rd @@ -15,6 +15,7 @@ vis_clus( alpha = NA, point_size = 2, auto_crop = TRUE, + na_color = "#CCCCCC40", ... ) } @@ -52,6 +53,12 @@ to \code{1.25}. Some colors look better if you use \code{2} for instance.} the image / plotting area, which is useful if the Visium capture area is not centered on the image and if the image is not a square.} +\item{na_color}{A \code{character(1)} specifying a color for the NA values. +If you set \code{alpha = NA} then it's best to set \code{na_color} to a color that has +alpha blending already, which will make non-NA values pop up more and the NA +values will show with a lighter color. This behavior is lost when \code{alpha} is +set to a non-\code{NA} value.} + \item{...}{Passed to \link[base:paste]{paste0()} for making the title of the plot following the \code{sampleid}.} } @@ -107,6 +114,20 @@ if (enough_ram()) { spatial = FALSE ) print(p3) + + ## With some NA values + spe$tmp <- spe$layer_guess_reordered + spe$tmp[spe$sample_id == "151673"][seq_len(500)] <- NA + p4 <- vis_clus( + spe = spe, + clustervar = "tmp", + sampleid = "151673", + colors = libd_layer_colors, + na_color = "white", + ... = " LIBD Layers" + ) + print(p4) + } } \seealso{ diff --git a/man/vis_clus_p.Rd b/man/vis_clus_p.Rd index ba154839..3706e6a2 100644 --- a/man/vis_clus_p.Rd +++ b/man/vis_clus_p.Rd @@ -15,7 +15,8 @@ vis_clus_p( image_id = "lowres", alpha = NA, point_size = 2, - auto_crop = TRUE + auto_crop = TRUE, + na_color = "#CCCCCC40" ) } \arguments{ @@ -56,6 +57,12 @@ to \code{1.25}. Some colors look better if you use \code{2} for instance.} \item{auto_crop}{A \code{logical(1)} indicating whether to automatically crop the image / plotting area, which is useful if the Visium capture area is not centered on the image and if the image is not a square.} + +\item{na_color}{A \code{character(1)} specifying a color for the NA values. +If you set \code{alpha = NA} then it's best to set \code{na_color} to a color that has +alpha blending already, which will make non-NA values pop up more and the NA +values will show with a lighter color. This behavior is lost when \code{alpha} is +set to a non-\code{NA} value.} } \value{ A \link[ggplot2:ggplot]{ggplot2} object. diff --git a/man/vis_grid_clus.Rd b/man/vis_grid_clus.Rd index 52fd0be5..6d9a3690 100644 --- a/man/vis_grid_clus.Rd +++ b/man/vis_grid_clus.Rd @@ -19,6 +19,7 @@ vis_grid_clus( sample_order = unique(spe$sample_id), point_size = 2, auto_crop = TRUE, + na_color = "#CCCCCC40", ... ) } @@ -69,6 +70,12 @@ to \code{1.25}. Some colors look better if you use \code{2} for instance.} the image / plotting area, which is useful if the Visium capture area is not centered on the image and if the image is not a square.} +\item{na_color}{A \code{character(1)} specifying a color for the NA values. +If you set \code{alpha = NA} then it's best to set \code{na_color} to a color that has +alpha blending already, which will make non-NA values pop up more and the NA +values will show with a lighter color. This behavior is lost when \code{alpha} is +set to a non-\code{NA} value.} + \item{...}{Passed to \link[base:paste]{paste0()} for making the title of the plot following the \code{sampleid}.} }