Skip to content

Commit 0fcc68d

Browse files
committed
Make ConvertToCramHandler more tolerant to job restarts
1 parent 7b7ecbf commit 0fcc68d

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

SequenceAnalysis/api-src/org/labkey/api/sequenceanalysis/pipeline/SamtoolsCramConverter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ private void doIndex(File input, @Nullable Integer threads) throws PipelineJobEx
7272
params.add(input.getPath());
7373
execute(params);
7474

75-
File idx = new File(input.getPath() + ".crai");
75+
File idx = getExpectedCramIndex(input);
7676
if (!idx.exists())
7777
{
7878
throw new PipelineJobException("Unable to find CRAM index: " + idx.getPath());
7979
}
8080
}
81+
82+
public static File getExpectedCramIndex(File input)
83+
{
84+
return new File(input.getPath() + ".crai");
85+
}
8186
}

SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/ConvertToCramHandler.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,37 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
109109
{
110110
ReferenceGenome genome = ctx.getSequenceSupport().getCachedGenome(so.getLibrary_id());
111111
File cram = new File(so.getFile().getParentFile(), FileUtil.getBaseName(so.getFile()) + ".cram");
112-
new SamtoolsCramConverter(ctx.getLogger()).convert(so.getFile(), cram, genome.getWorkingFastaFileGzipped(), true, threads);
112+
File cramIdx = SamtoolsCramConverter.getExpectedCramIndex(cram);
113+
if (!so.getFile().exists())
114+
{
115+
if (replaceOriginal && cramIdx.exists())
116+
{
117+
ctx.getLogger().debug("BAM does not exist, but CRAM index does. Proceeding on the assumption this is a resume of a failed job.");
118+
}
119+
else
120+
{
121+
throw new PipelineJobException("Unable to find BAM: " + so.getFile().getPath());
122+
}
123+
}
124+
else
125+
{
126+
new SamtoolsCramConverter(ctx.getLogger()).convert(so.getFile(), cram, genome.getWorkingFastaFileGzipped(), true, threads);
127+
}
128+
113129
checkCramAndIndex(so);
114130

115131
if (replaceOriginal)
116132
{
117133
ctx.getLogger().info("Deleting original BAM: " + so.getFile().getPath());
118-
new File(so.getFile().getPath() + ".bai").delete();
119-
so.getFile().delete();
134+
if (so.getFile().exists())
135+
{
136+
new File(so.getFile().getPath() + ".bai").delete();
137+
so.getFile().delete();
138+
}
139+
else
140+
{
141+
ctx.getLogger().debug("Input BAM not found, possibly deleted in earlier job iteration?");
142+
}
120143
}
121144
}
122145
}

0 commit comments

Comments
 (0)