Entering edit mode
9.7 years ago
timofeevbog
▴
30
How can I create tabix .tbi index file for some .vcf file using java (htsjdk)?
How can I create tabix .tbi index file for some .vcf file using java (htsjdk)?
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();
}
}
}
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.