Home > RAVEN > constructEquations.m

constructEquations

PURPOSE ^

constructEquations

SYNOPSIS ^

function equationStrings=constructEquations(model,rxns,useComps,sortRevRxns,sortMetNames)

DESCRIPTION ^

 constructEquations
   Construct equation strings for reactions

   model             a model structure
   rxns              either a cell array of reaction IDs, a logical vector with the 
                     same number of elements as reactions in the model, or a vector 
                     of reaction indexes (opt, default model.rxns)
    useComps          include the compartment of each metabolite (opt, default true)
    sortRevRxns       sort reversible reactions so that the metabolite that is first in
                     the lexiographic order is a reactant (opt, default
                     false)
    sortMetNames      sort the metabolite names in the equation. Uses
                     compartment even if useComps is false (opt, default
                     false)

   equationStrings     a cell array with equations

     Usage: equationStrings=constructEquations(model,rxns,useComps,...
           sortRevRxns,sortMetNames)

   Rasmus Agren, 2013-05-16

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function equationStrings=constructEquations(model,rxns,useComps,sortRevRxns,sortMetNames)
0002 % constructEquations
0003 %   Construct equation strings for reactions
0004 %
0005 %   model             a model structure
0006 %   rxns              either a cell array of reaction IDs, a logical vector with the
0007 %                     same number of elements as reactions in the model, or a vector
0008 %                     of reaction indexes (opt, default model.rxns)
0009 %    useComps          include the compartment of each metabolite (opt, default true)
0010 %    sortRevRxns       sort reversible reactions so that the metabolite that is first in
0011 %                     the lexiographic order is a reactant (opt, default
0012 %                     false)
0013 %    sortMetNames      sort the metabolite names in the equation. Uses
0014 %                     compartment even if useComps is false (opt, default
0015 %                     false)
0016 %
0017 %   equationStrings     a cell array with equations
0018 %
0019 %     Usage: equationStrings=constructEquations(model,rxns,useComps,...
0020 %           sortRevRxns,sortMetNames)
0021 %
0022 %   Rasmus Agren, 2013-05-16
0023 %
0024 
0025 if nargin<2
0026     rxns=model.rxns;
0027 end
0028 if nargin<3
0029     useComps=true;
0030 end
0031 if nargin<4
0032     sortRevRxns=false;
0033 end
0034 if nargin<5
0035     sortMetNames=false;
0036 end
0037 if isempty(rxns)
0038     rxns=model.rxns;
0039 end
0040 
0041 %Sort reversible equations
0042 if sortRevRxns==true
0043     model=sortModel(model);
0044 end
0045 
0046 %Sort metabolite names, including compartment
0047 if sortMetNames==true
0048     model=sortModel(model,false,true);
0049 end
0050 
0051 indexes=getIndexes(model,rxns,'rxns');
0052 
0053 equationStrings=cell(numel(indexes),1);
0054 
0055 for i=1:numel(indexes)
0056     reactants=find(model.S(:,indexes(i))<0);
0057     products=find(model.S(:,indexes(i))>0);
0058     eqn='';
0059 
0060     for j=1:numel(reactants)
0061         if j==1
0062             plusString='';
0063         else
0064             plusString=' + ';
0065         end
0066 
0067         stoich=num2str(model.S(reactants(j),indexes(i))*-1);
0068         
0069         if str2double(stoich)==1
0070             stoich='';
0071         else
0072             stoich=[stoich ' '];
0073         end
0074         
0075         if useComps==true
0076             eqn=[eqn plusString stoich model.metNames{reactants(j)} '[' model.comps{model.metComps(reactants(j))} ']'];
0077         else
0078             eqn=[eqn plusString stoich model.metNames{reactants(j)}];
0079         end
0080     end
0081        
0082     if model.rev(indexes(i))==0
0083         eqn=[eqn ' => '];
0084     else
0085         eqn=[eqn ' <=> '];
0086     end
0087        
0088     for j=1:numel(products)
0089         if j==1
0090             plusString='';
0091         else
0092             plusString=' + ';
0093         end
0094 
0095         stoich=num2str(model.S(products(j),indexes(i)));
0096         
0097         if str2double(stoich)==1
0098             stoich='';
0099         else
0100             stoich=[stoich ' '];
0101         end
0102         
0103         if useComps==true
0104             eqn=[eqn plusString stoich model.metNames{products(j)} '[' model.comps{model.metComps(products(j))} ']'];
0105         else
0106             eqn=[eqn plusString stoich model.metNames{products(j)}];
0107         end
0108     end
0109     equationStrings{i}=eqn;
0110 end
0111 end

Generated on Tue 16-Jul-2013 21:50:02 by m2html © 2005