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.9a3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c2704e3af79321aafb02f39148c86e2185f47c0caff626c620a84f545fd6e7d |
|
MD5 | 0e44da4ea7f24a0a24b512fa22e55aec |
|
BLAKE2b-256 | deab55e1a26f7529523711efab08985a7f2b88ac22881ee56a55363145571c06 |
Hashes for quicksectx-0.2.9a3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c63251c88441594e9b8395a3e390251b0508ac8d088992264b891d573f0ca470 |
|
MD5 | 220a4a0ed50ab2bc7ed0adf9c75e45c5 |
|
BLAKE2b-256 | 55dc63e6cc703b092b5ed26c9af5dbf87a7777f98775e149f323c9fbf8c16c68 |
Hashes for quicksectx-0.2.9a3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fbbbb9b70cd3294cb69580b41baf4a44d62dd48926110b1fc66a458a7236470 |
|
MD5 | fb10c8be62b68be8dc08b3bbc6568acb |
|
BLAKE2b-256 | 0f9e98da8679f56f31d3b267437f2c008287caa2c5cb41d24f7f686f104b2407 |
Hashes for quicksectx-0.2.9a3-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67ca0af91356e0ed5ddf3f3cff9762b97602653b6657ef4910998df80ab47c50 |
|
MD5 | 5df72120e8a410a334200eb542cebdbb |
|
BLAKE2b-256 | 6e80c2ba7989752530978a9cd49747acdb793b3895557edee4def06f3311c6b2 |
Hashes for quicksectx-0.2.9a3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68ec469ecc36c86488547bf2c9a0be1928e14e3d500491d463123180f6c6ea58 |
|
MD5 | ebb6cad9e63dfd17ba809c20a3adbe2c |
|
BLAKE2b-256 | cba60c50556ac7f880dab0b01c011e0fc629226f2ddfd99eb432df6dc0ec71ea |
Hashes for quicksectx-0.2.9a3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf2bb74d26211929ee0f4e732745cbdc46109d0e6fe50d0157ebd8bf68f377a0 |
|
MD5 | d8f3eb38f4e660f21487c20f1a319b5e |
|
BLAKE2b-256 | c28bf66bb962f75f38cecc5321d85307bee508807b3debd1fce9afcacd0e3b55 |
Hashes for quicksectx-0.2.9a3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8512d96aa82f068a521390e5737c41c97093bf3a511fd5b8d625249760858779 |
|
MD5 | 85866c3bffdbdf13ae884ad989aadda6 |
|
BLAKE2b-256 | 35be3dedebadddaa8820e645e402dc21cbf40206f0e60f32e0d26f59bbcb1583 |
Hashes for quicksectx-0.2.9a3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbaa9c224a93017c1085e205000a6fce4d3591cb8565a92d24c8a7dfb8dd7267 |
|
MD5 | 630940aa2065e36c15e78d7efe810207 |
|
BLAKE2b-256 | e316ac7871ba5ce521e616b5e60b1bebdf3d53a232fa08b4d2f385741f9eb485 |
Hashes for quicksectx-0.2.9a3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6ba79a30bafd3d9c11129245c757b6bc041ade25942f3c56eed79b8b27719ed |
|
MD5 | 4415eac681044182d7d1181430a28c7b |
|
BLAKE2b-256 | 4b4e06ad47226e4f1a542fce635394afedc6ade511986ff3e18cfb4ee82a70c8 |
Hashes for quicksectx-0.2.9a3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fccf506215a72fe3e3c5ae37ace1845584bb2ab5f3f0047bed6f0d34719be82 |
|
MD5 | fc84def9e2945809bd04a7fc56bb6db8 |
|
BLAKE2b-256 | 73605005ce456d8f05d498d4614691f1423779cf9256ab3b6b61f673c95daf19 |
Hashes for quicksectx-0.2.9a3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a7743750b96d7ef71ac83283b514a83bd6c54379beaef2f314fb52779192d9d |
|
MD5 | d2ad7d3e645ad7e60e4ee0f2ac96e5fa |
|
BLAKE2b-256 | 75325cfe2c59981c4b15610989df65938b4b9497afeb6ac6a4a0052b19742c8d |
Hashes for quicksectx-0.2.9a3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d86ab8d3e4d7971421f0c5a1e6f93d8693adb81ff5d44f198cb79432ec344dd |
|
MD5 | 820f90da097445fff128c7342c60eecf |
|
BLAKE2b-256 | be7d9ec74463fb251a78ce7e6f49023bda9a289925dd7c5e7dab39973d0eb692 |