Skip to content

Commit a847538

Browse files
committed
Improve SnpEff check for existing index
1 parent 0ec3f23 commit a847538

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/variant/SNPEffStep.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStep;
1616
import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStepOutputImpl;
1717
import org.labkey.api.sequenceanalysis.run.AbstractCommandPipelineStep;
18+
import org.labkey.api.util.FileUtil;
1819
import org.labkey.api.util.PageFlowUtil;
1920
import org.labkey.api.writer.PrintWriters;
2021
import org.labkey.sequenceanalysis.pipeline.SequenceTaskHelper;
@@ -75,18 +76,16 @@ public static File checkOrCreateIndex(SequenceAnalysisJobSupport support, Logger
7576

7677
SnpEffWrapper wrapper = new SnpEffWrapper(log);
7778
File snpEffIndexDir = wrapper.getExpectedIndexDir(snpEffBaseDir, genome.getGenomeId(), geneFileId);
78-
if (snpEffIndexDir.exists())
79-
{
80-
log.debug("previously created index found, re-using: " + snpEffIndexDir.getPath());
81-
return snpEffBaseDir;
82-
}
83-
84-
File binFile = new File(snpEffIndexDir, "snpEffectPredictor.bin");
79+
File binFile = FileUtil.appendName(snpEffIndexDir, "snpEffectPredictor.bin");
8580
if (!binFile.exists())
8681
{
8782
log.debug("existing index not found, expected: " + binFile.getPath());
8883
wrapper.buildIndex(snpEffBaseDir, genome, geneFile, geneFileId);
8984
}
85+
else
86+
{
87+
log.debug("previously created index found, re-using: " + snpEffIndexDir.getPath());
88+
}
9089

9190
return snpEffBaseDir;
9291
}
@@ -100,7 +99,7 @@ public Output processVariants(File inputVCF, File outputDirectory, ReferenceGeno
10099
Integer geneFileId = getProvider().getParameterByName(GENE_PARAM).extractValue(getPipelineCtx().getJob(), getProvider(), getStepIdx(), Integer.class);
101100
File snpEffBaseDir = checkOrCreateIndex(getPipelineCtx().getSequenceSupport(), getPipelineCtx().getLogger(), genome, geneFileId);
102101

103-
File outputVcf = new File(outputDirectory, SequenceTaskHelper.getUnzippedBaseName(inputVCF) + ".snpEff.vcf.gz");
102+
File outputVcf = FileUtil.appendName(outputDirectory, SequenceTaskHelper.getUnzippedBaseName(inputVCF) + ".snpEff.vcf.gz");
104103
if (outputVcf.exists())
105104
{
106105
getPipelineCtx().getLogger().debug("deleting pre-existing output file: " + outputVcf.getPath());
@@ -110,7 +109,7 @@ public Output processVariants(File inputVCF, File outputDirectory, ReferenceGeno
110109
File intFile = null;
111110
if (intervals != null)
112111
{
113-
intFile = new File(outputVcf.getParentFile(), "snpEffintervals.bed");
112+
intFile = FileUtil.appendName(outputVcf.getParentFile(), "snpEffintervals.bed");
114113
try (PrintWriter writer = PrintWriters.getPrintWriter(intFile))
115114
{
116115
getPipelineCtx().getLogger().debug("Adding SnpEff intervals: " + intervals.size());

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/variant/SnpEffWrapper.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,16 @@ public String getGenomeBasename(Integer genomeId, Integer geneFileId)
9494
public File getExpectedIndexDir(File snpEffBaseDir, Integer genomeId, Integer geneFileId)
9595
{
9696
String basename = getGenomeBasename(genomeId, geneFileId);
97-
return new File(snpEffBaseDir, basename);
97+
return FileUtil.appendName(snpEffBaseDir, basename);
9898
}
9999

100100
public void buildIndex(File snpEffBaseDir, ReferenceGenome genome, File genes, Integer geneFileId) throws PipelineJobException
101101
{
102102
getLogger().info("Building SnpEff index for: "+ genome.getGenomeId() + " / " + geneFileId);
103103

104104
File genomeDir = getExpectedIndexDir(snpEffBaseDir, genome.getGenomeId(), geneFileId);
105-
if (genomeDir.exists() && genomeDir.list().length > 0)
105+
File doneFile = FileUtil.appendName(snpEffBaseDir, "build.done");
106+
if (doneFile.exists())
106107
{
107108
getLogger().info("directory already exists, will not re-build");
108109
return;
@@ -144,8 +145,8 @@ else if ("gbk".equalsIgnoreCase(ext))
144145

145146
try
146147
{
147-
Files.createSymbolicLink(new File(genomeDir, "sequences.fa").toPath(), genome.getSourceFastaFile().toPath());
148-
Files.createSymbolicLink(new File(genomeDir, "genes." + ext).toPath(), genes.toPath());
148+
Files.createSymbolicLink(FileUtil.appendName(genomeDir, "sequences.fa").toPath(), genome.getSourceFastaFile().toPath());
149+
Files.createSymbolicLink(FileUtil.appendName(genomeDir, "genes." + ext).toPath(), genes.toPath());
149150
}
150151
catch (IOException e)
151152
{
@@ -183,11 +184,11 @@ private File getJarDir()
183184

184185
private File getSnpEffJar()
185186
{
186-
return new File(getJarDir(), "snpEff.jar");
187+
return FileUtil.appendName(getJarDir(), "snpEff.jar");
187188
}
188189

189190
private File getSnpEffConfigFile()
190191
{
191-
return new File(getJarDir(), "snpEff.config");
192+
return FileUtil.appendName(getJarDir(), "snpEff.config");
192193
}
193194
}

0 commit comments

Comments
 (0)