It is rather easy to extract the reads corresponding to a specific chromosome from a BAM file using SAMtools.
First we create the index file (BAI) for the BAM file with the following command:
samtools index HG00096.bam
The previous command will generate the file
Then we extract the data for specific region, for example chromosome 20.
samtools view -h HG00096.bam chr20 > HG00096.chr20.sam
(For Illumina BAM files, for example the ones from 1000 Genome Project, use only ’20’, without ‘chr’)
If we need to have a BAM file intsead of a SAM file, we can convert the SAM to BAM with:
samtools view -bS HG00096.chr20.sam > HG00096.chr20.bam