Home > core > constructEquations.m

constructEquations

PURPOSE ^

constructEquations

SYNOPSIS ^

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

DESCRIPTION ^

 constructEquations
   Construct equation strings for reactions

 Input:
   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 (optional, default
                     model.rxns)
   useComps          include the compartment of each metabolite (optional,
                     default true)
   sortRevRxns       sort reversible reactions so that the metabolite that
                     is first in the lexiographic order is a reactant
                     (optional, default false)
   sortMetNames      sort the metabolite names in the equation. Uses
                     compartment even if useComps is false (optional, default
                     false)
   useMetID          use metabolite ID in generated equations (optional,
                     default false)
   useFormula        use metabolite formula in generated equations (optional,
                     default false)
   useRevField       use the model.rev field to indicate reaction
                     reversibility, alternatively this is determined from
                     the model.ub and model.lb fields (optional, default true)

 Output:
   equationStrings   a cell array with equations

 If useRevField is false, then reactions should be organized in their
 forward direction (e.g. ub = 1000 and lb = -1000/0) for the 
 reversibility to be correctly determined.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function equationStrings=constructEquations(model,rxns,useComps,sortRevRxns,sortMetNames,useMetID,useFormula,useRevField)
0002 % constructEquations
0003 %   Construct equation strings for reactions
0004 %
0005 % Input:
0006 %   model             a model structure
0007 %   rxns              either a cell array of reaction IDs, a logical vector
0008 %                     with the same number of elements as reactions in the
0009 %                     model, or a vector of reaction indexes (optional, default
0010 %                     model.rxns)
0011 %   useComps          include the compartment of each metabolite (optional,
0012 %                     default true)
0013 %   sortRevRxns       sort reversible reactions so that the metabolite that
0014 %                     is first in the lexiographic order is a reactant
0015 %                     (optional, default false)
0016 %   sortMetNames      sort the metabolite names in the equation. Uses
0017 %                     compartment even if useComps is false (optional, default
0018 %                     false)
0019 %   useMetID          use metabolite ID in generated equations (optional,
0020 %                     default false)
0021 %   useFormula        use metabolite formula in generated equations (optional,
0022 %                     default false)
0023 %   useRevField       use the model.rev field to indicate reaction
0024 %                     reversibility, alternatively this is determined from
0025 %                     the model.ub and model.lb fields (optional, default true)
0026 %
0027 % Output:
0028 %   equationStrings   a cell array with equations
0029 %
0030 % If useRevField is false, then reactions should be organized in their
0031 % forward direction (e.g. ub = 1000 and lb = -1000/0) for the
0032 % reversibility to be correctly determined.
0033 %
0034 % Usage: equationStrings = constructEquations(model, rxns, useComps,...
0035 %           sortRevRxns, sortMetNames, useMetID, useFormula, useRevField)
0036 
0037 if nargin<2 || isempty(rxns)
0038     rxns=model.rxns;
0039 elseif ~islogical(rxns) && ~isnumeric(rxns)
0040     rxns=convertCharArray(rxns);
0041 end
0042 if nargin<3
0043     useComps=true;
0044 end
0045 if nargin<4
0046     sortRevRxns=false;
0047 end
0048 if nargin<5
0049     sortMetNames=false;
0050 end
0051 if nargin<6
0052     useMetID=false;
0053 end
0054 if nargin<7
0055     useFormula=false;
0056 end
0057 if nargin<8
0058     useRevField=true;
0059 end
0060 
0061 %Sort reversible equations
0062 if sortRevRxns==true
0063     model=sortModel(model);
0064 end
0065 
0066 %Sort metabolite names, including compartment
0067 if sortMetNames==true
0068     model=sortModel(model,false,true);
0069 end
0070 
0071 Rindexes=getIndexes(model,rxns,'rxns');
0072 
0073 equationStrings=cell(numel(Rindexes),1);
0074 
0075 for i=1:numel(Rindexes)
0076     Mindexes=find(model.S(:,Rindexes(i)));
0077     %Define metabolites by id, formula or name, and with or without compartment:
0078     if useMetID==true && useFormula==false
0079         mets = model.mets(Mindexes);
0080     elseif useMetID==false && useFormula==true
0081         mets = strcat('[',model.metFormulas(Mindexes),']');
0082     elseif useMetID==true && useFormula==true
0083         error('Arguments useMetID and useFormula cannot be both TRUE!');
0084     else
0085         mets = model.metNames(Mindexes);
0086     end
0087     if useComps==true
0088         comps = model.comps(model.metComps(Mindexes));
0089         mets  = strcat(mets,'[',comps,']');
0090     end
0091     %Define stoich coeffs and reversibility:
0092     stoichCoeffs = model.S(Mindexes,Rindexes(i));
0093     if useRevField == true
0094         isrev        = model.rev(Rindexes(i))==1;
0095     else
0096         isrev        = model.lb(Rindexes(i))<0 & model.ub(Rindexes(i))>0;
0097     end
0098     
0099     %Construct equation:
0100     equationStrings{i} = buildEquation(mets,stoichCoeffs,isrev);
0101 end
0102 end

Generated by m2html © 2005