Skip to content

Commit 01c6f24

Browse files
committed
Bugfixed to hashing/VDJ calls
1 parent a635b07 commit 01c6f24

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static public void setInstance(CellHashingService instance)
4545
_instance = instance;
4646
}
4747

48+
abstract public void prepareHashingIfNeeded(File sourceDir, PipelineJob job, SequenceAnalysisJobSupport support, String filterField, final boolean failIfNoHashing) throws PipelineJobException;
49+
4850
abstract public void prepareHashingAndCiteSeqFilesIfNeeded(File sourceDir, PipelineJob job, SequenceAnalysisJobSupport support, String filterField, boolean failIfNoHashing, boolean failIfNoCiteSeq) throws PipelineJobException;
4951

5052
abstract public File generateHashingCallsForRawMatrix(Readset parentReadset, PipelineOutputTracker output, SequenceOutputHandler.JobContext ctx, CellHashingParameters parameters, File rawCountMatrixDir) throws PipelineJobException;

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

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.labkey.api.writer.PrintWriters;
4444
import org.labkey.singlecell.run.CellRangerFeatureBarcodeHandler;
4545

46+
import java.io.BufferedReader;
4647
import java.io.File;
4748
import java.io.IOException;
4849
import java.io.PrintWriter;
@@ -81,13 +82,19 @@ public static CellHashingServiceImpl get()
8182
return _instance;
8283
}
8384

85+
@Override
86+
public void prepareHashingIfNeeded(File sourceDir, PipelineJob job, SequenceAnalysisJobSupport support, String filterField, final boolean failIfNoHashing) throws PipelineJobException
87+
{
88+
prepareHashingAndCiteSeqFilesIfNeeded(sourceDir, job, support, filterField, failIfNoHashing, false, true, true, false);
89+
}
90+
8491
@Override
8592
public void prepareHashingAndCiteSeqFilesIfNeeded(File sourceDir, PipelineJob job, SequenceAnalysisJobSupport support, String filterField, final boolean failIfNoHashing, final boolean failIfNoCiteSeq) throws PipelineJobException
8693
{
87-
prepareHashingAndCiteSeqFilesIfNeeded(sourceDir, job, support, filterField, failIfNoHashing, failIfNoCiteSeq, true);
94+
prepareHashingAndCiteSeqFilesIfNeeded(sourceDir, job, support, filterField, failIfNoHashing, failIfNoCiteSeq, true, true, true);
8895
}
8996

