Skip to content

Commit 1642168

Browse files
committed
Fault tolerance for ApplyBQSR
1 parent b211262 commit 1642168

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/bampostprocessing/BaseQualityScoreRecalibrator.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.labkey.api.sequenceanalysis.run.AbstractGatk4Wrapper;
1616
import org.labkey.api.util.FileUtil;
1717
import org.labkey.api.writer.PrintWriters;
18+
import org.labkey.sequenceanalysis.util.SequenceUtil;
1819

1920
import java.io.File;
2021
import java.io.IOException;
@@ -70,29 +71,39 @@ public File execute(File bam, File fasta, File output, @Nullable File knownVaria
7071
argsRecal.add(recalTable.getPath());
7172
execute(argsRecal);
7273

73-
List<String> argsApply = new ArrayList<>(getBaseArgs());
74-
argsApply.add("ApplyBQSR");
75-
argsApply.add("-I");
76-
argsApply.add(bam.getPath());
77-
argsApply.add("-R");
78-
argsApply.add(fasta.getPath());
79-
argsApply.add("--bqsr-recal-file");
80-
argsApply.add(recalTable.getPath());
81-
argsApply.add("-O");
82-
argsApply.add(output.getPath());
83-
execute(argsApply);
74+
// If there is not recal possible, the output has 132 lines.
75+
long lineCount = SequenceUtil.getLineCount(recalTable);
76+
if (lineCount > 132)
77+
{
78+
List<String> argsApply = new ArrayList<>(getBaseArgs());
79+
argsApply.add("ApplyBQSR");
80+
argsApply.add("-I");
81+
argsApply.add(bam.getPath());
82+
argsApply.add("-R");
83+
argsApply.add(fasta.getPath());
84+
argsApply.add("--bqsr-recal-file");
85+
argsApply.add(recalTable.getPath());
86+
argsApply.add("-O");
87+
argsApply.add(output.getPath());
88+
execute(argsApply);
89+
90+
if (!output.exists())
91+
{
92+
throw new PipelineJobException("Expected output not created: " + output.getPath());
93+
}
94+
}
95+
else
96+
{
97+
getLogger().info("No recalibration was possible, skipping ApplyBQSR");
98+
output = bam;
99+
}
84100

85101
if (deleteKnownVariantFile)
86102
{
87103
knownVariants.delete();
88104
new File(knownVariants.getPath() + ".idx").delete();
89105
}
90106

91-
if (!output.exists())
92-
{
93-
throw new PipelineJobException("Expected output not created: " + output.getPath());
94-
}
95-
96107
return output;
97108
}
98109

@@ -138,7 +149,7 @@ public Output processBam(Readset rs, File inputBam, ReferenceGenome referenceGen
138149
}
139150
}
140151

141-
getWrapper().execute(inputBam, referenceGenome.getWorkingFastaFile(), outputBam, knownVariants);
152+
outputBam = getWrapper().execute(inputBam, referenceGenome.getWorkingFastaFile(), outputBam, knownVariants);
142153

143154
output.setBAM(outputBam);
144155

0 commit comments

Comments
 (0)