MCPcopy Create free account
hub / github.com/chaimleib/intervaltree / slice

Method slice

intervaltree/intervaltree.py:521–541  ·  view source on GitHub ↗

Split Intervals that overlap point into two new Intervals. if specified, uses datafunc(interval, islower=True/False) to set the data field of the new Intervals. :param point: where to slice :param datafunc(interval, isupper): callable returning a new

(self, point, datafunc=None)

Source from the content-addressed store, hash-verified

519 self.update(insertions)
520
521 def slice(self, point, datafunc=None):
522 """
523 Split Intervals that overlap point into two new Intervals. if
524 specified, uses datafunc(interval, islower=True/False) to
525 set the data field of the new Intervals.
526 :param point: where to slice
527 :param datafunc(interval, isupper): callable returning a new
528 value for the interval's data field
529 """
530 hitlist = set(iv for iv in self.at(point) if iv.begin < point)
531 insertions = set()
532 if datafunc:
533 for iv in hitlist:
534 insertions.add(Interval(iv.begin, point, datafunc(iv, True)))
535 insertions.add(Interval(point, iv.end, datafunc(iv, False)))
536 else:
537 for iv in hitlist:
538 insertions.add(Interval(iv.begin, point, iv.data))
539 insertions.add(Interval(point, iv.end, iv.data))
540 self.difference_update(hitlist)
541 self.update(insertions)
542
543 def clear(self):
544 """

Callers 2

test_sliceFunction · 0.95
test_slice_datafuncFunction · 0.95

Calls 6

atMethod · 0.95
difference_updateMethod · 0.95
updateMethod · 0.95
IntervalClass · 0.85
datafuncFunction · 0.85
addMethod · 0.45

Tested by 2

test_sliceFunction · 0.76
test_slice_datafuncFunction · 0.76