Hi,
Is there a library in java which allows me to read BAM index files(.bai) ?
I want to understand how the index maps to BAM files' particular location. How do I get to directly reach a particular file location to read instead of parsing from the start of the file. Please suggest a good read for this.
Is it possible to deduce a particular byte to read in the BAM file by reading the index in the BAI ?
Thank You for your help.
2 answers
The picard library implements samtools in java. For more specific information about how BAM files are indexed check out the samtools format specification.
Don't reinvent the wheel an use the picard API. see this post for a simple code. You can get an iterator for a given genomic segment using http://picard.sourceforge.net/javadoc/net/sf/samtools/SAMFileReader.html#queryOverlapping%28java.lang.String,%20int,%20int%29
the SAM specs describes the bai indexes as a bin index ( see this post)
Log in to answer this question.