From da37553008276d90f89ed3a0d1f3f7bbc1dd3449 Mon Sep 17 00:00:00 2001 From: Gonzalo Vidal <35148159+Gonza10V@users.noreply.github.com> Date: Fri, 3 Oct 2025 14:38:25 -0600 Subject: [PATCH 1/3] Create robotutils.py --- src/sbol2build/robotutils.py | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/sbol2build/robotutils.py diff --git a/src/sbol2build/robotutils.py b/src/sbol2build/robotutils.py new file mode 100644 index 0000000..04470ac --- /dev/null +++ b/src/sbol2build/robotutils.py @@ -0,0 +1,71 @@ +def assembly_plan_RDF_to_JSON(file): + sbol2.Config.setOption('sbol_typed_uris', False) + doc = sbol2.Document() + doc.read(file) + + # Known SO roles + PRODUCT_ROLE = 'http://identifiers.org/so/SO:0000804' + BackBone_ROLE = 'http://identifiers.org/so/SO:0000755' + ENZYME_ROLE = 'http://identifiers.org/obi/OBI:0000732' + + PARTS_ROLE_LIST = [ + 'http://identifiers.org/so/SO:0000031', 'http://identifiers.org/so/SO:0000316', + 'http://identifiers.org/so/SO:0001977', 'http://identifiers.org/so/SO:0001956', + 'http://identifiers.org/so/SO:0000188', 'http://identifiers.org/so/SO:0000839', + 'http://identifiers.org/so/SO:0000167', 'http://identifiers.org/so/SO:0000139', + 'http://identifiers.org/so/SO:0001979', 'http://identifiers.org/so/SO:0001955', + 'http://identifiers.org/so/SO:0001546', 'http://identifiers.org/so/SO:0001263', + 'http://identifiers.org/SO:0000141', 'http://identifiers.org/so/SO:0000141' + ] + + product_dicts = [] + globalEnzyme = None + + for cd in doc.componentDefinitions: + print(f"\n🔍 Checking Component: {cd.displayId}") + print(f" Types: {cd.types}") + print(f" Roles: {cd.roles}") + + if ENZYME_ROLE in cd.roles: + globalEnzyme = cd.identity + print(f"✅ Found enzyme definition: {globalEnzyme}") + + if PRODUCT_ROLE in cd.roles: + result = { + 'Product': cd.identity, + 'Backbone': None, + 'PartsList': [], + 'Restriction Enzyme': None + } + + for comp in cd.components: + sub_cd = doc.componentDefinitions.get(comp.definition) + if sub_cd is None: + print(f"⚠️ Component definition for {comp.displayId} not found.") + continue + + print(f" → Subcomponent: {sub_cd.displayId}") + print(f" Roles: {sub_cd.roles}") + + if BackBone_ROLE in sub_cd.roles: + result['Backbone'] = sub_cd.identity + print(f" 🧬 Assigned Backbone: {sub_cd.identity}") + + if any(role in PARTS_ROLE_LIST for role in sub_cd.roles): + result['PartsList'].append(sub_cd.identity) + print(f" 🧩 Added Part: {sub_cd.identity}") + + if not result['Backbone']: + print(f"⚠️ No backbone found for product {cd.displayId}") + if not result['PartsList']: + print(f"⚠️ No parts found for product {cd.displayId}") + + product_dicts.append(result) + + for entry in product_dicts: + entry['Restriction Enzyme'] = globalEnzyme + + with open('output.json', 'w') as json_file: + json.dump(product_dicts, json_file, indent=4) + + return product_dicts From 1fc8614f8ae4ea436fe07223be4b31c94caf745b Mon Sep 17 00:00:00 2001 From: Gonzalo Vidal <35148159+Gonza10V@users.noreply.github.com> Date: Fri, 3 Oct 2025 14:45:42 -0600 Subject: [PATCH 2/3] Update robotutils.py --- src/sbol2build/robotutils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sbol2build/robotutils.py b/src/sbol2build/robotutils.py index 04470ac..6e48303 100644 --- a/src/sbol2build/robotutils.py +++ b/src/sbol2build/robotutils.py @@ -1,3 +1,6 @@ +import sbol2 +import JSON + def assembly_plan_RDF_to_JSON(file): sbol2.Config.setOption('sbol_typed_uris', False) doc = sbol2.Document() From 038476a4308966f43ff197860d94511a6978d845 Mon Sep 17 00:00:00 2001 From: Gonzalo Vidal <35148159+Gonza10V@users.noreply.github.com> Date: Fri, 17 Oct 2025 14:00:24 -0600 Subject: [PATCH 3/3] Fix import statement for JSON module --- src/sbol2build/robotutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sbol2build/robotutils.py b/src/sbol2build/robotutils.py index 6e48303..0d451b0 100644 --- a/src/sbol2build/robotutils.py +++ b/src/sbol2build/robotutils.py @@ -1,5 +1,5 @@ import sbol2 -import JSON +import json def assembly_plan_RDF_to_JSON(file): sbol2.Config.setOption('sbol_typed_uris', False)