Skip to content

Commit

Permalink
Merge pull request #300 from UC-Davis-molecular-computing/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dave-doty committed Mar 28, 2024
2 parents 710410b + 9b7c833 commit 78fcc89
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
65 changes: 43 additions & 22 deletions scadnano/scadnano.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -7755,17 +7755,57 @@ 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) -> dict:
use_strand_colors: bool = True) -> str:
"""
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:
string in oxView text format
"""
Exports to oxView 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)
Expand Down Expand Up @@ -7859,25 +7899,6 @@ def to_oxview_format(self, warn_duplicate_strand_names: bool = True,

return oxvsystem

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)

def to_oxdna_format(self, warn_duplicate_strand_names: bool = True) -> Tuple[str, str]:
"""Exports to oxdna format.
Expand Down
8 changes: 4 additions & 4 deletions tests/scadnano_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 78fcc89

Please sign in to comment.