samtools tips

To calculate the total number of reads in a bam file:

$samtools view -c mapping.bam
119244250

To calculate only mapped reads:

$samtools view -c -F 4 mapping.bam
103642171

Here “-F 4” is the flag used in the sam format. Similarly we can use “-f 4” to get the number of unmapped reads.

$samtools view -f4 mapping.bam
15602079

The sum of the mapped and unmapped reads equals the total reads:

$echo "103642171 + 15602079" |bc
119244250
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s