I want to extract all reads from a bam file that have the orientation R2F1, as in the following image:
.
I have try to do this with samtools or pysam and I have not been able. I have seen in other posts some scripts for doing this with C++ or java, but, besides I don't know how to code in this languages, I want this to be a part of a larger script in python/bash, and thus, it will be great to have it in python/bash
I have try both samtools and pysam. With samtools, I have try to extract them using the bitwise flag (145 flag) but the output is not the expected one, it includes reads supporting inversions (<- <-, FF orientation). With pysam,l I have tried the following, with very few reads in the output (not expected):
for read in bam.fetch('chr1',195411284,195423136):
if read.is_reverse == True and read.is_second == True:
if read.mate_is_reverse == False:
#save the read and its mate to file
Also, I have tried using gridss ExtractSVreads, but it includes reads that support inversions (<- <-, FF orientation), which I don't want.
What did you try with samtools or pysam? Or you haven't been able to try at all?
I would not have asked if I haven't tried :)
I have try both samtools and pysam. With samtools, I have try to extract them using the bitwise flag (145 flag) but the output is not the expected one, it includes reads supporting inversions (<- <-, FF orientation). With pysam,l I have tried the following, with very few reads in the output (not expected):
Also, I have tried using gridss ExtractSVreads, but it includes reads that support inversions (<- <-, FF orientation), which I don't want.
Thanks