findOverlaps - how to get adjacent ranges?
1
0
Entering edit mode
Last seen 5.0 years ago

Hi there,

I am trying to locate a function that finds pairs of adjacent ranges - ranges where the end of range A is exactly start-1 of range B. Example with 3 ranges:

AAAAABBBBBCCCCC

pair 1 AAAAA BBBBB

pair 2 BBBBB CCCCC

I thought that would be possible using findOverlaps() or findOverlapPairs() in the IRanges package, but the type argument only lets me select

type=c("any", "start", "end", "within", "equal")

so I can either compare the start pos., the end or both,  but I cannot find a way to compare start vs. end.

Is there really no way to do this with the current functions?

Greetings,

Tobi

findOverlaps IRanges • 777 views
0
Entering edit mode
@michael-lawrence-3846
Last seen 5 months ago
United States

There's always the option of finding all overlaps, and then filtering them. By setting maxgap=1L, adjacent ranges will be considered overlapping. Then, just filter the result for those that are adjacent:

p <- findOverlapPairs(a, b, maxgap=1L)
subset(p, start(first) == end(second) + 1L | end(first) == start(second) - 1L)