-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestimateVmax.m
267 lines (251 loc) · 10.6 KB
/
estimateVmax.m
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
function [vmax, flux, exchangeFluxes] = estimateVmax(metabolicModel, reactor, solverPars, coupledReactionID, targetMu)
%ESTIMATEVMAX Given a growth rate, this function computes which uptake flux
%of the growth limiting substrate gives rise to this growth rate, assuming
%that all other uptake fluxes are set to reasonable / problem-specific
%values. If
% Detailed explanation goes here
orig.vmax = metabolicModel.coupledReactions.vmax;
orig.ks = metabolicModel.coupledReactions.ks;
numberOfReactions = length(metabolicModel.coupledReactions.vmax);
%% report on growth rate under conditions specified in model
metabolicModel.coupledReactions.ks = zeros(numberOfReactions, 1);
[ dbio, dcompound, flux, success ] = getDy(metabolicModel, ones(1,length(reactor.compounds)), -1, solverPars);
if success == true
if solverPars.logLevel > 1
fprintf("Growth rate under original model uptake conditions = %d 1/h.\n", flux(metabolicModel.biomassReac))
end
else
if solverPars.logLevel > 1
fprintf("Original conditions do not allow for growth.\n");
end
end
%% check if selected compound is required for growth; if not: adjust all
% flux boundaries
growthLimiting = true;
metabolicModel.coupledReactions.vmax(coupledReactionID) = 0;
[ dbio, dcompound, flux, success ] = getDy(metabolicModel, ones(1,length(reactor.compounds)), -1, solverPars);
if success == true
growthLimiting = false;
if solverPars.logLevel > 1
fprintf("Selected compound not required for growth, adjusting all flux limits together.\n");
fprintf("Check if uncoupled (and coupled) exchange reactions still contain\ngrowth-relevant fluxes (such as c-sources).\n")
end
else
if solverPars.logLevel > 1
fprintf("Selected compound is required for growth.\n");
end
end
if growthLimiting == true
stepSize = 10;
subStepSize = 1;
else
stepSize = 0.1;
subStepSize = 0.01;
switch metabolicModel.FBAsolver
case 1
orig.lb = metabolicModel.CNAmodel.reacMin(metabolicModel.exchangeReactions.ReacID);
orig.ub = metabolicModel.CNAmodel.reacMax(metabolicModel.exchangeReactions.ReacID);
case 2
orig.lb = metabolicModel.COBRAmodel.lb(metabolicModel.exchangeReactions.ReacID);
orig.ub = metabolicModel.COBRAmodel.ub(metabolicModel.exchangeReactions.ReacID);
otherwise
error('In estimateVmax: unknown FBA solver')
end
end
%% increase vmax until growth rate is larger then target growth rate
currentMu = 0;
if growthLimiting == true
vmax = 0;
else
vmax = stepSize/1000.0 - stepSize; % factor applied to all uptake fluxes
end
while currentMu < targetMu && vmax < 1000.0
vmax = vmax + stepSize;
if growthLimiting == true
metabolicModel.coupledReactions.vmax(coupledReactionID) = vmax;
else
for i = 1:length(metabolicModel.exchangeReactions.ReacID)
if metabolicModel.exchangeReactions.SecretionSense(i) == 1
switch metabolicModel.FBAsolver
case 1
metabolicModel.CNAmodel.reacMin(metabolicModel.exchangeReactions.ReacID(i)) = orig.lb(i) * vmax;
case 2
metabolicModel.COBRAmodel.lb(metabolicModel.exchangeReactions.ReacID(i)) = orig.lb(i) * vmax;
otherwise
error('In estimateVmax: unknown FBA solver')
end
else
if metabolicModel.exchangeReactions.SecretionSense(i) == -1
switch metabolicModel.FBAsolver
case 1
metabolicModel.CNAmodel.reacMax(metabolicModel.exchangeReactions.ReacID(i)) = orig.ub(i) * vmax;
case 2
metabolicModel.COBRAmodel.ub(metabolicModel.exchangeReactions.ReacID(i)) = orig.ub(i) * vmax;
otherwise
error('In estimateVmax: unknown FBA solver')
end
end
end
end
metabolicModel.coupledReactions.vmax = orig.vmax * vmax;
end
[ dbio, dcompound, flux, success ] = getDy(metabolicModel, ones(1,length(reactor.compounds)), -1, solverPars);
if success == true
currentMu = flux(metabolicModel.biomassReac);
else
currentMu = 0;
end
end
if currentMu < targetMu
if solverPars.logLevel > 1
fprintf('Target µ (%d) not reachable, just reached %d 1/h\n', targetMu, currentMu);
end
vmax = -1;
return
end
%% establish lower bound with growth
lowBound = vmax - stepSize - subStepSize;
solvable = false;
while solvable == false
lowBound = lowBound + subStepSize;
if growthLimiting == true
metabolicModel.coupledReactions.vmax(coupledReactionID) = lowBound;
else
for i = 1:length(metabolicModel.exchangeReactions.ReacID)
if metabolicModel.exchangeReactions.SecretionSense(i) == 1
switch metabolicModel.FBAsolver
case 1
metabolicModel.CNAmodel.reacMin(metabolicModel.exchangeReactions.ReacID(i)) = orig.lb(i) * lowBound;
case 2
metabolicModel.COBRAmodel.lb(metabolicModel.exchangeReactions.ReacID(i)) = orig.lb(i) * lowBound;
otherwise
error('In estimateVmax: unknown FBA solver')
end
else
if metabolicModel.exchangeReactions.SecretionSense(i) == -1
switch metabolicModel.FBAsolver
case 1
metabolicModel.CNAmodel.reacMax(metabolicModel.exchangeReactions.ReacID(i)) = orig.ub(i) * lowBound;
case 2
metabolicModel.COBRAmodel.ub(metabolicModel.exchangeReactions.ReacID(i)) = orig.ub(i) * lowBound;
otherwise
error('In estimateVmax: unknown FBA solver')
end
end
end
end
metabolicModel.coupledReactions.vmax = orig.vmax * lowBound;
end
[ dbio, dcompound, flux, success ] = getDy(metabolicModel, ones(1,length(reactor.compounds)), -1, solverPars);
if success == true
solvable = true;
end
end
if flux(metabolicModel.biomassReac) > targetMu
if solverPars.logLevel > 1
fprintf('Failed to find proper lower bound. Chose smaller subStepSize\n');
end
vmax = -1;
return
end
%% now approach target mu
highBound = vmax;
while abs(currentMu - targetMu) > solverPars.minimalGrowth
vmax = (lowBound + highBound) / 2.0;
if growthLimiting == true
metabolicModel.coupledReactions.vmax(coupledReactionID) = vmax;
else
for i = 1:length(metabolicModel.exchangeReactions.ReacID)
if metabolicModel.exchangeReactions.SecretionSense(i) == 1
switch metabolicModel.FBAsolver
case 1
metabolicModel.CNAmodel.reacMin(metabolicModel.exchangeReactions.ReacID(i)) = orig.lb(i) * vmax;
case 2
metabolicModel.COBRAmodel.lb(metabolicModel.exchangeReactions.ReacID(i)) = orig.lb(i) * vmax;
otherwise
error('In estimateVmax: unknown FBA solver')
end
else
if metabolicModel.exchangeReactions.SecretionSense(i) == -1
switch metabolicModel.FBAsolver
case 1
metabolicModel.CNAmodel.reacMin(metabolicModel.exchangeReactions.ReacID(i)) = orig.ub(i) * vmax;
case 2
metabolicModel.COBRAmodel.ub(metabolicModel.exchangeReactions.ReacID(i)) = orig.ub(i) * vmax;
otherwise
error('In estimateVmax: unknown FBA solver')
end
end
end
end
metabolicModel.coupledReactions.vmax = orig.vmax * vmax;
end
[ dbio, dcompound, flux, success ] = getDy(metabolicModel, ones(1,length(reactor.compounds)), -1, solverPars);
if success == true
currentMu = flux(metabolicModel.biomassReac);
if currentMu < targetMu
lowBound = vmax;
else
highBound = vmax;
end
else
if solverPars.logLevel > 1
fprintf('Fail in approaching target µ!\n');
end
vmax = -1;
return
end
end
[exchangeFluxes, limitedFluxesIDs] = getExchangeFluxes(metabolicModel, flux, solverPars, ones(1,length(reactor.compounds)));
if growthLimiting == true
if solverPars.logLevel > 1
fprintf('For getting µ = %d 1/h, choose vmax = %d mmol/gDW/h \nfor the %i th coupled reaction.\n', targetMu, vmax, coupledReactionID);
end
else
if solverPars.logLevel > 1
fprintf('Applying a factor of %d to all uptake limits results in µ = %d 1/h.\n', vmax, targetMu);
fprintf('vmax values for coupled reactions:\n');
for i = 1:numberOfReactions
fprintf('%i: %d\n', i, metabolicModel.coupledReactions.vmax(i));
end
end
end
if solverPars.logLevel > 1
fprintf('\nFluxes at limit:\n');
for i = 1:length(limitedFluxesIDs)
switch metabolicModel.FBAsolver
case 1
fprintf("ID %i (%s): %d ", limitedFluxesIDs(i), metabolicModel.CNAmodel.reacID(limitedFluxesIDs(i),:), flux(limitedFluxesIDs(i)));
case 2
fprintf("ID %i (%s): %d ", limitedFluxesIDs(i), metabolicModel.COBRAmodel.rxnNames{limitedFluxesIDs(i)}, flux(limitedFluxesIDs(i)));
otherwise
error('In estimateVmax: unknown FBA solver')
end
if ismember(limitedFluxesIDs(i), metabolicModel.exchangeReactions.ReacID)
fprintf("(Exchange reaction, ");
if ismember(limitedFluxesIDs(i), metabolicModel.coupledReactions.ReacID)
fprintf("coupled)");
else
fprintf("uncoupled)");
end
end
fprintf('\n');
end
fprintf('\n');
end
%likely not really necessary; just for peace of mind
metabolicModel.coupledReactions.vmax = orig.vmax;
metabolicModel.coupledReactions.ks = orig.ks;
if growthLimiting == false
switch metabolicModel.FBAsolver
case 1
metabolicModel.CNAmodel.reacMin(metabolicModel.exchangeReactions.ReacID) = orig.lb;
metabolicModel.CNAmodel.reacMax(metabolicModel.exchangeReactions.ReacID) = orig.ub;
case 2
metabolicModel.COBRAmodel.lb(metabolicModel.exchangeReactions.ReacID) = orig.lb;
metabolicModel.COBRAmodel.ub(metabolicModel.exchangeReactions.ReacID) = orig.ub;
otherwise
error('In estimateVmax: unknown FBA solver')
end
end
end