Skip to content

Commit 79e5468

Browse files
committed
Add ecc2compTC generation scripts
1 parent 3c2b3fe commit 79e5468

File tree

5 files changed

+3188
-1367
lines changed

5 files changed

+3188
-1367
lines changed

get_exchange_reactions.py

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2021 PSB
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
"""Generation script for the community model 'ecolicore2double'.
17+
18+
ecolicore2double models a community of two EcoliCore2 'organisms'. Its intention and usage is explained in
19+
more detail in commmodelpy's publication.
20+
"""
21+
# IMPORT SECTION
22+
# External modules
23+
import cobra
24+
import copy
25+
from typing import Dict
26+
# Internal modules
27+
from commmodelpy.submodules.helper_general import json_write, json_load
28+
29+
model = cobra.io.read_sbml_model("./publication_runs/ecoli_models/publication_sbmls_and_dG0_jsons/ecc2compDouble_model.xml")
30+
31+
exchg_reaction_ids = [x.id for x in model.reactions if x.id.startswith("EXCHG_")]
32+
for exchg_reaction_id in exchg_reaction_ids:
33+
reaction = model.reactions.get_by_id(exchg_reaction_id)
34+
if ("_adp_" in reaction.id) or ("_pi_" in reaction.id) or ("_h_" in reaction.id) or ("_h2o_" in reaction.id):
35+
continue
36+
if "ecoli1" in reaction.id:
37+
id_addition = "ecoli1"
38+
else:
39+
id_addition = "ecoli2"
40+
if ((reaction.lower_bound == 0) and (reaction.upper_bound == 0)):
41+
new_pseudo_metabolite = cobra.Metabolite(id=reaction.id+"_PSEUDOMET_REV", compartment="exchg")
42+
reaction.add_metabolites({new_pseudo_metabolite: -1})
43+
new_pseudo_reaction_1 = cobra.Reaction(id=reaction.id.replace("EXCHG_", "").replace("ecoli1_", "").replace("ecoli2_", "")+"_PSEUDOREAC1_REV_"+id_addition,
44+
lower_bound=0,
45+
upper_bound=float("inf"))
46+
new_pseudo_reaction_1.add_metabolites({
47+
new_pseudo_metabolite: 1,
48+
})
49+
new_pseudo_reaction_2 = cobra.Reaction(id=reaction.id.replace("EXCHG_", "").replace("ecoli1_", "").replace("ecoli2_", "")+"_PSEUDOREAC2_REV_"+id_addition,
50+
lower_bound=0,
51+
upper_bound=float("inf"))
52+
new_pseudo_reaction_2.add_metabolites({
53+
new_pseudo_metabolite: -1,
54+
model.metabolites.get_by_id("h2o_c_"+id_addition): -1/3,
55+
model.metabolites.get_by_id("atp_c_"+id_addition): -1/3,
56+
model.metabolites.get_by_id("adp_c_"+id_addition): 1/3,
57+
model.metabolites.get_by_id("h_c_"+id_addition): 1/3,
58+
model.metabolites.get_by_id("pi_c_"+id_addition): 1/3,
59+
})
60+
model.add_reactions([new_pseudo_reaction_1, new_pseudo_reaction_2])
61+
if ((reaction.lower_bound == 0) and (reaction.upper_bound == 0)):
62+
new_pseudo_metabolite = cobra.Metabolite(id=reaction.id+"_PSEUDOMET_FWD", compartment="exchg")
63+
reaction.add_metabolites({new_pseudo_metabolite: 1})
64+
new_pseudo_reaction_1 = cobra.Reaction(id=reaction.id.replace("EXCHG_", "").replace("ecoli1_", "").replace("ecoli2_", "")+"_PSEUDOREAC1_FWD_"+id_addition,
65+
lower_bound=0,
66+
upper_bound=float("inf"))
67+
new_pseudo_reaction_1.add_metabolites({
68+
new_pseudo_metabolite: 1
69+
})
70+
new_pseudo_reaction_2 = cobra.Reaction(id=reaction.id.replace("EXCHG_", "").replace("ecoli1_", "").replace("ecoli2_", "")+"_PSEUDOREAC2_FWD_"+id_addition,
71+
lower_bound=0,
72+
upper_bound=float("inf"))
73+
new_pseudo_reaction_2.add_metabolites({
74+
new_pseudo_metabolite: -1,
75+
model.metabolites.get_by_id("h2o_c_"+id_addition): -1/3,
76+
model.metabolites.get_by_id("atp_c_"+id_addition): -1/3,
77+
model.metabolites.get_by_id("adp_c_"+id_addition): 1/3,
78+
model.metabolites.get_by_id("h_c_"+id_addition): 1/3,
79+
model.metabolites.get_by_id("pi_c_"+id_addition): 1/3,
80+
})
81+
model.add_reactions([new_pseudo_reaction_1, new_pseudo_reaction_2])
82+
83+
print("Test TC model with FBA...")
84+
with model:
85+
model.reactions.get_by_id("EX_C_glc__D_exchg").lower_bound = -10
86+
print("TC model FBA solution:")
87+
fba_solution = model.optimize()
88+
print(model.summary())
89+
for reaction in model.reactions:
90+
if not reaction.id.startswith("EXCHG_"):
91+
continue
92+
if fba_solution.fluxes[reaction.id] != 0:
93+
print(f"{reaction.id}: {fba_solution.fluxes[reaction.id] }")
94+
print("~~~")
95+
96+
# Store model as SBML
97+
cobra.io.write_sbml_model(
98+
model, "./publication_runs/ecoli_models/publication_sbmls_and_dG0_jsons/ecc2compDoubleTC_model.xml")
99+
100+
# Write new dG0 data
101+
dG0_data_dict = json_load("./publication_runs/ecoli_models/publication_sbmls_and_dG0_jsons/ecolicore2double_dG0.json")
102+
json_write("./publication_runs/ecoli_models/publication_sbmls_and_dG0_jsons/ecc2compDoubleTC_dG0.json", dG0_data_dict)

0 commit comments

Comments
 (0)