fast, simple interval intersection
Project description
Description
Quicksect is a fast python / cython implementation of interval search based on the pure python version in bx-python I pulled it out, optimized and converted to cython and James Taylor has incoporated it back into bx-python with his improvements.
I have brought this project back from the dead because I want a fast, simple, no-dependencies Interval tree.
Extended with removal operations and allows pretty print to display tree structure (By Jianlin)
License is MIT.
Installation
pip install quicksect
or
conda install -c bioconda quicksect
Use
To use extended quicksect(quicksectx):
>>> from quicksectx import IntervalNode, IntervalTree, Interval >>> tree = IntervalTree() >>> tree.add(1, 3, 100) >>> tree.add(3, 7, 110) >>> tree.add(2, 5, 120) >>> tree.add(4, 6, 130) >>> print(tree.pretty_print()) Inv(1, 3, d=100) r: Inv(3, 7, d=110) l: Inv(2, 5, d=120) r: Inv(4, 6, d=130) >>> print(tree.find(Interval(2, 5))) [Inv(1, 3, d=100), Inv(3, 7, d=110), Inv(2, 5, d=120), Inv(4, 6, d=130)] >>> tree.remove(Interval(2, 5)) >>> print(tree.find(Interval(2, 5))) [Inv(1, 3, d=100), Inv(3, 7, d=110), Inv(4, 6, d=130)]
To use traditional quicksect, you can still using the same syntax:
>>> from quicksect import IntervalNode, Interval, IntervalTree
Most common use will be via IntervalTree:
>>> tree = IntervalTree() >>> tree.add(23, 45) >>> tree.add(55, 66) >>> tree.search(46, 47) [] >>> tree.search(44, 56) [Interval(55, 66), Interval(23, 45)]>>> tree.insert(Interval(88, 444)) >>> res = tree.find(Interval(99, 100)) >>> res [Interval(88, 444)] >>> res[0].start, res[0].end (88, 444)
Thats pretty much everything you need to know about the tree.
Test
$ python setup.py test
Low-Level
In some cases, users may want to utilize the lower-level interface that accesses the nodes of the tree:
>>> inter = IntervalNode(Interval(22, 33)) >>> inter = inter.insert(Interval(44, 55)) >>> inter.intersect(24, 26) [Interval(22, 33)]>>> inter.left(Interval(34, 35), n=1) [Interval(22, 33)]>>> inter.right(Interval(34, 35), n=1) [Interval(44, 55)]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for quicksectx-0.2.3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 848d05c0f4aaac3119d3bb1f5652060f278cb64b9d92c1a78b9a67c2c337f2a9 |
|
MD5 | e3941b9284d6167beb81df93c560be6d |
|
BLAKE2b-256 | 8ad8e52693b108656c07842224863dced8c9f08eb03b22fb0c36e3576ee8e4af |
Hashes for quicksectx-0.2.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 476e3ed292d62bb7e82e0edf01abb3b38576a86918b591afe4aafa9701e5533d |
|
MD5 | 5f5b7456276a07bde6f4f4f43fcec092 |
|
BLAKE2b-256 | 13ea61927c46393b33e53481272f2e9a81b9a8e7f20a729b2893671cf288ec70 |
Hashes for quicksectx-0.2.3-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92bd28c94fb7799bbb463b94194cfa8f86daddb503dc4b51c20d893810fbf678 |
|
MD5 | c4ed01ffe8df6047a5d2f4e356ebc5c9 |
|
BLAKE2b-256 | 1357b13b4c04e09a90de36b0204c27ced8cf89e1127871df659d0ebdce25f838 |
Hashes for quicksectx-0.2.3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f81d6e3a38d316a32617629df79fda61460c991fc08b660a466a38f6b0a942c |
|
MD5 | a8dd418bd3821448ff85267c83389aab |
|
BLAKE2b-256 | e40804a835dbc81cf37b3e51c9e8d37beb68e280c7439ee2446f1b76bcbb598f |
Hashes for quicksectx-0.2.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c18c1e5789cf04390b6239978025f47f78d84c4f7e210577323af7d541667acf |
|
MD5 | 4fab4425b20b52a166822f8930af82c4 |
|
BLAKE2b-256 | 4d8a66ccba79da4355f0b08ab9c631361cc3f42d3a8da7feca6db547921c8c1b |
Hashes for quicksectx-0.2.3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73368095b07a137e56f86ad17ba16dd911f024027324291fbc35df1f2bb19672 |
|
MD5 | bc596260a66464dfb13bd65d1f0a7e62 |
|
BLAKE2b-256 | d96f612e692d22c0926bdaf7560a9848f828d15676a0163733d929bb3329795a |
Hashes for quicksectx-0.2.3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b3282e9a04819ab9ecd4c3c78ed155ee3a8ced5217a18a1434ec19ab0b37f70 |
|
MD5 | 0a201ad0ed8ebf64fde3a45ff402ea33 |
|
BLAKE2b-256 | e15a581fbfbec8208e6d8c49b3281e85c409bca77266d92e96ca905cf113c9c9 |
Hashes for quicksectx-0.2.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24ece739305a008c63c9d60bcdf23fe61c5846aaa9f822f365f77b2331a9597d |
|
MD5 | 560353b180bf1c57c427b0151aee84cd |
|
BLAKE2b-256 | f235b7260eba1cd5b218cf96e8b28b231ae20455573e385ea6291dd49994df9b |
Hashes for quicksectx-0.2.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b17ee7d108a634f57e45f9dff922e91b4cc46e07cf474b54e89b8e252c25a3e |
|
MD5 | 2534eb2fbc334befa43270c445c00549 |
|
BLAKE2b-256 | 5d24dd6336dd59c1e519ea33723d45ba366a723f7ecb0b26f7b42fd5eb15a89e |