Skip to content

Commit 25b2e15

Browse files
committed
Smarter resume in specHLA
1 parent 5694b2e commit 25b2e15

1 file changed

Lines changed: 53 additions & 19 deletions

File tree

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

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,36 +60,70 @@ public Output performAnalysisPerSampleRemote(Readset rs, File inputBam, Referenc
6060
throw new PipelineJobException("Missing file: " + gzippedFasta.getPath());
6161
}
6262

63+
File doneFile = FileUtil.appendName(outputDir, FileUtil.getBaseName(inputBam) + ".subset.done");
64+
output.addIntermediateFile(doneFile);
65+
6366
File subsetBam = FileUtil.appendName(outputDir, FileUtil.getBaseName(inputBam) + ".subset.bam");
6467
SamtoolsRunner sr = new SamtoolsRunner(getWrapper().getLogger());
65-
sr.execute(Arrays.asList(
66-
sr.getSamtoolsPath().getPath(),
67-
"view",
68-
"-h",
69-
"-F", "12", //This selects pairs where either mate is mapped
70-
"-T", gzippedFasta.getPath(),
71-
"-o", subsetBam.getPath(),
72-
inputBam.getPath()
73-
));
68+
if (doneFile.exists())
69+
{
70+
getPipelineCtx().getLogger().debug("Done file exists, skipping samtools view");
71+
}
72+
else
73+
{
74+
sr.execute(Arrays.asList(
75+
sr.getSamtoolsPath().getPath(),
76+
"view",
77+
"-h",
78+
"-F", "12", //This selects pairs where either mate is mapped
79+
"-T", gzippedFasta.getPath(),
80+
"-o", subsetBam.getPath(),
81+
inputBam.getPath()
82+
));
83+
}
7484
output.addIntermediateFile(subsetBam);
7585

76-
File queryNameSortBam = new SamSorter(getPipelineCtx().getLogger()).execute(subsetBam, FileUtil.appendName(outputDir, FileUtil.getBaseName(inputBam) + ".querySort.bam"), SAMFileHeader.SortOrder.queryname);
86+
File queryNameSortBam = FileUtil.appendName(outputDir, FileUtil.getBaseName(inputBam) + ".querySort.bam");
87+
if (doneFile.exists())
88+
{
89+
getPipelineCtx().getLogger().debug("Done file exists, skipping samtools sort");
90+
}
91+
else
92+
{
93+
new SamSorter(getPipelineCtx().getLogger()).execute(subsetBam, queryNameSortBam, SAMFileHeader.SortOrder.queryname);
94+
}
7795
output.addIntermediateFile(queryNameSortBam);
7896

7997
File fq1 = FileUtil.appendName(outputDir, FileUtil.getBaseName(inputBam) + ".R1.fastq.gz");
8098
File fq2 = FileUtil.appendName(outputDir, FileUtil.getBaseName(inputBam) + ".R2.fastq.gz");
81-
sr.execute(Arrays.asList(
82-
sr.getSamtoolsPath().getPath(),
83-
"fastq",
84-
"-1",
85-
fq1.getPath(),
86-
"-2",
87-
fq2.getPath(),
88-
queryNameSortBam.getPath()
89-
));
99+
if (doneFile.exists())
100+
{
101+
getPipelineCtx().getLogger().debug("Done file exists, skipping samtools fastq");
102+
}
103+
else
104+
{
105+
sr.execute(Arrays.asList(
106+
sr.getSamtoolsPath().getPath(),
107+
"fastq",
108+
"-1",
109+
fq1.getPath(),
110+
"-2",
111+
fq2.getPath(),
112+
queryNameSortBam.getPath()
113+
));
114+
}
90115
output.addIntermediateFile(fq1);
91116
output.addIntermediateFile(fq2);
92117

118+
try
119+
{
120+
FileUtils.touch(doneFile);
121+
}
122+
catch (IOException e)
123+
{
124+
throw new PipelineJobException(e);
125+
}
126+
93127
File specHlaExe = AbstractCommandWrapper.resolveFileInPath("spechla", null, true);
94128

95129
List<String> toRun = new ArrayList<>(Arrays.asList(

0 commit comments

Comments
 (0)