Skip to content

Commit e849ae5

Browse files
committed
Add warn_duplicate_strand_names argument to from_scadnano_file
1 parent 897f66d commit e849ae5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

scadnano/scadnano.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4702,7 +4702,8 @@ def __init__(self, *,
47024702
strands: List[Strand] = None,
47034703
grid: Grid = Grid.none,
47044704
helices_view_order: List[int] = None,
4705-
geometry: Geometry = None) -> None:
4705+
geometry: Geometry = None,
4706+
warn_duplicate_strand_names: bool = True) -> None:
47064707
"""
47074708
:param helices:
47084709
List of :any:`Helix`'s; if missing, set based on `strands`.
@@ -4784,9 +4785,9 @@ def __init__(self, *,
47844785
helices_in_group = [self.helices[idx] for idx in helix_idxs_in_group]
47854786
_check_helices_grid_legal(group.grid, helices_in_group)
47864787

4787-
self.__post_init__()
4788+
self.__post_init__(warn_duplicate_strand_names=warn_duplicate_strand_names)
47884789

4789-
def __post_init__(self) -> None:
4790+
def __post_init__(self, warn_duplicate_strand_names: bool = True) -> None:
47904791
# XXX: exact order of these calls is important
47914792
self._ensure_helices_distinct_objects()
47924793
self._ensure_strands_distinct_objects()
@@ -4795,7 +4796,7 @@ def __post_init__(self) -> None:
47954796
self._set_helices_min_max_offsets(update=False)
47964797
self._ensure_helix_groups_exist()
47974798
self._assign_default_helices_view_orders_to_groups()
4798-
self._check_legal_design()
4799+
self._check_legal_design(warn_duplicate_strand_names=warn_duplicate_strand_names)
47994800

48004801
if self.automatically_assign_color:
48014802
self._assign_colors_to_strands()
@@ -4882,7 +4883,7 @@ def roll_of_helix(self, helix: Helix) -> float:
48824883
return self.groups[helix.group].roll + helix.roll
48834884

48844885
@staticmethod
4885-
def from_scadnano_file(filename: str) -> 'Design': # remove quotes when Py3.6 support dropped
4886+
def from_scadnano_file(filename: str, warn_duplicate_strand_names: bool = True) -> 'Design': # remove quotes when Py3.6 support dropped
48864887
"""
48874888
Loads a :any:`Design` from the file with the given name.
48884889
@@ -4891,10 +4892,10 @@ def from_scadnano_file(filename: str) -> 'Design': # remove quotes when Py3.6 s
48914892
"""
48924893
with open(filename) as f:
48934894
json_str = f.read()
4894-
return Design.from_scadnano_json_str(json_str)
4895+
return Design.from_scadnano_json_str(json_str, warn_duplicate_strand_names=warn_duplicate_strand_names)
48954896

48964897
@staticmethod
4897-
def from_scadnano_json_str(json_str: str) -> 'Design': # remove quotes when Py3.6 support dropped
4898+
def from_scadnano_json_str(json_str: str, warn_duplicate_strand_names: bool = True) -> 'Design': # remove quotes when Py3.6 support dropped
48984899
"""
48994900
Loads a :any:`Design` from the given JSON string.
49004901
@@ -4903,7 +4904,7 @@ def from_scadnano_json_str(json_str: str) -> 'Design': # remove quotes when Py3
49034904
"""
49044905
json_map = json.loads(json_str)
49054906
try:
4906-
design = Design.from_scadnano_json_map(json_map)
4907+
design = Design.from_scadnano_json_map(json_map, warn_duplicate_strand_names=warn_duplicate_strand_names)
49074908
return design
49084909
except KeyError as e:
49094910
raise IllegalDesignError(f'I was expecting a JSON key but did not find it: {e}')
@@ -5096,7 +5097,7 @@ def _helices_and_groups_and_grid_from_json(json_map: Dict) -> Tuple[List[Helix],
50965097

50975098
@staticmethod
50985099
def from_scadnano_json_map(
5099-
json_map: dict) -> 'Design': # remove quotes when Py3.6 support dropped
5100+
json_map: dict, warn_duplicate_strand_names: bool = True) -> 'Design': # remove quotes when Py3.6 support dropped
51005101
"""
51015102
Loads a :any:`Design` from the given JSON object (i.e., Python object obtained by calling
51025103
json.loads(json_str) from a string representing contents of a JSON file.
@@ -5152,6 +5153,7 @@ def from_scadnano_json_map(
51525153
grid=grid,
51535154
helices_view_order=helices_view_order,
51545155
geometry=geometry,
5156+
warn_duplicate_strand_names=warn_duplicate_strand_names,
51555157
)
51565158

51575159
def to_json_serializable(self, suppress_indent: bool = True, **kwargs: Any) -> Dict[str, Any]:

0 commit comments

Comments
 (0)