Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
manulera committed Jan 18, 2024
1 parent 3fe9218 commit f1a38fd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
40 changes: 40 additions & 0 deletions dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pydna.dseqrecord import Dseqrecord
from Bio.SeqFeature import SeqFeature, SimpleLocation
from Bio.Restriction import EcoRI
# _shift_location(SimpleLocation(x_start, x_start + length), 0, len(first)

# seq = Dseqrecord("acgtTTTaatt", circular=True)
# seq.features.append(SeqFeature(SimpleLocation(4, 7), id='full_overlap'))
# seq.features.append(SeqFeature(SimpleLocation(3, 7), id='left_side'))
# seq.features.append(SeqFeature(SimpleLocation(4, 8), id='right_side'))
# # print(*seq.features, sep='\n')
# print('===')
# dummy_cut = ((4, 7), type('DynamicClass', (), {'ovhg': -3})())
# open_seq = seq.apply_cut(dummy_cut, dummy_cut)

# print(*open_seq.features, sep='\n')
# print(open_seq.seq.__repr__())



# opened = Dseqrecord('aaGAATTCaa', circular=True).cut(EcoRI)[0]



# dummy = Dseqrecord('aaGAATTCaa', circular=False)

# print(dummy)
# print(dummy.apply_cut(None, None))


def ranges_overlap(x, y):
return (x[1] > y[0]) != (y[1] < x[0])

print(ranges_overlap((1, 2), (3, 4)))
print(ranges_overlap((1, 3), (2, 4)))
print(ranges_overlap((1, 4), (2, 3)))
print(ranges_overlap((2, 3), (1, 4)))
print(ranges_overlap((2, 4), (1, 3)))
print(ranges_overlap((3, 4), (1, 2)))
print(ranges_overlap((1, 2), (2, 3)))

2 changes: 1 addition & 1 deletion src/pydna/dseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ def right_end_position(self) -> tuple[int, int]:
def apply_cut(self, left_cut, right_cut):

left_watson, left_crick = left_cut[0] if left_cut is not None else self.left_end_position()
ovhg = self.ovhg if left_cut is None else left_cut[1].ovhg
ovhg = left_cut[1].ovhg if left_cut is not None else self.ovhg
right_watson, right_crick = right_cut[0] if right_cut is not None else self.right_end_position()
return Dseq(
str(self[left_watson:right_watson]),
Expand Down
13 changes: 13 additions & 0 deletions tests/test_module_dseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,5 +838,18 @@ def test_apply_cut():
assert seq.apply_cut(None, EcoRI_cut) == Dseq.from_full_sequence_and_overhangs('aaGAATT', watson_ovhg=-4, crick_ovhg=-1)
assert seq.apply_cut(EcoRI_cut, None) == Dseq.from_full_sequence_and_overhangs('AATTCaa', watson_ovhg=-1, crick_ovhg=-4)

# A repeated cut in a circular molecule opens it up
seq = Dseq('aaGAATTCaa', circular=True)
assert seq.apply_cut(EcoRI_cut, EcoRI_cut) == Dseq.from_full_sequence_and_overhangs('AATTCaaaaGAATT', watson_ovhg=-4, crick_ovhg=-4)

# Two cuts extract a subsequence
seq = Dseq('aaGAATTCaaGAATTCaa', circular=True)
EcoRI_cut_2 = ((11, 15), type('DynamicClass', (), {'ovhg': -4})())
assert seq.apply_cut(EcoRI_cut, EcoRI_cut_2) == Dseq.from_full_sequence_and_overhangs('AATTCaaGAATT', watson_ovhg=-4, crick_ovhg=-4)

# TODO: Overlapping cuts should return an error
EcoRI_cut_2 = ((4, 8), type('DynamicClass', (), {'ovhg': -4})())
assert seq.apply_cut(EcoRI_cut, EcoRI_cut_2)

if __name__ == "__main__":
pytest.main([__file__, "-vv", "-s"])

0 comments on commit f1a38fd

Please sign in to comment.