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 568345 # counting only mapped (primary aligned) reads samtools view -c -F 260 SAMPLE.bam 345623 options -c count reads and print the total number -f bitcode output reads that fulfill the checked 'bitcode' criteria, see SAM bitcode fields -F bitcode exclude reads that match one or more checked 'bitcode' criteria, see SAM bitcode fields -F 260 output primary aligned mapped reads read unmapped & not primary alignment criteria 3 & 9 are selected for exclusion bit 3 + bit 9 = 4 + 256 = 260 decode SAM bitcode flag number (meaning of flag bits) http://broadinstitute.github.io/picard/explain-flags.html |