Skip to content

Commit 2b12b7c

Browse files
committed
Further simplify hashing params code
1 parent dd1fb73 commit 2b12b7c

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

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

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,18 @@ public static class CellHashingParameters
7777
{
7878
public BARCODE_TYPE type;
7979

80-
private File htoOrCiteseqBarcodesFile;
81-
public Set<String> allowableHtoOrCiteseqBarcodes;
80+
private File htoBarcodesFile;
81+
public Set<String> allowableHtoBarcodes;
8282

8383
public File cellBarcodeWhitelistFile;
8484

8585
public boolean createOutputFiles = true;
8686
public @Nullable String outputCategory;
8787

88-
public Readset htoOrCiteseqReadset;
88+
public Readset htoReadset;
8989
public Readset parentReadset;
9090

9191
public @Nullable Integer genomeId;
92-
public Integer editDistance = 2;
93-
public boolean scanEditDistances = false;
9492
public boolean skipNormalizationQc = false;
9593
public Integer minCountPerCell = 5;
9694
public List<CALLING_METHOD> methods = CALLING_METHOD.getDefaultMethods();
@@ -102,17 +100,15 @@ private CellHashingParameters()
102100

103101
}
104102

105-
public static CellHashingService.CellHashingParameters createFromStep(SequenceOutputHandler.JobContext ctx, SingleCellStep step, CellHashingService.BARCODE_TYPE type, Readset htoOrCiteseqReadset, @Nullable Readset parentReadset, @Nullable File htoOrCiteseqBarcodesFile) throws PipelineJobException
103+
public static CellHashingService.CellHashingParameters createFromStep(SequenceOutputHandler.JobContext ctx, SingleCellStep step, CellHashingService.BARCODE_TYPE type, Readset htoReadset, @Nullable Readset parentReadset) throws PipelineJobException
106104
{
107105
CellHashingService.CellHashingParameters ret = new CellHashingService.CellHashingParameters();
108106
ret.type = type;
109-
ret.scanEditDistances = step.getProvider().getParameterByName("scanEditDistances").extractValue(ctx.getJob(), step.getProvider(), step.getStepIdx(), Boolean.class, false);
110107
ret.skipNormalizationQc = step.getProvider().getParameterByName("skipNormalizationQc").extractValue(ctx.getJob(), step.getProvider(), step.getStepIdx(), Boolean.class, false);
111-
ret.editDistance = step.getProvider().getParameterByName("editDistance").extractValue(ctx.getJob(), step.getProvider(), step.getStepIdx(), Integer.class, 2);
112108
ret.minCountPerCell = step.getProvider().getParameterByName("minCountPerCell").extractValue(ctx.getJob(), step.getProvider(), step.getStepIdx(), Integer.class, 3);
113-
ret.htoOrCiteseqReadset = htoOrCiteseqReadset;
109+
ret.htoReadset = htoReadset;
114110
ret.parentReadset = parentReadset;
115-
ret.htoOrCiteseqBarcodesFile = htoOrCiteseqBarcodesFile == null ? new File(ctx.getSourceDirectory(), type.getAllBarcodeFileName()) : htoOrCiteseqBarcodesFile;
111+
ret.htoBarcodesFile = new File(ctx.getSourceDirectory(), type.getAllBarcodeFileName());
116112

117113
if (type == BARCODE_TYPE.hashing)
118114
{
@@ -131,17 +127,15 @@ public static CellHashingService.CellHashingParameters createFromStep(SequenceOu
131127
return ret;
132128
}
133129

134-
public static CellHashingParameters createFromJson(BARCODE_TYPE type, File webserverDir, JSONObject params, Readset htoOrCiteseqReadset, @Nullable Readset parentReadset, @Nullable File htoOrCiteseqBarcodesFile) throws PipelineJobException
130+
public static CellHashingParameters createFromJson(BARCODE_TYPE type, File webserverDir, JSONObject params, Readset htoReadset, @Nullable Readset parentReadset) throws PipelineJobException
135131
{
136132
CellHashingParameters ret = new CellHashingParameters();
137133
ret.type = type;
138-
ret.scanEditDistances = params.optBoolean("scanEditDistances", false);
139134
ret.skipNormalizationQc = params.optBoolean("skipNormalizationQc", false);
140-
ret.editDistance = params.optInt("editDistance", 2);
141135
ret.minCountPerCell = params.optInt("minCountPerCell", 3);
142-
ret.htoOrCiteseqReadset = htoOrCiteseqReadset;
136+
ret.htoReadset = htoReadset;
143137
ret.parentReadset = parentReadset;
144-
ret.htoOrCiteseqBarcodesFile = htoOrCiteseqBarcodesFile == null ? new File(webserverDir, type.getAllBarcodeFileName()) : htoOrCiteseqBarcodesFile;
138+
ret.htoBarcodesFile = new File(webserverDir, type.getAllBarcodeFileName());
145139
ret.methods = extractMethods(params.optString("methods"));
146140

147141
if (type == BARCODE_TYPE.hashing && ret.methods.isEmpty())
@@ -185,12 +179,12 @@ public static CellHashingParameters createFromJson(BARCODE_TYPE type, File webse
185179

186180
public int getEffectiveReadsetId()
187181
{
188-
return parentReadset != null ? parentReadset.getReadsetId() : htoOrCiteseqReadset.getReadsetId();
182+
return parentReadset != null ? parentReadset.getReadsetId() : htoReadset.getReadsetId();
189183
}
190184

191-
public File getHtoOrCiteSeqBarcodeFile()
185+
public File getHtoBarcodeFile()
192186
{
193-
return htoOrCiteseqBarcodesFile;
187+
return htoBarcodesFile;
194188
}
195189

196190
public String getReportTitle()
@@ -208,9 +202,9 @@ else if (parentReadset != null)
208202
{
209203
return FileUtil.makeLegalName(parentReadset.getName());
210204
}
211-
else if (htoOrCiteseqReadset != null)
205+
else if (htoReadset != null)
212206
{
213-
return FileUtil.makeLegalName(htoOrCiteseqReadset.getName());
207+
return FileUtil.makeLegalName(htoReadset.getName());
214208
}
215209

216210
throw new IllegalStateException("Neither basename, parent readset, nor hashing/citeseq readset provided");
@@ -223,35 +217,35 @@ public void validate()
223217

224218
public void validate(boolean allowMissingHtoReadset)
225219
{
226-
if (!allowMissingHtoReadset && htoOrCiteseqReadset == null)
220+
if (!allowMissingHtoReadset && htoReadset == null)
227221
{
228-
throw new IllegalStateException("Missing Hashing/Cite-seq readset");
222+
throw new IllegalStateException("Missing Hashing readset");
229223
}
230224

231225
if (createOutputFiles && outputCategory == null)
232226
{
233227
throw new IllegalStateException("Missing output category");
234228
}
235229

236-
if (htoOrCiteseqBarcodesFile == null)
230+
if (htoBarcodesFile == null)
237231
{
238-
throw new IllegalStateException("Missing all HTO/CITE-seq barcodes file");
232+
throw new IllegalStateException("Missing all HTO barcodes file");
239233
}
240234
}
241235

242236
public Set<String> getAllowableBarcodeNames() throws PipelineJobException
243237
{
244-
if (allowableHtoOrCiteseqBarcodes != null)
238+
if (allowableHtoBarcodes != null)
245239
{
246-
return Collections.unmodifiableSet(allowableHtoOrCiteseqBarcodes);
240+
return Collections.unmodifiableSet(allowableHtoBarcodes);
247241
}
248-
if (htoOrCiteseqBarcodesFile == null)
242+
if (htoBarcodesFile == null)
249243
{
250244
throw new IllegalArgumentException("Barcode file was null");
251245
}
252246

253247
Set<String> allowableBarcodes = new HashSet<>();
254-
try (CSVReader reader = new CSVReader(Readers.getReader(htoOrCiteseqBarcodesFile), '\t'))
248+
try (CSVReader reader = new CSVReader(Readers.getReader(htoBarcodesFile), '\t'))
255249
{
256250
String[] line;
257251
while ((line = reader.readNext()) != null)

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,21 @@ public File getValidHashingBarcodeFile(File sourceDir)
390390
@Override
391391
public File generateHashingCallsForRawMatrix(Readset parentReadset, PipelineOutputTracker output, SequenceOutputHandler.JobContext ctx, CellHashingParameters parameters, File rawCountMatrixDir) throws PipelineJobException
392392
{
393+
if (parameters.type != BARCODE_TYPE.hashing)
394+
{
395+
throw new PipelineJobException("This is only intended for cell hashing data");
396+
}
397+
393398
parameters.validate(true);
394-
Map<Integer, Integer> readsetToHashingOrCite = parameters.type == BARCODE_TYPE.hashing ? getCachedHashingReadsetMap(ctx.getSequenceSupport()) : getCachedCiteSeqReadsetMap(ctx.getSequenceSupport());
395-
if (readsetToHashingOrCite.isEmpty())
399+
Map<Integer, Integer> readsetToHashing = getCachedHashingReadsetMap(ctx.getSequenceSupport());
400+
if (readsetToHashing.isEmpty())
396401
{
397402
ctx.getLogger().info("No cached " + parameters.type.name() + " readsets, skipping");
398403
return null;
399404
}
400405

401406
//prepare whitelist of barcodes, based on cDNA records
402-
File htoBarcodeWhitelist = parameters.getHtoOrCiteSeqBarcodeFile();
407+
File htoBarcodeWhitelist = parameters.getHtoBarcodeFile();
403408
if (!htoBarcodeWhitelist.exists())
404409
{
405410
throw new PipelineJobException("Unable to find file: " + htoBarcodeWhitelist.getPath());
@@ -412,15 +417,15 @@ public File generateHashingCallsForRawMatrix(Readset parentReadset, PipelineOutp
412417
return null;
413418
}
414419

415-
ctx.getLogger().debug("total cached readset/" + parameters.type.name() + " readset pairs: " + readsetToHashingOrCite.size());
420+
ctx.getLogger().debug("total cached readset/" + parameters.type.name() + " readset pairs: " + readsetToHashing.size());
416421
ctx.getLogger().debug("unique indexes: " + lineCount);
417422

418-
Readset htoOrCiteReadset = ctx.getSequenceSupport().getCachedReadset(readsetToHashingOrCite.get(parentReadset.getReadsetId()));
419-
if (htoOrCiteReadset == null)
423+
Readset htoReadset = ctx.getSequenceSupport().getCachedReadset(readsetToHashing.get(parentReadset.getReadsetId()));
424+
if (htoReadset == null)
420425
{
421426
throw new PipelineJobException("Unable to find HTO readset for readset: " + parentReadset.getRowId());
422427
}
423-
parameters.htoOrCiteseqReadset = htoOrCiteReadset;
428+
parameters.htoReadset = htoReadset;
424429

425430
parameters.validate();
426431

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ protected Map<Integer, File> prepareCountData(SingleCellOutput output, SequenceO
8484
{
8585
ctx.getLogger().info("Total barcodes for readset: " + htosPerReadset.size());
8686

87-
CellHashingService.CellHashingParameters params = CellHashingService.CellHashingParameters.createFromStep(ctx, this, CellHashingService.BARCODE_TYPE.hashing, null, parentReadset, null);
87+
CellHashingService.CellHashingParameters params = CellHashingService.CellHashingParameters.createFromStep(ctx, this, CellHashingService.BARCODE_TYPE.hashing, null, parentReadset);
8888
params.outputCategory = CATEGORY;
8989
params.genomeId = wrapper.getSequenceOutputFile().getLibrary_id();
9090
params.cellBarcodeWhitelistFile = cellBarcodesParsed;
9191
File existingCountMatrixUmiDir = CellHashingService.get().getExistingFeatureBarcodeCountDir(parentReadset, CellHashingService.BARCODE_TYPE.hashing, ctx.getSequenceSupport());
92-
params.allowableHtoOrCiteseqBarcodes = htosPerReadset;
92+
params.allowableHtoBarcodes = htosPerReadset;
9393

9494
hashingCalls = CellHashingService.get().generateHashingCallsForRawMatrix(parentReadset, output, ctx, params, existingCountMatrixUmiDir);
9595
}

0 commit comments

Comments
 (0)