Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
* 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).
* Use all samples when sample selection is blank (#102).
* Report found Heatmap features before missing requested features without duplicate warnings (#103).
26 changes: 12 additions & 14 deletions R/Heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,19 @@ heatmapSC <- function(object,
}
transcript.data <- object@assays[[use.assay]]@scale.data
missing.genes <- setdiff(transcripts, rownames(transcript.data))
transcripts <- transcripts[transcripts %in% rownames(transcript.data)]
if (length(transcripts) > 0) {
message("Transcripts found in ", use.assay, ": ",
paste(transcripts, collapse = ", "))
}
if (length(missing.genes) > 0) {
missing.transcript.message <- paste0(
"There are ", length(missing.genes), " gene(s) absent from dataset: ",
paste(shQuote(missing.genes), collapse = ", "),
". Possible reasons are that gene is not official gene symbol or gene is ",
"not highly expressed and has been filtered."
".\n Possible reasons are that gene is not official gene symbol ",
"or gene is not highly expressed and has been filtered."
)
message(missing.transcript.message)
warning(missing.transcript.message)
}
transcripts <- transcripts[transcripts %in% rownames(transcript.data)]
if (length(transcripts) > 0) {
message("Transcripts found in ", use.assay, ": ",
paste(transcripts, collapse = ", "))
}

if (length(proteins) > 0 && !"Protein" %in% names(object@assays)) {
Expand All @@ -314,18 +313,17 @@ heatmapSC <- function(object,

if (length(proteins) > 0) {
missing.proteins <- setdiff(proteins, rownames(object$Protein@scale.data))
proteins <- proteins[proteins %in% rownames(object$Protein@scale.data)]
if (length(proteins) > 0) {
message("Proteins found in Protein assay: ",
paste(proteins, collapse = ", "))
}
if (length(missing.proteins) > 0) {
missing.protein.message <- paste0(
"Proteins not found in Protein assay: ",
paste(missing.proteins, collapse = ", "), ". They will be excluded."
)
message(missing.protein.message)
warning(missing.protein.message)
}
proteins <- proteins[proteins %in% rownames(object$Protein@scale.data)]
if (length(proteins) > 0) {
message("Proteins found in Protein assay: ",
paste(proteins, collapse = ", "))
}
}

Expand Down
47 changes: 27 additions & 20 deletions tests/testthat/test-Heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,22 @@ test_that("Heatmap run with bad gene name", {
#Spike in with bad gene name
cr.object$transcripts <- c("badgene", cr.object$transcripts)
missing.transcript.message <- paste0(
"There are 1 gene(s) absent from dataset: 'badgene'. Possible reasons are ",
"that gene is not official gene symbol or gene is not highly expressed and ",
"has been filtered."
"There are 1 gene(s) absent from dataset: 'badgene'.\n",
" Possible reasons are that gene is not official gene symbol or gene ",
"is not highly expressed and has been filtered."
)

expect_warning(
expect_message(
expect_no_warning(
logs <- capture.output(
do.call(heatmapSC, cr.object),
missing.transcript.message,
fixed = TRUE
),
missing.transcript.message,
fixed = TRUE
type = "message"
)
)
log.text <- paste(logs, collapse = "\n")
expect_true(grepl(missing.transcript.message, log.text, fixed = TRUE))
expect_lt(
grep("Transcripts found in", logs, fixed = TRUE)[[1]],
grep("There are 1 gene(s) absent from dataset", logs, fixed = TRUE)[[1]]
)
})

Expand All @@ -213,12 +216,18 @@ test_that("Heatmap reports missing proteins and retains available proteins", {
cr.object$proteins <- c("CD3", "not_a_protein")
cr.object$protein.annotations <- NULL

expect_warning(
expect_message(
expect_no_warning(
logs <- capture.output(
output <- do.call(heatmapSC, cr.object),
"Proteins not found in Protein assay: not_a_protein. They will be excluded."
),
type = "message"
)
)
missing.protein.message <-
"Proteins not found in Protein assay: not_a_protein. They will be excluded."
expect_true(any(grepl(missing.protein.message, logs, fixed = TRUE)))
expect_lt(
grep("Proteins found in", logs, fixed = TRUE)[[1]],
grep(missing.protein.message, logs, fixed = TRUE)[[1]]
)

expect_true("CD3_Prot" %in% output$data$gene)
Expand Down Expand Up @@ -264,20 +273,18 @@ test_that("Heatmap run with error for missing all genes", {
c("APOE", "ARG1", "CD38", "CD3D", "CD3E", "CD3G")
missing.transcript.message <- paste0(
"There are 6 gene(s) absent from dataset: 'APOE', 'ARG1', 'CD38', 'CD3D', ",
"'CD3E', 'CD3G'. Possible reasons are that gene is not official gene symbol ",
"or gene is not highly expressed and has been filtered."
"'CD3E', 'CD3G'.\n Possible reasons are that gene is not official ",
"gene symbol or gene is not highly expressed and has been filtered."
)
expect_warning(
expect_no_warning(
expect_message(
expect_error(
do.call(heatmapSC, cr.object),
"No requested transcripts or proteins were found in the selected assays."
),
missing.transcript.message,
fixed = TRUE
),
missing.transcript.message,
fixed = TRUE
)
)

})
Expand Down
Loading