Skip to content

Commit 47de093

Browse files
committed
Add support for demuxmix in cell hashing
1 parent 6987904 commit 47de093

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.IOException;
2525
import java.util.ArrayList;
2626
import java.util.Arrays;
27+
import java.util.Collection;
2728
import java.util.Collections;
2829
import java.util.HashSet;
2930
import java.util.List;
@@ -71,7 +72,7 @@ static public void setInstance(CellHashingService instance)
7172

7273
abstract public boolean usesCiteSeq(SequenceAnalysisJobSupport support, List<SequenceOutputFile> inputFiles) throws PipelineJobException;
7374

74-
abstract public List<ToolParameterDescriptor> getHashingCallingParams(boolean allowDemuxEm);
75+
abstract public List<ToolParameterDescriptor> getHashingCallingParams(boolean allowMethodsNeedingGex);
7576

7677
abstract public Set<String> getHtosForParentReadset(Integer parentReadsetId, File webserverJobDir, SequenceAnalysisJobSupport support, boolean throwIfNotFound) throws PipelineJobException;
7778

@@ -316,17 +317,25 @@ public enum CALLING_METHOD
316317
htodemux(false, false),
317318
dropletutils(true, true),
318319
gmm_demux(true, true),
319-
demuxem(true, true),
320+
demuxem(true, true, true),
321+
demuxmix(true, true, true),
320322
bff_cluster(true, true),
321323
bff_raw(true, false);
322324

323325
boolean isDefaultRun;
324326
boolean isDefaultConsensus;
327+
boolean requiresH5;
325328

326329
CALLING_METHOD(boolean isDefaultRun, boolean isDefaultConsensus)
330+
{
331+
this(isDefaultRun, isDefaultConsensus, false);
332+
}
333+
334+
CALLING_METHOD(boolean isDefaultRun, boolean isDefaultConsensus, boolean requiresH5)
327335
{
328336
this.isDefaultRun = isDefaultRun;
329337
this.isDefaultConsensus = isDefaultConsensus;
338+
this.requiresH5 = requiresH5;
330339
}
331340

332341
public boolean isDefaultRun()
@@ -339,6 +348,11 @@ public boolean isDefaultConsensus()
339348
return isDefaultConsensus;
340349
}
341350

351+
public boolean isRequiresH5()
352+
{
353+
return requiresH5;
354+
}
355+
342356
private static List<CALLING_METHOD> getDefaultRunMethods()
343357
{
344358
return Arrays.stream(values()).filter(CALLING_METHOD::isDefaultRun).collect(Collectors.toList());
@@ -358,6 +372,22 @@ public static List<String> getDefaultConsensusMethodNames()
358372
{
359373
return getDefaultConsensusMethods().stream().map(Enum::name).collect(Collectors.toList());
360374
}
375+
376+
public static boolean requiresH5(String methodNames)
377+
{
378+
methodNames = StringUtils.trimToNull(methodNames);
379+
if (methodNames == null)
380+
{
381+
return false;
382+
}
383+
384+
return requiresH5(Arrays.stream(methodNames.split(";")).map(CALLING_METHOD::valueOf).collect(Collectors.toList()));
385+
}
386+
387+
public static boolean requiresH5(Collection<CALLING_METHOD> methods)
388+
{
389+
return methods.stream().anyMatch(CALLING_METHOD::isRequiresH5);
390+
}
361391
}
362392

363393
public enum BARCODE_TYPE

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public static CellHashingServiceImpl get()
9595
@Override
9696
public void prepareHashingForVdjIfNeeded(SequenceOutputHandler.JobContext ctx, final boolean failIfNoHashingReadset) throws PipelineJobException
9797
{
98-
boolean useDemEM = ctx.getParams().optString("methods", "").contains(CellHashingService.CALLING_METHOD.demuxem.name());
99-
prepareHashingAndCiteSeqFilesIfNeeded(ctx.getOutputDir(), ctx.getJob(), ctx.getSequenceSupport(), TCR_FIELD, failIfNoHashingReadset, false, true, true, false, useDemEM);
98+
boolean needsH5 = CALLING_METHOD.requiresH5(ctx.getParams().optString("methods", ""));
99+
prepareHashingAndCiteSeqFilesIfNeeded(ctx.getOutputDir(), ctx.getJob(), ctx.getSequenceSupport(), TCR_FIELD, failIfNoHashingReadset, false, true, true, false, needsH5);
100100
}
101101

