Skip to content

Commit 78fcc89

Browse files
authored
Merge pull request #300 from UC-Davis-molecular-computing/dev
Dev
2 parents 710410b + 9b7c833 commit 78fcc89

2 files changed

Lines changed: 47 additions & 26 deletions

File tree

scadnano/scadnano.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# needed to use forward annotations: https://docs.python.org/3/whatsnew/3.7.html#whatsnew37-pep563
5555
from __future__ import annotations
5656

57-
__version__ = "0.19.3" # version line; WARNING: do not remove or change this line or comment
57+
__version__ = "0.19.4" # version line; WARNING: do not remove or change this line or comment
5858

5959
import collections
6060
import dataclasses
@@ -7755,17 +7755,57 @@ def _write_plates_default(self, directory: str, filename: Optional[str], strands
77557755

77567756
workbook.save(filename_plate)
77577757

7758+
def write_oxview_file(self, directory: str = '.', filename: Optional[str] = None,
7759+
warn_duplicate_strand_names: bool = True, use_strand_colors: bool = True) -> None:
7760+
"""Writes an oxView file rerpesenting this design.
7761+
7762+
:param directory:
7763+
directy in which to write the file (default: current working directory)
7764+
:param filename:
7765+
name of the file to write (default: name of the running script with .oxview extension)
7766+
:param warn_duplicate_strand_names:
7767+
if True, prints a warning to the screen indicating when strands are found to
7768+
have duplicate names. (default: True)
7769+
:param use_strand_colors:
7770+
if True (default), sets the color of each nucleotide in a strand in oxView to the color
7771+
of the strand.
7772+
"""
7773+
text = self.to_oxview_format(warn_duplicate_strand_names=warn_duplicate_strand_names,
7774+
use_strand_colors=use_strand_colors)
7775+
write_file_same_name_as_running_python_script(text, 'oxview', directory, filename)
7776+
77587777
def to_oxview_format(self, warn_duplicate_strand_names: bool = True,
7759-
use_strand_colors: bool = True) -> dict:
7778+
use_strand_colors: bool = True) -> str:
7779+
"""
7780+
Exports to oxView format: https://github.com/sulcgroup/oxdna-viewer/blob/master/file-format.md
7781+
7782+
:param warn_duplicate_strand_names:
7783+
if True, prints a warning to the screen indicating when strands are found to
7784+
have duplicate names. (default: True)
7785+
:param use_strand_colors:
7786+
if True (default), sets the color of each nucleotide in a strand in oxView to the color
7787+
of the strand.
7788+
:return:
7789+
string in oxView text format
77607790
"""
7761-
Exports to oxView format.
7791+
oxvsystem = self.to_oxview_json(warn_duplicate_strand_names=warn_duplicate_strand_names,
7792+
use_strand_colors=use_strand_colors)
7793+
text = json.dumps(oxvsystem)
7794+
return text
7795+
7796+
def to_oxview_json(self, warn_duplicate_strand_names: bool = True,
7797+
use_strand_colors: bool = True) -> dict:
7798+
"""
7799+
Exports to oxView format: https://github.com/sulcgroup/oxdna-viewer/blob/master/file-format.md
77627800
77637801
:param warn_duplicate_strand_names:
77647802
if True, prints a warning to the screen indicating when strands are found to
77657803
have duplicate names. (default: True)
77667804
:param use_strand_colors:
77677805
if True (default), sets the color of each nucleotide in a strand in oxView to the color
77687806
of the strand.
7807+
:return:
7808+
Python dict
77697809
"""
77707810
import datetime
77717811
self._check_legal_design(warn_duplicate_strand_names)
@@ -7859,25 +7899,6 @@ def to_oxview_format(self, warn_duplicate_strand_names: bool = True,
78597899

78607900
return oxvsystem
78617901

7862-
def write_oxview_file(self, directory: str = '.', filename: Optional[str] = None,
7863-
warn_duplicate_strand_names: bool = True, use_strand_colors: bool = True) -> None:
7864-
"""Writes an oxView file rerpesenting this design.
7865-
7866-
:param directory:
7867-
directy in which to write the file (default: current working directory)
7868-
:param filename:
7869-
name of the file to write (default: name of the running script with .oxview extension)
7870-
:param warn_duplicate_strand_names:
7871-
if True, prints a warning to the screen indicating when strands are found to
7872-
have duplicate names. (default: True)
7873-
:param use_strand_colors:
7874-
if True (default), sets the color of each nucleotide in a strand in oxView to the color
7875-
of the strand.
7876-
"""
7877-
oxvsystem = self.to_oxview_format(warn_duplicate_strand_names=warn_duplicate_strand_names,
7878-
use_strand_colors=use_strand_colors)
7879-
write_file_same_name_as_running_python_script(json.dumps(oxvsystem), 'oxview', directory, filename)
7880-
78817902
def to_oxdna_format(self, warn_duplicate_strand_names: bool = True) -> Tuple[str, str]:
78827903
"""Exports to oxdna format.
78837904

tests/scadnano_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6987,8 +6987,8 @@ def test_export(self):
69876987

69886988
oxdna_system = _convert_design_to_oxdna_system(design)
69896989

6990-
oxv = design.to_oxview_format(use_strand_colors=True)
6991-
oxv_no_color = design.to_oxview_format(use_strand_colors=False)
6990+
oxv = design.to_oxview_json(use_strand_colors=True)
6991+
oxv_no_color = design.to_oxview_json(use_strand_colors=False)
69926992

69936993
# Is the box correct?
69946994
self.assertEqual(list(oxdna_system.compute_bounding_box()), oxv['box'])
@@ -7038,7 +7038,7 @@ def test_bp(self):
70387038
des.draw_strand(2, 20).extension_5p(8).to(12).extension_3p(8).with_sequence(
70397039
'ATACTGGAACTACGCGCGTGAATT', assign_complement=False)
70407040

7041-
oxv = des.to_oxview_format()
7041+
oxv = des.to_oxview_json()
70427042

70437043
strands = oxv['systems'][0]['strands']
70447044

@@ -7092,7 +7092,7 @@ def test_export_file(self):
70927092
sc.Color(254, 123, 222))
70937093
design.draw_strand(0, 7).move(-7).cross(1).move(7)
70947094

7095-
oxv = design.to_oxview_format(use_strand_colors=True)
7095+
oxv = design.to_oxview_json(use_strand_colors=True)
70967096

70977097
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
70987098
design.write_oxview_file(filename=f.name)

0 commit comments

Comments
 (0)