|
33 | 33 | from pydna.utils import rc |
34 | 34 | from pydna.utils import flatten |
35 | 35 | from pydna.utils import cuts_overlap |
| 36 | +from pydna.utils import deduplicate |
36 | 37 |
|
37 | 38 | from pydna.alphabet import basepair_dict |
38 | 39 | from pydna.alphabet import dscode_to_watson_table |
@@ -2762,6 +2763,9 @@ def apply_cut( |
2762 | 2763 | left_watson, left_crick, ovhg_left = self.get_cut_parameters(left_cut, True) |
2763 | 2764 | right_watson, right_crick, _ = self.get_cut_parameters(right_cut, False) |
2764 | 2765 |
|
| 2766 | + print("%%") |
| 2767 | + print(self[left_watson:right_watson]) |
| 2768 | + print(self[left_crick:right_crick]) |
2765 | 2769 | return Dseq( |
2766 | 2770 | self[left_watson:right_watson]._data.translate(dscode_to_watson_table), |
2767 | 2771 | self[left_crick:right_crick] |
@@ -2831,42 +2835,46 @@ def shift_melt_cutsite_pairs( |
2831 | 2835 | """ |
2832 | 2836 | ss_crick_bytes = set(ss_letters_crick.encode("ascii")) |
2833 | 2837 | ss_watson_bytes = set(ss_letters_watson.encode("ascii")) |
| 2838 | + n = len(self._data) |
| 2839 | + data = self._data * 2 if self.circular else self._data |
2834 | 2840 |
|
2835 | 2841 | new_cutsite_pairs = [] |
2836 | 2842 | for left_cut, right_cut in cutsite_pairs: |
2837 | 2843 | if left_cut is not None: |
2838 | 2844 | (watson, ovhg), enz = left_cut |
2839 | 2845 | crick = watson - ovhg |
2840 | 2846 | if ovhg > 0: |
2841 | | - while ( |
2842 | | - watson < len(self._data) |
2843 | | - and self._data[watson] in ss_crick_bytes |
2844 | | - ): |
| 2847 | + while watson < len(data) and data[watson] in ss_crick_bytes: |
2845 | 2848 | watson += 1 |
2846 | | - ovhg += 1 |
2847 | 2849 | elif ovhg < 0: |
2848 | | - while ( |
2849 | | - crick < len(self._data) and self._data[crick] in ss_watson_bytes |
2850 | | - ): |
| 2850 | + while crick < len(data) and data[crick] in ss_watson_bytes: |
2851 | 2851 | crick += 1 |
2852 | | - ovhg -= 1 |
2853 | | - left_cut = ((watson, ovhg), enz) |
| 2852 | + if self.circular: |
| 2853 | + left_cut = ((watson % n, (watson % n) - (crick % n)), enz) |
| 2854 | + else: |
| 2855 | + left_cut = ((watson, watson - crick), enz) |
2854 | 2856 |
|
2855 | 2857 | if right_cut is not None: |
2856 | 2858 | (watson, ovhg), enz = right_cut |
2857 | 2859 | crick = watson - ovhg |
2858 | 2860 | if ovhg > 0: |
2859 | | - while crick > 0 and self._data[crick - 1] in ss_watson_bytes: |
| 2861 | + while crick > 0 and data[crick - 1] in ss_watson_bytes: |
2860 | 2862 | crick -= 1 |
2861 | | - ovhg += 1 |
2862 | 2863 | elif ovhg < 0: |
2863 | | - while watson > 0 and self._data[watson - 1] in ss_crick_bytes: |
| 2864 | + while watson > 0 and data[watson - 1] in ss_crick_bytes: |
2864 | 2865 | watson -= 1 |
2865 | | - ovhg -= 1 |
2866 | | - right_cut = ((watson, ovhg), enz) |
| 2866 | + if self.circular: |
| 2867 | + right_cut = ((watson % n, (watson % n) - (crick % n)), enz) |
| 2868 | + else: |
| 2869 | + right_cut = ((watson, watson - crick), enz) |
2867 | 2870 |
|
2868 | 2871 | new_cutsite_pairs.append((left_cut, right_cut)) |
2869 | 2872 |
|
| 2873 | + if self.circular: |
| 2874 | + new_cutsite_pairs = [ |
| 2875 | + cut for pair in deduplicate(new_cutsite_pairs) for cut in pair |
| 2876 | + ] |
| 2877 | + |
2870 | 2878 | return new_cutsite_pairs |
2871 | 2879 |
|
2872 | 2880 | def get_parts(self): |
|
0 commit comments