Read Binary Sequence Alignment/Map Index (BAI) file
Index = bamindexread(File)
Index = bamindexread(File) reads File, a BAI file, and returns Index, a MATLAB® structure that specifies the offsets into the compressed Binary Sequence Alignment/Map (BAM) file and decompressed data block for each reference sequence and range of positions (bins) on each reference sequence.
String specifying a file name, or a path and a file name, of a BAM file or a BAI file. If File is a BAM file, bamindexread reads the corresponding BAI file, that is, the BAI file with the same root name and stored in the same folder as the BAM file. If you specify only a file name, that file must be on the MATLAB search path or in the Current Folder.
MATLAB array of structures that specifies the offsets into the compressed Binary Sequence Alignment/Map (BAM) file and decompressed data block for each reference sequence and range of positions (bins) on the reference sequence. Index contains the following fields.
The bamread function uses the Index structure returned by bamindexread to index into a BAM file to extract alignment records in a specified range of a specific reference sequence. Passing the Index structure array to the bamread function improves performance when reading from the same BAM file multiple times, for example, when reading different ranges of a reference sequence.
 Li, H., Handsaker, B., Wysoker, A., Fennell, T., Ruan, J., Homer, N., Marth, G., Goncalo, A., and Durbin, R. (2009). The Sequence Alignment/Map format and SAMtools. Bioinformatics 25, 16, 2078–2079.