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.
Hi all, 

I found the answer to this issue, its a very simple fix. Sorry for replying so late. Got busy with some other stuff and totally forgot to reply. Anyways, if one wants to select regions outside of a given region, you can use -U option, but as I said earlier it doesnt work with the range specified on command line. But if you give a bedfile containing the region ad then provide -U option, it will work. 

For example:
Create bedfile  (my.bed):
2       33050509        33154206        LINC00486
and now use this bedfile to extract region other than the ones in the given bedfile by:
$samtools view  sample.bam -L my.bed -U without-bed > /dev/null

To my knowledge with this approach, a read that has even a single base in the specified region gets counted as within region, the read just need to span over either of the start or stop of the region (even if its a single base). 

Let me know if you have any questions.

Thanks.