Skip to content

Commit e586692

Browse files
committed
Allow pipeline to preferentially use previously generated cellbender filtered matrix
1 parent 9cabc80 commit e586692

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

singlecell/resources/chunks/PrepareRawCounts.R

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@ for (datasetId in names(seuratObjects)) {
22
rawCountDir <- seuratObjects[[datasetId]]
33

44
datasetName <- datasetIdToName[[datasetId]]
5-
seuratObj <- CellMembrane::ReadAndFilter10xData(dataDir = rawCountDir, datasetId = datasetId, datasetName = datasetName, emptyDropsLower = emptyDropsLower, emptyDropsFdrThreshold = emptyDropsFdrThreshold, useEmptyDropsCellRanger = useEmptyDropsCellRanger, nExpectedCells = nExpectedCells, useCellBender = useCellBender, useSoupX = useSoupX)
5+
6+
previouslyFilteredMatrix <- NULL
7+
if (useCellBender) {
8+
# This is the 10x project:
9+
print('Will use cellbender-adjusted counts instead of raw counts:')
10+
previouslyFilteredMatrix <- paste0(rawCountDir, 'raw_feature_bc_matrix.cellbender_filtered.h5')
11+
if (!file.exists(previouslyFilteredMatrix)) {
12+
stop(paste0('Unable to find file: ', previouslyFilteredMatrix, '. You can re-run cellbender to fix this.'))
13+
}
14+
}
15+
16+
seuratObj <- CellMembrane::ReadAndFilter10xData(dataDir = rawCountDir, datasetId = datasetId, datasetName = datasetName, emptyDropsLower = emptyDropsLower, emptyDropsFdrThreshold = emptyDropsFdrThreshold, useEmptyDropsCellRanger = useEmptyDropsCellRanger, nExpectedCells = nExpectedCells, useSoupX = useSoupX, previouslyFilteredMatrix = previouslyFilteredMatrix)
617

718
if (!is.null(maxAllowableCells) && ncol(seuratObj) > maxAllowableCells) {
819
addErrorMessage(paste0('The seurat object has ', ncol(seuratObj), ' cells, which is more than the max allowable cells (', maxAllowableCells, '). Please review emptyDrops results as this probably means thresholds were suboptimal.'))

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.labkey.api.singlecell.CellHashingService;
3737
import org.labkey.api.singlecell.pipeline.AbstractSingleCellPipelineStep;
3838
import org.labkey.api.singlecell.pipeline.AbstractSingleCellStep;
39+
import org.labkey.api.singlecell.pipeline.SingleCellRawDataStep;
3940
import org.labkey.api.singlecell.pipeline.SingleCellStep;
4041
import org.labkey.api.util.FileUtil;
4142
import org.labkey.api.util.PageFlowUtil;
@@ -144,6 +145,16 @@ public Processor(boolean doProcessRawCounts)
144145
@Override
145146
public void init(JobContext ctx, List<SequenceOutputFile> inputFiles, List<RecordedAction> actions, List<SequenceOutputFile> outputsToCreate) throws UnsupportedOperationException, PipelineJobException
146147
{
148+
List<PipelineStepCtx<SingleCellRawDataStep>> rawCountSteps = SequencePipelineService.get().getSteps(ctx.getJob(), SingleCellRawDataStep.class);
149+
if (!rawCountSteps.isEmpty())
150+
{
151+
for (PipelineStepCtx<SingleCellRawDataStep> stepCtx : rawCountSteps)
152+
{
153+
SingleCellRawDataStep step = stepCtx.getProvider().create(ctx);
154+
step.init(ctx, inputFiles);
155+
}
156+
}
157+
147158
boolean requiresHashing = false;
148159
boolean requiresCite = false;
149160
boolean doH5Caching = false;

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package org.labkey.singlecell.pipeline.singlecell;
22

3-
import org.apache.logging.log4j.Logger;
43
import org.json.JSONObject;
54
import org.junit.Assert;
65
import org.junit.Test;
7-
import org.labkey.api.pipeline.PipelineJob;
8-
import org.labkey.api.pipeline.WorkDirectory;
6+
import org.labkey.api.pipeline.PipelineJobException;
7+
import org.labkey.api.sequenceanalysis.SequenceOutputFile;
98
import org.labkey.api.sequenceanalysis.pipeline.AbstractPipelineStepProvider;
109
import org.labkey.api.sequenceanalysis.pipeline.PipelineContext;
11-
import org.labkey.api.sequenceanalysis.pipeline.SequenceAnalysisJobSupport;
10+
import org.labkey.api.sequenceanalysis.pipeline.SequenceOutputHandler;
1211
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
1312
import org.labkey.api.singlecell.pipeline.SeuratToolParameter;
1413
import org.labkey.api.singlecell.pipeline.SingleCellRawDataStep;
1514

1615
import java.io.File;
1716
import java.util.Arrays;
17+
import java.util.List;
1818

1919
public class PrepareRawCounts extends AbstractCellMembraneStep
2020
{
@@ -60,6 +60,25 @@ public PrepareRawCounts create(PipelineContext ctx)
6060
}
6161
}
6262

63+
@Override
64+
public void init(SequenceOutputHandler.JobContext ctx, List<SequenceOutputFile> inputFiles) throws PipelineJobException
65+
{
66+
for (SequenceOutputFile so : inputFiles)
67+
{
68+
boolean useCellBender = getProvider().getParameterByName("useCellBender").extractValue(ctx.getJob(), getProvider(), getStepIdx(), Boolean.class, false);
69+
if (useCellBender)
70+
{
71+
// This is the outs dir:
72+
File source = so.getFile().getParentFile();
73+
File expected = new File(source, "raw_feature_bc_matrix.cellbender_filtered.h5");
74+
if (!expected.exists())
75+
{
76+
throw new IllegalArgumentException("Missing cellbender-corrected matrix. You can re-run cellbender on the loupe file to fix this: " + expected.getPath());
77+
}
78+
}
79+
}
80+
}
81+
6382
@Override
6483
public String getFileSuffix()
6584
{

0 commit comments

Comments
 (0)