forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseRxnFormula.m
94 lines (90 loc) · 2.91 KB
/
parseRxnFormula.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
function [metaboliteList,stoichCoeffList,revFlag] = parseRxnFormula(formula)
%parseRxnFormula Parse reaction formula into a list of metabolites and a
%list of S coefficients
%
% [metaboliteList,stoichCoeffList,revFlag] = parseRxnFormula(formula)
%
%INPUT
% formula Reaction formula, may contain symbols '+', '->', '<=>' in
% addition to stoichiometric coefficients and metabolite names
% examples:
% '0.01 cdpdag-SC[m] + 0.01 pg-SC[m] -> 0.01 clpn-SC[m] + cmp[m] + h[m]' (irreversible reaction)
% 'cit[c] + icit[x] <=> cit[x] + icit[c] ' (reversible reaction)
% If no stoichiometric coefficient is provided, it is assumed
% to be = 1
%
%OUTPUTS
% metaboliteList Cell array with metabolite names
% stoichCoeffList List of S coefficients
% revFlag Indicates whether the reaction is reversible (true) or
% not (false)
%
% Example:
%
% formula = '0.01 cdpdag-SC[m] + 0.01 pg-SC[m] -> 0.01 clpn-SC[m] + cmp[m] + h[m]'
%
% [metaboliteList,stoichCoeffList,revFlag] = parseRxnFormula(formula)
%
% metaboliteList =
% 'cdpdag-SC[m]' 'pg-SC[m]' 'clpn-SC[m]' 'cmp[m]' 'h[m]'
% stoichCoeffList =
% -0.01 -0.01 0.01 1 1
% revFlag =
% false
%
% Markus Herrgard 6/1/07
%
% Richard Que 1/25/10 Modified to handle '-->' and '<==>' as arrows
% as well as reactionsformatted as '[compartment] : A --> C'.
tokens = splitString(formula);
stoichCoeffList = [];
metaboliteList = {};
revFlag = true;
% Marks the start of a new stoichiometry + metabolite block
newMetFlag = true;
% Designates products vs reactants
productFlag = false;
compartment = '';
for i = 1:length(tokens)
t = tokens{i};
if strcmp(t(1),'[')
%set compartment
compartment = t;
elseif strcmp(t,':')
%Do nothing
elseif strcmp(t,'+')
% Do nothing
newMetFlag = true;
elseif strcmp(t,'->') || strcmp(t,'-->')
% Irreversible
revFlag = false;
productFlag = true;
newMetFlag = true;
elseif strcmp(t,'<=>') || strcmp(t,'<==>')
% Reversible
revFlag = true;
productFlag = true;
newMetFlag = true;
else
sCoeff = str2double(t);
if (~isnan(sCoeff))
% Stoich coefficient
if ~productFlag
sCoeff = -sCoeff;
end
stoichCoeffList(end+1) = sCoeff;
newMetFlag = false;
else
% Metabolite name
metaboliteList{end+1} = strcat(t,compartment);
if newMetFlag
if ~productFlag
stoichCoeffList(end+1) = -1;
else
stoichCoeffList(end+1) = 1;
end
newMetFlag = true;
end
end
end
end