From 412f839104330b6ba4a29c52682d5a3a872f2e31 Mon Sep 17 00:00:00 2001 From: Tom Mitchell Date: Thu, 2 Apr 2020 15:23:43 -0400 Subject: [PATCH 1/3] Start using NotFoundError This change serves as backward and forward compatible with pySBOL swig and native pySBOL. It also serves as better documentation about what the raised error means, and why the code responds the way it does. --- sequences_to_features/sequences_to_features.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sequences_to_features/sequences_to_features.py b/sequences_to_features/sequences_to_features.py index 7aaf694..bba9c3a 100644 --- a/sequences_to_features/sequences_to_features.py +++ b/sequences_to_features/sequences_to_features.py @@ -9,6 +9,15 @@ from sbol 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) @@ -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) @@ -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) From 6bc8f79d216f75ca6a424542447badf69655a128 Mon Sep 17 00:00:00 2001 From: Tom Mitchell Date: Fri, 5 Jun 2020 11:04:34 -0400 Subject: [PATCH 2/3] Add forward compatible sbol2 exception handling --- features_to_circuits/features_to_circuits.py | 5 +++++ sequences_to_features/sequences_to_features.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/features_to_circuits/features_to_circuits.py b/features_to_circuits/features_to_circuits.py index 6341159..f6a980e 100644 --- a/features_to_circuits/features_to_circuits.py +++ b/features_to_circuits/features_to_circuits.py @@ -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) diff --git a/sequences_to_features/sequences_to_features.py b/sequences_to_features/sequences_to_features.py index bba9c3a..5ad853c 100644 --- a/sequences_to_features/sequences_to_features.py +++ b/sequences_to_features/sequences_to_features.py @@ -331,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 @@ -356,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 From ba2f98e40ebd6db6d6cdf02aeb684d3fdbf97188 Mon Sep 17 00:00:00 2001 From: Tom Mitchell Date: Fri, 5 Jun 2020 11:05:10 -0400 Subject: [PATCH 3/3] Change to use sbol2 --- features_to_circuits/features_to_circuits.py | 2 +- sequences_to_features/sequences_to_features.py | 2 +- setup.py | 3 ++- test/test_curation.py | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/features_to_circuits/features_to_circuits.py b/features_to_circuits/features_to_circuits.py index f6a980e..0bb6460 100644 --- a/features_to_circuits/features_to_circuits.py +++ b/features_to_circuits/features_to_circuits.py @@ -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 diff --git a/sequences_to_features/sequences_to_features.py b/sequences_to_features/sequences_to_features.py index 5ad853c..5894250 100644 --- a/sequences_to_features/sequences_to_features.py +++ b/sequences_to_features/sequences_to_features.py @@ -6,7 +6,7 @@ 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 diff --git a/setup.py b/setup.py index d9dd014..083b05c 100644 --- a/setup.py +++ b/setup.py @@ -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' ] diff --git a/test/test_curation.py b/test/test_curation.py index c1bb2f1..9c5796f 100644 --- a/test/test_curation.py +++ b/test/test_curation.py @@ -1,6 +1,6 @@ import unittest import os -from sbol import * +from sbol2 import * from sequences_to_features import * from features_to_circuits import * @@ -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() \ No newline at end of file + unittest.main()