Metadata-Version: 2.1
Name: itree
Version: 0.0.2
Summary: An interval tree data structure
Home-page: UNKNOWN
Author: Bob Zimmermann
Author-email: robert.zimmermann@univie.ac.at
License: MIT
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics

# 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:

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

* **Insertion**

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

```python
>>> 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

```python 
>>> t.search(i(1,4)) 
[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).

```python
>>> t.pstring()
      ┌–(1,15)
–(3,20)
            ┌–(4,20)
      └–(5,15)
            └–(6,7)

>>> t.remove(i(1,15))
>>> t.pstring()
      ┌–(3,20)
            └–(4,20)
–(5,15)
      └–(6,7)
``` 

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


