Skip to content

Commit 9e9b965

Browse files
committed
fix(MarkersPlot): exclude groups that failed DE analysis from plotting
1 parent 4bd18a3 commit 9e9b965

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

R/markersplot.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,18 @@ MarkersPlot <- function(
314314
sig_mat <- as.data.frame(sig_mat)
315315
rownames(sig_mat) <- sig_mat$gene
316316
sig_mat$gene <- NULL
317+
# There might be some groups failed to run DE analysis
318+
# So we just exclude them
319+
failed_groups <- setdiff(groups, colnames(sig_mat))
320+
if (length(failed_groups) > 1) {
321+
warning(
322+
"[MarkersPlot] The following groups in `subset_by` '", subset_by_1,
323+
"' are not found in the markers data frame and will be ignored: ",
324+
paste(failed_groups, collapse = ", "),
325+
immediate. = TRUE
326+
)
327+
}
328+
groups <- intersect(groups, colnames(sig_mat))
317329
sig_mat <- sig_mat[genes, groups, drop = FALSE]
318330
sig_mat <- as.matrix(sig_mat)
319331

@@ -335,6 +347,18 @@ MarkersPlot <- function(
335347
ds_mat <- as.data.frame(ds_mat)
336348
rownames(ds_mat) <- ds_mat$gene
337349
ds_mat$gene <- NULL
350+
# There might be some groups failed to run DE analysis
351+
# So we just exclude them
352+
failed_groups <- setdiff(groups, colnames(ds_mat))
353+
if (length(failed_groups) > 1) {
354+
warning(
355+
"[MarkersPlot] The following groups in `subset_by` '", subset_by_1,
356+
"' are not found in the markers data frame and will be ignored: ",
357+
paste(failed_groups, collapse = ", "),
358+
immediate. = TRUE
359+
)
360+
}
361+
groups <- intersect(groups, colnames(ds_mat))
338362
ds_mat <- ds_mat[genes, groups, drop = FALSE]
339363
ds_mat <- as.matrix(ds_mat)
340364

0 commit comments

Comments
 (0)