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.3b1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f328780bc49bcf6b38d06fe06867adb7850f76c27cf1629a9240bed398ccb26 |
|
MD5 | 7d285abca3d9af04b0a2ab34f92993d3 |
|
BLAKE2b-256 | 506470af8df4802be0d27796ab2d06c9857659608596299e91ea0394f4015c6b |
Hashes for quicksectx-0.2.3b1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0e5cc9c29a4ce7803def97798565a4d0ac8a03df77c93d2a147b845b3e5dac2 |
|
MD5 | 6baa67896bbf975b074b3dfa1c441fdd |
|
BLAKE2b-256 | 7f8fb9964f9bb9995f64d2c6ae4964f53b7ddb9f6614e2eec5ba578ad9ab64e5 |
Hashes for quicksectx-0.2.3b1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 850648ee69e8cd8d44ad85417df1ab9a4eb7f3911463f81e4b78830c67885dcc |
|
MD5 | 8ca4936ac5b178b548cdd0419f065e85 |
|
BLAKE2b-256 | a6fee292529b6fee4c994b1ed2e6b58e845290504ea0f6ca9a66cdbfe3a06a57 |
Hashes for quicksectx-0.2.3b1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d83541c80bfc366a6f6a3813a131bf48250c9987637f1843ae328a85519ed66 |
|
MD5 | b0afe3cdb80a8944b78bc90e26573d8d |
|
BLAKE2b-256 | 681920f569776729651a51918d9c9b007758ba578bbad6e80ae9de429b906e3a |
Hashes for quicksectx-0.2.3b1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42340c4575db7692094252f19467ebbbaa7a13d02ffac6017a8e2f47d3ad1087 |
|
MD5 | 0a467168957f32a4cbfc11c23454ca36 |
|
BLAKE2b-256 | 02fe4d28915716c599a4fe43e31e1e6a1dcec45f557f55b8818b801eaab1c806 |
Hashes for quicksectx-0.2.3b1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff64dbc755c496cf4d0558a76fcdf753b09893880f69936dced0c6fc9f437fef |
|
MD5 | 5013df256410413a24c72ff99141499b |
|
BLAKE2b-256 | a607e45343cdf9248662f03f555f401e707c8e7bd72729b3c02626dc5bf7d084 |
Hashes for quicksectx-0.2.3b1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee4a86aa75b20f6e56c6aa0fcaa6cd9098b91e9c39108bc5a041bb20950577cb |
|
MD5 | fa17d6bae8d349fcd57d14678f1d152a |
|
BLAKE2b-256 | 1f82ad006ecd29a2e66c82626ff16871478b93837815d57eed82ff320d26b3c3 |
Hashes for quicksectx-0.2.3b1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 409ed299d27fa00c283aa57ab375c4e37adfd91705683f4b8d06ac6231df099b |
|
MD5 | 7a478cf0038f1086c7d5dfbbed2f3361 |
|
BLAKE2b-256 | f8a6c12fff360327a1cfd248dc2924083345476336256417fdee478ddc6caff1 |
Hashes for quicksectx-0.2.3b1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 412164275e5adf400ac3f30cf0d2a9c52532e581d95336a7b6a78560d5552983 |
|
MD5 | 6fdf834ce4f5b5b47b19920f29d774d1 |
|
BLAKE2b-256 | 8d362c7254b22d2eb1cba65c8fa8179727ad1311d186a64605895abaf7eb1d32 |