bx.intervals package
Subpackages
- bx.intervals.operations package
- Submodules
- bx.intervals.operations.base_coverage module
- bx.intervals.operations.complement module
- bx.intervals.operations.concat module
- bx.intervals.operations.coverage module
- bx.intervals.operations.find_clusters module
- bx.intervals.operations.intersect module
- bx.intervals.operations.join module
- bx.intervals.operations.merge module
- bx.intervals.operations.quicksect module
- bx.intervals.operations.subtract module
- Module contents
- Submodules
Submodules
- bx.intervals.cluster module
- bx.intervals.cluster_tests module
TestClusterTestCluster.insertpairs()TestCluster.setUp()TestCluster.test_another()TestCluster.test_distance()TestCluster.test_duplicates()TestCluster.test_easymerge()TestCluster.test_hardmerge()TestCluster.test_large_sorted()TestCluster.test_larger()TestCluster.test_merge_case()TestCluster.test_merge_left_right()TestCluster.test_minregions()TestCluster.test_none()TestCluster.test_startbeforeend()TestCluster.test_trivial()
- bx.intervals.intersection module
IntersecterIntervalIntervalNodeIntervalTreeIntervalTree.add()IntervalTree.add_interval()IntervalTree.after()IntervalTree.after_interval()IntervalTree.before()IntervalTree.before_interval()IntervalTree.downstream_of_interval()IntervalTree.find()IntervalTree.insert()IntervalTree.insert_interval()IntervalTree.traverse()IntervalTree.upstream_of_interval()
- bx.intervals.intersection_tests module
- bx.intervals.io module
- bx.intervals.random_intervals module
Module contents
Tools and data structures for working with genomic intervals (or sets of regions on a line in general) efficiently.
- bx.intervals.Intersecter
alias of
IntervalTree
- class bx.intervals.Interval
Bases:
objectBasic feature, with required integer start and end properties. Also accepts optional strand as +1 or -1 (used for up/downstream queries), a name, and any arbitrary data is sent in on the info keyword argument
>>> from bx.intervals.intersection import Interval >>> from collections import OrderedDict
>>> f1 = Interval(23, 36) >>> f2 = Interval(34, 48, value=OrderedDict([('chr', 12), ('anno', 'transposon')]))
- chrom
- end
- start
- strand
- value
- class bx.intervals.IntervalNode
Bases:
objectA single node of an IntervalTree.
- NOTE: Unless you really know what you are doing, you probably should us
IntervalTree rather than using this directly.
- end
- find(start, end, sort=True)
given a start and a end, return a list of features falling within that range
- insert(start, end, interval)
Insert a new IntervalNode into the tree of which this node is currently the root. The return value is the new root of the tree (which may or may not be this node!)
- intersect(start, end, sort=True)
given a start and a end, return a list of features falling within that range
- interval
- left(position, n=1, max_dist=2500)
find n features with a start > than position f: a Interval object (or anything with an end attribute) n: the number of features to return max_dist: the maximum distance to look before giving up.
- left_node
- right(position, n=1, max_dist=2500)
find n features with a end < than position f: a Interval object (or anything with a start attribute) n: the number of features to return max_dist: the maximum distance to look before giving up.
- right_node
- root_node
- start
- traverse(func)
- class bx.intervals.IntervalTree
Bases:
objectData structure for performing window intersect queries on a set of of possibly overlapping 1d intervals.
Usage
Create an empty IntervalTree
>>> from bx.intervals.intersection import Interval, IntervalTree >>> intersecter = IntervalTree()
An interval is a start and end position and a value (possibly None). You can add any object as an interval:
>>> intersecter.insert( 0, 10, "food" ) >>> intersecter.insert( 3, 7, dict(foo='bar') )
>>> intersecter.find( 2, 5 ) ['food', {'foo': 'bar'}]
If the object has start and end attributes (like the Interval class) there is are some shortcuts:
>>> intersecter = IntervalTree() >>> intersecter.insert_interval( Interval( 0, 10 ) ) >>> intersecter.insert_interval( Interval( 3, 7 ) ) >>> intersecter.insert_interval( Interval( 3, 40 ) ) >>> intersecter.insert_interval( Interval( 13, 50 ) )
>>> intersecter.find( 30, 50 ) [Interval(3, 40), Interval(13, 50)] >>> intersecter.find( 100, 200 ) []
Before/after for intervals
>>> intersecter.before_interval( Interval( 10, 20 ) ) [Interval(3, 7)] >>> intersecter.before_interval( Interval( 5, 20 ) ) []
Upstream/downstream
>>> intersecter.upstream_of_interval(Interval(11, 12)) [Interval(0, 10)] >>> intersecter.upstream_of_interval(Interval(11, 12, strand="-")) [Interval(13, 50)]
>>> intersecter.upstream_of_interval(Interval(1, 2, strand="-"), num_intervals=3) [Interval(3, 7), Interval(3, 40), Interval(13, 50)]
- add(start, end, value=None)
Insert the interval [start,end) associated with value value.
- add_interval(interval)
Insert an “interval” like object (one with at least start and end attributes)
- after(position, num_intervals=1, max_dist=2500)
Find num_intervals intervals that lie after position and are no further than max_dist positions away
- after_interval(interval, num_intervals=1, max_dist=2500)
Find num_intervals intervals that lie completely after interval and are no further than max_dist positions away
- before(position, num_intervals=1, max_dist=2500)
Find num_intervals intervals that lie before position and are no further than max_dist positions away
- before_interval(interval, num_intervals=1, max_dist=2500)
Find num_intervals intervals that lie completely before interval and are no further than max_dist positions away
- downstream_of_interval(interval, num_intervals=1, max_dist=2500)
Find num_intervals intervals that lie completely downstream of interval and are no further than max_dist positions away
- find(start, end)
Return a sorted list of all intervals overlapping [start,end).
- insert(start, end, value=None)
Insert the interval [start,end) associated with value value.
- insert_interval(interval)
Insert an “interval” like object (one with at least start and end attributes)
- traverse(fn)
call fn for each element in the tree
- upstream_of_interval(interval, num_intervals=1, max_dist=2500)
Find num_intervals intervals that lie completely upstream of interval and are no further than max_dist positions away