# mavis.interval

## class mavis.interval.Interval

### mavis.interval.Interval.overlaps()

checks if two intervals have any portion of their given ranges in common

``````@classmethod
def overlaps(cls, first, other):
``````

Args

• first (`Interval`): an interval to be compared
• other (`Interval`): an interval to be compared

Examples

``````>>> 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
``````

### mavis.interval.Interval.center()

the middle of the interval

``````@property
def center(self):
``````

Args

• self

Examples

``````>>> Interval(1, 10).center
5.5
>>> Interval(1, 11).center
6
``````

### mavis.interval.Interval.dist()

returns the minimum distance between intervals

``````@classmethod
def dist(cls, first, other):
``````

Args

• first
• other

Examples

``````>>> Interval.dist((1, 4), (5, 7))
-1
>>> Interval.dist((5, 7), (1, 4))
1
>>> Interval.dist((5, 8), (7, 9))
0
``````

### mavis.interval.Interval.convert_ratioed_pos()

convert any given position given a mapping of intervals to another range

``````@classmethod
def convert_ratioed_pos(cls, mapping, pos, forward_to_reverse=None):
``````

Args

• mapping (`Dict[Interval,Interval]`): a mapping of a set of continuous intervals
• pos (`int`): a position in the first coordinate system
• forward_to_reverse

Returns

• `Interval`: the position in the alternate coordinate system given the input mapping

Raises

• `AttributeError`: if the input position is outside the set of input segments
• `IndexError`: if the input position cannot be converted to the output system

Examples

``````>>> mapping = {(1, 10): (101, 110), (11, 20): (555, 564)}
>>> Interval.convert_pos(mapping, 5)
5
>>> Interval.convert_pos(mapping, 15)
559
``````

### mavis.interval.Interval.union()

returns the union of the set of input intervals

``````@classmethod
def union(cls, *intervals):
``````

Examples

``````>>> Interval.union((1, 2), (4, 6), (4, 9), (20, 21))
Interval(1, 21)
``````

### mavis.interval.Interval.intersection()

returns None if there is no intersection

``````@classmethod
def intersection(cls, *intervals):
``````

Examples

``````>>> Interval.intersection((1, 10), (2, 8), (7, 15))
Interval(7, 8)
>>> Interval.intersection((1, 2), (5, 9))
None
``````

### mavis.interval.Interval.min_nonoverlapping()

for a list of intervals, orders them and merges any overlap to return a list of non-overlapping intervals O(nlogn)

``````@classmethod
def min_nonoverlapping(cls, *intervals):
``````

Examples

``````>>> Interval.min_nonoverlapping((1, 10), (7, 8), (6, 14), (17, 20))
[Interval(1, 14), Interval(17, 20)]
``````

### mavis.interval.Interval.split_overlap()

for a given set of intervals splits any overlap so that the result is a new list of intervals with a single bp overlap

``````@classmethod
def split_overlap(cls, *intervals, weight_mapping={}):
``````

Warning

this method is meant for integer intervals only

## class mavis.interval.IntervalMapping

mapping between coordinate systems using intervals. source intervals cannot overlap but no such assertion is enforced on the target intervals

### mavis.interval.IntervalMapping.__init__()

``````def __init__(self, mapping=None, opposing=None):
``````

Args

• mapping
• opposing

### mavis.interval.IntervalMapping.convert_ratioed_pos()

convert any given position given a mapping of intervals to another range

``````def convert_ratioed_pos(self, pos):
``````

Args

• pos (`Interval`): a position in the first coordinate system

Returns

: the position in the alternate coordinate system given the input mapping - int: if simplify is True - Interval: if simplify is False

Raises

• `IndexError`: if the input position is not in any of the mapped intervals

Examples

``````>>> mapping = IntervalMapping(mapping={(1, 10): (101, 110), (11, 20): (555, 564)})
>>> mapping.convert_pos(5)
5
>>> mapping.convert_pos(15)
559
``````

### mavis.interval.IntervalMapping.convert_pos()

convert any given position given a mapping of intervals to another range

``````def convert_pos(self, pos):
``````

Args

• pos (`int`): a position in the first coordinate system

Returns

: the position in the alternate coordinate system given the input mapping - int: if simplify is True - Interval: if simplify is False

Raises

• `IndexError`: if the input position is not in any of the mapped intervals

Examples

``````>>> mapping = IntervalMapping(mapping={(1, 10): (101, 110), (11, 20): (555, 564)})
>>> mapping.convert_pos(5)
5
>>> mapping.convert_pos(15)
559
``````