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

Convert to sbol2 #49

Merged
merged 3 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion features_to_circuits/features_to_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys

from Bio.Seq import Seq
from sbol import *
from sbol2 import *
from flashtext import KeywordProcessor
from sequences_to_features import Feature
from sequences_to_features import FeatureLibrary
Expand Down Expand Up @@ -185,6 +185,11 @@ def copy_module_definition(cls, mod_definition, source_doc, sink_doc):
return sink_doc.getComponentDefinition(mod_definition.identity)
except RuntimeError:
definition_copy = mod_definition.copy(sink_doc)
except SBOLError as exc:
if exc.error_code() == SBOLErrorCode.NOT_FOUND_ERROR:
definition_copy = mod_definition.copy(sink_doc)
else:
raise

for sub_mod in mod_definition.modules:
sub_mod_definition = source_doc.getModuleDefinition(sub_mod.definition)
Expand Down
27 changes: 23 additions & 4 deletions sequences_to_features/sequences_to_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
import json

from Bio.Seq import Seq
from sbol import *
from sbol2 import *
from flashtext import KeywordProcessor

# Set up the not found error for catching
try:
# SBOLError is in the native python module
NotFoundError = SBOLError
except NameError:
# The swig wrapper raises RuntimeError on not found
NotFoundError = RuntimeError


def load_sbol(sbol_file):
logging.info('Loading %s', sbol_file)

Expand Down Expand Up @@ -237,9 +246,9 @@ def copy_component_definition(cls, comp_definition, source_doc, sink_doc, import
else:
try:
sink_doc.getComponentDefinition(comp_definition.identity)

return None
except RuntimeError:
except NotFoundError:
definition_copy = comp_definition.copy(sink_doc)

definition_copy.sequences = list(comp_definition.sequences)
Expand Down Expand Up @@ -280,7 +289,7 @@ def copy_component_definition(cls, comp_definition, source_doc, sink_doc, import
for seq_URI in comp_definition.sequences:
try:
sink_doc.getSequence(seq_URI)
except RuntimeError:
except NotFoundError:
seq = source_doc.getSequence(seq_URI)

seq.copy(sink_doc)
Expand Down Expand Up @@ -322,6 +331,11 @@ def __create_sub_component(cls, parent_definition, child_definition):
sub_comp = parent_definition.components.create('_'.join([child_definition.displayId, str(i)]))
except RuntimeError:
sub_comp = None
except SBOLError as exc:
if exc.error_code() == SBOLErrorCode.SBOL_ERROR_URI_NOT_UNIQUE:
sub_comp = None
else:
raise

if sub_comp is None:
i = i + 1
Expand All @@ -347,6 +361,11 @@ def __create_sequence_annotation(cls, parent_definition, child_definition, orien
str(i)]))
except RuntimeError:
seq_anno = None
except SBOLError as exc:
if exc.error_code() == SBOLErrorCode.SBOL_ERROR_URI_NOT_UNIQUE:
seq_anno = None
else:
raise

if seq_anno is None:
i = i + 1
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

install_requires = [
'biopython>=1.7.4',
'dnaplotlib>=1.0',
'flashtext>=2.7',
'pysbol>=2.3.1',
'sbol2',
'matplotlib>=1.5.0'
]

Expand Down
4 changes: 2 additions & 2 deletions test/test_curation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
import os
from sbol import *
from sbol2 import *

from sequences_to_features import *
from features_to_circuits import *
Expand Down Expand Up @@ -167,4 +167,4 @@ def test_curate_nand_circuit(self):
"Inferred circuit is missing expected sub-circuits: {mi}".format(mi=', '.join(sub_circuit_difference)))

if __name__ == '__main__':
unittest.main()
unittest.main()