Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warn_duplicate_strand_names argument to from_scadnano_file #244

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions scadnano/scadnano.py
Original file line number Diff line number Diff line change
Expand Up @@ -4702,7 +4702,8 @@ def __init__(self, *,
strands: List[Strand] = None,
grid: Grid = Grid.none,
helices_view_order: List[int] = None,
geometry: Geometry = None) -> None:
geometry: Geometry = None,
warn_duplicate_strand_names: bool = True) -> None:
"""
:param helices:
List of :any:`Helix`'s; if missing, set based on `strands`.
Expand Down Expand Up @@ -4784,9 +4785,9 @@ def __init__(self, *,
helices_in_group = [self.helices[idx] for idx in helix_idxs_in_group]
_check_helices_grid_legal(group.grid, helices_in_group)

self.__post_init__()
self.__post_init__(warn_duplicate_strand_names=warn_duplicate_strand_names)

def __post_init__(self) -> None:
def __post_init__(self, warn_duplicate_strand_names: bool = True) -> None:
# XXX: exact order of these calls is important
self._ensure_helices_distinct_objects()
self._ensure_strands_distinct_objects()
Expand All @@ -4795,7 +4796,7 @@ def __post_init__(self) -> None:
self._set_helices_min_max_offsets(update=False)
self._ensure_helix_groups_exist()
self._assign_default_helices_view_orders_to_groups()
self._check_legal_design()
self._check_legal_design(warn_duplicate_strand_names=warn_duplicate_strand_names)

if self.automatically_assign_color:
self._assign_colors_to_strands()
Expand Down Expand Up @@ -4882,7 +4883,7 @@ def roll_of_helix(self, helix: Helix) -> float:
return self.groups[helix.group].roll + helix.roll

@staticmethod
def from_scadnano_file(filename: str) -> 'Design': # remove quotes when Py3.6 support dropped
def from_scadnano_file(filename: str, warn_duplicate_strand_names: bool = True) -> 'Design': # remove quotes when Py3.6 support dropped
"""
Loads a :any:`Design` from the file with the given name.

Expand All @@ -4891,10 +4892,10 @@ def from_scadnano_file(filename: str) -> 'Design': # remove quotes when Py3.6 s
"""
with open(filename) as f:
json_str = f.read()
return Design.from_scadnano_json_str(json_str)
return Design.from_scadnano_json_str(json_str, warn_duplicate_strand_names=warn_duplicate_strand_names)

@staticmethod
def from_scadnano_json_str(json_str: str) -> 'Design': # remove quotes when Py3.6 support dropped
def from_scadnano_json_str(json_str: str, warn_duplicate_strand_names: bool = True) -> 'Design': # remove quotes when Py3.6 support dropped
"""
Loads a :any:`Design` from the given JSON string.

Expand All @@ -4903,7 +4904,7 @@ def from_scadnano_json_str(json_str: str) -> 'Design': # remove quotes when Py3
"""
json_map = json.loads(json_str)
try:
design = Design.from_scadnano_json_map(json_map)
design = Design.from_scadnano_json_map(json_map, warn_duplicate_strand_names=warn_duplicate_strand_names)
return design
except KeyError as e:
raise IllegalDesignError(f'I was expecting a JSON key but did not find it: {e}')
Expand Down Expand Up @@ -5096,7 +5097,7 @@ def _helices_and_groups_and_grid_from_json(json_map: Dict) -> Tuple[List[Helix],

@staticmethod
def from_scadnano_json_map(
json_map: dict) -> 'Design': # remove quotes when Py3.6 support dropped
json_map: dict, warn_duplicate_strand_names: bool = True) -> 'Design': # remove quotes when Py3.6 support dropped
"""
Loads a :any:`Design` from the given JSON object (i.e., Python object obtained by calling
json.loads(json_str) from a string representing contents of a JSON file.
Expand Down Expand Up @@ -5152,6 +5153,7 @@ def from_scadnano_json_map(
grid=grid,
helices_view_order=helices_view_order,
geometry=geometry,
warn_duplicate_strand_names=warn_duplicate_strand_names,
)

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