From 122445cddf0a67b0d6b44a08074d914fcc22bf8f Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Thu, 12 May 2022 16:41:49 -0700 Subject: [PATCH] In to, check for 3' extension; fixed some tests --- scadnano/scadnano.py | 9 +++++++++ tests/scadnano_tests.py | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/scadnano/scadnano.py b/scadnano/scadnano.py index 6b086c8a..ea31a71f 100644 --- a/scadnano/scadnano.py +++ b/scadnano/scadnano.py @@ -2351,6 +2351,9 @@ def to(self, offset: int) -> 'StrandBuilder[StrandLabel, DomainLabel]': '(strictly increasing or strictly decreasing) ' 'when calling to() twice in a row') + if self._contains_extension_3p(): + raise IllegalDesignError('cannot make a new domain once 3\' extension has been added') + if offset > self.current_offset: forward = True start = self.current_offset @@ -2374,6 +2377,12 @@ def to(self, offset: int) -> 'StrandBuilder[StrandLabel, DomainLabel]': return self + def _contains_extension_3p(self) -> bool: + if self._strand is None: + return False + domains = self._strand.domains + return len(domains) > 1 and isinstance(domains[-1], Extension) + # remove quotes when Py3.6 support dropped def update_to(self, offset: int) -> 'StrandBuilder[StrandLabel, DomainLabel]': """ diff --git a/tests/scadnano_tests.py b/tests/scadnano_tests.py index bf0ca38c..b7ce7d33 100644 --- a/tests/scadnano_tests.py +++ b/tests/scadnano_tests.py @@ -121,13 +121,14 @@ def test_strand__5p_extension(self) -> None: def test_strand__update_to_after_5p_extension_ok(self) -> None: design = self.design_6helix - sb = design.draw_strand(0, 0, extension_5p_length=5) + sb = design.draw_strand(0, 0) + sb.extension_5p(5) sb.to(10) sb.update_to(15) expected_strand: sc.Strand = sc.Strand([ - sc.Extension(5, (-1, -1)), + sc.Extension(5), sc.Domain(0, True, 0, 15), ]) @@ -136,12 +137,13 @@ def test_strand__update_to_after_5p_extension_ok(self) -> None: def test_strand__move_after_5p_extension_ok(self) -> None: design = self.design_6helix - sb = design.draw_strand(0, 0, extension_5p_length=5) + sb = design.draw_strand(0, 0) + sb.extension_5p(5) sb.move(15) expected_strand: sc.Strand = sc.Strand([ - sc.Extension(5, (-1, -1)), + sc.Extension(5), sc.Domain(0, True, 0, 15), ])