Skip to content

Commit dccf4c7

Browse files
committed
Ensure BAM index exists
1 parent 311f538 commit dccf4c7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/analysis/SawfishAnalysis.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.labkey.api.sequenceanalysis.pipeline.PipelineContext;
1313
import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider;
1414
import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome;
15+
import org.labkey.api.sequenceanalysis.pipeline.SamtoolsIndexer;
1516
import org.labkey.api.sequenceanalysis.pipeline.SamtoolsRunner;
1617
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
1718
import org.labkey.api.sequenceanalysis.run.SimpleScriptWrapper;
@@ -53,11 +54,21 @@ public Output performAnalysisPerSampleRemote(Readset rs, File inputBam, Referenc
5354
{
5455
CramToBam samtoolsRunner = new CramToBam(getPipelineCtx().getLogger());
5556
File bam = new File(getPipelineCtx().getWorkingDirectory(), inputFile.getName().replaceAll(".cram$", ".bam"));
56-
samtoolsRunner.convert(inputFile, bam, referenceGenome.getWorkingFastaFile(), SequencePipelineService.get().getMaxThreads(getPipelineCtx().getLogger()));
57+
File bamIdx = new File(bam.getPath() + ".bai");
58+
if (!bamIdx.exists())
59+
{
60+
samtoolsRunner.convert(inputFile, bam, referenceGenome.getWorkingFastaFile(), SequencePipelineService.get().getMaxThreads(getPipelineCtx().getLogger()));
61+
new SamtoolsIndexer(getPipelineCtx().getLogger()).execute(bam);
62+
}
63+
else
64+
{
65+
getPipelineCtx().getLogger().debug("BAM index exists, will not re-convert CRAM");
66+
}
67+
5768
inputFile = bam;
5869

5970
output.addIntermediateFile(bam);
60-
output.addIntermediateFile(new File(bam.getPath() + ".bai"));
71+
output.addIntermediateFile(bamIdx);
6172
}
6273

6374
List<String> args = new ArrayList<>();

0 commit comments

Comments
 (0)