Obtain Number of PE Reads in BAM file Mapped to Each Chromosome
Given a sorted/indexed BAM file (or SAM file if that is easier) which was produced by aligning PE reads to a reference genome, how can I enumerate the:
1) number of read pairs with both reads mapping to a particular chromosome
2) number of read pairs with only one of the reads mapping to a particular chromosome
i.e. scenario #1
--R1--> <--R2--
scenario #2
--R1-->
OR
<--R2--
• 2,264 views
•
link
1 answer
1) Number of properly paired, mapped reads only on chr1:
samtools view -f 1 -F 12 -b file.bam chr1 | wc -l
2) It's possible for only first pair to be unmapped, or only second pair, so combine two commands:
samtools view -f 4 -F 264 file.bam chr1 | wc -l
samtools view -f 8 -F 260 file.bam chr1 | wc -l
Add those two output together to get total number of reads where one pair is unmapped
Change the chromosome name as needed, this example was for chr1
• 1 views
•
link
Log in to answer this question.