I have two GRanges objects. I would like to calculate distances between specific items in one to specific items in the other. For example, I have genes and peaks and I want to get distances between them. Is there a good way to do that?
GenomicRanges::distance, but that expects a single range. I tried using that and it works fine for individual pairs of ranges. However, iterating through all the combinations takes a really long time. Using
apply or multi-threaded
foreach is still slow (more than a day for a million pairs). This can't be the proper way.
I am familiar with
GenomicRanges::distanceToNearest and that works when you are comparing two GRanges objects, but it only returns the nearest hit.
So is there an efficient way to determine distances between items in two GRanges?