Skip to content

Commit a5e2a4e

Browse files
committed
Add ability to create FeaturePlots in seurat pipeline
1 parent 3ebf066 commit a5e2a4e

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
for (datasetId in names(seuratObjects)) {
2+
seuratObj <- seuratObjects[[datasetId]]
3+
seuratObjects[[datasetId]] <- NULL
4+
5+
for (field in fieldNames) {
6+
if (ncol(Seurat::FetchData(seuratObj, vars = c('ident', field))) != 2) {
7+
next
8+
}
9+
10+
P1 <- Seurat::FeaturePlot(seuratObj, features = c(field), reduction = 'tsne')
11+
P2 <- Seurat::FeaturePlot(seuratObj, features = c(field), reduction = 'umap')
12+
13+
if ('wnn.umap' %in% names(seuratObj@reductions)) {
14+
P3 <- Seurat::FeaturePlot(seuratObj, features = c(field), reduction = 'wnn.umap')
15+
P1 <- P1 | P2 | P3
16+
} else {
17+
P1 <- P1 | P2
18+
}
19+
20+
P1 <- P1 + patchwork::plot_annotation(title = field) + patchwork::plot_layout(guides = "collect")
21+
}
22+
23+
# Cleanup
24+
rm(seuratObj)
25+
gc()
26+
}

singlecell/src/org/labkey/singlecell/SingleCellModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public static void registerPipelineSteps()
155155
SequencePipelineService.get().registerPipelineStep(new CiteSeqWnn.Provider());
156156
SequencePipelineService.get().registerPipelineStep(new AvgExpression.Provider());
157157
SequencePipelineService.get().registerPipelineStep(new DimPlots.Provider());
158+
SequencePipelineService.get().registerPipelineStep(new FeaturePlots.Provider());
158159
SequencePipelineService.get().registerPipelineStep(new CiteSeqDimReduxPca.Provider());
159160
SequencePipelineService.get().registerPipelineStep(new CiteSeqPlots.Provider());
160161
SequencePipelineService.get().registerPipelineStep(new PhenotypePlots.Provider());
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.labkey.singlecell.pipeline.singlecell;
2+
3+
import org.json.JSONObject;
4+
import org.labkey.api.sequenceanalysis.pipeline.AbstractPipelineStepProvider;
5+
import org.labkey.api.sequenceanalysis.pipeline.PipelineContext;
6+
import org.labkey.api.singlecell.pipeline.SeuratToolParameter;
7+
import org.labkey.api.singlecell.pipeline.SingleCellStep;
8+
import org.labkey.api.util.PageFlowUtil;
9+
10+
import java.util.Arrays;
11+
import java.util.Collection;
12+
13+
public class FeaturePlots extends AbstractCellMembraneStep
14+
{
15+
public FeaturePlots(PipelineContext ctx, FeaturePlots.Provider provider)
16+
{
17+
super(provider, ctx);
18+
}
19+
20+
public static class Provider extends AbstractPipelineStepProvider<SingleCellStep>
21+
{
22+
public Provider()
23+
{
24+
super("FeaturePlots", "Create FeaturePlots", "Seurat", "This will generate FeaturePlots for each of the features/variables below. Any variable not present is skipped.", Arrays.asList(
25+
SeuratToolParameter.create("fieldNames", "Fields To Plot", "Enter one field name per line", "sequenceanalysis-trimmingtextarea", new JSONObject(){{
26+
put("allowBlank", false);
27+
put("height", 150);
28+
put("delimiter", ",");
29+
}}, null)
30+
), Arrays.asList("/sequenceanalysis/field/TrimmingTextArea.js"), null);
31+
}
32+
33+
34+
@Override
35+
public FeaturePlots create(PipelineContext ctx)
36+
{
37+
return new FeaturePlots(ctx, this);
38+
}
39+
}
40+
41+
@Override
42+
public Collection<String> getRLibraries()
43+
{
44+
return PageFlowUtil.set("Seurat", "patchwork");
45+
}
46+
47+
@Override
48+
public boolean createsSeuratObjects()
49+
{
50+
return false;
51+
}
52+
53+
@Override
54+
public String getFileSuffix()
55+
{
56+
return "featureplot";
57+
}
58+
}

0 commit comments

Comments
 (0)