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-02-06

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-02-06
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 
0038 %Sort reversible equations
0039 if sortRevRxns==true
0040     model=sortModel(model);
0041 end
0042 
0043 %Sort metabolite names, including compartment
0044 if sortMetNames==true
0045     model=sortModel(model,false,true);
0046 end
0047 
0048 indexes=getIndexes(model,rxns,'rxns');
0049 
0050 equationStrings=cell(numel(indexes),1);
0051 
0052 for i=1:numel(indexes)
0053     reactants=find(model.S(:,indexes(i))<0);
0054     products=find(model.S(:,indexes(i))>0);
0055     eqn='';
0056 
0057     for j=1:numel(reactants)
0058         if j==1
0059             plusString='';
0060         else
0061             plusString=' + ';
0062         end
0063 
0064         stoich=num2str(model.S(reactants(j),indexes(i))*-1);
0065         
0066         if str2double(stoich)==1
0067             stoich='';
0068         else
0069             stoich=[stoich ' '];
0070         end
0071         
0072         if useComps==true
0073             eqn=[eqn plusString stoich model.metNames{reactants(j)} '[' model.comps{model.metComps(reactants(j))} ']'];
0074         else
0075             eqn=[eqn plusString stoich model.metNames{reactants(j)}];
0076         end
0077     end
0078        
0079     if model.rev(indexes(i))==0
0080         eqn=[eqn ' => '];
0081     else
0082         eqn=[eqn ' <=> '];
0083     end
0084        
0085     for j=1:numel(products)
0086         if j==1
0087             plusString='';
0088         else
0089             plusString=' + ';
0090         end
0091 
0092         stoich=num2str(model.S(products(j),indexes(i)));
0093         
0094         if str2double(stoich)==1
0095             stoich='';
0096         else
0097             stoich=[stoich ' '];
0098         end
0099         
0100         if useComps==true
0101             eqn=[eqn plusString stoich model.metNames{products(j)} '[' model.comps{model.metComps(products(j))} ']'];
0102         else
0103             eqn=[eqn plusString stoich model.metNames{products(j)}];
0104         end
0105     end
0106     equationStrings{i}=eqn;
0107 end
0108 end

Generated on Tue 23-Apr-2013 15:18:37 by m2html © 2005