This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to filter bam file for only reads that span certain regions of the genome?

Hello, is there a tool that can find only the reads that span the entire section(s) that I am interested in. Ideally I would just need a sorted and indexed bam file and a bed file with the regions that I am interested in and it would output a new bam with just the reads of interest. I do not think that bedtools intersect would get me what I want, though I would be happy if someone could explain what arguments I might need if it can do what I want.

I want only the reads that span the entire region(s) of interest, as I am looking at highly repetitive regions using long read sequencing technologies.

Just checking in before I go ahead and make such a tool...

Thanks!

edit: it is possible that the bedtools intersect flag -f can let me do this, reading more now... "-f Minimum overlap required as a fraction of A. Default is 1E-9 (i.e. 1bp)." if I set f to a value of 1, it should only include reads that capture the entire region. I will continue to report back

reference-genome bam sam bedtools

Thank you for the quick reply, but I believe that solution will include partial reads that are at that location. I want only reads that span the entire region(s) to build a consensus from. I have the read depth for it.

1 answer

How about this: Does samtools view only show reads that completely span the region?

Log in to answer this question.