Skip to content

Commit f151797

Browse files
committed
Add check for hashing and HTOsDroppedAboveMinRetained
1 parent 1a383ba commit f151797

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

singlecell/api-src/org/labkey/api/singlecell/CellHashingService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ static public void setInstance(CellHashingService instance)
6464

6565
abstract public void processMetrics(SequenceOutputFile so, PipelineJob job, boolean updateDescription) throws PipelineJobException;
6666

67+
abstract public File getMetricsFile(File callFile);
68+
6769
/**
6870
* Using the sample metadata, return whether cell hashing is used.
6971
* NOTE: if readset ID is null, this will be interpreted as whether any readset in the input data uses hashing
@@ -92,6 +94,7 @@ public static class CellHashingParameters
9294
public boolean createOutputFiles = true;
9395
public @Nullable String outputCategory;
9496
public boolean retainRawCountFile = false;
97+
public boolean failIfUnexpectedHtosFound = true;
9598

9699
public Readset htoReadset;
97100
public Readset parentReadset;
@@ -124,6 +127,7 @@ public static CellHashingService.CellHashingParameters createFromStep(SequenceOu
124127
ret.callerDisagreementThreshold = step.getProvider().getParameterByName("callerDisagreementThreshold").extractValue(ctx.getJob(), step.getProvider(), step.getStepIdx(), Double.class, null);
125128
ret.doTSNE = step.getProvider().getParameterByName("doTSNE").extractValue(ctx.getJob(), step.getProvider(), step.getStepIdx(), Boolean.class, null);
126129
ret.retainRawCountFile = step.getProvider().getParameterByName("retainRawCountFile").extractValue(ctx.getJob(), step.getProvider(), step.getStepIdx(), Boolean.class, true);
130+
ret.failIfUnexpectedHtosFound = step.getProvider().getParameterByName("failIfUnexpectedHtosFound").extractValue(ctx.getJob(), step.getProvider(), step.getStepIdx(), Boolean.class, true);
127131
ret.htoReadset = htoReadset;
128132
ret.parentReadset = parentReadset;
129133
ret.htoBarcodesFile = new File(ctx.getSourceDirectory(), type.getAllBarcodeFileName());
@@ -165,6 +169,7 @@ public static CellHashingParameters createFromJson(BARCODE_TYPE type, File webse
165169
ret.callerDisagreementThreshold = params.get("callerDisagreementThreshold") == null ? null : params.getDouble("callerDisagreementThreshold");
166170
ret.doTSNE = params.get("doTSNE") == null || params.getBoolean("doTSNE");
167171
ret.retainRawCountFile = params.optBoolean("retainRawCountFile", true);
172+
ret.failIfUnexpectedHtosFound = params.optBoolean("failIfUnexpectedHtosFound", true);
168173
ret.htoReadset = htoReadset;
169174
ret.parentReadset = parentReadset;
170175
ret.htoBarcodesFile = new File(webserverDir, type.getAllBarcodeFileName());
@@ -280,6 +285,7 @@ public Set<String> getAllowableBarcodeNames() throws PipelineJobException
280285
{
281286
return Collections.unmodifiableSet(allowableHtoBarcodes);
282287
}
288+
283289
if (htoBarcodesFile == null)
284290
{
285291
throw new IllegalArgumentException("Barcode file was null");

singlecell/src/org/labkey/singlecell/CellHashingServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ public Sort getSortById(int rowId)
804804
return new TableSelector(SingleCellSchema.getInstance().getSchema().getTable(SingleCellSchema.TABLE_SORTS)).getObject(rowId, Sort.class);
805805
}
806806

807+
@Override
807808
public File getMetricsFile(File callFile)
808809
{
809810
return new File(callFile.getPath().replaceAll(CALL_EXTENSION, ".metrics.txt"));
@@ -951,7 +952,8 @@ public List<ToolParameterDescriptor> getHashingCallingParams(boolean allowMethod
951952
}}, 0.2),
952953
ToolParameterDescriptor.create("skipNormalizationQc", "Skip Normalization QC", null, "checkbox", null, true),
953954
ToolParameterDescriptor.create("doTSNE", "Do tSNE", "If true, tSNE will be performed as part of QC", "checkbox", null, true),
954-
ToolParameterDescriptor.create("retainRawCountFile", "Retain Raw Counts File", null, "checkbox", null, false)
955+
ToolParameterDescriptor.create("retainRawCountFile", "Retain Raw Counts File", null, "checkbox", null, false),
956+
ToolParameterDescriptor.create("failIfUnexpectedHtosFound", "Fail If Unexpected HTOs Found", "If checked and if there are any HTOs (testing all known HTOs) with counts above the HTOs expected in this experiment, then an error will be thrown", "checkbox", null, false)
955957
));
956958

957959
final List<String> allMethods = Arrays.stream(CALLING_METHOD.values()).filter(x -> allowMethodsNeedingGex || !x.isRequiresH5()).map(Enum::name).toList();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
abstract public class AbstractCellHashingCiteseqStep extends AbstractSingleCellPipelineStep
2121
{
22-
public AbstractCellHashingCiteseqStep(PipelineStepProvider provider, PipelineContext ctx)
22+
public AbstractCellHashingCiteseqStep(PipelineStepProvider<?> provider, PipelineContext ctx)
2323
{
2424
super(provider, ctx);
2525
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.labkey.singlecell.pipeline.singlecell;
22

3+
import au.com.bytecode.opencsv.CSVReader;
34
import org.apache.commons.io.FileUtils;
45
import org.labkey.api.pipeline.PipelineJobException;
56
import org.labkey.api.reader.Readers;
@@ -134,6 +135,36 @@ else if (!params.h5File.exists())
134135
}
135136

136137
hashingCalls = CellHashingService.get().generateHashingCallsForRawMatrix(parentReadset, output, ctx, params, existingCountMatrixUmiDir);
138+
139+
File metricFile = CellHashingService.get().getMetricsFile(hashingCalls);
140+
if (!metricFile.exists())
141+
{
142+
throw new PipelineJobException("Unable to find metrics file: " + metricFile.getPath());
143+
}
144+
145+
try (CSVReader reader = new CSVReader(Readers.getReader(metricFile), '\t'))
146+
{
147+
String[] line;
148+
while ((line = reader.readNext()) != null)
149+
{
150+
if ("HTOsDroppedAboveMinRetained".equals(line[1]))
151+
{
152+
String msg = "Hashing data contained HTOs with counts higher than those in the whitelist, this could indicate an error in the expected barcodes: " + line[2];
153+
if (params.failIfUnexpectedHtosFound)
154+
{
155+
throw new PipelineJobException(msg);
156+
}
157+
else
158+
{
159+
ctx.getLogger().warn(msg);
160+
}
161+
}
162+
}
163+
}
164+
catch (IOException e)
165+
{
166+
throw new PipelineJobException(e);
167+
}
137168
}
138169
else if (htosPerReadset.size() == 1)
139170
{

0 commit comments

Comments
 (0)