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.9b1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b5c917a1779784de562e4993415208e4d33150689a63ff9e3c903ef53ea277d |
|
MD5 | 709ed06c148b5fdcef15ea4f25b9e683 |
|
BLAKE2b-256 | 6e7797705be67f4a64e1b734af0de72463605c8d53c2e22c90105bada94c72f4 |
Hashes for quicksectx-0.2.9b1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02f525e4471d36c1829c128bdbf44d8f99c20f1764c5a73e74331f47d49b4a66 |
|
MD5 | 9b563292a6d1c602a892486f3419e320 |
|
BLAKE2b-256 | 1f03cb1dc8e4f40088a91b0fe57c9330a592ed8d83c2ca4e41cc11f50452eb29 |
Hashes for quicksectx-0.2.9b1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce41a223422873dca569477c8fd41fc193e5f54cff901a742dd2388f0be2f309 |
|
MD5 | f0a96af8182c208c762adb6be0b0f646 |
|
BLAKE2b-256 | 9c3e165f601a52b4e897d73ecf2ac81840aed6afe881fbd3f82e8f64198bd1c7 |
Hashes for quicksectx-0.2.9b1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfcb80bdddb4c1d4d851ab238d07dc56104846eb4ddefa0678190b74c964f876 |
|
MD5 | 8473654e0dda92b282200defd3145c45 |
|
BLAKE2b-256 | 9dcf642dc8ddc0dac96f1ad4bad574549b71feca8b7878a3e43f228ff25394f0 |
Hashes for quicksectx-0.2.9b1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cccd6bb6c66efe956a91d0dcaaaa1f2aa385e33d328b3e0bcd5fa9f893714446 |
|
MD5 | 46c3acb27e80f2c2e92fe1306c777553 |
|
BLAKE2b-256 | d5f70a1fec2255ed16465b50e4714e5e231b4fa81d025ab782a9fefe09887443 |
Hashes for quicksectx-0.2.9b1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54a64683ffa6a704c82db83d55421e010ffb0d784e89498fd38eff4ea7343d69 |
|
MD5 | 5e88b2b88bfc528c6f25af232d217d72 |
|
BLAKE2b-256 | 77b82a914f62c432af5c62625c843fa9e905520b58af2d0914a297cd5d41c19e |
Hashes for quicksectx-0.2.9b1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fda4a9a32e29cc634c0d2e6c97e69a653b2f08bdc371268184d2658e6b102cb7 |
|
MD5 | 991f0322574a8696f8bb92daa34a3f1a |
|
BLAKE2b-256 | 359066641fc786789ad01a61878ca81a35cc4b65225fe8fbc48bfb8a7d045b70 |
Hashes for quicksectx-0.2.9b1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf674e800c5e00c3186e6ac681184e102e4bb592cadeaa88e7b269a791ffbcd2 |
|
MD5 | bc2f698031036faa2004516cd369a284 |
|
BLAKE2b-256 | 137bc25d0b2c3b84b40701512aa93abfc7a7eddf4d2864210f618e39d5259086 |
Hashes for quicksectx-0.2.9b1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fd346fbcbbf17f99d93d2d39956d5a0b559f9a8dc615cbce3f68a8da28af574 |
|
MD5 | 5b6e4d3b10599e771714a67218a66525 |
|
BLAKE2b-256 | 29a08b0986c058c49590d865c8fb773dc8bcee3ba595af55c0dd19cfa80f882e |
Hashes for quicksectx-0.2.9b1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76d9ec4275074513b17a0f8946390fee893b6a738711351097c25d15b3a656bd |
|
MD5 | 3069043ff44aae1817d865be8b348727 |
|
BLAKE2b-256 | 7e28f2147414c405e29f45950686832ff6128c0984a5336bf7bab1ab19a73037 |
Hashes for quicksectx-0.2.9b1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7c63d901791f60294c39447c27161ab71b91dbd3f443d432f05f644c44142b3 |
|
MD5 | 00176423cdd39a804cfcca9e1781ff8d |
|
BLAKE2b-256 | 8c22df60d2cf51d693d8a6708a0ded3cffdd02396709d555c16ef82ebcdc7954 |
Hashes for quicksectx-0.2.9b1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2fdd497b563222f5e103fb470073b94c61dde7944689900b6f7bd584ba18384 |
|
MD5 | e4aaa277f24892dcee51fd07645189d9 |
|
BLAKE2b-256 | 65febbedb14097615f750f15a24aec8745a5f9af1aed92f8be41c3735dcbc72f |