Thursday, August 21, 2014

Filter BAM alignments for unmapped pairs

Next up we create three filter categories for:
  1. An unmapped read whose mate is mapped.
  2. A mapped read who's mate is unmapped
  3. Both reads of the pair are unmapped
These categories translate to the following filtering commands:
samtools view -u  -f 4 -F264 alignments.bam  > tmps1.bam
samtools view -u -f 8 -F 260 alignments.bam  > tmps2.bam
samtools view -u -f 12 -F 256 alignments.bam > tmps3.bam
The above step will work on sorted or unsorted BAM files.
We then merge these temporary bam files and sort into read name order. The sort is required to get the mates into the correct order.
samtools merge -u - tmps[123].bam | samtools sort -n - unmapped

No comments:

Post a Comment