Hi all,
I know this may sound simple, but I am really having trouble finding a way how to extract reads that fall outside a give region. I tried the -U option but it doesnt work (or maybe I am not using it correctly). I didn't find any example either which uses -U option of samtools view.
I am using this command: $samtools view sample.bam 2:33050509-33154206 -U without-region.sam
This is paired end data and I want to retain the other paired read that falls outside the region, therefore grepping reads other than the one in my specified region, wont work either.
Thanks in advance.
If you want to keep pairs then you'll need to write a script to do this. I'd recommend doing it in python with pysam.
Thanks Devon, I think that's the only way to go.
Out of curiosity, how much do you really lose if you follow your current approach? How strict are you, i.e. if single base falls in the region would you remove the read?
Please have a look at How to extract reads in a specific region from a BAM file and also their mates mapped elsewhere ? and at Extract reads within given region, and their mates
In concept, they are asking the opposite, but have the same concern... maybe it helps!