forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changeObjective.m
42 lines (37 loc) · 1.11 KB
/
changeObjective.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
function model = changeObjective(model,rxnNameList,objectiveCoeff)
%changeObjective Changes the objective function of a constraint-based model
%
% model = changeObjective(model,rxnNameList,objectiveCoeff)
%
%INPUTS
% model COBRA structure
% rxnNameList List of reactions (cell array or string)
%
%OPTIONAL INPUT
% objectiveCoeff Value of objective coefficient for each reaction
% (Default = 1)
%
%OUTPUT
% model COBRA model structure with new objective
%
% Monica Mo & Markus Herrgard - 8/21/06
if (nargin < 3)
objectiveCoeff = 1;
end
rxnID = findRxnIDs(model,rxnNameList);
model.c = zeros(size(model.c));
if iscell(rxnNameList)
missingRxns = rxnNameList(rxnID == 0);
for i = 1:length(missingRxns)
fprintf('%s not in model\n',missingRxns{i});
end
rxnID = rxnID(rxnID ~= 0);
if (length(objectiveCoeff) > 1)
objectiveCoeff = objectiveCoeff(rxnID ~= 0);
end
end
if (isempty(rxnID) | rxnID == 0)
error('Objective reactions not found in model!');
else
model.c(rxnID) = objectiveCoeff;
end