interval module¶
-
class
mavis.interval.
Interval
(start, end=None, freq=1, number_type=None)[source]¶ Bases:
object
Parameters: -
__and__
(other)[source]¶ the intersection of two intervals
Example
>>> Interval(1, 10) & Interval(5, 50) Interval(5, 10) >>> Interval(1, 2) & Interval(10, 11) None
-
__len__
()[source]¶ the length of the interval
Example
>>> len(Interval(1, 11)) 12
Warning
only works for integer intervals
-
__or__
(other)[source]¶ the union of two intervals
Example
>>> Interval(1, 10) | Interval(5, 50) Interval(1, 50) >>> Interval(1, 2) | Interval(10, 11) Interval(1, 11)
-
__sub__
(other)[source]¶ the difference of two intervals
Example
>>> Interval(1, 10) - Interval(5, 50) [Interval(1, 4)] >>> Interval(1, 2) - Interval(10, 11) [Interval(1, 2)] >>> Interval(1, 2) - Interval(-1, 10) []
-
center
¶ the middle of the interval
Example
>>> Interval(1, 10).center 5.5 >>> Interval(1, 11).center 6
-
classmethod
convert_ratioed_pos
(mapping, pos, forward_to_reverse=None)[source]¶ convert any given position given a mapping of intervals to another range
Parameters: Returns: the position in the alternate coordinate system given the input mapping
Return type: Raises: AttributeError
– if the input position is outside the set of input segmentsIndexError
– if the input position cannot be converted to the output system
Example
>>> mapping = {(1, 10): (101, 110), (11, 20): (555, 564)} >>> Interval.convert_pos(mapping, 5) 5 >>> Interval.convert_pos(mapping, 15) 559
-
classmethod
dist
(first, other)[source]¶ returns the minimum distance between intervals
Example
>>> Interval.dist((1, 4), (5, 7)) -1 >>> Interval.dist((5, 7), (1, 4)) 1 >>> Interval.dist((5, 8), (7, 9)) 0
-
classmethod
intersection
(*intervals)[source]¶ returns None if there is no intersection
Example
>>> Interval.intersection((1, 10), (2, 8), (7, 15)) Interval(7, 8) >>> Interval.intersection((1, 2), (5, 9)) None
-
classmethod
min_nonoverlapping
(*intervals)[source]¶ for a list of intervals, orders them and merges any overlap to return a list of non-overlapping intervals O(nlogn)
Example
>>> Interval.min_nonoverlapping((1, 10), (7, 8), (6, 14), (17, 20)) [Interval(1, 14), Interval(17, 20)]
-
classmethod
overlaps
(first, other)[source]¶ checks if two intervals have any portion of their given ranges in common
Parameters: Example
>>> Interval.overlaps(Interval(1, 4), Interval(5, 7)) False >>> Interval.overlaps(Interval(1, 10), Interval(10, 11)) True >>> Interval.overlaps((1, 10), (10, 11)) True
-