Skip to content

Commit 37475e5

Browse files
Merge pull request #20 from SynBioDex/taya-test
module, funcComp, biochemical reaction functions; trailing whitespace in domain name
2 parents 7e51bb5 + 4d143e1 commit 37475e5

File tree

5 files changed

+160
-2
lines changed

5 files changed

+160
-2
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.github/.DS_Store

0 Bytes
Binary file not shown.

excelutils/.DS_Store

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

excelutils/excel_sbol_utils/library2.py

Lines changed: 160 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,165 @@
1414
# if in lib2 or lib_both for version 2 and lib3 or lib_both for version 3
1515
# would reduce code duplication?
1616

17+
def biochemical_reaction(rowobj):
18+
chemical_name = rowobj.obj_uri.split("/")[-1]
19+
chemical_uri = rowobj.obj_uri
20+
module_def_name = f"{chemical_name}_production"
21+
22+
enzyme_name = None
23+
substrate_name = None
24+
25+
if module_def_name not in [m.displayId for m in rowobj.doc.moduleDefinitions]:
26+
module_def = sbol2.ModuleDefinition(module_def_name)
27+
else:
28+
module_def = rowobj.doc.moduleDefinitions.get(module_def_name)
29+
for col in rowobj.col_cell_dict.keys():
30+
val = rowobj.col_cell_dict[col]
31+
if col == "Enzyme":
32+
if isinstance(val, str):
33+
enzyme_uri = val
34+
enzyme_name = val.split("/")[-1]
35+
36+
if col == "Substrate":
37+
if isinstance(val, str):
38+
substrate_uri = val
39+
substrate_name = val.split("/")[-1]
40+
41+
# enzyme not provided
42+
if substrate_name is None:
43+
print("Substrate not provided. Just FC for enzyme will be created.")
44+
if enzyme_name not in [fc.displayId for fc in module_def.functionalComponents]:
45+
enzyme_fc = module_def.functionalComponents.create(enzyme_name)
46+
enzyme_fc.definition = enzyme_uri
47+
else:
48+
enzyme_fc = module_def.functionalComponents.get(enzyme_name)
49+
rowobj.doc.addModuleDefinition(module_def)
50+
return
51+
52+
# substrate not provided
53+
if enzyme_name is None:
54+
print("Enzyme not provided. Just FC for substrate will be created.")
55+
if substrate_name not in [fc.displayId for fc in module_def.functionalComponents]:
56+
substrate_fc = module_def.functionalComponents.create(substrate_name)
57+
substrate_fc.definition = substrate_uri
58+
else:
59+
substrate_fc = module_def.functionalComponents.get(substrate_name)
60+
rowobj.doc.addModuleDefinition(module_def)
61+
return
62+
63+
64+
# substrate fc
65+
if substrate_name not in [fc.displayId for fc in module_def.functionalComponents]:
66+
substrate_fc = module_def.functionalComponents.create(substrate_name)
67+
substrate_fc.definition = substrate_uri
68+
else:
69+
substrate_fc = module_def.functionalComponents.get(substrate_name)
70+
71+
# enzyme fc
72+
if enzyme_name not in [fc.displayId for fc in module_def.functionalComponents]:
73+
enzyme_fc = module_def.functionalComponents.create(enzyme_name)
74+
enzyme_fc.definition = enzyme_uri
75+
else:
76+
enzyme_fc = module_def.functionalComponents.get(enzyme_name)
77+
78+
# chemical fc
79+
if chemical_name not in [fc.displayId for fc in module_def.functionalComponents]:
80+
chemical_fc = module_def.functionalComponents.create(chemical_name)
81+
chemical_fc.definition = chemical_uri
82+
else:
83+
chemical_fc = module_def.functionalComponents.get(chemical_name)
84+
85+
# participation for substrate
86+
participation_substrate = sbol2.Participation(uri = f'{substrate_name}_reactant')
87+
participation_substrate.participant = substrate_fc
88+
participation_substrate.uri = f'{substrate_name}_reactant'
89+
participation_substrate.roles = [sbol2.SBO_REACTANT]
90+
91+
# participation for enzyme
92+
participation_enzyme = sbol2.Participation(uri = f'{enzyme_name}_modifier')
93+
participation_enzyme.participant = enzyme_fc
94+
participation_enzyme.uri = f'{enzyme_name}_modifier'
95+
participation_enzyme.roles = ["http://identifiers.org/biomodels.sbo/SBO:0000019"] #'SBO_MODIFIER'
96+
97+
# participation for profuct
98+
participation_product = sbol2.Participation(uri = f'{chemical_name}_product')
99+
participation_product.participant = chemical_fc
100+
participation_product.uri = f'{chemical_name}_product'
101+
participation_product.roles = [sbol2.SBO_PRODUCT]
102+
103+
# define the interaction
104+
interaction_name = f'{chemical_name}_biochemical_reaction'
105+
interaction_type = sbol2.SBO_BIOCHEMICAL_REACTION
106+
interaction = sbol2.Interaction(interaction_name, interaction_type)
107+
108+
interaction.participations.add(participation_substrate)
109+
interaction.participations.add(participation_enzyme)
110+
interaction.participations.add(participation_product)
111+
112+
module_def.interactions.add(interaction)
113+
rowobj.doc.addModuleDefinition(module_def)
114+
115+
116+
def module(rowobj):
117+
module_name_pref = rowobj.obj_uri.split("/")[-1]
118+
# print("Module Def Name: ", module_name_pref)
119+
module_def_name = f"{module_name_pref}_module_definition"
120+
if module_def_name not in [m.displayId for m in rowobj.doc.moduleDefinitions]:
121+
module_def = sbol2.ModuleDefinition(module_def_name)
122+
else:
123+
module_def = rowobj.doc.moduleDefinitions.get(module_def_name)
124+
for col in rowobj.col_cell_dict.keys():
125+
val = rowobj.col_cell_dict[col]
126+
127+
for col in rowobj.col_cell_dict.keys():
128+
val = rowobj.col_cell_dict[col]
129+
130+
if isinstance(val, str):
131+
module_uris = val.split(",")
132+
133+
for module_uri in module_uris:
134+
module_uri = module_uri.strip()
135+
module_name = module_uri.split("/")[-2]
136+
# print("Module Name: ", module_name)
137+
# print("Module URI: ", module_uri)
138+
if module_name not in [m.displayId for m in module_def.modules]:
139+
mod = module_def.modules.create(module_name)
140+
mod.definition = module_uri
141+
else:
142+
mod = module_def.modules.get(module_name)
143+
144+
if module_name not in [m.displayId for m in rowobj.doc.moduleDefinitions]:
145+
rowobj.doc.addModuleDefinition(module_def)
146+
147+
148+
def funcComp(rowobj):
149+
module_def_name = rowobj.obj_uri.split("/")[-1]
150+
# print("MD Name: ", module_def_name)
151+
fc_name = None
152+
module_name = f"{module_def_name}_module_definition"
153+
if module_name not in [m.displayId for m in rowobj.doc.moduleDefinitions]:
154+
module_def = sbol2.ModuleDefinition(module_name)
155+
else:
156+
module_def = rowobj.doc.moduleDefinitions.get(module_name)
157+
158+
for col in rowobj.col_cell_dict.keys():
159+
val = rowobj.col_cell_dict[col]
160+
# print("FC links: ", val)
161+
fc_uris = [val] if isinstance(val, str) else val
162+
163+
for fc_uri in fc_uris:
164+
fc_name = fc_uri.split("/")[-2]
165+
# print("FC Name: ", fc_name)
166+
# print("FC URI: ", fc_uri)
167+
if fc_name not in [fc.displayId for fc in module_def.functionalComponents]:
168+
fc = module_def.functionalComponents.create(fc_name)
169+
fc.definition = fc_uri
170+
else:
171+
fc = module_def.functionalComponents.get(fc_name)
172+
173+
if module_name not in [m.displayId for m in rowobj.doc.moduleDefinitions]:
174+
rowobj.doc.addModuleDefinition(module_def)
175+
17176

18177

19178
def objectType(rowobj):
@@ -34,7 +193,7 @@ def displayId(rowobj):
34193

35194
dict = os.getenv("SBOL_DICTIONARY")
36195
data = json.loads(dict)
37-
url = data["Domain"]
196+
url = data["Domain"].strip()
38197
if url.endswith('/'):
39198
url = url[:-1]
40199
collection = data["Library Name"]
@@ -49,7 +208,6 @@ def displayId(rowobj):
49208
private_collection = False
50209

51210
if data["Master Collection"].strip() == "":
52-
53211
master_collection = False
54212
else:
55213
collection = data["Master Collection"]

0 commit comments

Comments
 (0)