|
39 | 39 | % param: Structure optionally containing the relaxation parameters:
|
40 | 40 | %
|
41 | 41 | % * .internalRelax:
|
42 |
| -% |
43 | 42 | % * 0 = do not allow to relax bounds on internal reactions
|
44 | 43 | % * 1 = do not allow to relax bounds on internal reactions with finite bounds
|
45 | 44 | % * {2} = allow to relax bounds on all internal reactions
|
46 | 45 | %
|
47 | 46 | % * .exchangeRelax:
|
48 |
| -% |
49 | 47 | % * 0 = do not allow to relax bounds on exchange reactions
|
50 | 48 | % * 1 = do not allow to relax bounds on exchange reactions of the type [0,0]
|
51 | 49 | % * {2} = allow to relax bounds on all exchange reactions
|
52 | 50 | %
|
53 | 51 | % * .steadyStateRelax:
|
54 |
| -% |
55 | 52 | % * 0 = do not allow to relax the steady state constraint S*v = b
|
56 | 53 | % * {1} = allow to relax the steady state constraint S*v = b
|
57 | 54 | %
|
58 | 55 | % * .toBeUnblockedReactions - nRxns x 1 vector indicating the reactions to be unblocked
|
59 |
| -% |
60 | 56 | % * toBeUnblockedReactions(i) = 1 : impose v(i) to be positive
|
61 | 57 | % * toBeUnblockedReactions(i) = -1 : impose v(i) to be negative
|
62 | 58 | % * toBeUnblockedReactions(i) = 0 : do not add any constraint (default)
|
63 | 59 | %
|
64 | 60 | % * .excludedReactions - nRxns x 1 bool vector indicating the reactions to be excluded from relaxation
|
65 |
| -% |
66 | 61 | % * excludedReactions(i) = false : allow to relax bounds on reaction i (default)
|
67 | 62 | % * excludedReactions(i) = true : do not allow to relax bounds on reaction i
|
68 | 63 | %
|
69 | 64 | % * .excludedReactionLB - nRxns x 1 bool vector indicating
|
70 | 65 | % the reactions with lower bounds to be excluded from
|
71 | 66 | % relaxation (overridden by excludedReactions)
|
72 |
| -% |
73 | 67 | % * excludedReactionLB(i) = false : allow to relax lower bounds on reaction i (default)
|
74 | 68 | % * excludedReactionLB(i) = true : do not allow to relax lower bounds on reaction i
|
75 | 69 | %
|
76 | 70 | % * .excludedReactionUB - nRxns x 1 bool vector indicating
|
77 | 71 | % the reactions with upper bounds to be excluded from relaxation (overridden by excludedReactions)
|
78 |
| -% |
79 | 72 | % * excludedReactionUB(i) = false : allow to relax upper bounds on reaction i (default)
|
80 | 73 | % * excludedReactionUB(i) = true : do not allow to relax upper bounds on reaction i
|
81 | 74 | %
|
82 | 75 | % * .excludedMetabolites - nMets x 1 bool vector indicating the metabolites to be excluded from relaxation
|
83 |
| -% |
84 | 76 | % * excludedMetabolites(i) = false : allow to relax steady state constraint on metabolite i (default)
|
85 | 77 | % * excludedMetabolites(i) = true : do not allow to relax steady state constraint on metabolite i
|
86 | 78 | %
|
|
99 | 91 | % the algorithm is useful when trying different values
|
100 | 92 | % of theta to start with the appropriate parameter
|
101 | 93 | % giving the lowest cardinality solution.
|
102 |
| -% * .relaxedPrintLevel (Default = 0) Printing information on relaxed reactions |
103 |
| -% * .maxRelaxR (Default = 1e4), maximum relaxation |
104 |
| -% of any bound or equality constraint permitted |
| 94 | +% * .relaxedPrintLevel (Default = 0) Printing information on relaxed reaction bounds and steady state constraints |
| 95 | +% * .maxRelaxR (Default = 1e4), maximum relaxation of any bound or equality constraint permitted |
105 | 96 | %
|
106 | 97 | % OUTPUT:
|
107 | 98 | % solution: Structure containing the following fields:
|
|
127 | 118 | issueConfirmationWarning('relaxedFBA ignores additional variables defined in the model (model field .E)!')
|
128 | 119 | end
|
129 | 120 |
|
| 121 | +feasTol = getCobraSolverParams('LP', 'feasTol'); |
| 122 | + |
130 | 123 | if ~isfield(model,'S')
|
131 | 124 | %relax generic LP problem ,e.g.
|
132 | 125 | % A: [1663×2942 double]
|
|
159 | 152 | param.minLB = min(-max(model.ub),min(model.lb));
|
160 | 153 | end
|
161 | 154 | if ~isfield(param,'maxRelaxR')
|
162 |
| - param.maxRelaxR = 1e4; %TODO - check this for multiscale models |
| 155 | + param.maxRelaxR = 1/feasTol; %TODO - check this for multiscale models |
163 | 156 | end
|
164 | 157 | if ~isfield(param,'printLevel')
|
165 | 158 | param.printLevel = 0; %TODO - check this for multiscale models
|
|
217 | 210 | end
|
218 | 211 | %TODO properly incorporate inf bounds
|
219 | 212 | %add a large finite lower bound here
|
220 |
| -model.lb(model.lb==-inf) = -1e6; |
| 213 | +model.lb(model.lb==-inf) = -1/feasTol; |
221 | 214 | %use this to override some other assignment
|
222 | 215 | excludedReactionLBTmp=param.excludedReactionLB | model.lb==-inf;
|
223 | 216 |
|
|
228 | 221 | param.excludedReactionUB = false(nRxns,1);
|
229 | 222 | end
|
230 | 223 | %add a large finite upper bound here
|
231 |
| -model.ub(model.ub==inf) = 1e6; |
| 224 | +model.ub(model.ub==inf) = 1/feasTol; |
232 | 225 | %use this to override some other assignment
|
233 | 226 | excludedReactionUBTmp=param.excludedReactionUB | model.ub==inf;
|
234 | 227 |
|
|
250 | 243 | end
|
251 | 244 |
|
252 | 245 | if isfield(param,'epsilon') == 0
|
253 |
| - feasTol = getCobraSolverParams('LP', 'feasTol'); |
254 |
| - param.epsilon=feasTol*100; |
| 246 | + param.epsilon=feasTol; |
255 | 247 | end
|
256 | 248 |
|
257 | 249 | if isfield(param,'theta') == 0
|
|
353 | 345 |
|
354 | 346 | %set global parameters on zero norm if they do not exist
|
355 | 347 | if ~isfield(param,'alpha') && ~isfield(param,'alpha0')
|
356 |
| - param.alpha = 10; %weight on relaxation of bounds of reactions |
| 348 | + param.alpha = 1; %weight on relaxation of bounds of reactions |
357 | 349 | end
|
358 | 350 | if ~isfield(param,'lambda') && ~isfield(param,'lambda0')
|
359 |
| - param.lambda = 10; %weight on relaxation of steady state constraints |
| 351 | + param.lambda = 1; %weight on relaxation of steady state constraints |
360 | 352 | end
|
361 | 353 | if ~isfield(param,'gamma') && ~isfield(param,'gamma0')
|
362 | 354 | %default should not be to aim for zero norm flux vector if the problem is infeasible at the begining
|
|
376 | 368 |
|
377 | 369 | %set local paramters on one norm for capped L1
|
378 | 370 | if ~isfield(param,'alpha1')
|
379 |
| - param.alpha1 = param.alpha0/10; |
| 371 | + param.alpha1 = feasTol; |
380 | 372 | end
|
381 | 373 | if ~isfield(param,'lambda1')
|
382 |
| - param.lambda1 = param.lambda0/10; |
| 374 | + param.lambda1 = feasTol; |
383 | 375 | end
|
384 | 376 | if ~isfield(param,'gamma1')
|
385 |
| - %always include some regularisation on the flux rates to keep it well |
386 |
| - %behaved |
387 |
| - param.gamma1 = 1e-6 + param.gamma0/10; |
| 377 | + %some regularisation on the flux rates to keep it well behaved |
| 378 | + param.gamma1 = feasTol; |
388 | 379 | end
|
389 | 380 |
|
390 | 381 | %Combine excludedReactions with internalRelax and exchangeRelax
|
|
426 | 417 | %override
|
427 | 418 | param.excludedMetabolites = param.excludedMetabolites | excludedMetabolitesTmp;
|
428 | 419 |
|
| 420 | +if param.printLevel>0 |
| 421 | + disp(param) |
| 422 | +end |
429 | 423 |
|
430 | 424 | %test if the problem is feasible or not
|
431 | 425 | FBAsolution = optimizeCbModel(model);
|
|
441 | 435 | else
|
442 | 436 |
|
443 | 437 | %too time consuming
|
444 |
| - if any(~isfinite(model.S),'all') |
445 |
| - [I,J]=find(~isfinite(model.S)) |
446 |
| - error('model.S has infinite entries') |
447 |
| - end |
448 |
| - if any(~isfinite(model.b)) |
449 |
| - [I,J]=find(~isfinite(model.b)) |
450 |
| - error('model.b has infinite entries') |
451 |
| - end |
452 |
| - if any(~isfinite(model.c)) |
453 |
| - [I,J]=find(~isfinite(model.c)) |
454 |
| - error('model.c has infinite entries') |
| 438 | + if isMATLABReleaseOlderThan('R2022a') |
| 439 | + if size(model.S,1)*size(model.S,2)<=1e4 |
| 440 | + if any(~isfinite(model.S),'all') |
| 441 | + [I,J]=find(~isfinite(model.S)) |
| 442 | + error('model.S has non-finite entries') |
| 443 | + end |
| 444 | + if any(~isfinite(model.b)) |
| 445 | + [I,J]=find(~isfinite(model.b)) |
| 446 | + error('model.b has non-finite entries') |
| 447 | + end |
| 448 | + if any(~isfinite(model.c)) |
| 449 | + [I,J]=find(~isfinite(model.c)) |
| 450 | + error('model.c has non-finite entries') |
| 451 | + end |
| 452 | + end |
| 453 | + else |
| 454 | + if ~allfinite(model.S) |
| 455 | + [I,J]=find(~isfinite(model.S)) |
| 456 | + error('model.S has non-finite entries') |
| 457 | + end |
| 458 | + if ~allfinite(model.b) |
| 459 | + [I,J]=find(~isfinite(model.b)) |
| 460 | + error('model.b has non-finite entries') |
| 461 | + end |
| 462 | + if ~allfinite(model.c) |
| 463 | + [I,J]=find(~isfinite(model.c)) |
| 464 | + error('model.c has non-finite entries') |
| 465 | + end |
455 | 466 | end
|
456 | 467 |
|
457 | 468 | solution = relaxFBA_cappedL1(model,param);
|
|
495 | 506 | printConstraints(model,-inf,inf, solution.q>=feasTol,relaxedModel, 0);
|
496 | 507 | end
|
497 | 508 | if param.relaxedPrintLevel>0 && any(abs(solution.r)>=feasTol)
|
498 |
| - fprintf('%s\n','The steady state constraint on this metabolite had to be relaxed:') |
| 509 | + fprintf('%s\n','The steady state constraints on these metabolites had to be relaxed:') |
499 | 510 | disp(model.mets(abs(solution.r)>=feasTol));
|
500 | 511 | end
|
501 | 512 | end
|
|
0 commit comments