Skip to main content

An interval tree data structure

Project description

# itree

`itree` is an interval tree data structure based on a self-balancing AVL binary search tree tree.
Suitable for use with sequence features in bioinformatics.

## Getting Started

* **Construction**

Creating an interval tree object:

>>> import itree
>>> t = itree.ITree()

* **Insertion**

Any item inserted into an interval tree must contain "start" and "end" attributes as integers.

>>> import collections
>>> i = collections.namedtuple('MyInterval', ['start','end'])
>>> t.insert(i(1,15))
>>> t.insert(i(3,20))
>>> t.insert(i(4,20))
>>> t.insert(i(5,15))
>>> t.insert(i(6,7))

* **Search**

Search for all intervals overlapping a given interval

[MyInterval(start=3, end=20), MyInterval(start=4, end=20), MyInterval(start=1, end=15)]

* **Removal**

Remove an interval exactly matching the given interval by its `start` and `end` attributes (but not necessarily the
same object).

>>> t.pstring()

>>> t.remove(i(1,15))
>>> t.pstring()

The `pstring` method is mostly for debugging, but here we illustrate the rebalancing of the tree.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for itree, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size itree-0.0.2-py3-none-any.whl (8.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size itree-0.0.2.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page