90-
public void prepareHashingAndCiteSeqFilesIfNeeded(File sourceDir, PipelineJob job, SequenceAnalysisJobSupport support, String filterField, final boolean failIfNoHashing, final boolean failIfNoCiteSeq, final boolean cacheCountMatrixFiles) throws PipelineJobException
97+
public void prepareHashingAndCiteSeqFilesIfNeeded(File sourceDir, PipelineJob job, SequenceAnalysisJobSupport support, String filterField, final boolean failIfNoHashing, final boolean failIfNoCiteSeq, final boolean cacheCountMatrixFiles, boolean requireValidHashingIfPresent, boolean requireValidCiteSeqIfPresent) throws PipelineJobException
9198
{
9299
Container target = job.getContainer().isWorkbook() ? job.getContainer().getParent() : job.getContainer();
93100
UserSchema sequenceAnalysis = QueryService.get().getUserSchema(job.getUser(), target, SingleCellSchema.SEQUENCE_SCHEMA_NAME);
@@ -217,6 +224,7 @@ public void prepareHashingAndCiteSeqFilesIfNeeded(File sourceDir, PipelineJob jo
217224
HashMap<Integer, File> readsetToCountMap = new HashMap<>();
218225
if (distinctHTOs.size() > 1)
219226
{
227+
Set<Integer> hashingToRemove = new HashSet<>();
220228
readsetToHashingMap.forEach((readsetId, hashingReadsetId) -> {
221229
if (cacheCountMatrixFiles)
222230
{
@@ -226,7 +234,15 @@ public void prepareHashingAndCiteSeqFilesIfNeeded(File sourceDir, PipelineJob jo
226234
TableSelector ts = new TableSelector(sequenceOutputs, filter, new org.labkey.api.data.Sort("-rowid"));
227235
if (!ts.exists())
228236
{
229-
throw new IllegalArgumentException("Unable to find existing count matrix for hashing readset: " + hashingReadsetId);
237+
if (requireValidHashingIfPresent)
238+
{
239+
throw new IllegalArgumentException("Unable to find existing count matrix for hashing readset: " + hashingReadsetId);
240+
}
241+
else
242+
{
243+
job.getLogger().warn("Unable to find existing count matrix for hashing readset: " + hashingReadsetId + ", skipping");
244+
hashingToRemove.add(readsetId);
245+
}
230246
}
231247
else
232248
{
@@ -238,6 +254,8 @@ public void prepareHashingAndCiteSeqFilesIfNeeded(File sourceDir, PipelineJob jo
238254
support.cacheReadset(hashingReadsetId, job.getUser());
239255

240256
});
257+
258+
hashingToRemove.forEach(readsetToHashingMap::remove);
241259
}
242260
else if (distinctHTOs.size() == 1)
243261
{
@@ -259,6 +277,7 @@ else if (distinctHTOs.size() == 1)
259277
job.getLogger().info("distinct HTOs: " + distinctHTOs.size());
260278
}
261279

280+
Set<Integer> citeToRemove = new HashSet<>();
262281
readsetToCiteSeqMap.forEach((readsetId, citeseqReadsetId) -> {
263282
if (cacheCountMatrixFiles)
264283
{
@@ -268,7 +287,15 @@ else if (distinctHTOs.size() == 1)
268287
TableSelector ts = new TableSelector(sequenceOutputs, filter, new org.labkey.api.data.Sort("-rowid"));
269288
if (!ts.exists())
270289
{
271-
throw new IllegalArgumentException("Unable to find existing count matrix for CITE-seq readset: " + citeseqReadsetId);
290+
if (requireValidCiteSeqIfPresent)
291+
{
292+
throw new IllegalArgumentException("Unable to find existing count matrix for CITE-seq readset: " + citeseqReadsetId);
293+
}
294+
else
295+
{
296+
job.getLogger().warn("Unable to find existing count matrix for CITE-seq readset: " + citeseqReadsetId + ", skipping");
297+
citeToRemove.add(readsetId);
298+
}
272299
}
273300
else
274301
{
@@ -280,6 +307,8 @@ else if (distinctHTOs.size() == 1)
280307
support.cacheReadset(citeseqReadsetId, job.getUser());
281308
});
282309

310+
citeToRemove.forEach(readsetToCiteSeqMap::remove);
311+
283312
support.cacheObject(READSET_TO_HASHING_MAP, readsetToHashingMap);
284313
support.cacheObject(READSET_TO_CITESEQ_MAP, readsetToCiteSeqMap);
285314
support.cacheObject(READSET_TO_COUNTS_MAP, readsetToCountMap);
@@ -940,7 +969,20 @@ public File generateCellHashingCalls(File citeSeqCountOutDir, File outputDir, St
940969
throw new PipelineJobException("Unable to find HTML file: " + htmlFile.getPath());
941970
}
942971

943-
if (!callsFile.exists())
972+
boolean callFileValid = callsFile.exists();
973+
if (callFileValid)
974+
{
975+
try (BufferedReader reader = Readers.getReader(callsFile))
976+
{
977+
callFileValid = reader.readLine() != null;
978+
}
979+
catch (IOException e)
980+
{
981+
throw new PipelineJobException(e);
982+
}
983+
}
984+
985+
if (!callFileValid)
944986
{
945987
//copy HTML locally to make debugging easier:
946988
if (localPipelineDir != null)

singlecell/src/org/labkey/singlecell/run/CellRangerFeatureBarcodeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ else if (rs.getApplication().equals("CITE-Seq"))
126126
throw new PipelineJobException("Unexpected application: " + rs.getApplication());
127127
}
128128

129-
CellHashingServiceImpl.get().prepareHashingAndCiteSeqFilesIfNeeded(outputDir, job, support, field, failIfNoHashing, failIfNoCiteseq, false);
129+
CellHashingServiceImpl.get().prepareHashingAndCiteSeqFilesIfNeeded(outputDir, job, support, field, failIfNoHashing, failIfNoCiteseq, false, failIfNoHashing, failIfNoCiteseq);
130130
}
131131

132132
@Override

0 commit comments

Comments
 (0)