Home > core > buildEquation.m

buildEquation

PURPOSE ^

buildEquation

SYNOPSIS ^

function equationString=buildEquation(mets,stoichCoeffs,isrev)

DESCRIPTION ^

 buildEquation
   Construct single equation string for a given reaction

   mets            cell array with metabolites involved in the reaction.
   stoichCoeffs    vector with corresponding stoichiometric coeffs.
   isrev           logical indicating if the reaction is or not
                   reversible.

   equationString  equation as a string

    Usage: equationString=buildEquation(mets,stoichCoeffs,isrev)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function equationString=buildEquation(mets,stoichCoeffs,isrev)
0002 % buildEquation
0003 %   Construct single equation string for a given reaction
0004 %
0005 %   mets            cell array with metabolites involved in the reaction.
0006 %   stoichCoeffs    vector with corresponding stoichiometric coeffs.
0007 %   isrev           logical indicating if the reaction is or not
0008 %                   reversible.
0009 %
0010 %   equationString  equation as a string
0011 %
0012 %    Usage: equationString=buildEquation(mets,stoichCoeffs,isrev)
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 %Reactant half:
0027 reactants       = mets(stoichCoeffs<0);
0028 reactantsCoeffs = abs(stoichCoeffs(stoichCoeffs<0));
0029 reactantsEqn    = concatenateEquation(reactants,reactantsCoeffs);
0030 
0031 %Product half:
0032 products       = mets(stoichCoeffs>0);
0033 productsCoeffs = abs(stoichCoeffs(stoichCoeffs>0));
0034 productsEqn    = concatenateEquation(products,productsCoeffs);
0035 
0036 %Full equation:
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 %This function concatenates metabolites and stoich. coefficients to form
0047 %either the left or right side of the rxn equation
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

Generated by m2html © 2005