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)
| 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 | """ |