Tools‎ > ‎SAMtools‎ > ‎

Number of reads in bam file

How to count the number of mapped reads in a BAM or SAM file?

# get the total number of reads of a BAM file (may include unmapped and duplicated multi-aligned reads)
samtools view -c SAMPLE.bam

# counting only mapped (primary aligned) reads
samtools view -c -F 260 SAMPLE.bam

  -c  count reads and print the total number
  -f bitcode  only output reads with all bits in 'bitcode' present in the FLAG field
  -F bitcode  skip reads with bits present in 'bitcode'
  -F 260  only output reads that are not unmapped (flag 4 is not set) and only primary alignment (flag 256 is not set)

decode SAM flag field (meaning of flag bits)