Home > RAVEN > changeRxns.m

changeRxns

PURPOSE ^

changeRxns

SYNOPSIS ^

function model=changeRxns(model,rxns,equations,eqnType,compartment,allowNewMets)

DESCRIPTION ^

 changeRxns
   Modifies the equations of reactions

   model            a model structure
   rxns             cell array with reaction ids
   equations        cell array with equations
   eqnType          double describing how the equation string should be
                    interpreted
                    1 - The metabolites are matched to model.mets. New
                        metabolites (if allowed) are added to
                        "compartment"
                    2 - The metabolites are matched to model.metNames and
                        all metabolites are assigned to "compartment". Any
                        new metabolites that are added will be assigned
                        IDs "m1", "m2"... If IDs on the same form are 
                        already used in the model then the numbering will
                        start from the highest used integer+1
                    3 - The metabolites are written as 
                        "metNames[compNames]". Only compartments in
                        model.compNames are allowed. Any
                        new metabolites that are added will be assigned
                        IDs "m1", "m2"... If IDs on the same form are 
                        already used in the model then the numbering will
                        start from the highest used integer+1  
   compartment      a string with the compartment the metabolites should
                    be placed in when using eqnType=2. Must match 
                    model.compNames (opt when eqnType=1 or eqnType=3) 
   allowNewMets     true if the function is allowed to add new
                    metabolites. It is highly recommended to first add
                    any new metabolites with addMets rather than
                    automatically through this function. addMets supports
                    more annotation of metabolites, allows for the use of
                    exchange metabolites, and using it reduces the risk
                    of parsing errors (opt, default false)
                     
   model            an updated model structure

   NOTE: This function should be used with some care, since it doesn't
   care about bounds on the reactions. Changing a irreversible reaction to
   a reversible one (or the other way around) will only change the 
   model.rev field and not the model.lb/model.ub fields. The reaction will
   therefore still be having the same reversibility because of the
   bounds. Use setParams to change the bounds.

   NOTE: When adding metabolites to a compartment where it previously
   doesn't exist, the function will copy any available information from
   the metabolite in another compartment.

   Usage: model=changeRxns(model,rxns,equations,eqnType,compartment,allowNewMets)

   Rasmus Agren, 2012-12-19

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function model=changeRxns(model,rxns,equations,eqnType,compartment,allowNewMets)
0002 % changeRxns
0003 %   Modifies the equations of reactions
0004 %
0005 %   model            a model structure
0006 %   rxns             cell array with reaction ids
0007 %   equations        cell array with equations
0008 %   eqnType          double describing how the equation string should be
0009 %                    interpreted
0010 %                    1 - The metabolites are matched to model.mets. New
0011 %                        metabolites (if allowed) are added to
0012 %                        "compartment"
0013 %                    2 - The metabolites are matched to model.metNames and
0014 %                        all metabolites are assigned to "compartment". Any
0015 %                        new metabolites that are added will be assigned
0016 %                        IDs "m1", "m2"... If IDs on the same form are
0017 %                        already used in the model then the numbering will
0018 %                        start from the highest used integer+1
0019 %                    3 - The metabolites are written as
0020 %                        "metNames[compNames]". Only compartments in
0021 %                        model.compNames are allowed. Any
0022 %                        new metabolites that are added will be assigned
0023 %                        IDs "m1", "m2"... If IDs on the same form are
0024 %                        already used in the model then the numbering will
0025 %                        start from the highest used integer+1
0026 %   compartment      a string with the compartment the metabolites should
0027 %                    be placed in when using eqnType=2. Must match
0028 %                    model.compNames (opt when eqnType=1 or eqnType=3)
0029 %   allowNewMets     true if the function is allowed to add new
0030 %                    metabolites. It is highly recommended to first add
0031 %                    any new metabolites with addMets rather than
0032 %                    automatically through this function. addMets supports
0033 %                    more annotation of metabolites, allows for the use of
0034 %                    exchange metabolites, and using it reduces the risk
0035 %                    of parsing errors (opt, default false)
0036 %
0037 %   model            an updated model structure
0038 %
0039 %   NOTE: This function should be used with some care, since it doesn't
0040 %   care about bounds on the reactions. Changing a irreversible reaction to
0041 %   a reversible one (or the other way around) will only change the
0042 %   model.rev field and not the model.lb/model.ub fields. The reaction will
0043 %   therefore still be having the same reversibility because of the
0044 %   bounds. Use setParams to change the bounds.
0045 %
0046 %   NOTE: When adding metabolites to a compartment where it previously
0047 %   doesn't exist, the function will copy any available information from
0048 %   the metabolite in another compartment.
0049 %
0050 %   Usage: model=changeRxns(model,rxns,equations,eqnType,compartment,allowNewMets)
0051 %
0052 %   Rasmus Agren, 2012-12-19
0053 %
0054 
0055 if nargin<5
0056     compartment=[];
0057 end
0058 if nargin<6
0059     allowNewMets=false;
0060 end
0061 
0062 if ischar(rxns)
0063     rxns={rxns};
0064 end
0065 if ischar(equations)
0066     equations={equations};
0067 end
0068 
0069 %Find the indexes of the reactions and throw an error if they aren't all
0070 %found
0071 [I J]=ismember(rxns,model.rxns);
0072 if ~all(I)
0073     throw(MException('','All reaction ids must exist in the model'));    
0074 end
0075 
0076 %The reactions are changed in the following manner. First create a
0077 %rxns-structure by copying info from the model. Then remove the old
0078 %reactions. Then add the updated ones using addRxns. Lastly, the model is
0079 %reordered to match the original order. This is done like this to make use
0080 %of the advanced parsing of equations that addRxns use.
0081 rxnsToChange.rxns=rxns;
0082 rxnsToChange.equations=equations;
0083 if isfield(model,'rxnNames')
0084     rxnsToChange.rxnNames=model.rxnNames(J);
0085 end
0086 if isfield(model,'lb')
0087     rxnsToChange.lb=model.lb(J);
0088 end
0089 if isfield(model,'ub')
0090     rxnsToChange.ub=model.ub(J);
0091 end
0092 if isfield(model,'c')
0093     rxnsToChange.c=model.c(J);
0094 end
0095 if isfield(model,'eccodes')
0096     rxnsToChange.eccodes=model.eccodes(J);
0097 end
0098 if isfield(model,'subSystems')
0099     rxnsToChange.subSystems=model.subSystems(J);
0100 end
0101 if isfield(model,'grRules')
0102     rxnsToChange.grRules=model.grRules(J);
0103 end
0104 if isfield(model,'rxnFrom')
0105     rxnsToChange.rxnFrom=model.rxnFrom(J);
0106 end
0107 if isfield(model,'rxnScores')
0108     rxnsToChange.rxnScores=model.rxnScores(J);
0109 end
0110 if isfield(model,'rxnMiriams')
0111     rxnsToChange.rxnMiriams=model.rxnMiriams(J);
0112 end
0113 
0114 %Calculate the new order of reactions
0115 order=ones(numel(model.rxns),1);
0116 order(J)=0;
0117 order=cumsum(order);
0118 order(J)=order(end)+1:order(end)+numel(rxns);
0119 
0120 %Remove the original reactions
0121 model=removeRxns(model,rxns);
0122 
0123 model=addRxns(model,rxnsToChange,eqnType,compartment,allowNewMets);
0124 model=permuteModel(model,order,'rxns');
0125 end

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