102102
public void prepareHashingAndCiteSeqFilesForFeatureCountsIfNeeded(File sourceDir, PipelineJob job, SequenceAnalysisJobSupport support, String filterField, final boolean failIfNoHashingReadset, final boolean failIfNoCiteSeqReadset) throws PipelineJobException
@@ -436,7 +436,7 @@ private Map<String, Integer> cacheH5Files(PipelineJob job, SequenceAnalysisJobSu
436436
{
437437
if (cachedGenomes.size() > 1)
438438
{
439-
throw new PipelineJobException("demuxEM was selected, but more than one cached genome found, cannot infer correct genome. Found: " + StringUtils.join(cachedGenomes, ", "));
439+
throw new PipelineJobException("demuxEM/demuxmix was selected, but more than one cached genome found, cannot infer correct genome. Found: " + StringUtils.join(cachedGenomes, ", "));
440440
}
441441

442442
gexGenomeId = cachedGenomes.iterator().next();
@@ -448,11 +448,11 @@ private Map<String, Integer> cacheH5Files(PipelineJob job, SequenceAnalysisJobSu
448448
HashSet<Integer> genomeIds = new HashSet<>(new TableSelector(ti, PageFlowUtil.set("library_id"), filter, new org.labkey.api.data.Sort("-rowid")).getArrayList(Integer.class));
449449
if (genomeIds.isEmpty())
450450
{
451-
throw new PipelineJobException("demuxEM was selected, but no suitable loupe files were found for GEX readset: " + gexReadset);
451+
throw new PipelineJobException("demuxEM/demuxmix was selected, but no suitable loupe files were found for GEX readset: " + gexReadset);
452452
}
453453
else if (genomeIds.size() > 1)
454454
{
455-
throw new PipelineJobException("demuxEM was selected. Attempting to identify loupe files using GEX readset: " + gexReadset + ", but more than one genome found. Found: " + StringUtils.join(cachedGenomes, ", "));
455+
throw new PipelineJobException("demuxEM/demuxmix was selected. Attempting to identify loupe files using GEX readset: " + gexReadset + ", but more than one genome found. Found: " + StringUtils.join(cachedGenomes, ", "));
456456
}
457457

458458
gexGenomeId = genomeIds.iterator().next();
@@ -479,7 +479,7 @@ else if (genomeIds.size() > 1)
479479

480480
if (cachedGenomes.size() > 1)
481481
{
482-
throw new PipelineJobException("demuxEM was selected, but more than one cached genome found, cannot infer correct genome. Found: " + StringUtils.join(cachedGenomes, ", "));
482+
throw new PipelineJobException("demuxEM/demuxmix was selected, but more than one cached genome found, cannot infer correct genome. Found: " + StringUtils.join(cachedGenomes, ", "));
483483
}
484484

485485
// NOTE: cache this using the source file's genome ID (which might be the TCR library), rather than the GEX genome
@@ -935,7 +935,7 @@ public void processMetrics(SequenceOutputFile so, PipelineJob job, boolean updat
935935
}
936936

937937
@Override
938-
public List<ToolParameterDescriptor> getHashingCallingParams(boolean allowDemuxEm)
938+
public List<ToolParameterDescriptor> getHashingCallingParams(boolean allowMethodsNeedingGex)
939939
{
940940
List<ToolParameterDescriptor> ret = new ArrayList<>(Arrays.asList(
941941
ToolParameterDescriptor.create("minCountPerCell", "Min Reads/Cell", null, "ldk-integerfield", null, 5),
@@ -954,7 +954,7 @@ public List<ToolParameterDescriptor> getHashingCallingParams(boolean allowDemuxE
954954
ToolParameterDescriptor.create("retainRawCountFile", "Retain Raw Counts File", null, "checkbox", null, false)
955955
));
956956

957-
final List<String> allMethods = Arrays.stream(CALLING_METHOD.values()).filter(x -> allowDemuxEm || x != CALLING_METHOD.demuxem).map(Enum::name).toList();
957+
final List<String> allMethods = Arrays.stream(CALLING_METHOD.values()).filter(x -> allowMethodsNeedingGex || !x.isRequiresH5()).map(Enum::name).toList();
958958
ret.add(ToolParameterDescriptor.create("methods", "Calling Methods", "The set of methods to use in calling.", "ldk-simplecombo", new JSONObject()
959959
{{
960960
put("multiSelect", true);
@@ -1182,16 +1182,16 @@ public File generateCellHashingCalls(File citeSeqCountOutDir, File outputDir, St
11821182

11831183
molInfo = ensureLocalCopy(molInfo, outputDir, log, toDelete);
11841184

1185-
// h5 file used by demuxEM:
1185+
// h5 file used by demuxEM/demuxmix:
11861186
File h5 = null;
11871187
if (parameters.h5File != null)
11881188
{
11891189
h5 = ensureLocalCopy(parameters.h5File, outputDir, log, toDelete);
11901190
}
11911191

1192-
if (parameters.methods.contains(CALLING_METHOD.demuxem) && h5 == null)
1192+
if (CALLING_METHOD.requiresH5(parameters.methods) && h5 == null)
11931193
{
1194-
throw new PipelineJobException("No h5 file provided, but demuxEM was specified");
1194+
throw new PipelineJobException("No h5 file provided, but demuxEM/demuxmix was specified");
11951195
}
11961196

11971197
citeSeqCountOutDir = ensureLocalCopy(citeSeqCountOutDir, outputDir, log, toDelete);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void init(JobContext ctx, List<SequenceOutputFile> inputFiles, List<Recor
188188
if (step.requiresHashing(ctx))
189189
{
190190
String methods = step.getProvider().hasParameter("methods") ? step.getProvider().getParameterByName("methods").extractValue(ctx.getJob(), step.getProvider(), step.getStepIdx(), String.class) : null;
191-
if (methods != null && methods.contains(CellHashingService.CALLING_METHOD.demuxem.name()))
191+
if (CellHashingService.CALLING_METHOD.requiresH5(methods))
192192
{
193193
doH5Caching = true;
194194
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected Map<Integer, File> prepareCountData(SingleCellOutput output, SequenceO
113113
File existingCountMatrixUmiDir = CellHashingService.get().getExistingFeatureBarcodeCountDir(parentReadset, CellHashingService.BARCODE_TYPE.hashing, ctx.getSequenceSupport());
114114
params.allowableHtoBarcodes = htosPerReadset;
115115
params.keepMarkdown = true;
116-
if (params.methods.contains(CellHashingService.CALLING_METHOD.demuxem))
116+
if (CellHashingService.CALLING_METHOD.requiresH5(params.methods))
117117
{
118118
Integer genomeId = wrapper.getSequenceOutputFile() == null ? null : wrapper.getSequenceOutputFile().getLibrary_id();
119119
if (genomeId == null)

0 commit comments

Comments
 (0)