Search in sources :

Example 26 with Index

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

the class IndexFeatureFileIntegrationTest method testSAMPileupGZIndex.

@Test
public void testSAMPileupGZIndex() {
    // made with bgzip
    final File ORIG_FILE = getTestFile("test_sampileup_for_index.pileup.gz");
    final File outName = createTempFile(ORIG_FILE.getName(), TabixUtils.STANDARD_INDEX_EXTENSION);
    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 TabixIndex);
    for (int chr : new int[] { 1, 2, 3, 4 }) {
        //note: unusual loop
        Assert.assertTrue(index.containsChromosome(String.valueOf(chr)), String.valueOf(chr));
    }
    for (int chr : new int[] { 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", "3", "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) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 27 with Index

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

the class IndexFeatureFileIntegrationTest method testVCFGZIndex_tabix.

@Test
public void testVCFGZIndex_tabix() {
    //made by bgzip
    final File ORIG_FILE = getTestFile("test_variants_for_index.vcf.blockgz.gz");
    final File outName = createTempFile("test_variants_for_index.blockgz.gz.", TabixUtils.STANDARD_INDEX_EXTENSION);
    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 TabixIndex);
    Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1", "2", "3", "4"));
    checkIndex(index, Arrays.asList("1", "2", "3", "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) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 28 with Index

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

the class IndexFeatureFileIntegrationTest method testVCFIndex_inferredName.

@Test
public void testVCFIndex_inferredName() {
    final File ORIG_FILE = getTestFile("test_variants_for_index.vcf");
    final String[] args = { "--feature_file", ORIG_FILE.getAbsolutePath() };
    final Object res = this.runCommandLine(args);
    final File tribbleIndex = Tribble.indexFile(ORIG_FILE);
    Assert.assertEquals(res, tribbleIndex.getAbsolutePath());
    tribbleIndex.deleteOnExit();
    final Index index = IndexFactory.loadIndex(res.toString());
    Assert.assertTrue(index instanceof LinearIndex);
    Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1", "2", "3", "4"));
    checkIndex(index, Arrays.asList("1", "2", "3", "4"));
}
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 29 with Index

use of htsjdk.tribble.index.Index in project jvarkit by lindenb.

the class KnimeVariantHelper method indexVcfFile.

/**
 * index a vcf file is needed
 */
public void indexVcfFile(final File file) throws IOException {
    IOUtil.assertFileIsReadable(file);
    if (file.getName().endsWith(".vcf.gz")) {
        LOG.info("writing tabix index for " + file);
        final File output = new File(file.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION);
        try {
            if (output.exists()) {
                getLogger().info("Tabix index " + output + " already exists.");
                return;
            }
            final TabixIndex index = IndexFactory.createTabixIndex(file, new VCFCodec(), (SAMSequenceDictionary) null);
            index.write(output);
        } catch (final Exception err) {
            LOG.error(err);
            throw new IOException(err);
        }
    } else if (file.getName().endsWith(".vcf")) {
        LOG.info("writing tribble index for " + file);
        final File output = new File(file.getAbsolutePath() + Tribble.STANDARD_INDEX_EXTENSION);
        try {
            if (output.exists()) {
                getLogger().info("Tribble index " + output + " already exists.");
            }
            final Index index = IndexFactory.createIndex(file, new VCFCodec(), IndexType.LINEAR);
            index.writeBasedOnFeatureFile(file);
        } catch (final Exception err) {
            LOG.error(err);
            throw new IOException(err);
        }
    } else {
        throw new IOException("Cannot index VCF file " + file);
    }
}
Also used : VCFCodec(htsjdk.variant.vcf.VCFCodec) TabixIndex(htsjdk.tribble.index.tabix.TabixIndex) TabixIndex(htsjdk.tribble.index.tabix.TabixIndex) Index(htsjdk.tribble.index.Index) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

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