From f973c9cce3f39b499ab818c3bdd9f88f8f43fa15 Mon Sep 17 00:00:00 2001 From: David Doty Date: Thu, 28 Mar 2024 14:43:24 -0700 Subject: [PATCH 1/3] bumped version --- scadnano/scadnano.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scadnano/scadnano.py b/scadnano/scadnano.py index 3b2c531..b8332ab 100644 --- a/scadnano/scadnano.py +++ b/scadnano/scadnano.py @@ -54,7 +54,7 @@ # needed to use forward annotations: https://docs.python.org/3/whatsnew/3.7.html#whatsnew37-pep563 from __future__ import annotations -__version__ = "0.19.3" # version line; WARNING: do not remove or change this line or comment +__version__ = "0.19.4" # version line; WARNING: do not remove or change this line or comment import collections import dataclasses From 3929a3c5ccb5cbd5b75b11acaeae7c5cb59993cd Mon Sep 17 00:00:00 2001 From: David Doty Date: Thu, 28 Mar 2024 15:02:20 -0700 Subject: [PATCH 2/3] changed return type of `Design.to_oxview_format` from dict to str --- scadnano/scadnano.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scadnano/scadnano.py b/scadnano/scadnano.py index b8332ab..ad0aee6 100644 --- a/scadnano/scadnano.py +++ b/scadnano/scadnano.py @@ -7756,9 +7756,9 @@ def _write_plates_default(self, directory: str, filename: Optional[str], strands workbook.save(filename_plate) def to_oxview_format(self, warn_duplicate_strand_names: bool = True, - use_strand_colors: bool = True) -> dict: + use_strand_colors: bool = True) -> str: """ - Exports to oxView format. + Exports to oxView format: https://github.com/sulcgroup/oxdna-viewer/blob/master/file-format.md :param warn_duplicate_strand_names: if True, prints a warning to the screen indicating when strands are found to @@ -7766,6 +7766,8 @@ def to_oxview_format(self, warn_duplicate_strand_names: bool = True, :param use_strand_colors: if True (default), sets the color of each nucleotide in a strand in oxView to the color of the strand. + :return: + string in oxView text format """ import datetime self._check_legal_design(warn_duplicate_strand_names) @@ -7857,7 +7859,8 @@ def to_oxview_format(self, warn_duplicate_strand_names: bool = True, 'systems': [{'id': 0, 'strands': oxview_strands}], 'forces': [], 'selections': []} - return oxvsystem + text = json.dumps(oxvsystem) + return text def write_oxview_file(self, directory: str = '.', filename: Optional[str] = None, warn_duplicate_strand_names: bool = True, use_strand_colors: bool = True) -> None: From 9b7c8336c64431c927516c7d2b822b01efde6f90 Mon Sep 17 00:00:00 2001 From: David Doty Date: Thu, 28 Mar 2024 15:12:20 -0700 Subject: [PATCH 3/3] fixed tests for oxview export --- scadnano/scadnano.py | 60 ++++++++++++++++++++++++++--------------- tests/scadnano_tests.py | 8 +++--- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/scadnano/scadnano.py b/scadnano/scadnano.py index ad0aee6..4ffe57e 100644 --- a/scadnano/scadnano.py +++ b/scadnano/scadnano.py @@ -7755,6 +7755,25 @@ def _write_plates_default(self, directory: str, filename: Optional[str], strands workbook.save(filename_plate) + def write_oxview_file(self, directory: str = '.', filename: Optional[str] = None, + warn_duplicate_strand_names: bool = True, use_strand_colors: bool = True) -> None: + """Writes an oxView file rerpesenting this design. + + :param directory: + directy in which to write the file (default: current working directory) + :param filename: + name of the file to write (default: name of the running script with .oxview extension) + :param warn_duplicate_strand_names: + if True, prints a warning to the screen indicating when strands are found to + have duplicate names. (default: True) + :param use_strand_colors: + if True (default), sets the color of each nucleotide in a strand in oxView to the color + of the strand. + """ + text = self.to_oxview_format(warn_duplicate_strand_names=warn_duplicate_strand_names, + use_strand_colors=use_strand_colors) + write_file_same_name_as_running_python_script(text, 'oxview', directory, filename) + def to_oxview_format(self, warn_duplicate_strand_names: bool = True, use_strand_colors: bool = True) -> str: """ @@ -7769,6 +7788,25 @@ def to_oxview_format(self, warn_duplicate_strand_names: bool = True, :return: string in oxView text format """ + oxvsystem = self.to_oxview_json(warn_duplicate_strand_names=warn_duplicate_strand_names, + use_strand_colors=use_strand_colors) + text = json.dumps(oxvsystem) + return text + + def to_oxview_json(self, warn_duplicate_strand_names: bool = True, + use_strand_colors: bool = True) -> dict: + """ + Exports to oxView format: https://github.com/sulcgroup/oxdna-viewer/blob/master/file-format.md + + :param warn_duplicate_strand_names: + if True, prints a warning to the screen indicating when strands are found to + have duplicate names. (default: True) + :param use_strand_colors: + if True (default), sets the color of each nucleotide in a strand in oxView to the color + of the strand. + :return: + Python dict + """ import datetime self._check_legal_design(warn_duplicate_strand_names) system = _convert_design_to_oxdna_system(self) @@ -7859,27 +7897,7 @@ def to_oxview_format(self, warn_duplicate_strand_names: bool = True, 'systems': [{'id': 0, 'strands': oxview_strands}], 'forces': [], 'selections': []} - text = json.dumps(oxvsystem) - return text - - def write_oxview_file(self, directory: str = '.', filename: Optional[str] = None, - warn_duplicate_strand_names: bool = True, use_strand_colors: bool = True) -> None: - """Writes an oxView file rerpesenting this design. - - :param directory: - directy in which to write the file (default: current working directory) - :param filename: - name of the file to write (default: name of the running script with .oxview extension) - :param warn_duplicate_strand_names: - if True, prints a warning to the screen indicating when strands are found to - have duplicate names. (default: True) - :param use_strand_colors: - if True (default), sets the color of each nucleotide in a strand in oxView to the color - of the strand. - """ - oxvsystem = self.to_oxview_format(warn_duplicate_strand_names=warn_duplicate_strand_names, - use_strand_colors=use_strand_colors) - write_file_same_name_as_running_python_script(json.dumps(oxvsystem), 'oxview', directory, filename) + return oxvsystem def to_oxdna_format(self, warn_duplicate_strand_names: bool = True) -> Tuple[str, str]: """Exports to oxdna format. diff --git a/tests/scadnano_tests.py b/tests/scadnano_tests.py index 61350cc..c3c48eb 100644 --- a/tests/scadnano_tests.py +++ b/tests/scadnano_tests.py @@ -6987,8 +6987,8 @@ def test_export(self): oxdna_system = _convert_design_to_oxdna_system(design) - oxv = design.to_oxview_format(use_strand_colors=True) - oxv_no_color = design.to_oxview_format(use_strand_colors=False) + oxv = design.to_oxview_json(use_strand_colors=True) + oxv_no_color = design.to_oxview_json(use_strand_colors=False) # Is the box correct? self.assertEqual(list(oxdna_system.compute_bounding_box()), oxv['box']) @@ -7038,7 +7038,7 @@ def test_bp(self): des.draw_strand(2, 20).extension_5p(8).to(12).extension_3p(8).with_sequence( 'ATACTGGAACTACGCGCGTGAATT', assign_complement=False) - oxv = des.to_oxview_format() + oxv = des.to_oxview_json() strands = oxv['systems'][0]['strands'] @@ -7092,7 +7092,7 @@ def test_export_file(self): sc.Color(254, 123, 222)) design.draw_strand(0, 7).move(-7).cross(1).move(7) - oxv = design.to_oxview_format(use_strand_colors=True) + oxv = design.to_oxview_json(use_strand_colors=True) with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f: design.write_oxview_file(filename=f.name)