Skip to content

Commit f224fb5

Browse files
committed
Add support for running VISION
1 parent 04882ed commit f224fb5

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
visionFiles <- data.frame(DatasetId = character(), FileName = character())
2+
3+
for (datasetId in names(seuratObjects)) {
4+
printName(datasetId)
5+
seuratObj <- readRDS(seuratObjects[[datasetId]])
6+
7+
visionObj <- CellMembrane::RunVisionForMSigDB(seuratObj, metadataCols = metadataCols)
8+
fileName <- paste0('vision.', datasetId, '.rds')
9+
saveRDS(visionObj, file = fileName)
10+
11+
visionFiles <- rbind(visionFiles, data.frame(DatasetId = datasetId, FileName = fileName))
12+
}
13+
14+
write.table(visionFiles, file = 'visionFiles.txt', row.names = FALSE, col.names = FALSE, quote = FALSE, sep = '\t')

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public static void registerPipelineSteps()
184184
SequencePipelineService.get().registerPipelineStep(new TrainCelltypist.Provider());
185185
SequencePipelineService.get().registerPipelineStep(new CheckExpectations.Provider());
186186
SequencePipelineService.get().registerPipelineStep(new CommonFilters.Provider());
187+
SequencePipelineService.get().registerPipelineStep(new RunVision.Provider());
187188

188189
SequenceAnalysisService.get().registerFileHandler(new NimbleAlignmentStep());
189190
}

singlecell/src/org/labkey/singlecell/pipeline/singlecell/FindMarkers.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public Provider()
4545
SeuratToolParameter.create("foldChangeThreshold", "Log2 Fold-Change Threshold", "Only genes with log2-foldchange above this will be reported", "ldk-numberfield", new JSONObject(){{
4646
put("minValue", 0);
4747
}}, 0.25),
48+
SeuratToolParameter.create("minPct", "Min Pct", "Only test genes that are detected in a minimum fraction of min.pct cells in either of the two populations", "ldk-numberfield", new JSONObject(){{
49+
put("minValue", 0);
50+
}}, 0.1),
51+
SeuratToolParameter.create("minDiffPct", "Min Diff Pct", "Only test genes that show a minimum difference in the fraction of detection between the two groups", "ldk-numberfield", new JSONObject(){{
52+
put("minValue", 0);
53+
}}, null, "minDiffPct", false),
4854
getSeuratThreadsParam()
4955
), Arrays.asList("/sequenceanalysis/field/TrimmingTextArea.js"), null);
5056
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package org.labkey.singlecell.pipeline.singlecell;
2+
3+
import au.com.bytecode.opencsv.CSVReader;
4+
import org.json.JSONObject;
5+
import org.labkey.api.pipeline.PipelineJobException;
6+
import org.labkey.api.reader.Readers;
7+
import org.labkey.api.sequenceanalysis.SequenceOutputFile;
8+
import org.labkey.api.sequenceanalysis.pipeline.AbstractPipelineStepProvider;
9+
import org.labkey.api.sequenceanalysis.pipeline.PipelineContext;
10+
import org.labkey.api.sequenceanalysis.pipeline.SequenceOutputHandler;
11+
import org.labkey.api.singlecell.pipeline.SeuratToolParameter;
12+
import org.labkey.api.singlecell.pipeline.SingleCellStep;
13+
14+
import java.io.File;
15+
import java.io.IOException;
16+
import java.util.Arrays;
17+
import java.util.List;
18+
import java.util.Set;
19+
import java.util.stream.Collectors;
20+
21+
public class RunVision extends AbstractCellMembraneStep
22+
{
23+
public RunVision(PipelineContext ctx, RunVision.Provider provider)
24+
{
25+
super(provider, ctx);
26+
}
27+
28+
public static class Provider extends AbstractPipelineStepProvider<SingleCellStep>
29+
{
30+
public Provider()
31+
{
32+
super("RunVision", "Run VISION", "VISION", "This will run VISION, a tool for functional interpretation of scRNA-seq data, saving the result to an RDS file.", Arrays.asList(
33+
SeuratToolParameter.create("metadataCols", "Field(s)", "This will subset the seuratObj to just these columns prior to running VISION.", "sequenceanalysis-trimmingtextarea", new JSONObject(){{
34+
put("allowBlank", false);
35+
put("height", 200);
36+
put("delimiter", ",");
37+
}}, "nCount_RNA,ClusterNames_0.2,ClusterNames_0.4,ClusterNames_0.6,ClusterNames_0.8", "metadataCols", true, true).delimiter(",")
38+
), Arrays.asList("/sequenceanalysis/field/TrimmingTextArea.js"), null);
39+
}
40+
41+
@Override
42+
public RunVision create(PipelineContext ctx)
43+
{
44+
return new RunVision(ctx, this);
45+
}
46+
}
47+
48+
@Override
49+
public boolean createsSeuratObjects()
50+
{
51+
return false;
52+
}
53+
54+
@Override
55+
public String getFileSuffix()
56+
{
57+
return "vision";
58+
}
59+
60+
@Override
61+
public Output execute(SequenceOutputHandler.JobContext ctx, List<SeuratObjectWrapper> inputObjects, String outputPrefix) throws PipelineJobException
62+
{
63+
Output output = super.execute(ctx, inputObjects, outputPrefix);
64+
65+
File saved = new File(ctx.getOutputDir(), "visionFiles.txt");
66+
if (!saved.exists())
67+
{
68+
throw new PipelineJobException("Unable to find file: " + saved.getPath());
69+
}
70+
71+
try (CSVReader reader = new CSVReader(Readers.getReader(saved), '\t'))
72+
{
73+
String[] line;
74+
while ((line = reader.readNext()) != null)
75+
{
76+
File rds = new File(ctx.getOutputDir(), line[1]);
77+
if (!rds.exists())
78+
{
79+
throw new PipelineJobException("Unable to find file: " + rds.getPath());
80+
}
81+
82+
final String datasetId = line[0];
83+
Set<SeuratObjectWrapper> wrappers = inputObjects.stream().filter(x -> datasetId.equals(x.getDatasetId())).collect(Collectors.toSet());
84+
if (wrappers.size() == 0)
85+
{
86+
throw new PipelineJobException("Unable to find seurat object wrapper for: " + datasetId);
87+
}
88+
else if (wrappers.size() > 1)
89+
{
90+
throw new PipelineJobException("More than one seurat object wrapper matched: " + datasetId + ", found: " + wrappers.stream().map(SeuratObjectWrapper::getDatasetId).collect(Collectors.joining(", ")));
91+
}
92+
93+
SeuratObjectWrapper wrapper = wrappers.iterator().next();
94+
95+
SequenceOutputFile so = new SequenceOutputFile();
96+
so.setFile(rds);
97+
so.setCategory("VISION Analysis");
98+
so.setLibrary_id(ctx.getSequenceSupport().getCachedGenomes().iterator().next().getGenomeId());
99+
so.setReadset(wrapper.getReadsetId());
100+
so.setName(wrapper.getDatasetName() == null ? wrapper.getDatasetId() : wrapper.getDatasetName() + ": VISION Analysis");
101+
102+
ctx.getFileManager().addSequenceOutput(so);
103+
}
104+
}
105+
catch (IOException e)
106+
{
107+
throw new PipelineJobException(e);
108+
}
109+
110+
ctx.getFileManager().addIntermediateFile(saved);
111+
112+
return output;
113+
}
114+
}

0 commit comments

Comments
 (0)