Question: Can genomicranges do bedtools-like intersection operations?
0
gravatar for endrebak
10 months ago by
endrebak740
endrebak740 wrote:

In bedtools intersect means "for each read in A, for each read in B that overlaps, find the part of A that overlaps with a read in B".

So that if you have 4 reads in A and 6 reads in B and all overlap you get 4*6 results.

GenomicRanges intersect works differently; for both A and B it first clusters overlapping reads into one read and then does the intersection operation. Is it possible to get GenomicRanges intersect to work like bedtools?

Here is the input with the expected output:

head tests/f2.bed tests/f3.bed
==> tests/f2.bed <==
chr1    1   2   f   0   +
chr1    6   7   f   0   -

==> tests/f3.bed <==
chr1    3   6   h   0   +
chr1    4   7   h   0   -
chr1    5   7   h   0   -
chr1    8   9   h   0   +
biocore-home ~/c/pyranges (master DU=) bedtools intersect -a tests/f3.bed -b tests/f2.bed
chr1    6   7   h   0   -
chr1    6   7   h   0   -
R • 448 views
ADD COMMENTlink modified 10 months ago by bruce.moran600 • written 10 months ago by endrebak740

Plase give an example of the inputs and expected output.

ADD REPLYlink written 10 months ago by ATpoint15k

Try findOverlaps. You can then use GenomicRanges::reduce on a 'combined' GRanges object made from the combined set of reads (using c() works for that IIRC). With the option revmap=TRUE, you can backtrack to find which rows of the combined GRanges correspond to that region, and so that particular overlap.

If you set up a reprex I can show you how this might work.

ADD REPLYlink modified 10 months ago • written 10 months ago by bruce.moran600

Okay, thanks. I am not that interested in the actual way of doing it, I was just wondering if it was possible without hand rolling a solution. It seems like most genomicranges operations are set-like.

ADD REPLYlink written 10 months ago by endrebak740

Great, just submitted an answer to your query

ADD REPLYlink written 10 months ago by bruce.moran600

Yes, it is possible.

ADD REPLYlink written 10 months ago by bruce.moran600

I like your style, Sir!

ADD REPLYlink written 10 months ago by ATpoint15k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1765 users visited in the last hour