Search in sources :

Example 21 with VCFCodec

use of htsjdk.variant.vcf.VCFCodec 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

VCFCodec (htsjdk.variant.vcf.VCFCodec)21 LineIterator (htsjdk.tribble.readers.LineIterator)12 VariantContext (htsjdk.variant.variantcontext.VariantContext)12 VCFHeader (htsjdk.variant.vcf.VCFHeader)11 File (java.io.File)11 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)6 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)5 PositionalBufferedStream (htsjdk.tribble.readers.PositionalBufferedStream)4 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)3 Index (htsjdk.tribble.index.Index)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 StructuralVariantFactory (com.hartwig.hmftools.common.variant.structural.StructuralVariantFactory)2 GenomicsDBFeatureReader (com.intel.genomicsdb.GenomicsDBFeatureReader)2 BlockCompressedInputStream (htsjdk.samtools.util.BlockCompressedInputStream)2 BlockCompressedOutputStream (htsjdk.samtools.util.BlockCompressedOutputStream)2 CloseableIterator (htsjdk.samtools.util.CloseableIterator)2 AbstractFeatureReader (htsjdk.tribble.AbstractFeatureReader)2 FeatureReader (htsjdk.tribble.FeatureReader)2 BCF2Codec (htsjdk.variant.bcf2.BCF2Codec)2