Does bai file contain chromosome names and their lengths?
1
1
Entering edit mode
3.6 years ago
Nowlan Freese ▴ 860

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

bai index • 1.6k views
ADD COMMENT
2
Entering edit mode

The header of the bam contains that information.

ADD REPLY
2
Entering edit mode

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.

ADD REPLY
1
Entering edit mode

As how to do it in practice, this thread may be relevant Make bam index human readable

ADD REPLY
0
Entering edit mode

I found the make bam index human readable thread to be very useful for exploring BAI files, especially Pierre Lindenbaum's tool for dumping the BAI as XML. In looking at the output of Pierre's tool, it does include the names and lengths of the chromosomes, but they are pulled from the bam header, not the BAI file. This fits with John Marshall's answer below.

ADD REPLY
6
Entering edit mode
3.6 years ago

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).

ADD COMMENT
2
Entering edit mode

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

ADD REPLY
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

Thank you John!

ADD REPLY

Login before adding your answer.

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