diff --git a/NEWS.md b/NEWS.md index 024b7c2..920ad9f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,4 +7,5 @@ ## heatmapSC * Add `sample.name.column` to select the metadata column used for sample filtering, defaulting to `orig.ident` (#100). -* Log requested sample filtering and displayed filtered/total cell counts (#101). \ No newline at end of file +* Log requested sample filtering and displayed filtered/total cell counts (#101). +* Use all samples when sample selection is blank (#102). diff --git a/R/Heatmap.R b/R/Heatmap.R index 7c214a5..72f3f15 100755 --- a/R/Heatmap.R +++ b/R/Heatmap.R @@ -4,7 +4,8 @@ #' gene or protein expression levels. Method is based on ComplexHeatmap::pheatmap #' #' @param object Seurat-class object -#' @param sample.names Sample names +#' @param sample.names Select which samples to include. Leave blank to use all +#' samples. #' @param sample.name.column Metadata column containing sample names. Blank #' values default to "orig.ident". #' @param metadata Metadata column to plot @@ -401,6 +402,11 @@ heatmapSC <- function(object, stop("Could not find requested sample name column: ", sample.name.column) } + if (length(samples.to.include) == 0) { + message("No samples specified. Using all samples.") + samples.to.include <- unique(object@meta.data[[sample.name.column]]) + } + requested.samples <- if (length(samples.to.include) > 0) { paste(shQuote(samples.to.include), collapse = ", ") } else { diff --git a/man/heatmapSC.Rd b/man/heatmapSC.Rd index 89abb41..6543b28 100644 --- a/man/heatmapSC.Rd +++ b/man/heatmapSC.Rd @@ -35,7 +35,8 @@ heatmapSC( \arguments{ \item{object}{Seurat-class object} -\item{sample.names}{Sample names} +\item{sample.names}{Select which samples to include. Leave blank to use all +samples.} \item{metadata}{Metadata column to plot} @@ -86,7 +87,7 @@ heatmapSC( (default is empty vector)} \item{sample.name.column}{Metadata column containing sample names. Blank -values default to "orig.ident". Sample values are matched exactly.} +values default to "orig.ident".} } \value{ This function returns a heatmap plot and the data underlying the diff --git a/tests/testthat/test-Heatmap.R b/tests/testthat/test-Heatmap.R index a578acd..a0a6b16 100755 --- a/tests/testthat/test-Heatmap.R +++ b/tests/testthat/test-Heatmap.R @@ -76,6 +76,19 @@ test_that("Heatmap supports a custom sample name column", { expect_identical(colnames(cr.object$object@meta.data), metadata.names) }) +test_that("Heatmap uses all samples when sample selection is blank", { + cr.object <- getParamHM("Chariou") + cr.object$sample.names <- c("") + + expect_message( + output <- do.call(heatmapSC, cr.object), + "No samples specified. Using all samples.", + fixed = TRUE + ) + + expect_setequal(colnames(output$data)[-1], rownames(cr.object$object@meta.data)) +}) + test_that("Heatmap preserves punctuation in sample names", { cr.object <- getParamHM("Chariou") sample.column <- "sample.name_1.2"