checkBalance

PURPOSE ^

Checks whether a set of reactions is elementally balanced.

SYNOPSIS ^

function [dE,E]=checkBalance(model,element,printLevel)

DESCRIPTION ^

 Checks whether a set of reactions is elementally balanced.

 note that exchange reactions are not elementally balanced

 INPUT
 model                 COBRA model structure
      .S               Stoichiometric matrix
      .metForumlas     Metabolite formulas
 element               Abbreviation of element e.g. C or Mg


 OPTIONAL INPUT
 printLevel                    {-1,(0),1} 
                               -1=print out missing formulae to a file
                               0=silent
                               1=print out  missing formulae to screen                             reactions to screen 

 OUTPUT
 dE        n x 1 vector of net change in elements per reaction bal = E*S
           If isnan(dE(n)) then the reaction involves a metabolite without
           a formula.

 E         m x 1 vector with number of elements in each metabolite
 
 Ronan M.T. Fleming    July 2009

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [dE,E]=checkBalance(model,element,printLevel)
0002 % Checks whether a set of reactions is elementally balanced.
0003 %
0004 % note that exchange reactions are not elementally balanced
0005 %
0006 % INPUT
0007 % model                 COBRA model structure
0008 %      .S               Stoichiometric matrix
0009 %      .metForumlas     Metabolite formulas
0010 % element               Abbreviation of element e.g. C or Mg
0011 %
0012 %
0013 % OPTIONAL INPUT
0014 % printLevel                    {-1,(0),1}
0015 %                               -1=print out missing formulae to a file
0016 %                               0=silent
0017 %                               1=print out  missing formulae to screen                             reactions to screen
0018 %
0019 % OUTPUT
0020 % dE        n x 1 vector of net change in elements per reaction bal = E*S
0021 %           If isnan(dE(n)) then the reaction involves a metabolite without
0022 %           a formula.
0023 %
0024 % E         m x 1 vector with number of elements in each metabolite
0025 %
0026 % Ronan M.T. Fleming    July 2009
0027 
0028 if ~isfield(model,'metFormulas')
0029     error('model structure must contain model.metForumlas field')
0030 end
0031 if ~exist('printLevel')
0032     printLevel=1;
0033 end
0034 
0035 [nMet,nRxn]=size(model.S);
0036 
0037     
0038 E=zeros(nMet,1);
0039 firstMissing=0;
0040 for m=1:nMet
0041     if isempty(model.metFormulas{m})
0042         if printLevel==1
0043             fprintf('%s\t%s\n',int2str(m),[model.mets{m} ' has no formula'])
0044         end
0045         if printLevel==-1
0046             if ~firstMissing
0047                 fid=fopen('metabolites_without_formulae.txt','w');
0048             end
0049             firstMissing=1;
0050             fprintf(fid,'%s\t%s\n',int2str(m),model.mets{m});
0051         end
0052         if 1
0053             %NaN will show up in dE for the corresponding reaction
0054             %inidcating that the mass balance of the reaction is unknown.
0055             E(m,1)=NaN;
0056         else
0057             error('model structure must contain model.metForumlas field for each metabolite');
0058         end
0059     else
0060         E(m,1)=numAtomsOfElementInFormula(model.metFormulas{m},element);
0061     end
0062 end
0063 
0064 dE=model.S'*E; 
0065 
0066 if exist('fid','var')
0067     fclose(fid);
0068 end

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003