This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Filter SAM file for read pairs that align on same strand

I want to filter a SAM file for read pairs that align to the same strand. That is for R1 and R2, I want the alignment to be either both on the forward strand (FF) or both on the reverse strand (RR).

I used samtools view -F 0x2 to exclude any instance where the pairs align correctly (FR) but it looks like it's still including some FR reads with short read 1 lengths.

How can I filter a SAM file to only give me read pairs that align on the same strand, either both reads on the forward strand or both reads on the reverse strand?

samtools alignment sam

1 answer

samtools view -e 'flag.paired && !flag.unmap && !flag.munmap && ((flag.reverse && flag.mreverse) || (!flag.reverse && !flag.mreverse))' in.bam

Log in to answer this question.