1. James Taylor
  2. bx-python
  3. Issues
Issue #32 new

Extending IntervalTree.find

vineeth_s
created an issue

While Interval//s// have chrom and strand attributes, these cannot be used within the find on an IntervalTree. One could traverse the list filtering for chrom and strand, and then on a newly created IntervalTree do the find.

Would it not be more elegant to extend find ?

Comments (1)

  1. Brent Pedersen

    This was previously supported by an additional class that would send incoming intervals into sub-trees after looking at the chromosome. I think that's a better solution that filtering through the results in find. It's fairly simple to do this on your own. e.g. something like (untested):

    class ChromTree:
        def __init__(self):
            self.trees = collections.defaultdict(IntervalTree)
    
        def insert_interval(self, interval):
            return self.trees[interval.chrom].insert_interval(interval)
    
        def find(self, start, end, chrom):
            return self.trees[chrom].find(start, end)
    
  2. Log in to comment