Count number of reads in a SAM/ BAM file

  1. Assuming each read consists of four lines:
    my.sam | wc -l
    
    Divide by four Note be aware of headers!
    samtools view my.bam | wc -l
    
    Divide by four, e.g. echo $((`samtools view my.bam | wc -l` / 4))
  2. Using samtools and awk:
    samtools idxstats my.bam | awk '{c+=$3+$4} END {print c}'
    
Share itShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *