This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Is There An Elegant Way To Extract Only The Properly-Paired Reads In A Sam/Bam File?

I know I should be filtering for the following tags: 99,163,83,147 and I know that samtools would work to get all the pairs. For example: samtools view -F 0x99 -b in.bam I was wondering if there was a more elegant way to do this than running samtools four times to filter for each tag. It also occured to me, I would probably have to sort the bam files afterward to ensure that the pairs were in the same order, which means I have to run the sort function 4 times as well.

I would appreciate knowing if there was a better way to do this.

paired-end samtools

1 answer

The single command should work for all the flags you are looking for: samtools view -f 0x2 -b input.bam > output.bam

Log in to answer this question.