0001 function equationString=buildEquation(mets,stoichCoeffs,isrev)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 mets=convertCharArray(mets);
0015 if ~isnumeric(stoichCoeffs)
0016 EM = 'stoichCoeffs must be a numeric vector';
0017 dispEM(EM);
0018 elseif ~islogical(isrev)
0019 EM = 'isrev must be a logical';
0020 dispEM(EM);
0021 elseif length(mets) ~= length(stoichCoeffs)
0022 EM = 'lengths of mets and stoichCoeffs should be the same';
0023 dispEM(EM);
0024 end
0025
0026
0027 reactants = mets(stoichCoeffs<0);
0028 reactantsCoeffs = abs(stoichCoeffs(stoichCoeffs<0));
0029 reactantsEqn = concatenateEquation(reactants,reactantsCoeffs);
0030
0031
0032 products = mets(stoichCoeffs>0);
0033 productsCoeffs = abs(stoichCoeffs(stoichCoeffs>0));
0034 productsEqn = concatenateEquation(products,productsCoeffs);
0035
0036
0037 if isrev
0038 equationString = [reactantsEqn ' <=> ' productsEqn];
0039 else
0040 equationString = [reactantsEqn ' => ' productsEqn];
0041 end
0042
0043 end
0044
0045 function eqn = concatenateEquation(mets,stoichCoeffs)
0046
0047
0048 eqn = '';
0049 for i = 1:length(stoichCoeffs)
0050 if i == 1
0051 plusString='';
0052 else
0053 plusString=' + ';
0054 end
0055 stoich = stoichCoeffs(i);
0056 if stoich == 1
0057 stoich = '';
0058 else
0059 stoich = [num2str(stoich) ' '];
0060 end
0061 eqn = [eqn plusString stoich mets{i}];
0062 end
0063 end