Entering edit mode
I have the following ranges as GRanges data {Ranges_1}: 1-2, 2-4, 3-6, 6-8, 2-8, 8-11.
{Ranges_2} 1-5, 6-10, 11-15,
I need a mapping from Ranges1 to Ranges2. Something like following (1-2) -> (1-5), (2-4) -> (1-5), (3-6) -> (1-5) & (6-10), (5-7) -> (1-5) & (6-10), (6-8) -> (6-10), (8-11) -> (6-10) & (11-15).
Could someone please help me with the R code for this?
findOverlapPairs()
is also relevant.What if I dont want one-to-many mapping. e.g., Above there is:
Since, chr1:3-6 lies more in chr1:1-5, so , I would not like 4 chr1:3-6 chr1:6-10 in the result. Is there any elegant way of doing it?
You'll have to wait for Michael to respond if you want elegant (see above). If you want super hackification, I'm your man.
It's possible to only find the overlaps once:
Also you could find the pairs with the most overlap doing this
It may be more intuitive to use plyranges, but not sure how to do it.
One more modification:
How to drop a range which belongs to the first GRanges and does not map to any range in the second GRanges.
For such case I want the mapping to be something like:
I think that would have to be separate and Michael's more elegant method won't work?
Getting an error:
I know this is a warning, but the output is empty.
Modifying my original solution, you can exclude NA cases and subset the Hits object. Since Hits tracks the "universe" of the original input, like a factor, you can pass it to a HelloRanges utility to perform the left outer join and generate the closest thing to a NA value.
By elegant, I mean something that works and is easy to grasp ans you did that exactly. Thanks again.