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

Adding new intervals to a contig after querying for intersections does not work. #40

Open
TedBrookings opened this issue Nov 21, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@TedBrookings
Copy link

The OverlapDetector has an issue that its intervaltree must be indexed before any overlaps can be checked, however the cgranges object it is based on will only index once (it checks if it's already indexed and skips a second call).

This results in a bug where adding new intervals to the tree does not result in them being returned for overlap checks.

detector = OverlapDetector()
detector.add(Interval("chr1", 100, 200, name="foo"))
detector.get_overlaps(Interval("chr1", 100, 200))
# yields "foo"
detector.add(Interval("chr1", 101, 201, name="bar"))
detector.get_overlaps(Interval("chr1", 100, 200))
# still only yields "foo"
@TedBrookings TedBrookings added the bug Something isn't working label Nov 21, 2024
@TedBrookings
Copy link
Author

I can confirm that superintervals does not have this problem. IntervalSet (supposedly, see below) must be re-indexed when new intervals are added, but pybedlite OverlapDetector already does this. superintervals.IntervalSet actually performs the reindex. It looks like a relatively easy fix to replace cgranges:

  • IntervalSet add intervals with a start, end, and value, and the value could be set to the index in refname_to_intervals. Then the logic is very similar.
  • IntervalSet uses closed intervals, so I think we'd want to add 1 to start in order to maintain backwards compatibility

example:

iset = superintervals.IntervalSet()
iset.add(100, 200, 0)
iset.index()
iset.find_overlaps(100, 200)
# returns [0]
iset.add(100, 200, 1)
iset.index()
iset.find_overlaps(100, 200)
# returns [1, 0]

In my testing this worked even without reindexing. Since in the README it claims indexing is required, I would keep it just to be safe.

@TedBrookings TedBrookings self-assigned this Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant