How to use .tbi index for looking through .vcf file?
1
0
Entering edit mode
9.1 years ago
timofeevbog ▴ 30

I've got this code for creating my .tbi index file: (inputFile is my .vcf File)

VCFFileReader vcfReader = new VCFFileReader(inputFile, false);
TabixIndexCreator creator = new TabixIndexCreator(new TabixFormat().VCF);
int I = 0;
for (VariantContext context : vcfReader) {
    creator.addFeature(context, i);
    i++;
}
vcfReader.close();
creator.finalizeIndex(i).writeBasedOnFeatureFile(inputFile);

After that I try to iterate throw my my .vcf file using next construction:

VCFFileReader vcfReader2 = new VCFFileReader(inputFile, new File(inputFile.getAbsolutePath() + ".tbi"));
CloseableIterator iter = vcfReader2.query("gi|448814763|ref|NC_000962.3|", 1, 5);

and iter.hasNext() is false, though I've got this in my .vcf file.

Thanks

vcf index • 3.4k views
ADD COMMENT
0
Entering edit mode

I have a similar problem. I have a .tbi file and I want to use it to access my vcf file. I have this code:

VCFFileReader fileR= new VCFFileReader(new File("ex.vcf"), new File("ex.gz.tbi"), true);
VCFHeader fileHeader = fileR.getFileHeader();
VCFRecordCodec recCodec = new VCFRecordCodec(fileHeader);

TabixIndex tic = new TabixIndex("ex.gz.tbi"); 
BlockCompressedInputStream inputStream = new BlockCompressedInputStream("ex.gz"); 
long p = 0; 

String rrline = inputStream.readLine();

while(rrline!=null){
    System.out.println("LINE: " + rrline);
    p = inputStream.getFilePointer();
    rrline = inputStream.readLine();
}

I don't know how to use TabixIndex and BlockCompressedInputStream. Maybe the problem is that I don't understand what they are and what they do.

ADD REPLY
2
Entering edit mode
9.1 years ago

The way you use TabixIndexCreator is not correct. You must read/write the vcf file using a BlockCompressedInputStream/BlockCompressedOutputStream

The second argument of creator.addFeature is not the nth index but the virtual pointer location.

See https://github.com/shenkers/ComparativeBrowser/blob/f75f6fcb23e2fa4d7b5ae42f9e33cd0b99b2046c/src/test/java/htsjdk/samtools/tabix/IndexingFeatureWriterNGTest.java for a example.

ADD COMMENT

Login before adding your answer.

Traffic: 1814 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