Extracting reads for a single chromosome from BAM/SAM file with samtools

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: