Hi,
I have a GRanges object und would like to retrieve sets of reciprocal overlaps:
library(GenomicRanges) gr = GRanges(seqnames = rep("chr1",4), ranges = IRanges(start = c(1,2,3,8), end = c(12,6,6,10)), strand = rep("+", 4)) > gr GRanges object with 4 ranges and 0 metadata columns: seqnames ranges strand <Rle> <IRanges> <Rle> [1] chr1 [1, 12] + [2] chr1 [2, 6] + [3] chr1 [3, 6] + [4] chr1 [8, 10] + -------
Range #1 overlaps with all other ranges, however I would like to get only those overlaps which hold in a transitive manner. such as: Range #1 overlaps with #2, #2 with #3 and #3 with #1.
At the moment I am filtering the output of findOverlaps (unsatisfactorily with the help of a loop..). Is there a more direct way to do this?
Many thanks for any comments,
Stefanie
I'll note that RBGL package has a transitive.closure function that operates on various types
of graph defined in the graph package. Transforming the range data into a graph for this purpose
doesn't seem particularly hard, but in a naive approach there would be pairwise testing.
Thanks for pointing out the graph perspective. I will consider to reformulate the problem in this context!
What a neat, elegant way :) thanks a lot!
I wish all my posts were associated with "neat" and "elegant"--thanks!