|
@@ -35,11 +35,18 @@ class OverlapConsolidator(Consolidator): |
|
|
An overlap is defined as two features that share a common interval of time,ie: |
|
|
An overlap is defined as two features that share a common interval of time,ie: |
|
|
interval1.end < interval2.start or |
|
|
interval1.end < interval2.start or |
|
|
interval2.start < interval1.end |
|
|
interval2.start < interval1.end |
|
|
|
|
|
|
|
|
|
|
|
An optional delta parameter can be provided to allow for a 'fudge factor' in the comparison, |
|
|
|
|
|
this is used to allow for small gaps between features to be considered as overlapping. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, features: list=[], delta: float=0.0): |
|
|
|
|
|
super().__init__(features) |
|
|
|
|
|
self.delta = delta |
|
|
|
|
|
|
|
|
def consolidate(self): |
|
|
def consolidate(self): |
|
|
"""Consolidate overlapping features""" |
|
|
"""Consolidate overlapping features""" |
|
|
# sort features by start time |
|
|
|
|
|
|
|
|
# sort features by start time ascending |
|
|
self.features.sort(key=lambda x: x.interval.start) |
|
|
self.features.sort(key=lambda x: x.interval.start) |
|
|
|
|
|
|
|
|
# merge overlapping features |
|
|
# merge overlapping features |
|
@@ -47,13 +54,13 @@ class OverlapConsolidator(Consolidator): |
|
|
consolidated = [] |
|
|
consolidated = [] |
|
|
current = self.features[0] |
|
|
current = self.features[0] |
|
|
for feature in self.features[1:]: |
|
|
for feature in self.features[1:]: |
|
|
if current.interval.end < feature.interval.start: |
|
|
|
|
|
|
|
|
if current.interval.end + self.delta < feature.interval.start - self.delta: |
|
|
# no overlap |
|
|
# no overlap |
|
|
consolidated.append(current) |
|
|
consolidated.append(current) |
|
|
current = feature |
|
|
current = feature |
|
|
else: |
|
|
else: |
|
|
# overlap |
|
|
# overlap |
|
|
current.interval.end = max(current.interval.end, feature.interval.end) |
|
|
|
|
|
|
|
|
current.interval.move_end(max(current.interval.end, feature.interval.end)) |
|
|
consolidated.append(current) |
|
|
consolidated.append(current) |
|
|
|
|
|
|
|
|
self.features = consolidated |
|
|
self.features = consolidated |