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.6-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51cb888bd9c6bf18f2c871ca664eddf568e34433aa9ecc01966e5a2e5ded9a35 |
|
MD5 | f605722dbb8525202c15ef76a83185d7 |
|
BLAKE2b-256 | 7409814c76c1be59ec8d942c28b8f4a437620c81ca3bc45e8c613f40f7873c65 |
Hashes for quicksectx-0.2.6-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 649d1c8616009cd0d710feff0efa393fb21514191ae6a2b895038553d1d1d4c5 |
|
MD5 | 86ea7b5761b4bf03e90a1c5e33491c1e |
|
BLAKE2b-256 | 3aa92228f4afd7b0e88e51591860bb994c90a2aed685046e911e2cf053d70581 |
Hashes for quicksectx-0.2.6-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be35967e86092e548a7fd73e4f3461890a5b31c0dcbc145611db9dfbcb5af7da |
|
MD5 | 88c02c528e40384ed42231b4d361522b |
|
BLAKE2b-256 | e70369f825db0f873c245c098843ff862ec0e73c0cfae8adafdbea3fd11471ef |
Hashes for quicksectx-0.2.6-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61512f2707bc04cbd07e7d2d1c529169fa81fc7dce08333fd5a01a94549e0a97 |
|
MD5 | ca5167e6b2718043e7f4240ddcb3fbd4 |
|
BLAKE2b-256 | 19da6d155a27434d1aaefbac5887ead2c41716ea11aede0d16be34a9c88b10b7 |
Hashes for quicksectx-0.2.6-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae05ccf5866ec562d19ff9f033252b8d8557c4eccf225b3352febb9add8537bb |
|
MD5 | 95872a44b9340a578651eaf8b0000a0b |
|
BLAKE2b-256 | 3c340a563b25fee26f4cd50cd4a7b639c4f2c2447cbc9a591051323eb5c55c90 |
Hashes for quicksectx-0.2.6-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5080a7993de5e2eb2ed58522d1465029c654f2d6023ed26b0a2e801855a9a3ee |
|
MD5 | a80eecd9cc2a5f7b9a0fef6c8565e037 |
|
BLAKE2b-256 | bf9c183eb2eb173129cdf28805fce3eb9b4edf3baa5747d1f761022487d7dff1 |
Hashes for quicksectx-0.2.6-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 939ef590399a6a85edf632fea94e1563f4b30addd554b32607c1e78292b3da5e |
|
MD5 | 8dc05c11f912844707f5f914f8e99089 |
|
BLAKE2b-256 | 3da6451d9a727d3c461d7a20d1eae5fe3e097c0507edb9d157ac5674c693d755 |
Hashes for quicksectx-0.2.6-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c2a4c3b0297f84daea6bc8bf12a01ab90203583aa414811eabb38636a4b19b2 |
|
MD5 | 73b3010131c6947b5221c6e63dab58e4 |
|
BLAKE2b-256 | 36a702adec2567703737fe1bbe7a4ee2c4c94b124029cc9de668170c3005c581 |
Hashes for quicksectx-0.2.6-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8eca6fc06a854d3c5c1cf060f3a4892b973a8b062324b64ed8711640c4e871fa |
|
MD5 | db416a32823333c45dd63bb90e05b794 |
|
BLAKE2b-256 | f74ceb3a57573679083bfb1f159d8e36ed19142ae1c4c7b704668b4c6a63b20e |