I had my mRNA seq reads aligned by my institutions core faciltiiy and I attempted it myself using Hisat2 and cufflinks. Throughout my process, I didn't seem to require a bam.bai file. However, my core facility sent me one with all of my data. What sorts of programs is the bam.bai used for?
I understand that the bai file is sort of a table of contents for the bam file, I just don't understand its utility.
.bai files are used by genome viewers (e.g. IGV/IGB etc). If you want to jump from displaying Chr 1 to Chr 13 in a sorted BAM file (which can be GB in size) you don't want to have to read that entire file to locate the place where the chromosome of your interest starts.
For some applications, you need to seek to some genome position from a sorted bam file, you need an index file, which stores the BAM file offsets of genome positions.
Note that BAM is actually made of a list of small zip packs. Each pack has different sizes, that makes random access directly by calculating file offset not possible. That's why you need a BAI for random access.