How to create .tbi index file?
2
3
Entering edit mode
9.1 years ago
timofeevbog ▴ 30

How can I create tabix .tbi index file for some .vcf file using java (htsjdk)?

tabix • 4.6k views
ADD COMMENT
3
Entering edit mode
9.1 years ago

Use a TabixIndexCreator

ADD COMMENT
0
Entering edit mode
8.0 years ago

Use createLinearIndex,

"a helper method for creating a linear binned index with default bin size"

http://samtools.github.io/htsjdk/javadoc/htsjdk/htsjdk/tribble/index/IndexFactory.html

static LinearIndex  createLinearIndex(java.io.File inputFile, FeatureCodec codec)

with a VCFCodec as FeatureCodec type parameter:

http://samtools.github.io/htsjdk/javadoc/htsjdk/htsjdk/variant/vcf/VCFCodec.html

and write it as in IGVtools.java writeTribbleIndex method:

public static void writeTribbleIndex(Index idx, String idxFile) throws IOException {
        LittleEndianOutputStream stream = null;
        try {
            stream = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile)));
            idx.write(stream);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            // Delete output file as its probably corrupt
            File tmp = new File(idxFile);
            if (tmp.exists()) {
                tmp.delete();
            }
        } finally {
            if (stream != null) {
                stream.close();
            }
        }
    }
ADD COMMENT

Login before adding your answer.

Traffic: 1793 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6