Skip to content

Commit 45c367d

Browse files
committed
Expose option to change strandedness threshold
1 parent af0c4ba commit 45c367d

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/analysis/AbstractCombineGeneCountsHandler.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,16 @@ private static List<ToolParameterDescriptor> getParams(boolean allowInferStrande
8181

8282
if (allowInferStranded)
8383
{
84-
ret.add(ToolParameterDescriptor.create(STRANDED, "Strand 1", "Choose whether to treat these data as stranded, unstranded, or to have the script infer the strandedness", "ldk-simplecombo", new JSONObject()
84+
ret.add(ToolParameterDescriptor.create(STRANDED, "Strandedness", "Choose whether to treat these data as stranded, unstranded, or to have the script infer the strandedness", "ldk-simplecombo", new JSONObject()
8585
{{
8686
put("storeValues", STRAND1 + ";" + STRAND2 + ";" + UNSTRANDED + ";" + INFER);
8787
put("value", INFER);
8888
}}, INFER));
89+
ret.add(ToolParameterDescriptor.create("strandedThreshold", "Strandedness Threshold", "If infer is selected, Choose whether to treat these data as stranded, unstranded, or to have the script infer the strandedness", "ldk-simplecombo", new JSONObject(){{
90+
put("minValue", 0);
91+
put("maxValue", 1);
92+
put("decimalPrecision", 2);
93+
}}, 0.9));
8994
}
9095

9196
return ret;
@@ -305,29 +310,20 @@ public void prepareFiles(JobContext ctx, List<SequenceOutputFile> inputFiles, St
305310
header.add(hp.getHeader(ctx, outputFileMap.get(rowId)));
306311
}
307312

308-
writer.writeNext(header.toArray(new String[header.size()]));
313+
writer.writeNext(header.toArray(new String[0]));
309314

310315
Set<String> genesWithoutData = new TreeSet<>();
311316
for (String geneId : results.distinctGenes)
312317
{
313318
List<String> row = new ArrayList<>(inputFiles.size() + 3);
314319
if (translator.getGeneMap().containsKey(geneId))
315320
{
316-
if (translator.getGeneMap().containsKey(geneId))
317-
{
318-
row.add(geneId);
319-
row.add(translator.getGeneMap().get(geneId).get("gene_name"));
320-
row.add(translator.getGeneMap().get(geneId).get("gene_description"));
321-
}
322-
else
323-
{
324-
row.add(geneId);
325-
row.add("");
326-
row.add("");
327-
}
321+
row.add(geneId);
322+
row.add(translator.getGeneMap().get(geneId).get("gene_name"));
323+
row.add(translator.getGeneMap().get(geneId).get("gene_description"));
328324

329325
List<String> toAdd = new ArrayList<>();
330-
Integer totalWithData = 0;
326+
int totalWithData = 0;
331327
for (Integer rowId : outputFileMap.keySet())
332328
{
333329
Double count = results.counts.get(rowId).get(geneId);
@@ -341,9 +337,9 @@ public void prepareFiles(JobContext ctx, List<SequenceOutputFile> inputFiles, St
341337

342338
if (totalWithData > 0 || !doSkipGenesWithoutData)
343339
{
344-
row.add(totalWithData.toString());
340+
row.add(String.valueOf(totalWithData));
345341
row.addAll(toAdd);
346-
writer.writeNext(row.toArray(new String[row.size()]));
342+
writer.writeNext(row.toArray(new String[0]));
347343
}
348344

349345
if (totalWithData == 0 && !OTHER_IDS.contains(geneId))

SequenceAnalysis/src/org/labkey/sequenceanalysis/analysis/CombineStarGeneCountsHandler.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public CombineStarGeneCountsHandler()
3131
@Override
3232
protected void processOutputFiles(CountResults results, List<SequenceOutputFile> inputFiles, JSONObject params, GeneToNameTranslator translator, PipelineJob job, RecordedAction action) throws PipelineJobException
3333
{
34-
3534
String strandedSelection = params.optString(STRANDED, INFER);
3635

3736
//next iterate all read count TSVs to guess strandedness
@@ -69,12 +68,12 @@ protected void processOutputFiles(CountResults results, List<SequenceOutputFile>
6968
continue;
7069
}
7170

72-
Long unstranded = Long.parseLong(cells[1]);
73-
Long strand1 = Long.parseLong(cells[2]);
71+
long unstranded = Long.parseLong(cells[1]);
72+
long strand1 = Long.parseLong(cells[2]);
7473
totalStrand1 += strand1;
75-
Long strand2 = Long.parseLong(cells[3]);
74+
long strand2 = Long.parseLong(cells[3]);
7675
totalStrand2 += strand2;
77-
Long strandMax = Math.max(strand1, strand2);
76+
long strandMax = Math.max(strand1, strand2);
7877

7978
results.distinctGenes.add(geneId);
8079

@@ -103,9 +102,9 @@ protected void processOutputFiles(CountResults results, List<SequenceOutputFile>
103102
strand2Map = new HashMap<>(Math.max(results.distinctGenes.size() + 500, 5000));
104103
}
105104

106-
unstrandedMap.put(geneId, unstranded.doubleValue());
107-
strand1Map.put(geneId, strand1.doubleValue());
108-
strand2Map.put(geneId, strand2.doubleValue());
105+
unstrandedMap.put(geneId, (double)unstranded);
106+
strand1Map.put(geneId, (double)strand1);
107+
strand2Map.put(geneId, (double)strand2);
109108

110109
unstrandedCounts.put(so.getRowid(), unstrandedMap);
111110
strand1Counts.put(so.getRowid(), strand1Map);
@@ -125,8 +124,9 @@ protected void processOutputFiles(CountResults results, List<SequenceOutputFile>
125124

126125
//finally build output
127126
double avgStrandRatio = sumStrandRatio / countStrandRatio;
127+
double threshold = params.optDouble("strandedThreshold", 0.9);
128128
job.getLogger().info("the average stranded/unstranded ratio for all samples was: " + avgStrandRatio);
129-
double threshold = 0.9;
129+
130130
String inferredStrandedness;
131131
job.getLogger().info("Attempting to infer strandedness");
132132
if (avgStrandRatio > threshold)

0 commit comments

Comments
 (0)