Home > core > 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. Alternatively, it can be a
                    structure with the fields "mets" and "stoichCoeffs",
                    in the same fashion as addRxns. E.g.:
                    equations.mets = {{'met1','met2'},{'met1','met3'}}
                    equations.stoichCoeffs = {[-1,+2],[-1,+1]}
   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" (default)
                    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 (optional 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 (optional, 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)

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

Generated by m2html © 2005