Skip to content

Commit

Permalink
Reenable IndexFeatureFile.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnbroad committed Aug 16, 2017
1 parent 69fd379 commit 1bb7254
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");

Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -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<VariantContext> originalSource = new FeatureDataSource<>(inputVCF);
final FeatureDataSource<VariantContext> indexedSource = new FeatureDataSource<>(inputCopy)) {
Iterator<VariantContext> originalIterator = originalSource.iterator();
while (originalIterator.hasNext()) {
final VariantContext originalVC = originalIterator.next();
final Iterator<VariantContext> 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 = {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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
Expand All @@ -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");
Expand Down Expand Up @@ -264,7 +302,7 @@ private void testBedIndex(final File ORIG_FILE, final Class<? extends Index> 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);
}
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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");
Expand Down
Binary file not shown.

0 comments on commit 1bb7254

Please sign in to comment.