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.9-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38a3fe9e8aa349ea69c09f104b98f508f5e40299f52f50491cb7b967c4f883e4 |
|
MD5 | 31b175a39ca6adc24a1b99a35eed558d |
|
BLAKE2b-256 | 16df6c540d7ff4cf626af581bc28eb370a9dbcd01c9af6a07cf42f1274713a20 |
Hashes for quicksectx-0.2.9-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19e73034fd3484ca32ee62dc1c6d272dc63c8ff005167c5638d2cc5fd5dbeb01 |
|
MD5 | 6673d4cb2d6e7a6eaef11cb749f96846 |
|
BLAKE2b-256 | 0455906d7e59b9621660837f8b1cef54c0f309ea9829d90d34922e44ccdbbd9d |
Hashes for quicksectx-0.2.9-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d597404012c2832302f4ce92900eaef96975ab572c23ec3737787f4abcff76fb |
|
MD5 | 4dbe71da1592bc8eb20091829a8bbdd2 |
|
BLAKE2b-256 | f0dc47089e50fab5b944336c64a3198805d30b58f2d743ae6507382812808b0e |
Hashes for quicksectx-0.2.9-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50013b7e3c3e744b6a7090839b744c6e4b1f35ec8e08d2bf3930e8c9c577630a |
|
MD5 | d3a88e6a036367b061f6c5ee2c341682 |
|
BLAKE2b-256 | 66334c6fb1887e0aba045397422e11211b4c79e62de27888852f0b49d242237d |
Hashes for quicksectx-0.2.9-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 614b93e0fa82cbf04df07cd63d1ff9def59b004137e61eec129b7bb6338cf2a2 |
|
MD5 | 665b2260ddf0752e31daccb4dbe3b6b1 |
|
BLAKE2b-256 | eb73510a16a6d0021e362986126476450dae24341ec409faba73f8c57d274069 |
Hashes for quicksectx-0.2.9-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bdbf4b6f319c56fa7e6bf42a1904917440717868afac3beeb3ce2f47d52018e |
|
MD5 | b153e578c68ea8b338e0a0df33f8b40d |
|
BLAKE2b-256 | 8985612cb861dab77cbab48ba24e0da8ed6248d3782d64a5da7f50703c7a6cdd |
Hashes for quicksectx-0.2.9-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc996de10ff22a33c49b5263c807a33aefef771b084dde8de18dd6f29df98684 |
|
MD5 | 806b37a118b4b4ac4133cdc836bf30da |
|
BLAKE2b-256 | 7e52fa490dcf9191a7c143af3fc39a09a548118309f6c19fc585858fad34afc3 |
Hashes for quicksectx-0.2.9-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 031d40d3136cb2b31629978be348d4bfd9ec4592133383b3fa937cb775b72d1f |
|
MD5 | ce235fd6e5f6aa449a5d4f3800ab71ae |
|
BLAKE2b-256 | 71a6b47edce1933073615acc45a3418a91db2b6802c36361c8747740651491fa |
Hashes for quicksectx-0.2.9-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e19a1098cbc047359a12769849360fb909f356eb3dc3882885cc7444ed3b652 |
|
MD5 | b85f2afa693431ff7309832eacd195d4 |
|
BLAKE2b-256 | 877d3c107e339ca48180fc287088066011044f449f1371ecf7d9cc6d0830fc0d |
Hashes for quicksectx-0.2.9-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5743ff083fc361ce4f9906b4af17ed4dcec9b8c473a27974f141d5bdd8af4809 |
|
MD5 | 72a2a7b5675b7a906cdff429c88a4eed |
|
BLAKE2b-256 | ef8cadfb078e802f862bbf4d3cd83e85e0ef7a9819a1cf88390bd77393378119 |
Hashes for quicksectx-0.2.9-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e57768cbecb0690514d1217e56dcc765ddbe3a47ec476af5615f42ced004e61 |
|
MD5 | 497352173132f550314ac10eb943a740 |
|
BLAKE2b-256 | 2440919dd8b203922e3d5224a958517f21db1ff4481baa27490a4ab64c6c1df6 |
Hashes for quicksectx-0.2.9-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65c928c6f95f95b6da5ddceb7ae1b4608f79dd58f63cba4029a9fcb6204059b9 |
|
MD5 | 7f20737a96d9e36948469eeedec38a3f |
|
BLAKE2b-256 | 38b19a88c940f309905b9ea4f1bd63be12e06f955510a463ab5b78ff6da38f5e |