Skip to content

Commit

Permalink
Redo test_strand__5p_extension
Browse files Browse the repository at this point in the history
  • Loading branch information
UnHumbleBen committed May 12, 2022
1 parent 3048af8 commit 0e4c694
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
32 changes: 13 additions & 19 deletions scadnano/scadnano.py
Original file line number Diff line number Diff line change
Expand Up @@ -2189,10 +2189,7 @@ class StrandBuilder(Generic[StrandLabel, DomainLabel]):
"""

# remove quotes when Py3.6 support dropped
def __init__(
self, design: 'Design[StrandLabel, DomainLabel]', helix: int, offset: int,
extension_5p_length: int = 0):
#TODO: Document extension_5p_length argument
def __init__(self, design: 'Design[StrandLabel, DomainLabel]', helix: int, offset: int):
self.design: Design[StrandLabel, DomainLabel] = design
self.current_helix: int = helix
self.current_offset: int = offset
Expand Down Expand Up @@ -2274,6 +2271,15 @@ def extension_3p(self, num_bases: int, display_length: float = 1.0, display_angl
self.design.append_domain(self._strand, ext)
return self

def extension_5p(self, num_bases: int, display_length: float = 1.0, display_angle: float = 45.0) -> 'StrandBuilder[StrandLabel, DomainLabel]':
if self._strand is not None:
raise IllegalDesignError('Cannot add a 5\' extension when there are already domains. Did you mean to create a 3\' extension?')
ext: Extension = Extension(num_bases=num_bases, display_length=display_length,
display_angle=display_angle)
self._strand = Strand(domains=[ext])
self.design.add_strand(self._strand)
return self

def with_relative_offset(self, relative_offset: Tuple[float, float]) -> 'StrandBuilder[StrandLabel, DomainLabel]':
"""
TODO: write doc
Expand Down Expand Up @@ -2361,24 +2367,13 @@ def to(self, offset: int) -> 'StrandBuilder[StrandLabel, DomainLabel]':
if self._strand is not None:
self.design.append_domain(self._strand, domain)
else:
self._strand = Strand(domains=self._create_initial_substrands_list(domain))
self._strand = Strand(domains=[domain])
self.design.add_strand(self._strand)

self.current_offset = offset

return self

def _create_initial_substrands_list(self, domain: Domain):
domains: List[Union[Domain, Loopout, Extension]] = []
self._add_extension_5p_if_not_none(domains, domain.forward)
domains.append(domain)
return domains

def _add_extension_5p_if_not_none(self, substrands: List[Union[Domain, Loopout, Extension]], forward: bool):
if self.extension_5p_builder is not None:
self.extension_5p_builder.relative_offset = (-1, -1) if forward else (1, 1)
substrands.append(self.extension_5p_builder.build())

# remove quotes when Py3.6 support dropped
def update_to(self, offset: int) -> 'StrandBuilder[StrandLabel, DomainLabel]':
"""
Expand Down Expand Up @@ -5320,7 +5315,7 @@ def _ensure_mods_unique_names(all_mods: Set[Modification]) -> None:
raise IllegalDesignError(f'two different modifications share the id {mod.id}; '
f'one is\n {mod}\nand the other is\n {other_mod}')

def draw_strand(self, helix: int, offset: int, extension_5p_length: int = 0) -> StrandBuilder:
def draw_strand(self, helix: int, offset: int) -> StrandBuilder:
"""Used for chained method building the :any:`Strand` domain by domain, in order from 5' to 3'.
For example
Expand Down Expand Up @@ -5378,8 +5373,7 @@ def draw_strand(self, helix: int, offset: int, extension_5p_length: int = 0) ->
:param offset: starting offset on `helix`
:return: :any:`StrandBuilder` object representing the partially completed :any:`Strand`
"""
#TODO: Document extension_5p_length argument
return StrandBuilder(self, helix, offset, extension_5p_length)
return StrandBuilder(self, helix, offset)

def strand(self, helix: int, offset: int) -> StrandBuilder:
"""
Expand Down
5 changes: 3 additions & 2 deletions tests/scadnano_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ def test_strand__3p_extension(self) -> None:

def test_strand__5p_extension(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)

expected_strand: sc.Strand = sc.Strand([
sc.Extension(5, (-1, -1)),
sc.Extension(5),
sc.Domain(0, True, 0, 10),
])

Expand Down

0 comments on commit 0e4c694

Please sign in to comment.