Skip to content

Commit cb345c1

Browse files
committed
Bugfix to FeaturePlots.R when tsne not present
1 parent d11cec0 commit cb345c1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

singlecell/resources/chunks/FeaturePlots.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ for (datasetId in names(seuratObjects)) {
88
}
99

1010
tryCatch({
11-
P1 <- Seurat::FeaturePlot(seuratObj, features = c(field), reduction = 'tsne', min.cutoff = 'q05', max.cutoff = 'q95')
12-
P2 <- Seurat::FeaturePlot(seuratObj, features = c(field), reduction = 'umap', min.cutoff = 'q05', max.cutoff = 'q95')
13-
14-
if ('wnn.umap' %in% names(seuratObj@reductions)) {
15-
P3 <- Seurat::FeaturePlot(seuratObj, features = c(field), reduction = 'wnn.umap', min.cutoff = 'q05', max.cutoff = 'q95')
16-
P1 <- P1 | P2 | P3
17-
} else {
18-
P1 <- P1 | P2
11+
reductions <- intersect(c('tsne', 'umap', 'wnn.umap'), names(seuratObj@reductions))
12+
if (length(reductions) == 0) {
13+
stop('No reductions found to plot')
1914
}
2015

21-
P1 <- P1 + patchwork::plot_annotation(title = field) + patchwork::plot_layout(guides = "collect")
16+
plotList <- list()
17+
i <- 0
18+
for (reduction in reductions) {
19+
i <- i + 1
20+
plotList[[i]] <- Seurat::FeaturePlot(seuratObj, features = c(field), reduction = reduction, min.cutoff = 'q05', max.cutoff = 'q95')
21+
}
2222

23-
print(P1)
23+
print(patchwork::wrap_plots(plotList, ncol = length(reductions)) + patchwork::plot_annotation(title = field) + patchwork::plot_layout(guides = "collect"))
2424
}, error = function(e){
2525
print(paste0('Error running FeaturePlots for: ', datasetId))
2626
print(conditionMessage(e))

0 commit comments

Comments
 (0)