Skip to content

Commit b32d6ea

Browse files
committed
Update DimplotLogic to allow missing reductions
1 parent cc6b74b commit b32d6ea

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

singlecell/resources/chunks/DimPlots.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ for (datasetId in names(seuratObjects)) {
1313
next
1414
}
1515

16-
P1 <- Seurat::DimPlot(seuratObj, group.by = field, reduction = 'tsne')
17-
P2 <- Seurat::DimPlot(seuratObj, group.by = field, reduction = 'umap')
16+
plotList <- list()
17+
if ('tsne' %in% names(seuratObj@reductions)) {
18+
plotList[['tsne']] <- Seurat::DimPlot(seuratObj, group.by = field, reduction = 'tsne')
19+
}
20+
21+
if ('umap' %in% names(seuratObj@reductions)) {
22+
plotList[['umap']] <- Seurat::DimPlot(seuratObj, group.by = field, reduction = 'umap')
23+
}
1824

1925
if ('wnn.umap' %in% names(seuratObj@reductions)) {
20-
P3 <- Seurat::DimPlot(seuratObj, group.by = field, reduction = 'wnn.umap')
21-
P1 <- P1 | P2 | P3
22-
} else {
23-
P1 <- P1 | P2
26+
plotList[['wnn.umap']] <- Seurat::DimPlot(seuratObj, group.by = field, reduction = 'wnn.umap')
2427
}
2528

26-
P1 <- P1 + patchwork::plot_annotation(title = field) + patchwork::plot_layout(guides = "collect")
29+
P1 <- patchwork::wrap_plots(plotList) + patchwork::plot_layout(ncol = length(plotList)) + patchwork::plot_annotation(title = field) + patchwork::plot_layout(guides = "collect")
2730

2831
print(P1)
2932
}

0 commit comments

Comments
 (0)