Thursday, May 29, 2014

samtools flagstat won't output the number of reads mapped

I have been using samtools flagstat to get statistics summary of my BAM/SAM file, like many tutorial suggested (e.g. Dave Tang's note).

But then I noticed that flagstat reports the number of mapping (or alignments/hits, whatever you like to call), but not the number of reads mapped. This can be very different if your alignment contains multiple mappers (and this is especially true if you use default setting or without setting "-g 1" in Tophat). To get the number of reads mapped (e.g. in order to get mappability), you can use the following command:

samtools view -cF 0x100 accepted_hits.bam

Note: Even with multiple mappers, only one hit has flag of 0x100 in the output SAM file. I've already explained this in one of my previous posts.


  1. Hi,
    I tried the command you mentioned above (samtools view -cF 0x100 accepted_hits.bam). But I got the same number which i get with samtools flagstat. Not getting number of aligned reads.

  2. Thanks! This worked for me.

  3. Brajendra Kumar11:12 AM

    Hi Chirag, Seems like you would have set only unique alignment option with your mapping tool.