Please help me find the number of mapped reads from a bam file. I was going through forums and tutorials. Looking at samtools flagstat resulted the following:
My total read count is 413,033. So, I understand 453,800 to be number of alignments. Now, is it that 391,696 reads mapped? According to this tutorial, Yes.
1)samtools flagstat file.sorted.bam
453800 + 0 in total (QC-passed reads + QC-failed reads)
0 + 0 duplicates
391696 + 0 mapped (86.31%:-nan%) 0 + 0 paired in sequencing
0 + 0 read1
0 + 0 read2
0 + 0 properly paired (-nan%:-nan%)
0 + 0 with itself and mate mapped
0 + 0 singletons (-nan%:-nan%)
0 + 0 with mate mapped to a different chr
0 + 0 with mate mapped to a different chr (mapQ>=5)
Found this another explanation at this page. It says 391,696 is the number of locations that reads mapped. A number same as flagstat is giving us above and the number of mapped reads are 413,033 same as my original fasta sequence number. Check commands below.
2) Number of Mapped locations:
samtools view -F 0x04 -c file.sorted.bam
3) Number of Mapped reads:
samtools view -F 0x40 file.sorted.bam | cut -f1 | sort | uniq | wc -l
Could I please know, which one, should I follow to find the number of reads that mapped the reference from my original fasta file? Suppose the reads are to be single end. I would thankful to your explanations.