forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangeRxnBounds.m
89 lines (83 loc) · 2.77 KB
/
changeRxnBounds.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
function model = changeRxnBounds(model, rxnNameList, value, boundType)
% Changes upper or lower bounds of a reaction or a set of reactions
%
% USAGE:
%
% model = changeRxnBounds(model, rxnNameList, value, boundType)
%
% INPUTS:
% model: COBRA model structure
% rxnNameList: List of reactions (cell array or string)
% value: Bound values.
% Can either be a vector or a single scalar value if the same
% bound value is to be assinged to all reactions
%
% OPTIONAL INPUT:
% boundType: 'u' - upper, 'l' - lower, 'b' - both (Default = 'b')
% Bound type can either be a cell array of strings or a
% string with as many letters as there are reactions in `rxnNameList`
%
% OUTPUT:
% model: COBRA model structure with modified reaction bounds
%
% .. Author: - Markus Herrgard 4/21/06
if (nargin < 4)
boundType = 'b';
end
if ((length(value) ~= length(rxnNameList) & length(value) > 1) | (length(boundType) ~= length(rxnNameList) & length(boundType) > 1))
error('Inconsistent lenghts of arguments: rxnNameList, value & boundType');
end
rxnID = findRxnIDs(model,rxnNameList);
% Remove reactions that are not in the model
if (iscell(rxnNameList))
missingRxns = rxnNameList(rxnID == 0);
for i = 1:length(missingRxns)
warning('Reaction %s not in model',missingRxns{i});
end
if (length(boundType) > 1)
boundType = boundType(rxnID ~= 0);
end
if (length(value) > 1)
value = value(rxnID ~= 0);
end
rxnID = rxnID(rxnID ~= 0);
else
if rxnID==0
warning('Reaction %s not in model',rxnNameList)
end
end
if (isempty(rxnID))
%rxnNameList was a cell with a single reaction not found
%Warning would have already been triggered in line 39 above
%So do nothing!
elseif (sum(rxnID) == 0)
warning('Reaction %s not in model',rxnNameList);
else
nRxns = length(rxnID);
if (length(boundType) > 1)
if (length(value) == 1)
value = repmat(value,nRxns,1);
end
for i = 1:nRxns
switch lower(boundType{i})
case 'u'
model.ub(rxnID(i)) = value(i);
case 'l'
model.lb(rxnID(i)) = value(i);
case 'b'
model.lb(rxnID(i)) = value(i);
model.ub(rxnID(i)) = value(i);
end
end
else
switch lower(boundType)
case 'u'
model.ub(rxnID) = value;
case 'l'
model.lb(rxnID) = value;
case 'b'
model.lb(rxnID) = value;
model.ub(rxnID) = value;
end
end
end