Skip to content

Commit

Permalink
Create stub methods for Python-native conversion between SBOL3 and SBOL2
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebeal committed Oct 6, 2023
1 parent ae3d852 commit f5877ae
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sbol_utilities/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from sbol_utilities.helper_functions import strip_sbol2_version, GENETIC_DESIGN_FILE_TYPES, \
find_top_level
from sbol_utilities.sbol3_genbank_conversion import GenBankSBOL3Converter
from sbol_utilities.sbol3_sbol2_conversion import SBOL2SBOL3Converter
from sbol_utilities.workarounds import id_sort

# sbol javascript executable based on https://github.com/sboltools/sbolgraph
Expand Down Expand Up @@ -69,13 +70,18 @@ def convert_identities2to3(sbol3_data: str) -> str:
return g.serialize(format="xml")


def convert2to3(sbol2_doc: Union[str, sbol2.Document], namespaces=None) -> sbol3.Document:
def convert2to3(sbol2_doc: Union[str, sbol2.Document], namespaces=None, use_native_converter: bool = True) \
-> sbol3.Document:
"""Convert an SBOL2 document to an equivalent SBOL3 document
:param sbol2_doc: Document to convert
:param namespaces: list of URI prefixes to treat as namespaces
:param use_native_converter: if true, use experimental Python converter instead of JavaScript call-out
:return: equivalent SBOL3 document
"""
if use_native_converter:
return SBOL2SBOL3Converter.convert2to3(sbol2_doc)

# if we've started with a Document in memory, write it to a temp file
if namespaces is None:
namespaces = []
Expand Down Expand Up @@ -167,12 +173,16 @@ def change_orientation(o):
return doc


def convert3to2(doc3: sbol3.Document) -> sbol2.Document:
def convert3to2(doc3: sbol3.Document, use_native_converter: bool = False) -> sbol2.Document:
"""Convert an SBOL3 document to an equivalent SBOL2 document
:param doc3: Document to convert
:param use_native_converter: if true, use experimental Python converter instead of JavaScript call-out
:return: equivalent SBOL2 document
"""
if use_native_converter:
return SBOL2SBOL3Converter.convert3to2(doc3)

# TODO: remove workarounds after conversion errors fixed in https://github.com/sboltools/sbolgraph/issues/16
# remap sequence encodings:
encoding_remapping = {
Expand Down
26 changes: 26 additions & 0 deletions sbol_utilities/sbol3_sbol2_conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sbol3
import sbol2


class SBOL2SBOL3Converter:
@staticmethod
def convert3to2(doc3: sbol3.Document) -> sbol2.Document:
"""Convert an SBOL3 document to an SBOL2 document
:param doc3: SBOL3 document to convert
:returns: SBOL2 document
"""
doc2 = sbol2.Document()
# TODO: build converter here
return doc2

@staticmethod
def convert2to3(doc2: sbol2.Document) -> sbol3.Document:
"""Convert an SBOL2 document to an SBOL3 document
:param doc2: SBOL2 document to convert
:returns: SBOL3 document
"""
doc3 = sbol3.Document()
# TODO: build converter here
return doc3

0 comments on commit f5877ae

Please sign in to comment.