Splits the variant into two at the anchor point. If the anchor point falls within the variant's reference sequence, the variant is split into two new variants: one upstream of the anchor and one downstream. If the anchor is outside the variant's reference sequence, the original vari
(self, anchor: int)
| 830 | ) |
| 831 | |
| 832 | def split(self, anchor: int) -> tuple[Self | None, Self | None]: |
| 833 | """Splits the variant into two at the anchor point. |
| 834 | |
| 835 | If the anchor point falls within the variant's reference sequence, the |
| 836 | variant is split into two new variants: one upstream of the anchor and one |
| 837 | downstream. If the anchor is outside the variant's reference sequence, |
| 838 | the original variant is returned on the appropriate side, and None on the |
| 839 | other. |
| 840 | |
| 841 | Example: |
| 842 | position= 3 |
| 843 | ref: ...[ A C ]... |
| 844 | alt: .....T G T C |
| 845 | anchor=3 | |
| 846 | returns: (chr1:3:A>T, chr1:4:C>GTC) |
| 847 | |
| 848 | Args: |
| 849 | anchor: The 0-based anchor point to split the variant. |
| 850 | |
| 851 | Returns: |
| 852 | A tuple of the upstream and downstream variants. If the variant is only |
| 853 | on one side of the anchorpoint, then None is returned. |
| 854 | """ |
| 855 | if anchor <= self.start: |
| 856 | return None, self.copy() |
| 857 | elif anchor >= self.end: |
| 858 | return self.copy(), None |
| 859 | else: |
| 860 | mid = anchor - self.start |
| 861 | upstream, downstream = self.copy(), self.copy() |
| 862 | upstream.reference_bases = self.reference_bases[:mid] |
| 863 | upstream.alternate_bases = self.alternate_bases[:mid] |
| 864 | |
| 865 | downstream.position = anchor + 1 |
| 866 | downstream.reference_bases = self.reference_bases[mid:] |
| 867 | downstream.alternate_bases = self.alternate_bases[mid:] |
| 868 | return upstream, downstream |
| 869 | |
| 870 | |
| 871 | @dataclasses.dataclass |