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.7-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78f790a9ab8819de042c4d8fda886c5c84cd14494e53f3d0a47756dd5bb9736c |
|
MD5 | 586191d35ed2754ee97b30380ffd8ef1 |
|
BLAKE2b-256 | 2807619cda027feddc8da4b728437955eef3baca440f80230b2c765ba614d27a |
Hashes for quicksectx-0.2.7-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad2483b1fdf98857b7770b7d9a3fe081b69694bbe12ea75ddb0f3c7916d0fea0 |
|
MD5 | dd6df18a6dedfb798199d2d3066d2507 |
|
BLAKE2b-256 | ffd169bf4926c11dfd9652639079426ba3c698344e5eba0e741ad8ca8c2b8ee2 |
Hashes for quicksectx-0.2.7-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03c379f9af72a7e50ad04387a52d7e1a418a19a047bc0fbda075e51ce61b8847 |
|
MD5 | 5201f6ea4a96cac0bb1e6561c594f7f1 |
|
BLAKE2b-256 | f2f2d6b72aaa6f30200d4f9f64b3f7a4dcfefb2cd062ccde8ded5e87b33571ea |
Hashes for quicksectx-0.2.7-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad853a2233f6911995582b3dad255438174a6d3869d440054a0431ad07d85427 |
|
MD5 | 33b4803d19542ee85239206f013fa610 |
|
BLAKE2b-256 | c8732d9330d852fb9cfbde8e8b4fb0689dbc388a98865ba08cc4a427d480ce86 |
Hashes for quicksectx-0.2.7-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2528543ef2da79ec2227ee607951d7d471d8549da935721fa4ea34cd29208004 |
|
MD5 | 058d8774fc8115cb24f30d4a06528948 |
|
BLAKE2b-256 | 1a2a54b7403fc3ec7867dbeedee6d547425cc2abba3da8dcec40574cea739cd4 |
Hashes for quicksectx-0.2.7-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76836bacc9780db37eaea28fdc108651c9e6dceb6499f024b261241f28ee61d2 |
|
MD5 | 84acefdce8b99b69b4b145763ba4d119 |
|
BLAKE2b-256 | cbb9c2e9c5e898c3fb9fabcd152eae559743283350a79b001e0f01aee038a168 |
Hashes for quicksectx-0.2.7-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30ca67f9e9c93d14bfd8b30593d4d98277bce23824b7a2574cb19757b26aa951 |
|
MD5 | 668ee1920d98d15f8740ed5a8c790646 |
|
BLAKE2b-256 | 1cb7aaf69003f2b58d211d2cdaaad5b677a76b2eb3cace9999be0c3ad14e0573 |
Hashes for quicksectx-0.2.7-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e426c9d191ffbb160d6f314edc2f84fa15d1d919d8859f5adf80a777632de9b |
|
MD5 | 7151fa91a15243cae7ba7763b067fcf6 |
|
BLAKE2b-256 | 4216ed19531bf234999009dc05cbb884533dc03fb865022d93c3d7055372f8d2 |
Hashes for quicksectx-0.2.7-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4953fdea38cb6359f04111a5dda77d030145c68fc0272e7efc3c068972ecab73 |
|
MD5 | b279ebbfa2485b6e510f940014f23e4c |
|
BLAKE2b-256 | a194d987621042a607013f84351edc1b476b25258e8bc5b3ead83b0f86bc7e3f |
Hashes for quicksectx-0.2.7-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ce10c442b155f99dd0b342b4db236fa97cd086ada296307f20fc9ef8b20fc41 |
|
MD5 | 883f4c1b6b613c5702d34ec1fb1ca0d5 |
|
BLAKE2b-256 | d7eee36586209aca79c833ad3b0971d0ad2b5215cdbd87014c57ec1e070ecf04 |
Hashes for quicksectx-0.2.7-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41982c8f13b785ed37d8f78536f68ee99e8a513bdb8ba7135aa7e7082be408a7 |
|
MD5 | 0031979efcb8617899991a73890756ce |
|
BLAKE2b-256 | e5342c0df0b7b1f2d785b03e8cc18b92a15c1bdeadede8dcf060d70a0949c070 |
Hashes for quicksectx-0.2.7-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df722e3e233aa5c8a4ace82d6aae2d52e8b80dc01148f133467ab18e68413f5e |
|
MD5 | 8a3df65951b8f8d3ad17ff440a9af9fd |
|
BLAKE2b-256 | 7671eb133ede4dcb46fdeb7e8214c7081aea01eb98e4ba08c38426d0b3f06ec0 |