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'.
0001 function [metaboliteList,stoichCoeffList,revFlag] = parseRxnFormula(formula) 0002 %parseRxnFormula Parse reaction formula into a list of metabolites and a 0003 %list of S coefficients 0004 % 0005 % [metaboliteList,stoichCoeffList,revFlag] = parseRxnFormula(formula) 0006 % 0007 %INPUT 0008 % formula Reaction formula, may contain symbols '+', '->', '<=>' in 0009 % addition to stoichiometric coefficients and metabolite names 0010 % examples: 0011 % '0.01 cdpdag-SC[m] + 0.01 pg-SC[m] -> 0.01 clpn-SC[m] + cmp[m] + h[m]' (irreversible reaction) 0012 % 'cit[c] + icit[x] <=> cit[x] + icit[c] ' (reversible reaction) 0013 % If no stoichiometric coefficient is provided, it is assumed 0014 % to be = 1 0015 % 0016 %OUTPUTS 0017 % metaboliteList Cell array with metabolite names 0018 % stoichCoeffList List of S coefficients 0019 % revFlag Indicates whether the reaction is reversible (true) or 0020 % not (false) 0021 % 0022 % Example: 0023 % 0024 % formula = '0.01 cdpdag-SC[m] + 0.01 pg-SC[m] -> 0.01 clpn-SC[m] + cmp[m] + h[m]' 0025 % 0026 % [metaboliteList,stoichCoeffList,revFlag] = parseRxnFormula(formula) 0027 % 0028 % metaboliteList = 0029 % 'cdpdag-SC[m]' 'pg-SC[m]' 'clpn-SC[m]' 'cmp[m]' 'h[m]' 0030 % stoichCoeffList = 0031 % -0.01 -0.01 0.01 1 1 0032 % revFlag = 0033 % false 0034 % 0035 % Markus Herrgard 6/1/07 0036 % 0037 % Richard Que 1/25/10 Modified to handle '-->' and '<==>' as arrows 0038 % as well as reactionsformatted as '[compartment] : A --> C'. 0039 0040 tokens = splitString(formula); 0041 0042 stoichCoeffList = []; 0043 metaboliteList = {}; 0044 revFlag = true; 0045 0046 % Marks the start of a new stoichiometry + metabolite block 0047 newMetFlag = true; 0048 % Designates products vs reactants 0049 productFlag = false; 0050 compartment = ''; 0051 for i = 1:length(tokens) 0052 t = tokens{i}; 0053 if strcmp(t(1),'[') 0054 %set compartment 0055 compartment = t; 0056 elseif strcmp(t,':') 0057 %Do nothing 0058 elseif strcmp(t,'+') 0059 % Do nothing 0060 newMetFlag = true; 0061 elseif strcmp(t,'->') || strcmp(t,'-->') 0062 % Irreversible 0063 revFlag = false; 0064 productFlag = true; 0065 newMetFlag = true; 0066 elseif strcmp(t,'<=>') || strcmp(t,'<==>') 0067 % Reversible 0068 revFlag = true; 0069 productFlag = true; 0070 newMetFlag = true; 0071 else 0072 sCoeff = str2double(t); 0073 if (~isnan(sCoeff)) 0074 % Stoich coefficient 0075 if ~productFlag 0076 sCoeff = -sCoeff; 0077 end 0078 stoichCoeffList(end+1) = sCoeff; 0079 newMetFlag = false; 0080 else 0081 % Metabolite name 0082 metaboliteList{end+1} = strcat(t,compartment); 0083 if newMetFlag 0084 if ~productFlag 0085 stoichCoeffList(end+1) = -1; 0086 else 0087 stoichCoeffList(end+1) = 1; 0088 end 0089 newMetFlag = true; 0090 end 0091 end 0092 end 0093 end 0094