forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printRxnFormula.m
183 lines (166 loc) · 4.87 KB
/
printRxnFormula.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
function formulas = printRxnFormula(model,rxnAbbrList,printFlag,lineChangeFlag,metNameFlag,fid,directionFlag)
%printRxnFormula Print the reaction formulas for a list of reactions
%
%
%INPUTS
% model COBRA model structure
%
%OPTIONAL INPUTS
% rxnAbbrList Abbrs of reactions whose formulas are to be printed
% printFlag Print formulas or just return them (Default = true)
% lineChangeFlag Append a line change at the end of each line
% (Default = true)
% metNameFlag print full met names instead of abbreviations
% (Default = false)
% fid Optional file identifier for printing in files
% directionFlag Checks directionality of reaction. See Note.
% (Default = true)
%
%OUTPUT
% formulas Cell array containing formulas of specified reactions
%
% NOTE: Reactions that have an upperbound <= 0 and lowerbound < 0 will have
% its directionality reversed unless directionFlag = false.
%
% Markus Herrgard 11/17/05
%
% 04/30/08 Ronan Fleming
% altered code since findRxnIDs used abbreviations not names of reactions
%
% 10/11/09 Jeff Orth
% added metNameFlag option
%
% 03/10/10 Richard Que
% added lb < 0 requirement for reversing directionality
if (nargin < 2)
rxnAbbrList = model.rxns;
end
if (nargin < 3)
printFlag = true;
end
if (nargin < 4)
lineChangeFlag = true;
end
if (nargin <5)
metNameFlag = false;
end
if (nargin < 6)
fid = 1;
end
if (nargin < 7)
directionFlag = true;
end
if (~iscell(rxnAbbrList))
if (strcmp(rxnAbbrList,'all'))
rxnAbbrList = model.rxns;
else
rxnAbbrTmp = rxnAbbrList;
clear rxnAbbrList;
rxnAbbrList{1} = rxnAbbrTmp;
end
end
for i = 1:length(rxnAbbrList);
rxnAbbr = rxnAbbrList{i};
rxnID = findRxnIDs(model,rxnAbbr);
if (printFlag)
fprintf(fid,'%s\t',rxnAbbr);
end
if (rxnID > 0)
Srxn = full(model.S(:,rxnID));
if directionFlag && (isfield(model,'ub') && model.ub(rxnID) <= 0) && (isfield(model,'lb') && model.lb(rxnID) < 0)
Srxn = -Srxn;
end
Sprod = (Srxn(Srxn > 0));
if metNameFlag
prodMets = model.metNames(Srxn > 0);
else
prodMets = model.mets(Srxn > 0);
end
Sreact = (Srxn(Srxn < 0));
if metNameFlag
reactMets = model.metNames(Srxn < 0);
else
reactMets = model.mets(Srxn < 0);
end
formulaStr = '';
for j = 1:length(reactMets)
if (j > 1)
if (printFlag)
fprintf(fid,'+ ');
end
formulaStr = [formulaStr '+ '];
end
if (abs(Sreact(j)) ~= 1)
if (printFlag)
fprintf(fid,'%f %s ',abs(Sreact(j)),reactMets{j});
end
formulaStr = [formulaStr num2str(abs(Sreact(j))) ' ' reactMets{j} ' '];
else
if (printFlag)
fprintf(fid,'%s ',reactMets{j});
end
formulaStr = [formulaStr reactMets{j} ' '];
end
end
if (model.rev(rxnID))
if (printFlag)
fprintf(fid,'\t<=>\t');
end
formulaStr = [formulaStr ' <=> '];
else
if (printFlag)
fprintf(fid,'\t->\t');
end
formulaStr = [formulaStr ' -> '];
end
if 0
if length(formulaStr)>200
%most probably this is the biomass reaction
if (printFlag)
fprintf(fid,'\n');
end
end
end
for j = 1:length(prodMets)
if (j > 1)
if (printFlag)
fprintf(fid,'+ ');
end
formulaStr = [formulaStr '+ '];
end
if (Sprod(j) ~= 1)
if (printFlag)
fprintf(fid,'%f %s ',Sprod(j),prodMets{j});
end
formulaStr = [formulaStr num2str(Sprod(j)) ' ' prodMets{j} ' '];
else
if (printFlag)
fprintf(fid,'%s ',prodMets{j});
end
formulaStr = [formulaStr prodMets{j} ' '];
end
end
if (printFlag) & 0
fprintf('\t.');
end
else
if (printFlag)
fprintf(fid,'not in model');
end
formulaStr = 'NA';
end
if (printFlag)
if (rxnID > 0) && (isfield(model,'grRules'))
if (isempty(model.grRules{rxnID}))
fprintf('\t');
else
fprintf('\t%s',model.grRules{rxnID});
end
end
if (lineChangeFlag)
fprintf(fid,'\n');
end
end
formulas{i} = formulaStr;
end
formulas = formulas';