Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for finding regions overlapped by two different IntervalTrees #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ssadedin
Copy link

@ssadedin ssadedin commented May 9, 2015

This change adds a function for finding the common regions between two interval trees. That is, the intervals in the result are the ranges where at least one interval in both trees overlap each other.

splits = (self | other)
splits.split_overlaps()
self_int_other = IntervalTree(filter(lambda r: self.overlaps(r) and other.overlaps(r), splits))
self_int_other.merge_overlaps()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that the overlaps have to be merged? This causes a new tree to be created a second time, which is O(nlogn).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly, I was after API compatibility with the R functions that do the same thing (in this case, IRanges intersect() function - unfortunately 'intersect' is already used with different semantics in this library). My own use case for this kind of function always involves merging because I want to do computations on the parts in common between two sets of ranges, and I rarely want to do that computation on the same interval twice, so merging makes sense. I can imagine there could be uses where that's not the case. I tend to port a lot of code b/w R and python so having something that behaves the same way between the two was useful to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants