Search in sources :

Example 21 with Index

use of htsjdk.tribble.index.Index in project gatk by broadinstitute.

the class IndexUtilsUnitTest method testLoadIndex_noIndex.

@Test
public void testLoadIndex_noIndex() throws Exception {
    final File featureFile = new File(getToolTestDataDir(), "test_variants_for_index.noIndex.vcf");
    final Index index = IndexUtils.loadTribbleIndex(featureFile);
    Assert.assertNull(index);
}
Also used : Index(htsjdk.tribble.index.Index) File(java.io.File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 22 with Index

use of htsjdk.tribble.index.Index in project gatk by broadinstitute.

the class IndexUtilsUnitTest method testLoadIndexAcceptOldIndex.

@Test
public void testLoadIndexAcceptOldIndex() throws Exception {
    final File featureFile = new File(getToolTestDataDir(), "test_variants_for_index.newerThanIndex.vcf");
    final File featureFileIdx = new File(getToolTestDataDir(), "test_variants_for_index.newerThanIndex.vcf.idx");
    final File tmpDir = BaseTest.createTempDir("testLoadIndexAcceptOldIndex");
    final Path tmpFeatureFilePath = tmpDir.toPath().resolve(featureFile.toPath().getFileName());
    final Path tmpFeatureFileIdxPath = tmpDir.toPath().resolve(featureFileIdx.toPath().getFileName());
    Files.copy(featureFile.toPath(), tmpFeatureFilePath);
    Files.copy(featureFileIdx.toPath(), tmpFeatureFileIdxPath);
    final File tmpVcf = tmpFeatureFilePath.toFile();
    //wait a second
    Thread.sleep(1000L);
    //touch the file but not the index
    tmpFeatureFilePath.toFile().setLastModified(System.currentTimeMillis());
    final Index index = IndexUtils.loadTribbleIndex(tmpVcf);
    Assert.assertNotNull(index);
//this should NOT blow up (files newer than indices are tolerated)
}
Also used : Path(java.nio.file.Path) Index(htsjdk.tribble.index.Index) File(java.io.File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 23 with Index

use of htsjdk.tribble.index.Index in project gatk-protected by broadinstitute.

the class AnnotateTargetsIntegrationTest method createTargetFile.

@BeforeClass
public void createTargetFile() throws IOException {
    final SAMSequenceDictionary referenceDictionary = resolveReferenceDictionary();
    final List<SimpleInterval> targetIntervals = createRandomIntervals(referenceDictionary, NUMBER_OF_TARGETS, MIN_TARGET_SIZE, MAX_TARGET_SIZE, MEAN_TARGET_SIZE, TARGET_SIZE_STDEV);
    final List<Target> targets = targetIntervals.stream().map(Target::new).collect(Collectors.toList());
    TargetWriter.writeTargetsToFile(TARGET_FILE, targets);
    final Index index = IndexFactory.createIndex(TARGET_FILE, new TargetCodec(), IndexFactory.IndexType.LINEAR);
    final LittleEndianOutputStream stream = new LittleEndianOutputStream(new FileOutputStream(TARGET_FILE_IDX));
    index.write(stream);
    stream.close();
}
Also used : LittleEndianOutputStream(htsjdk.tribble.util.LittleEndianOutputStream) TargetCodec(org.broadinstitute.hellbender.utils.codecs.TargetCodec) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Index(htsjdk.tribble.index.Index) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) BeforeClass(org.testng.annotations.BeforeClass)

Example 24 with Index

use of htsjdk.tribble.index.Index in project gatk by broadinstitute.

the class IndexFeatureFileIntegrationTest method testGVCFTreatedAsVCFIndex.

@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
    final File ORIG_FILE = getTestFile("test_variants_for_index.gvcf_treated_as_vcf.vcf");
    final File outName = createTempFile("test_variants_for_index.gvcf_treated_as_vcf.vcf.", ".idx");
    final String[] args = { "--feature_file", ORIG_FILE.getAbsolutePath(), "-O", outName.getAbsolutePath() };
    final Object res = this.runCommandLine(args);
    Assert.assertEquals(res, outName.getAbsolutePath());
    final Index index = IndexFactory.loadIndex(res.toString());
    Assert.assertTrue(index instanceof LinearIndex);
    Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1"));
    checkIndex(index, Arrays.asList("1"));
}
Also used : LinearIndex(htsjdk.tribble.index.linear.LinearIndex) Index(htsjdk.tribble.index.Index) TabixIndex(htsjdk.tribble.index.tabix.TabixIndex) File(java.io.File) LinearIndex(htsjdk.tribble.index.linear.LinearIndex) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 25 with Index

use of htsjdk.tribble.index.Index in project gatk by broadinstitute.

the class IndexFeatureFileIntegrationTest method testBedIndex.

private void testBedIndex(final File ORIG_FILE, final Class<? extends Index> indexClass) {
    final File outName = createTempFile(ORIG_FILE.getName(), (indexClass == TabixIndex.class) ? TabixUtils.STANDARD_INDEX_EXTENSION : ".idx");
    final String[] args = { "--feature_file", ORIG_FILE.getAbsolutePath(), "-O", outName.getAbsolutePath() };
    final Object res = this.runCommandLine(args);
    Assert.assertEquals(res, outName.getAbsolutePath());
    final Index index = IndexFactory.loadIndex(res.toString());
    Assert.assertTrue(indexClass.isInstance(index));
    for (int chr : new int[] { 1, 2, 4 }) {
        //note: unusual loop
        Assert.assertTrue(index.containsChromosome(String.valueOf(chr)), String.valueOf(chr));
    }
    for (int chr : new int[] { 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 }) {
        //note: unusual loop
        Assert.assertFalse(index.containsChromosome(String.valueOf(chr)), String.valueOf(chr));
    }
    for (final String chr : Arrays.asList("X", "Y", "MT")) {
        Assert.assertFalse(index.containsChromosome(chr), String.valueOf(chr));
    }
    Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1", "2", "4"));
}
Also used : TabixIndex(htsjdk.tribble.index.tabix.TabixIndex) LinearIndex(htsjdk.tribble.index.linear.LinearIndex) Index(htsjdk.tribble.index.Index) TabixIndex(htsjdk.tribble.index.tabix.TabixIndex) File(java.io.File)

Aggregations

Index (htsjdk.tribble.index.Index)29 File (java.io.File)20 Test (org.testng.annotations.Test)15 TabixIndex (htsjdk.tribble.index.tabix.TabixIndex)12 LinearIndex (htsjdk.tribble.index.linear.LinearIndex)9 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)8 IOException (java.io.IOException)7 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)7 BlockCompressedOutputStream (htsjdk.samtools.util.BlockCompressedOutputStream)3 TabixIndexCreator (htsjdk.tribble.index.tabix.TabixIndexCreator)3 VCFCodec (htsjdk.variant.vcf.VCFCodec)3 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)2 LineIterator (htsjdk.tribble.readers.LineIterator)2 LittleEndianOutputStream (htsjdk.tribble.util.LittleEndianOutputStream)2 IndexFeatureFile (org.broadinstitute.hellbender.tools.IndexFeatureFile)2 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)2 TargetCodec (org.broadinstitute.hellbender.utils.codecs.TargetCodec)2 BeforeClass (org.testng.annotations.BeforeClass)2 LocationAwareOutputStream (com.github.lindenb.jvarkit.io.LocationAwareOutputStream)1 BedLine (com.github.lindenb.jvarkit.util.bio.bed.BedLine)1