Search in sources :

Example 6 with Index

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

the class IndexUtilsUnitTest method testLoadIndex.

@Test(dataProvider = "okFeatureFiles")
public void testLoadIndex(final File featureFile) throws Exception {
    final Index index = IndexUtils.loadTribbleIndex(featureFile);
    Assert.assertNotNull(index);
}
Also used : Index(htsjdk.tribble.index.Index) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 7 with Index

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

the class IndexUtilsUnitTest method testFailLoadTabixIndex.

@Test(dataProvider = "failTabixIndexFiles")
public void testFailLoadTabixIndex(final File featureFile) throws Exception {
    final Index index = IndexUtils.loadTabixIndex(featureFile);
    Assert.assertNull(index);
}
Also used : Index(htsjdk.tribble.index.Index) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 8 with Index

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

the class IndexFeatureFile method doWork.

@Override
protected Object doWork() {
    if (!featureFile.canRead()) {
        throw new UserException.CouldNotReadInputFile(featureFile);
    }
    // Get the right codec for the file to be indexed. This call will throw an appropriate exception
    // if featureFile is not in a supported format or is unreadable.
    final FeatureCodec<? extends Feature, ?> codec = new ProgressReportingDelegatingCodec<>(FeatureManager.getCodecForFile(featureFile), ProgressMeter.DEFAULT_SECONDS_BETWEEN_UPDATES);
    final Index index = createAppropriateIndexInMemory(codec);
    final File indexFile = determineFileName(index);
    try {
        index.write(indexFile);
    } catch (final IOException e) {
        throw new UserException.CouldNotCreateOutputFile("Could not write index to file " + indexFile.getAbsolutePath(), e);
    }
    logger.info("Successfully wrote index to " + indexFile.getAbsolutePath());
    return indexFile.getAbsolutePath();
}
Also used : ProgressReportingDelegatingCodec(org.broadinstitute.hellbender.utils.codecs.ProgressReportingDelegatingCodec) Index(htsjdk.tribble.index.Index) TabixIndex(htsjdk.tribble.index.tabix.TabixIndex) IOException(java.io.IOException) UserException(org.broadinstitute.hellbender.exceptions.UserException) File(java.io.File)

Example 9 with Index

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

the class IndexUtils method loadIndex.

/**
     * Loads and returns the index of the feature file or null if there is no index.
     * First it tries to load the tribble index and then to load the tabix index.
     */
public static Index loadIndex(final File featureFile) {
    Utils.nonNull(featureFile);
    final Index tribbleIndex = loadTribbleIndex(featureFile);
    if (tribbleIndex != null) {
        return tribbleIndex;
    }
    final Index tabixIndex = loadTabixIndex(featureFile);
    if (tabixIndex != null) {
        return tabixIndex;
    }
    return null;
}
Also used : Index(htsjdk.tribble.index.Index)

Example 10 with Index

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

the class IndexUtils method loadTribbleIndex.

/**
     * Load a Tribble .idx index from disk, checking for out of date indexes and old versions
     * @return an Index, or null if we're unable to load
     */
public static Index loadTribbleIndex(final File featureFile) {
    Utils.nonNull(featureFile);
    final File indexFile = Tribble.indexFile(featureFile);
    if (!indexFile.canRead()) {
        return null;
    }
    logger.debug("Loading Tribble index from disk for file " + featureFile);
    try {
        final Index index = IndexFactory.loadIndex(indexFile.getAbsolutePath());
        checkIndexVersionAndModificationTime(featureFile, indexFile, index);
        return index;
    } catch (final RuntimeException e) {
        return null;
    }
}
Also used : Index(htsjdk.tribble.index.Index) File(java.io.File) IndexFeatureFile(org.broadinstitute.hellbender.tools.IndexFeatureFile)

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