diff --git a/src/main/java/org/broadinstitute/hellbender/tools/IndexFeatureFile.java b/src/main/java/org/broadinstitute/hellbender/tools/IndexFeatureFile.java index 951f2f0adb0..93586adb1b3 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/IndexFeatureFile.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/IndexFeatureFile.java @@ -31,11 +31,11 @@ * Such files must have an index in order to be queried by interval. */ @CommandLineProgramProperties( - summary = "(Disabled) Creates indices for Feature-containing files, such as VCF and BED files", - oneLineSummary = "(Disabled) Creates indices for Feature-containing files (eg VCF and BED files)", + summary = "Creates indices for Feature-containing files, such as VCF and BED files", + oneLineSummary = "Creates indices for Feature-containing files (eg VCF and BED files)", programGroup = VariantProgramGroup.class ) -@BetaFeature +@DocumentedFeature public final class IndexFeatureFile extends CommandLineProgram { private static final Logger logger = LogManager.getLogger(IndexFeatureFile.class); @@ -53,12 +53,6 @@ public final class IndexFeatureFile extends CommandLineProgram { @Override protected Object doWork() { - // When https://github.com/broadinstitute/gatk/issues/2801 is fixed and this tool is re-enabled, we should - // remove the @BetaFeature annotation, restore the @DocumentedFeature annotation, remove the "(Disabled)" string - // from the CommandLineProgramProperties strings, remove this throw, re-enable the integration tests. - if (true) { - throw new UserException("The IndexFeatureFile tool is temporarily disabled."); - } if (!featureFile.canRead()) { throw new UserException.CouldNotReadInputFile(featureFile); } diff --git a/src/test/java/org/broadinstitute/hellbender/tools/IndexFeatureFileIntegrationTest.java b/src/test/java/org/broadinstitute/hellbender/tools/IndexFeatureFileIntegrationTest.java index 561933584bb..a0c441c6b77 100644 --- a/src/test/java/org/broadinstitute/hellbender/tools/IndexFeatureFileIntegrationTest.java +++ b/src/test/java/org/broadinstitute/hellbender/tools/IndexFeatureFileIntegrationTest.java @@ -7,19 +7,25 @@ import htsjdk.tribble.index.linear.LinearIndex; import htsjdk.tribble.index.tabix.TabixIndex; import htsjdk.tribble.util.TabixUtils; +import htsjdk.variant.variantcontext.VariantContext; import org.broadinstitute.hellbender.CommandLineProgramTest; +import org.broadinstitute.hellbender.engine.FeatureDataSource; import org.broadinstitute.hellbender.exceptions.UserException; +import org.broadinstitute.hellbender.utils.SimpleInterval; import org.testng.Assert; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.util.Arrays; +import java.util.Iterator; import java.util.List; public final class IndexFeatureFileIntegrationTest extends CommandLineProgramTest { - @Test(enabled = false) + @Test public void testVCFIndex() { final File ORIG_FILE = getTestFile("test_variants_for_index.vcf"); final File outName = createTempFile("test_variants_for_index.vcf", ".idx"); @@ -38,8 +44,7 @@ public void testVCFIndex() { checkIndex(index, Arrays.asList("1", "2", "3", "4")); } - - @Test(enabled = false) + @Test public void testVCFIndex_inferredName() { final File ORIG_FILE = getTestFile("test_variants_for_index.vcf"); @@ -57,7 +62,7 @@ public void testVCFIndex_inferredName() { checkIndex(index, Arrays.asList("1", "2", "3", "4")); } - @Test(enabled = false, expectedExceptions = UserException.NoSuitableCodecs.class) + @Test(expectedExceptions = UserException.NoSuitableCodecs.class) public void testIndexNonFeatureFileGZ() { final File ORIG_FILE = getTestFile("test_nonFeature_file.txt.blockgz.gz"); //made by bgzip final File outName = createTempFile("test_nonFeature_file.txt.blockgz.gz.", ".tbi"); @@ -69,7 +74,7 @@ public void testIndexNonFeatureFileGZ() { final Object res = this.runCommandLine(args); } - @Test(enabled=false, expectedExceptions = UserException.NoSuitableCodecs.class) + @Test(expectedExceptions = UserException.NoSuitableCodecs.class) public void testIndexBCFFileGZ() { final File ORIG_FILE = getTestFile("test_variants_for_index.bcf.blockgz.gz"); //made by bgzip final File outName = createTempFile("test_variants_for_index.bcf.blockgz.gz.", ".tbi"); @@ -81,7 +86,7 @@ public void testIndexBCFFileGZ() { final Object res = this.runCommandLine(args); } - @Test(enabled=false, expectedExceptions = UserException.class) + @Test(expectedExceptions = UserException.class) public void testVCFGZIndex_tabixRequires_tbi_name() { final File ORIG_FILE = getTestFile("test_variants_for_index.vcf.blockgz.gz"); //made by bgzip final File outName = createTempFile("test_variants_for_index.blockgz.gz.", ".idx"); @@ -93,7 +98,7 @@ public void testVCFGZIndex_tabixRequires_tbi_name() { this.runCommandLine(args); } - @Test(enabled=false) + @Test public void testVCFGZIndex_tabix() { final File ORIG_FILE = getTestFile("test_variants_for_index.vcf.blockgz.gz"); //made by bgzip final File outName = createTempFile("test_variants_for_index.blockgz.gz.", TabixUtils.STANDARD_INDEX_EXTENSION); @@ -112,7 +117,40 @@ public void testVCFGZIndex_tabix() { checkIndex(index, Arrays.asList("1", "2", "3", "4")); } - @Test(enabled=false) + @Test + public void testVCFGZLargeHeaderIndex_tabix() throws IOException { + // copy the input file, and create an index + final File inputVCF = getTestFile("4featuresHG38Header.vcf.gz"); + final File tempDir = createTempDir("testVCFGZLargeHeaderIndex"); + final File inputCopy = new File(tempDir, inputVCF.getName()); + Files.copy(inputVCF.toPath(), inputCopy.toPath()); + final File outIndexFile = new File(tempDir, inputCopy.getName() + TabixUtils.STANDARD_INDEX_EXTENSION); + + final String[] args = { + "--feature_file" , inputCopy.getAbsolutePath(), + "-O" , outIndexFile.getAbsolutePath() + }; + final Object res = this.runCommandLine(args); + Assert.assertEquals(res, outIndexFile.getAbsolutePath()); + + // use the location of every variant in the input as a query interval for the indexed copy of the same file + try (final FeatureDataSource originalSource = new FeatureDataSource<>(inputVCF); + final FeatureDataSource indexedSource = new FeatureDataSource<>(inputCopy)) { + Iterator originalIterator = originalSource.iterator(); + while (originalIterator.hasNext()) { + final VariantContext originalVC = originalIterator.next(); + final Iterator indexedIterator = indexedSource.query(new SimpleInterval(originalVC)); + Assert.assertTrue(indexedIterator.hasNext()); + final VariantContext queriedVC = indexedIterator.next(); + Assert.assertEquals(queriedVC.getContig(), originalVC.getContig()); + Assert.assertEquals(queriedVC.getStart(), originalVC.getStart()); + Assert.assertEquals(queriedVC.getEnd(), originalVC.getEnd()); + Assert.assertFalse(indexedIterator.hasNext()); + } + } + } + + @Test public void testVCFGZIndex_inferredName(){ final File ORIG_FILE = getTestFile("test_variants_for_index.vcf.blockgz.gz"); //made by bgzip final String[] args = { @@ -131,7 +169,7 @@ public void testVCFGZIndex_inferredName(){ checkIndex(index, Arrays.asList("1", "2", "3", "4")); } - @Test(enabled=false, expectedExceptions = UserException.MalformedFile.class) + @Test(expectedExceptions = UserException.MalformedFile.class) public void testVCFGZIPIndex() throws IOException { //This tests blows up because the input file is not blocked gzipped final File ORIG_FILE = getTestFile("test_variants_for_index.vcf.gzip.gz"); //made by gzip @@ -143,7 +181,7 @@ public void testVCFGZIPIndex() throws IOException { final Object res = this.runCommandLine(args); } - @Test(enabled=false, expectedExceptions = UserException.MalformedFile.class) + @Test(expectedExceptions = UserException.MalformedFile.class) public void testVCFGZIPIndex_inferredName() throws IOException { //This tests blows up because the input file is not blocked gzipped final File ORIG_FILE = getTestFile("test_variants_for_index.vcf.gzip.gz"); //made by gzip @@ -153,7 +191,7 @@ public void testVCFGZIPIndex_inferredName() throws IOException { final Object res = this.runCommandLine(args); } - @Test(enabled=false) + @Test public void testBCFIndex() { final File ORIG_FILE = getTestFile("test_variants_for_index.bcf"); final File outName = createTempFile("test_variants_for_index.bcf.", ".idx"); @@ -171,7 +209,7 @@ public void testBCFIndex() { checkIndex(index, Arrays.asList("1")); } - @Test(enabled=false, expectedExceptions = TribbleException.InvalidHeader.class) + @Test(expectedExceptions = TribbleException.InvalidHeader.class) public void testUncompressedBCF2_2Index() { final File ORIG_FILE = getTestFile("test_variants_for_index.BCF22uncompressed.bcf"); final File outName = createTempFile("test_variants_for_index.BCF22uncompressed.bcf", ".idx"); @@ -183,7 +221,7 @@ public void testUncompressedBCF2_2Index() { final Object res = this.runCommandLine(args); } - @Test(enabled=false, expectedExceptions = UserException.NoSuitableCodecs.class) + @Test(expectedExceptions = UserException.NoSuitableCodecs.class) public void testCompressedBCF2_2Index() { final File ORIG_FILE = getTestFile("test_variants_for_index.BCF22compressed.bcf.blockgz.gz"); //made by bgzip final File outName = createTempFile("test_variants_for_index.BCF22compressed.bcf.blockgz.gz", ".idx"); @@ -195,7 +233,7 @@ public void testCompressedBCF2_2Index() { final Object res = this.runCommandLine(args); } - @Test(enabled=false) + @Test public void testGVCFTreatedAsVCFIndex() { // Here we're testing what happens when we have a GVCF that is treated by the tool as a // regular VCF due to the lack of a .g.vcf extension @@ -215,7 +253,7 @@ public void testGVCFTreatedAsVCFIndex() { checkIndex(index, Arrays.asList("1")); } - @Test(enabled=false) + @Test public void testGVCFIndex() { final File ORIG_FILE = getTestFile("test_variants_for_index.g.vcf"); final File outName = createTempFile("test_variants_for_index.g.vcf.", ".idx"); @@ -264,7 +302,7 @@ private void testBedIndex(final File ORIG_FILE, final Class ind Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1", "2", "4")); } - @Test(enabled=false) + @Test public void testBedIndex() { testBedIndex(getTestFile("test_bed_for_index.bed"), LinearIndex.class); } @@ -277,7 +315,7 @@ public void testBedGZIndex() { testBedIndex(getTestFile("test_bed_for_index.bed.gz"), TabixIndex.class); } - @Test(enabled=false) + @Test public void testSAMPileupGZIndex() { final File ORIG_FILE = getTestFile("test_sampileup_for_index.pileup.gz"); // made with bgzip final File outName = createTempFile(ORIG_FILE.getName(), TabixUtils.STANDARD_INDEX_EXTENSION); @@ -304,7 +342,7 @@ public void testSAMPileupGZIndex() { Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1", "2", "3", "4")); } - @Test(enabled=false, expectedExceptions = UserException.CouldNotReadInputFile.class) + @Test(expectedExceptions = UserException.CouldNotReadInputFile.class) public void testVCFIndex_missingFile() { final File ORIG_FILE = getTestFile("missing_file.vcf"); final File outName = createTempFile("test_variants_for_index.vcf.", ".idx"); @@ -316,7 +354,7 @@ public void testVCFIndex_missingFile() { final Object res = this.runCommandLine(args); } - @Test(enabled=false, expectedExceptions = UserException.CouldNotCreateOutputFile.class) + @Test(expectedExceptions = UserException.CouldNotCreateOutputFile.class) public void testVCFIndex_cannotWrite() { final File ORIG_FILE = getTestFile("test_variants_for_index.vcf"); final File tempDir = createTempDir("fred"); diff --git a/src/test/resources/org/broadinstitute/hellbender/tools/IndexFeatureFile/4featuresHG38Header.vcf.gz b/src/test/resources/org/broadinstitute/hellbender/tools/IndexFeatureFile/4featuresHG38Header.vcf.gz new file mode 100644 index 00000000000..c2abb26e399 Binary files /dev/null and b/src/test/resources/org/broadinstitute/hellbender/tools/IndexFeatureFile/4featuresHG38Header.vcf.gz differ