Skip to content

Commit 611570b

Browse files
committed
getting there, but melt_ss_dna needs fixing for melt to work
1 parent 5b1dc20 commit 611570b

File tree

5 files changed

+59
-52
lines changed

5 files changed

+59
-52
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
2-
ignore = E203, E266, E501, W503, F403, E741, B905, B950
2+
ignore = E203, E266, E501, W503, F403, E741, B905, B950, C901
33
max-line-length = 88
44
max-complexity = 18
55
select = B,C,E,F,W,T4,B9

dummy.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,3 @@
1919
assert new_cutsite_pairs[0] == (None, ((0, -2), None))
2020
assert new_cutsite_pairs[1] == (((0, -4), None), ((7, -4), None))
2121
assert new_cutsite_pairs[2] == (((10, -1), None), None)
22-
23-
seq = Dseq("AGEEGaGJJJg", circular=True)
24-
25-
26-
for shift in range(len(seq)):
27-
new_seq = seq.shifted(shift)
28-
cutsite_pairs = new_seq.get_ds_meltsites(2)
29-
assert len(cutsite_pairs) == 0
30-
31-
print("==")
32-
cutsite_pairs = new_seq.get_cutsite_pairs(new_seq.get_ds_meltsites(3))
33-
34-
print(repr(new_seq))
35-
expected_product = new_seq.apply_cut(((10, 6), None), ((4, 4), None))
36-
print(repr(expected_product))
37-
break
38-
39-
print(cutsite_pairs)
40-
print(new_seq.shift_melt_cutsite_pairs(cutsite_pairs))
41-
print(repr(new_seq))
42-
print(new_seq.melt(2))

dummy2.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77

88
shifted_cutsite_pairs = seq.shift_melt_cutsite_pairs(cutsite_pairs)
99

10-
assert shifted_cutsite_pairs == [((10, 6), None), ((7, 5), None)]
10+
assert shifted_cutsite_pairs == [(((10, 6), None), ((7, 5), None))]
1111

1212
expected_product = seq.apply_cut(((10, 6), None), ((7, 5), None), allow_overlap=True)
1313

14+
15+
print(expected_product._data)
1416
for shift in range(len(seq)):
15-
print(shift)
1617
new_seq = seq.shifted(shift)
1718

1819
cutsite_pairs = new_seq.get_cutsite_pairs(new_seq.get_ds_meltsites(3))
1920
shifted_cutsite_pairs = new_seq.shift_melt_cutsite_pairs(cutsite_pairs)
20-
print(shifted_cutsite_pairs)
21-
assert len(shifted_cutsite_pairs) == 2
22-
# prod = new_seq.apply_cut(*shifted_cutsite_pairs, allow_overlap=True)
23-
# assert prod == expected_product
21+
assert len(shifted_cutsite_pairs) == 1
22+
prod = new_seq.apply_cut(*shifted_cutsite_pairs[0], allow_overlap=True)
23+
print(prod._data)
24+
assert prod == expected_product

dummy3.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
from pydna.dseq import Dseq
3+
4+
seq = Dseq("AGEEGaGJJJg", circular=True)
5+
6+
7+
cutsite_pairs = seq.get_cutsite_pairs(seq.get_ds_meltsites(3))
8+
shifted_cutsite_pairs = seq.shift_melt_cutsite_pairs(cutsite_pairs)
9+
expected_product = seq.apply_cut(((10, 6), None), ((7, 5), None), allow_overlap=True)
10+
11+
print(expected_product._data)
12+
13+
assert seq.melt(3) == (seq, seq)

src/pydna/dseq.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,6 @@ def get_ds_meltsites(self: DseqType, length: int) -> List[CutSiteType]:
24402440
if self.circular:
24412441
spacer = length
24422442
cutfrom = self._data[-length:] + self._data + self._data[:length]
2443-
print(cutfrom)
24442443
else:
24452444
spacer = 0
24462445
cutfrom = self._data
@@ -2561,8 +2560,13 @@ def melt(self, length):
25612560
cutsites = new.get_ds_meltsites(length)
25622561

25632562
cutsite_pairs = self.get_cutsite_pairs(cutsites)
2563+
cutsite_pairs = self.shift_melt_cutsite_pairs(cutsite_pairs)
25642564

