diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java index dd84f79a8..696b23534 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java @@ -61,7 +61,7 @@ public class TribbleRMDTrackBuilder extends PluginManager implemen // the linear index extension - private static final String linearIndexExtension = ".idx"; + public static final String linearIndexExtension = ".idx"; /** Create a new plugin manager. */ public TribbleRMDTrackBuilder() { @@ -118,7 +118,7 @@ public class TribbleRMDTrackBuilder extends PluginManager implemen * @return a linear index for the specified type * @throws IOException if we cannot write the index file */ - private LinearIndex createIndex(File inputFile, FeatureCodec codec) throws IOException { + public static LinearIndex createIndex(File inputFile, FeatureCodec codec) throws IOException { LinearIndexCreator create = new LinearIndexCreator(inputFile, codec); return create.createIndex(); } @@ -131,7 +131,7 @@ public class TribbleRMDTrackBuilder extends PluginManager implemen * @param inputFile the target file to make an index for * @return true if we need to create an index, false otherwise */ - private boolean requireIndex(File inputFile) { + public static boolean requireIndex(File inputFile) { // can we read the index? if not, create an index File indexFile = new File(inputFile.getAbsolutePath() + linearIndexExtension); if (!(indexFile.canRead())) return true; diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/utils/GATKFeature.java b/java/src/org/broadinstitute/sting/gatk/refdata/utils/GATKFeature.java index ea3153dd6..af1eaa209 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/utils/GATKFeature.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/utils/GATKFeature.java @@ -63,13 +63,15 @@ public abstract class GATKFeature implements Feature { */ public static class TribbleGATKFeature extends GATKFeature { private final Feature feature; - + private GenomeLoc position = null; + public TribbleGATKFeature(Feature f, String name) { super(name); feature = f; } public GenomeLoc getLocation() { - return GenomeLocParser.createGenomeLoc(feature.getChr(), feature.getStart(), feature.getEnd()); + if (position == null) position = GenomeLocParser.createGenomeLoc(feature.getChr(), feature.getStart(), feature.getEnd()); + return position; } /** Return the features reference sequence name, e.g chromosome or contig */ diff --git a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFReader.java b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFReader.java index b844fe4e7..e65859284 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFReader.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFReader.java @@ -21,7 +21,9 @@ import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; import org.broad.tribble.FeatureReader; +import org.broad.tribble.index.linear.LinearIndex; import org.broad.tribble.vcf.*; +import org.broadinstitute.sting.gatk.refdata.tracks.builders.TribbleRMDTrackBuilder; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.Utils; @@ -57,6 +59,14 @@ public class VCFReader implements Iterator, Iterable { private void initialize(File vcfFile, VCFCodec.LineTransform transform) { VCFCodec codec = new VCFCodec(); + LinearIndex index = null; + if (TribbleRMDTrackBuilder.requireIndex(vcfFile)) { + try { + index = TribbleRMDTrackBuilder.createIndex(vcfFile, new VCFCodec()); + } catch (IOException e) { + throw new StingException("Unable to make required index for file " + vcfFile + " do you have write permissions to the directory?"); + } + } if (transform != null) codec.setTransformer(transform); try { vcfReader = new FeatureReader(vcfFile,codec); diff --git a/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java b/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java index 5089f2b76..c1162b9fa 100644 --- a/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java +++ b/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java @@ -2,6 +2,7 @@ package org.broadinstitute.sting.utils.genotype.vcf; import org.broad.tribble.vcf.*; import org.broadinstitute.sting.BaseTest; +import org.broadinstitute.sting.gatk.refdata.tracks.builders.TribbleRMDTrackBuilder; import org.broadinstitute.sting.utils.fasta.IndexedFastaSequenceFile; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.GenomeLocParser; @@ -54,6 +55,7 @@ public class VCFWriterUnitTest extends BaseTest { } Assert.assertEquals(2,counter); reader.close(); + new File(fakeVCFFile + TribbleRMDTrackBuilder.linearIndexExtension).delete(); fakeVCFFile.delete(); }