Skip to content

Commit

Permalink
Add SimpleInterval to pure Python implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mobiusklein committed May 23, 2024
1 parent 3962100 commit 07cfb89
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/ms_deisotope/peak_dependency_network/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ class SpanningMixin(object):
that same dimension.
"""

__slots__ = []

def __init__(self, start, end):
self.start = start
self.end = end

def __contains__(self, i):
"""
Tests for point inclusion, `start <= i <= end`
Test for point inclusion, `start <= i <= end`
Parameters
----------
Expand All @@ -30,7 +32,7 @@ def __contains__(self, i):

def contains(self, i):
"""
Tests for point inclusion, `start <= i <= end`
Test for point inclusion, `start <= i <= end`
Parameters
----------
Expand All @@ -45,7 +47,7 @@ def contains(self, i):

def overlaps(self, interval):
"""
Tests whether another spanning entity with
Test whether another spanning entity with
a defined start and end point overlaps with
this spanning entity
Expand Down Expand Up @@ -77,7 +79,7 @@ def overlap_size(self, interval):

def is_contained_in_interval(self, interval):
"""
Tests whether this spanning entity is
Test whether this spanning entity is
completely contained inside the other entity
Parameters
Expand All @@ -93,7 +95,7 @@ def is_contained_in_interval(self, interval):

def contains_interval(self, interval):
"""
Tests whether the other spanning entity is
Test whether the other spanning entity is
completely contained inside this entity
Parameters
Expand All @@ -108,6 +110,17 @@ def contains_interval(self, interval):
return self.start <= interval.start and self.end >= interval.end


class SimpleInterval(SpanningMixin):
__slots__ = ['start', 'end']

def __init__(self, start, end):
self.start = start
self.end = end

def __repr__(self):
return "{self.__class__.__name__}({self.start}, {self.end})".format(self=self)


class Interval(SpanningMixin):
"""
A generic wrapper around data associated
Expand Down Expand Up @@ -212,7 +225,7 @@ def __init__(self, center, left, contained, right, level=0, parent=None):

def contains_point(self, x):
"""
Returns the list of contained intervals for all
Return the list of contained intervals for all
nodes which contain the point `x`.
Parameters
Expand Down Expand Up @@ -247,7 +260,7 @@ def _overlaps_interval(self, start, end):

def overlaps(self, start, end):
"""
Returns the list of all contained intervals which
Return the list of all contained intervals which
overlap with the interval described by `start` and `end`
Parameters
Expand Down Expand Up @@ -412,7 +425,7 @@ def balance(self):

def iterative_build_interval_tree(cls, intervals):
"""
Builds an IntervalTreeNode hierarchy from `intervals`. This
Build an IntervalTreeNode hierarchy from `intervals`. This
iterative method is preferable to avoid recursion limits.
Parameters
Expand Down

0 comments on commit 07cfb89

Please sign in to comment.