Skip to content

Commit aca1246

Browse files
committed
Initial support for futures::plan and seurat steps
1 parent 58a882c commit aca1246

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

singlecell/api-src/org/labkey/api/singlecell/pipeline/AbstractSingleCellPipelineStep.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.apache.commons.lang3.StringUtils;
66
import org.apache.commons.lang3.math.NumberUtils;
77
import org.jetbrains.annotations.Nullable;
8+
import org.json.JSONObject;
89
import org.labkey.api.pipeline.PipelineJobException;
910
import org.labkey.api.reader.Readers;
1011
import org.labkey.api.sequenceanalysis.SequenceAnalysisService;
@@ -32,6 +33,8 @@
3233

3334
abstract public class AbstractSingleCellPipelineStep extends AbstractPipelineStep implements SingleCellStep
3435
{
36+
public static final String SEURAT_THREADS = "seuratMaxThreads";
37+
3538
public AbstractSingleCellPipelineStep(PipelineStepProvider provider, PipelineContext ctx)
3639
{
3740
super(provider, ctx);
@@ -250,12 +253,25 @@ protected void executeR(SequenceOutputHandler.JobContext ctx, File rmd, String o
250253
errorFile.delete();
251254
}
252255

253-
executeR(ctx, getDockerContainerName(), outputPrefix, lines);
256+
Integer seuratThreads = null;
257+
if (getProvider().getParameterByName(SEURAT_THREADS) != null)
258+
{
259+
seuratThreads = getProvider().getParameterByName(SEURAT_THREADS).extractValue(ctx.getJob(), getProvider(), getStepIdx(), Integer.class, null);
260+
}
261+
262+
executeR(ctx, getDockerContainerName(), outputPrefix, lines, seuratThreads);
254263

255264
handlePossibleFailure(ctx, outputPrefix);
256265
}
257266

258-
public static void executeR(SequenceOutputHandler.JobContext ctx, String dockerContainerName, String outputPrefix, List<String> lines) throws PipelineJobException
267+
protected static SeuratToolParameter getSeuratThreadsParam()
268+
{
269+
return SeuratToolParameter.create(SEURAT_THREADS, "Max Threads", "If provided, the docker session will set future::plan(strategy='multisession', workers=XXX), which is supported by certain Seurat functions.", "ldk-integerfield", new JSONObject(){{
270+
put("minValue", 0);
271+
}}, null);
272+
}
273+
274+
public static void executeR(SequenceOutputHandler.JobContext ctx, String dockerContainerName, String outputPrefix, List<String> lines, @Nullable Integer seuratThreads) throws PipelineJobException
259275
{
260276
File localRScript = new File(ctx.getOutputDir(), FileUtil.makeLegalName(outputPrefix + ".R").replaceAll(" ", "_"));
261277
try (PrintWriter writer = PrintWriters.getPrintWriter(localRScript))
@@ -285,6 +301,11 @@ public static void executeR(SequenceOutputHandler.JobContext ctx, String dockerC
285301
writer.println("\t-e SEQUENCEANALYSIS_MAX_THREADS=" + maxThreads + " \\");
286302
}
287303

304+
if (seuratThreads != null)
305+
{
306+
writer.println("\t-e SEURAT_MAX_THREADS=" + seuratThreads + " \\");
307+
}
308+
288309
Integer maxRam = SequencePipelineService.get().getMaxRam();
289310
if (maxRam != null)
290311
{

singlecell/src/org/labkey/singlecell/analysis/AbstractSingleCellHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ else if (step.createsSeuratObjects())
503503
File finalHtml = new File(ctx.getOutputDir(), "finalHtml.html");
504504
List<String> lines = new ArrayList<>();
505505
lines.add("rmarkdown::render(output_file = '" + finalHtml.getName() + "', input = '" + finalMarkdownFile.getName() + "', intermediates_dir = '/work')");
506-
AbstractSingleCellPipelineStep.executeR(ctx, AbstractCellMembraneStep.CONTAINER_NAME, "pandoc", lines);
506+
AbstractSingleCellPipelineStep.executeR(ctx, AbstractCellMembraneStep.CONTAINER_NAME, "pandoc", lines, null);
507507
_resumer.getFileManager().addIntermediateFile(finalMarkdownFile);
508508
_resumer.getFileManager().addIntermediateFiles(_resumer.getMarkdownsInOrder());
509509
_resumer.getFileManager().addIntermediateFiles(_resumer.getHtmlFilesInOrder());

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public Provider()
4444
}}, 0.001),
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);
47-
}}, 0.25)
47+
}}, 0.25),
48+
getSeuratThreadsParam()
4849
), Arrays.asList("/sequenceanalysis/field/TrimmingTextArea.js"), null);
4950
}
5051

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public Provider()
4848
}}, false),
4949
SeuratToolParameter.create("nVariableFeatures", "# Variable Features", "Controls the number of variable features that will be used. This only applies to the standard NormalizeData/ScaleData pipeline, not SCTransform", "ldk-integerfield", new JSONObject(){{
5050
put("minValue", 0);
51-
}}, null)
51+
}}, null),
52+
getSeuratThreadsParam()
5253
), Arrays.asList("/sequenceanalysis/field/TrimmingTextArea.js"), null);
5354
}
5455

0 commit comments

Comments
 (0)