This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Does bai file contain chromosome names and their lengths?

Can the chromosome names and lengths to which a bam file was aligned be determined solely from its bai file?

bai index

The header of the bam contains that information.

That is not what OP is asking though. Based on the SAM specs section 5.2 these information should (I guess) be in the index but I do not have a strategy ready to extract them. https://samtools.github.io/hts-specs/SAMv1.pdf ok see answer below.

1 answer

No. The BAI format is described in §5.2 of SAMv1.pdf and does not contain the chromosome names or lengths. Instead it merely identifies reference sequences by their index, 0 <= n < n_ref, in the corresponding BAM file's (binary) header.

The CSI format operates similarly.

The Tabix format OTOH does contain the names of reference sequences (but not their lengths).

John Marshall is one of the SAMtools maintainers so we can accept this answer as the "correct" one.

I am at present one of the editors of the SAM specification and a former SAMtools maintainer. But in fact this answer, like any other, should be accepted as correct or not based on its own merits, not its author — I included links to the various specifications precisely so that the claims made can be verified, and as references for further detail.

Log in to answer this question.