-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgeckoopt.py
More file actions
154 lines (120 loc) · 5.74 KB
/
geckoopt.py
File metadata and controls
154 lines (120 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright (C) 2019- Centre of Biological Engineering,
# University of Minho, Portugal
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Author: Vitor Pereira
GECKO E. coli model optimization
"""
from collections import OrderedDict
from time import time
from mewpy.model.gecko import GeckoModel
from mewpy.optimization import EA
from mewpy.optimization.evaluation import BPCY, WYIELD, TargetFlux, ModificationType
from mewpy.problems.gecko import GeckoKOProblem, GeckoOUProblem
ITERATIONS = 10
def ec_gecko_ko(compound, display=False, filename=None):
""" GECKO enzyme deletion example.
It runs a multi objective optimization for the increased production of a certain compound on E. Coli.
The GECKO model is the yeast model companion from the GECKO paper "Improving the phenotype predictions
of a yeast genome‐scale metabolic model by incorporating enzymatic
constraints" https://doi.org/10.15252/msb.20167411.
Runs over the MEWpy implementation.
:param compound: A target reaction identifier.
:param display: Prints the best solution.
:param filename: If given, saves the results as csv to filename.
"""
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
PATH = os.path.join(dir_path, '../../../examples/models/gecko')
DATA_FILE = os.path.join(PATH, 'eciML1515_batch.xml')
from reframed.io.sbml import load_cbmodel
m = load_cbmodel(DATA_FILE)
model = GeckoModel(m, biomass_reaction_id='R_BIOMASS_Ec_iML1515_core_75p37M',
protein_pool_exchange_id='R_prot_pool_exchange', reaction_prefix='R_')
model.set_objective({'R_BIOMASS_Ec_iML1515_core_75p37M': 1.0})
envcond = OrderedDict()
# the evaluation (objective) functions
evaluator_1 = BPCY("R_BIOMASS_Ec_iML1515_core_75p37M", compound, method='lMOMA')
evaluator_2 = WYIELD("R_BIOMASS_Ec_iML1515_core_75p37M", compound)
# The optimization problem
problem = GeckoKOProblem(model,
fevaluation=[evaluator_1, evaluator_2],
envcond=envcond,
prot_prefix='R_draw_prot_',
candidate_max_size=6)
# A new instance of the EA optimizer
ea = EA(problem, max_generations=ITERATIONS)
# runs the optimization
ea.run()
# optimization results
if display:
print(ea.dataframe())
# save final population to file
if filename:
print("Saving solutions to file")
ea.dataframe().to_csv(filename)
def ec_gecko_ou(compound, display=False, filename=None):
""" GECKO enzyme over/under expression example.
It runs a multi objective optimization for the increased production of a certain compound on E. Coli.
The GECKO model is the yeast model companion from the GECKO paper "Improving the phenotype predictions
of a yeast genome‐scale metabolic model by incorporating enzymatic
constraints" https://doi.org/10.15252/msb.20167411.
Runs over the MEWpy implementation.
:param compound: A target reaction identifier.
:param display: Prints the best solution.
:param filename: If given, saves the results as csv to filename.
"""
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
PATH = os.path.join(dir_path, '../../examples/models/ec/')
DATA_FILE = os.path.join(PATH, 'eciML1515_batch.xml')
print(DATA_FILE)
from reframed.io.sbml import load_cbmodel
m = load_cbmodel(DATA_FILE)
model = GeckoModel(m, biomass_reaction_id='R_BIOMASS_Ec_iML1515_core_75p37M',
protein_pool_exchange_id='R_prot_pool_exchange', reaction_prefix='R_')
model.set_objective({'R_BIOMASS_Ec_iML1515_core_75p37M': 1.0})
# change protein pool bound (suggested by Leslie)
model.reactions['R_prot_pool_exchange'].ub = 0.26
# define environmental consitions
envcond = OrderedDict()
# the evaluation (objective) functions
evaluator_1 = BPCY("R_BIOMASS_Ec_iML1515_core_75p37M", compound, method='lMOMA')
# FVA MAX is strangely very high... changing the default alpha (0.3) to compensate..
evaluator_2 = WYIELD("R_BIOMASS_Ec_iML1515_core_75p37M", compound, alpha=0.01)
evaluator_3 = TargetFlux(compound)
# The optimization problem
problem = GeckoOUProblem(model,
fevaluation=[evaluator_1, evaluator_2, evaluator_3],
envcond=envcond,
prot_prefix='R_draw_prot_',
candidate_max_size=30)
# A new instance of the EA optimizer
ea = EA(problem, max_generations=ITERATIONS, mp=True,algorithm='NSGAIII')
# runs the optimization
final_pop = ea.run()
# optimization results
if display:
print(ea.dataframe())
# save final population to file
if filename:
print("Saving solutions to file")
ea.dataframe().to_csv(filename)
if __name__ == '__main__':
N_EXP = 1
compounds = {'TYR':'R_EX_tyr__L_e'}
for k, v in compounds.items():
for _ in range(N_EXP):
millis = int(round(time() * 1000))
ec_gecko_ou(v,
display=True,
filename="gecko_{}_OU_{}.csv".format(k, millis))