2565-
result = tuple(new.apply_cut(*cutsite_pair) for cutsite_pair in cutsite_pairs)
2565+
result = tuple(
2566+
new.apply_cut(*cutsite_pair, allow_overlap=True)
2567+
for cutsite_pair in cutsite_pairs
2568+
)
2569+
print(result)
25662570

25672571
result = tuple([new]) if strands and not result else result
25682572

@@ -2763,9 +2767,6 @@ def apply_cut(
27632767
left_watson, left_crick, ovhg_left = self.get_cut_parameters(left_cut, True)
27642768
right_watson, right_crick, _ = self.get_cut_parameters(right_cut, False)
27652769

2766-
print("%%")
2767-
print(self[left_watson:right_watson])
2768-
print(self[left_crick:right_crick])
27692770
return Dseq(
27702771
self[left_watson:right_watson]._data.translate(dscode_to_watson_table),
27712772
self[left_crick:right_crick]
@@ -2836,45 +2837,58 @@ def shift_melt_cutsite_pairs(
28362837
ss_crick_bytes = set(ss_letters_crick.encode("ascii"))
28372838
ss_watson_bytes = set(ss_letters_watson.encode("ascii"))
28382839
n = len(self._data)
2839-
data = self._data * 2 if self.circular else self._data
2840+
is_circular = self.circular
28402841

28412842
new_cutsite_pairs = []
28422843
for left_cut, right_cut in cutsite_pairs:
28432844
if left_cut is not None:
28442845
(watson, ovhg), enz = left_cut
2845-
crick = watson - ovhg
28462846
if ovhg > 0:
2847-
while watson < len(data) and data[watson] in ss_crick_bytes:
2847+
for _ in range(n):
2848+
if (not is_circular and watson >= n) or self._data[
2849+
watson % n
2850+
] not in ss_crick_bytes:
2851+
break
28482852
watson += 1
2853+
ovhg += 1
28492854
elif ovhg < 0:
2850-
while crick < len(data) and data[crick] in ss_watson_bytes:
2851-
crick += 1
2852-
if self.circular:
2853-
left_cut = ((watson % n, (watson % n) - (crick % n)), enz)
2855+
for _ in range(n):
2856+
if (not is_circular and watson - ovhg >= n) or self._data[
2857+
(watson - ovhg) % n
2858+
] not in ss_watson_bytes:
2859+
break
2860+
ovhg -= 1
2861+
if is_circular:
2862+
left_cut = ((watson % n, ovhg % n), enz)
28542863
else:
2855-
left_cut = ((watson, watson - crick), enz)
2864+
left_cut = ((watson, ovhg), enz)
28562865

28572866
if right_cut is not None:
28582867
(watson, ovhg), enz = right_cut
2859-
crick = watson - ovhg
28602868
if ovhg > 0:
2861-
while crick > 0 and data[crick - 1] in ss_watson_bytes:
2862-
crick -= 1
2869+
for _ in range(n):
2870+
if (not is_circular and watson - ovhg <= 0) or self._data[
2871+
(watson - ovhg - 1) % n
2872+
] not in ss_watson_bytes:
2873+
break
2874+
ovhg += 1
28632875
elif ovhg < 0:
2864-
while watson > 0 and data[watson - 1] in ss_crick_bytes:
2876+
for _ in range(n):
2877+
if (not is_circular and watson <= 0) or self._data[
2878+
(watson - 1) % n
2879+
] not in ss_crick_bytes:
2880+
break
28652881
watson -= 1
2866-
if self.circular:
2867-
right_cut = ((watson % n, (watson % n) - (crick % n)), enz)
2882+
ovhg -= 1
2883+
if is_circular:
2884+
right_cut = ((watson % n, ovhg % n), enz)
28682885
else:
2869-
right_cut = ((watson, watson - crick), enz)
2886+
right_cut = ((watson, ovhg), enz)
28702887

28712888
new_cutsite_pairs.append((left_cut, right_cut))
28722889

28732890
if self.circular:
2874-
new_cutsite_pairs = [
2875-
cut for pair in deduplicate(new_cutsite_pairs) for cut in pair
2876-
]
2877-
2891+
new_cutsite_pairs = deduplicate(new_cutsite_pairs)
28782892
return new_cutsite_pairs
28792893

28802894
def get_parts(self):

0 commit comments

Comments
 (0)