Refinement¶
-
addCOBRAConstraints
(model, idList, d, varargin)[source]¶ Add a constraint to the model in the form c1 * v(id1) + c2 * v(id2) * ... cj * v(idj) dsense d where c is a vector with coefficients for each element in idList (default 1 for each reaction), dsense is one of lower than (‘L’, default), greater than (‘G’), or equal (‘E’), and d is a value. Usage
model = addCOBRAConstraints(model, idList, d, varargin)Inputs
- model – model structure
- idList – cell array of ids either from either the rxns, or the evars vectors. Can also be a a double vector of indices (in which case indices in evars have to be set off by numel(rxns).
- d – The right hand side of the C*v <= d constraint (or a vector, for multiple simultaneous addition;
- varargin –
- c: the coefficients to use with one entry per
- reaction of a constraint for multiple constraints, a matrix (default: 1 for each element indicated in idList)
- dsense: the constraint sense (‘L’: <= ,
- ‘G’: >=, ‘E’: =), or a vector for multiple constraints (default: (‘L’))
- ConstraintID: the Name of the constraint. by
- (default: ‘ConstraintXYZ’ with XYZ being the initial position in the ctrs vector) or a cell array of Strings for multiple Constraints
- checkDuplicates: check whether the constraint already
- exists, and if it does, don’t add it (default: false)
Output
modelConstrained – The constrained model containing the added constraints in the respective fields:
- .C - The constraint matrix containing coefficients for reactions
- .ctrs - The constraint IDs
- .dsense - The constraint senses
- .d the constraint right hand side values
- Optional: D, the matrix conatining coefficients for additional variables.
Example
Add a constraint that leads to EX_glc and EX_fru not carrying a combined flux higher than 5 model = addCOBRAConstraints(model, {'EX_glc','EX_fru'}, 5) Assume Reaction 4 to be 2 A -> D and reaction 5 being A -> F. Create a constraint that requires that the two reactions remove at least 4 units of A: model = addCOBRAConstraints(model, model.rxns(4:5), 4, 'c', [2 1], 'dsense', 'G')
Note
This function will, if not present create the C, ctrs, dsense, d and, if additional variables (i.e. the E matrix) is present, the D field as defined in the model field definitions. The C field containts the constraint coefficients referring to reactions, while the D field contains the Constraint coefficients referring to additional variables. d represents the right hand side of constraints and dsense the sense (lower -‘L’ , equal - ‘E’ or greater than - ‘G’) of the constraint. ctrs stores unique IDs for the constraints.
Author: Thomas Pfau, Nov 2017
-
addCOBRAVariables
(model, idList, varargin)[source]¶ Add a Variable to the COBRA model provided. These variables can be referred to by additional constraints added via addCOBRAConstraint. Their IDs have to be mutually exclusive with the IDs in model.rxns Usage
model = addCOBRAVariables(model, idList, varargin)Inputs
- model – model structure
- idList – cell array of ids
- varargin –
- lb: The lower bounds of the variables
- Has to be of the same size as idlist (default: -1000)
- ub: The upper bounds of the variables.
- Has to be of the same size as idlist (default: 1000)
- c: The objective coefficient of the variables
- Has to be of the same size as idlist (default: 0)
- Names: Descriptive names of the variables.
- (default: idList)
Output
model – constrained model containing the new variables in the respective fields (E,`evars`,`evarub`,`evarlb`,`evarc`)
- .E - The coefficient matrix for coefficients of metabolites for the variables
- .evars - The variable IDs
- .evarlb - The variable lower bounds
- .evarub - The variable upper bounds
- .evarc - The variable objective coefficient
- Optional: D, the matrix conatining coefficients for additional variables.
Note
This function will, if not present create the E, evars, evarlb, evarub, evarc and, if additional Constraints (i.e. the C matrix) is present, the D field as defined in the model field definitions. The E matrix containts the Variable coefficients referring to metabolites, while the D field contains the variable coefficients referring to additional Constraints from C. evars contains the IDs of the additional variables, with one entrey per column of E. evarlb and evarub represent the lower and upper bounds of the variables respectively. evarc are objective coefficients of the variables.
Author: Thomas Pfau, Oct 2018
-
addDemandReaction
(model, metaboliteNameList, printLevel)[source]¶ Adds demand reactions for a set of metabolites The reaction names for the demand reactions will be DM_[metaboliteName]`
Usage
model = addDemandReaction(model, metaboliteNameList)Inputs
- model – COBRA model structure
- metaboliteNameList – List of metabolite names (cell array)
Optional input
- printLevel – If > 0 will print out the reaction formulas (Default: 1).
Outputs
- model – COBRA model structure with added demand reactions
- rxnNames – List of added reactions
-
addExchangeRxn
(model, metList, lb, ub)[source]¶ Adds exchange reactions
Usage
newModel = addExchangeRxn(model, metList, lb, ub)Inputs
- model – Cobra model structure
- metList – List of metabolites
Optional inputs
- lb – Array of lower bounds
- ub – Array of upper bounds
Output
- newModel – COBRA model with added exchange reactions
-
addGenes
(model, geneIDs, varargin)[source]¶ Add Genes (or a single gene) to the model
Usage
model = addGenes(model,geneIDs,varargin)Inputs
model – The model to add the Metabolite batch to.
geneIDs – The IDs of the genes that shall be added.
varargin – fieldName, Value pairs. The given fields will be set according to the values. Only defined COBRA fields may be used. The following fields will be ignored (as they are dependent on the existing model structure):
- rxnGeneMat - The size will be extended, but no associations will be set.
Output
- newmodel – The model structure with the additional reactions.
Example
%To add genes with specific fields use: `model = addGenes(model, {'G1', 'Gene2', 'InterestingGene'}, 'proteins', {'Protein1','Protein B','Protein Alpha'}, 'geneField2', {'D','E','F'})`
Note
All fields (geneField1/geneField2) have to be present in the model, or defined in the field definitions, otherwise they are ignored.
-
addMIRIAMAnnotations
(model, elementIDs, databases, ids, varargin)[source]¶ Add a MIRIAM style annotation to the model
Usage
model = addMIRIAMAnnotation(model, elementID, database, id, ...)Inputs
- model – A COBRA Style model struct
- elementID – The element IDs to annotate (either a single ID as a char array, or a cell array of model IDs. Must be present in one of the basic fields of the model.
- databases – The databases for which annotations are added. Either a single char array if it is the same database for all annotated elements, or a cell array of strings with one element for each added element. The databases have to be registered with identifiers.org and must match either the identifiers.org prefix or the exact name!
- ids – The IDs to set for each element. Either a char array if only a single element is annotated, or a cell array of chars if multiple elements are annotated.
Optional input
varargin – Additional parameters either as parameter/value pairs or as a parameter struct with the following options/fieldnames:
- referenceField - the field in which to look up the ids (e.g. rxns, mets, comps etc...) If this is ‘model’, than the annotation will be assumed to be a model annotation, and the ID will be ignored. If empty, the whole model will be checked, and all matching ids will be annotated.
- annotationTypes - The type of the annotation. either ‘bio’ or ‘model’. Default(‘bio’)
- annotationQualifiers - The qualifier of the annotation ( see http://co.mbine.org/standards/qualifiers ) for possible qualifiers (Default: ‘is’)
- replaceAnnotation - Replace existing annotations with those supplied now (Default: false)
- printLevel - How much output to produce - 0, silent ; 1, verbose - (Default: 0)
Output
- model – The COBRA model with the added annotations
-
addMetabolite
(model, metID, varargin)[source]¶ Adds a Metabolite to the Current Reconstruction
Usage
newModel = addMetabolite(model, metID, metName, formula, ChEBIID, KEGGId, PubChemID, InChi, Charge, b)Inputs
- model – Cobra model structure
- metID – The ID(s) of the metabolite(s) (will be the identifier in model.mets)
Optional input
varargin – Optional Inputs provided as ‘ParameterName’, Value pairs. the following parameternames are available:
- metName: Human readable name(s) (default metID, String)
- metFormula: The chemical formula(s) (default ‘’, String)
- ChEBIID: The CHEBI Id(s) (default ‘’, String)
- KEGGId: The KEGG Compound ID(s) (default ‘’, String)
- PubChemID: The PubChemID(s) (default ‘’, String)
- InChi: The InChi description(s) (default ‘’, String)
- Charge: The Charge(s) (default NaN, int)
- b: The accumulation(s) or release(s) (default 0, double)
- csense: The sense of this metabolite (default ‘E’, char)
Output
- newModel – COBRA model with added metabolite(s)
Example
1) add a Metabolite which should be accumulated model = addMetabolite(model,'MetToAcc','b',5); 2) Add a Metabolite with a given Formula and a given Charge model = addMetabolite(model,'MetWithForm','metFormula','H3O','metCharge',1);
Note
metID and all optional arguments either have to be a single value or cell arrays. Charge and b have to be double arrays.
-
addMultipleMetabolites
(model, metIDs, varargin)[source]¶ Simultaneously add multiple metabolites. Allows the use of the field names of the model struct to specify additional properties of the metabolites added.
Usage
newmodel = addMultipleMetabolites(model, metIDs, varargin)Inputs
- model – The model to add the Metabolite batch to.
- metIDs – The metabolite IDs to add. No duplicate IDs may be provided and no ID may be present in the supplied model.
Optional input
varargin – fieldName, Value pairs with additional properties for the added metabolites. In addition, a ‘printLevel’ flag can be used (default: 0). The given values fields will be set according to the values. Only fields associated with mets defined in the COBRA definitions (except S) or fields already in the model may be used. Examples for this use would be:
- ‘metNames’,{‘Glucose’;’Pyruvate’}
- ‘metCharges’,[0;-2]
Output
- newmodel – The model structure with the additional metabolites.
Example
% To add metabolites, with charges, formulas and KEGG ids: model = addMultipleMetabolites(model,{'A','b','c'},'metCharges', [ -1 1 0], 'metFormulas', {'C','CO2','H2OKOPF'}, 'metKEGGID',{'C000012','C000023','C000055'})
-
addMultipleReactions
(model, rxnIDs, metList, Stoichiometries, varargin)[source]¶ Add multiple Reactions to the model. In contrast to addReaction, this function allows the addition of multiple reactions at once but requires all used metabolites to be already present in the model.
Usage
newmodel = addMultipleReactions(model,rxnIDs,metList,Stoichiometries,varargin)Inputs
- model – The model to add the Metabolite batch to.
- rxnIDs – The IDs of the reactions that shall be added (cell Array).
- metList – A list of metabolites for which stoichiometric coefficients are given
- Stoichiometries – A Stoichiometric matrix of dimension numel(metList) x numel(rxnID).
Optional input
varargin – fieldName, Value pairs. The given fields will be set according to the values. Only defined COBRA fields may be used. The following fields will be ignored (as they are dependent on the existing model structure)
- S: this is being resolved by the metList/Stoichiometries combination
- rxnGeneMat: This depends on the original model structure, and is thus nor considered.
You can provide GPR rules in different ways to this function:
- By providing a grRules array in the varargin
- By providing a genes field in the varargin and a corresponding rules field
- By providing a rules field, that directly refers to the genes in the model.
Examples of parameters are:
- ‘rxnNames’,{‘RuBisCo’,’Transketloase’}
- ‘rxnKEGGID,{‘R00024’,’R01641’}
- ‘lb’,[0,-1000]
- or any field name associated with reactions (except for S and rxnGeneMat) as defined in the COBRA Model field definitions.
It is also possible to add a printout to the function by using the ‘printLevel’, 1 argument.
Output
- newmodel – The model structure with the additional reactions.
Example
% To add the following reactions, with lower and upper bounds: % ExA: A <-> ; ATob: A <-> B ; BToC: B <-> C model = addMultipleReactions(model, {'ExA','ATob','BToC'}, {'A','b','c'}, [1 -1 0; 0,1,-1;0,0,1], 'lb', [-50,30,1], 'ub', [0,60,15]) % To add them with GPRs in text form: % ExA: A <-> ; ATob: A <-> B ; BToC: B <-> C model = addMultipleReactions(model, {'ExA','ATob','BToC'}, {'A','b','c'}, [1 -1 0; 0,1,-1;0,0,1], 'grRules', {'G1 or G2', 'G3 and G4',''}) % To add them with the same GPRs in logical format assuming that model.genes is {'G1';'G2';'G3';'G4'}: % ExA: A <-> ; ATob: A <-> B ; BToC: B <-> C model = addMultipleReactions(model, {'ExA','ATob','BToC'}, {'A','b','c'}, [1 -1 0; 0,1,-1;0,0,1], 'rules', {'x(1) | x(2)', 'x(3) and x(4)',''}) % To add them with the same GPRs in logical format without assuming anything for the model: % ExA: A <-> ; ATob: A <-> B ; BToC: B <-> C model = addMultipleReactions(model, {'ExA','ATob','BToC'}, {'A','b','c'}, [1 -1 0; 0,1,-1;0,0,1], 'rules', {'x(3) | x(2)', 'x(4) & x(1)',''}, 'genes', {'G4';'G2';'G1';'G3'}) % Print the above: model = addMultipleReactions(model, {'ExA','ATob','BToC'}, {'A','b','c'}, [1 -1 0; 0,1,-1;0,0,1], 'printLevel', 1, 'rules', {'x(3) | x(2)', 'x(4) & x(1)',''}, 'genes', {'G4';'G2';'G1';'G3'})
-
addReaction
(model, rxnID, varargin)[source]¶ Adds a reaction to the model or modify an existing reaction
Usage
[model, rxnIDexists] = addReaction(model, rxnID, varargin)Inputs
- model – COBRA model structure
- rxnID – Reaction name abbreviation (i.e. ‘ACALD’)
Optional input
- varargin –
Input of additional information as parameter/Value pairs
- reactionName - a Descriptive name of the reaction (default ID)
- metaboliteList - Cell array of metabolite names. Either this parameter or reactionFormula are required.
- stoichCoeffList - List of stoichiometric coefficients (reactants -ve, products +ve), if not provided, all stoichiometries are assumed to be -1 (Exchange, or consumption).
- reactionFormula - A Reaction formula in string format (‘A + B -> C’). If this parameter is provided metaboliteList MUST be empty, and vice versa.
- reversible - Reversibility flag (Default = true)
- lowerBound - Lower bound (Default = 0 or -vMax`)
- upperBound - Upper bound (Default = vMax)
- objectiveCoef - Objective coefficient (Default = 0)
- subSystem - Subsystem (Default = {‘’})
- geneRule - Gene-reaction rule in boolean format (and/or allowed) (Default = ‘’);
- geneNameList - List of gene names (used only for translation from common gene names to systematic gene names) (Default empty)
- systNameList - List of systematic names (Default empty)
- checkDuplicate - Check S matrix too see if a duplicate reaction is already in the model (Deafult false)
- printLevel - default = 1
Outputs
- model – COBRA model structure with new reaction
- rxnIDexists – Empty if the reaction did not exist previously, or if checkDuplicate is false. Otherwise it contains the ID of an identical reaction already present in the model.
Example
%1) Add a new irreversible reaction using the formula approach model = addReaction(model,'newRxn1','reactionFormula','A -> B + 2 C') %2) Add a the same reaction using the list approach model = addReaction(model,'newRxn1','metaboliteList',{'A','B','C'},'stoichCoeffList',[-1 1 2], 'reversible',false); %3) Add a new irreversible reaction using the formula approach with a given GPR Rule model = addReaction(model,'newRxn1','reactionFormula','A -> B + 2 C',... 'geneRule', 'Gene1 or Gene2'); %4) Add a the same reaction but also mark it as being in the Glycolysis subSystem model = addReaction(model,'newRxn1','reactionFormula','A -> B + 2 C', ... 'subSystem', 'Glycolysis', 'geneRule', 'Gene1 or Gene2');
Note
Using addReaction to add several reactions iteratively is a very inefficient procedure, as it extends all reaction related fields one at a time, leading to a large memory reallocation overhead. There are also many checks performed which allow for a more flexible use of the function, but which simultaneously lead to a slower computation time. This function is mainly intended to be used when adding individual reactions during analysis. When adding multiple reactions, in particular when coding for a more compex methodology, please use the addMultipleReactions function which only performs very basic checks, but is much more efficient.
-
addReactionGEM
(model, rxns, rxnNames, rxnFormulas, rev, lb, ub, nRxn, subSystems, grRules, rules, genes, HTABLE)[source]¶ Manually adds reactions to a specified model, may add one or more reactions at a time
Usage
[newmodel, HTABLE] = addReactionGEM(model, rxns, rxnNames, rxnFormulas, rev, lb, ub, nRxn, subSystems, grRules, rules, genes, HTABLE)Inputs
- model – COBRA model structure
- rxns – Identifiers for the reactions
- rxnNames – List of reactions
- rxnFormulas – reactions’ formulas
- rev – 0 = irrev, 1 = rev
- lb – The lower bounds for fluxes
- ub – The upper bounds for fluxes
- subSystems – subSystem assignment for each reaction, default = ‘’
- grRules – A string representation of the GPR rules defined in a readable format, default = ‘’
- rules – GPR rules in evaluateable format for each reaction, default = ‘’
- genes – Identifiers of the genes in the model, default = ‘’
- HTABLE – hash table
Outputs
- newmodel – changed model
- HTABLE – hash table
Example
[modelLB_NH3] = addReactionSmiley(modelLB, 'NH3r', 'NH3 protonization', cellstr('1 NH3[c] + 1 H[c] <==> 1 NH4[c]'), 1, -1000, 1000, 'Others');
Note
Manually add reactions to a specified model, can either add one or multiple reactions at a time
All syntax standards must comply with the specified model
For reaction formulas, use: ‘–>’ for irreversible or ‘<==>’ for reversible
-
addSinkReactions
(model, metabolites, lb, ub)[source]¶ Adds a sink reaction for the list of metabolites
Usage
[model] = addSinkReactions(model, metabolites, lb, ub)Inputs
- model – COBRA model structure
- metabolites – Cell array of metabolite abreviations as they appear in model.mets
Optional inputs
- lb – Lower bounds of reactions
- ub – Upper bounds of reactions
Outputs
- model – COBRA model structure containing sink reactions
- rxnsInModel – Vector, contains -1 if the reaction did not exist previously, otherwise it contains the reaction ID of an identical reaction already present in the model
-
addSubSystemsToReactions
(model, reactions, subSystems)[source]¶ Adds the subSystems to the specified reactions
Usage
[model] = addSubSystemToReaction(model,reaction,subSystem)Inputs
- model – A COBRA model struct with at least rxns and subSystems fields
- reactions – Either a string identifying a reaction, or a cell array of strings identifying multiple reactions, or a double vector or boolean vector identifying positions.
- subSystems – A String identifying a subsystem, or a cell array of strings to add multiple subSystems. An empty string will be filtered. All subSystems will be added to all identified reactions.
Output
- model – The model with the subSystems added to the respective reactions (old, non empty, values are retained).
Example
% Add TCA to a set of reactions [model] = addSubSystemsToReactions(model,{'ACONTa';'ACONTb';'AKGDH';'CS';'FUM';'ICDHyr';'MDH';'SUCOAS'},'TCA') % Add Glycolysis/Gluconeogenesis to a the reaction 18 of the model [model] = addSubSystemsToReactions(model,18,{'Glycolysis','Gluconeogenesis'})
-
alphabetizeModel
(model)[source]¶ Sorts the rxns, metabolites, and genes in a model into alphabetical order, useful after adding new reactions to a model. This function needs to be modified to work on models with different fields than these (currently set for iAF1260c)
Usage
abcModel = alphabetizeModel(model)Input
- model – COBRA model structure
Output
- abcModel – the alphabetized model
-
assignGPRA
(model, gpraFile)[source]¶ Assigns each reaction a Gene-protein-reaction association
Usage
model = assignGPRA(model, gpraFile)Inputs
- model – COBRA model structure
- gpraFile – SimPheny GPRA file
Output
- model – COBRA model with gene-protein-reaction assoction
-
assignSubSystems
(model, gpraFile)[source]¶ Assigns each reaction a subsystem in the model structure
Usage
model = assignSubSystems(model, gpraFile)Inputs
- model – COBRA model structure
- gpraFile – SimPheny GPRA file
Output
- model – COBRA model structure with subsystem assignment
-
changeCOBRAConstraints
(model, constraintID, varargin)[source]¶ Modify an existing COBRA constraint by providing new settings for the constraint to update existing settings. Usage
model = changeCOBRAConstraints(model, constraintID, varargin)Inputs
- model – model structure
- constraintID – The ID of the constraint (or the index in the ctrs field)
Optional input
- varargin – all elements (name, d, dsense and c can be modified as indicated below. * idList: cell array of ids either from either the rxns, or the evars vectors. Can also be a a double vector of indices (in which case indices in evars have to be set off by numel(rxns). * c: the elements of the C matrix. If idList is empty, this has to be a vector of length #rxns + #evars * dsense: the constraint sense (‘L’: <= ,’G’: >=, ‘E’: =), or a vector for multiple constraints * d: The right hand side of the C*v <= d constraint (or a vector, for multiple simultaneous addition) * name: The new, descriptive name of the constraint.
Output
- model – constrained model
Example
Modify the constraint 'A_and_B_Lower_10' to read A + B + C <= 10 model = addCOBRAConstraints(model, 'A_and_B_Lower_10', 'idList', {'A','B','C'}, 'c', [1,1,1]);
Note
If c is provided, the whole constraint coefficients will be reset and existing coefficients will be removed!
Author: Thomas Pfau, Oct 2018
-
changeCOBRAVariable
(model, variableID, varargin)[source]¶ Modify an existing COBRA variable by providing new settings for the variable to update existing settings. Usage
model = changeCOBRAVariable(model, variableID, varargin)Inputs
- model – model structure
- variableID – The ID of the variable (or the index in the evars field)
Optional input
- varargin –
- lb: the lower bound of the variable
- ub: the upper bound of the variable
- c: the objective coefficient of the variable
- Name: The new, descriptive name of the variable.
Output
- model – model with modified variable
Author: Thomas Pfau, Oct 2018
-
changeGeneAssociation
(model, rxnName, grRule, geneNameList, systNameList, addRxnGeneMat)[source]¶ Change gene associations in a model
Usage
model = changeGeneAssociation(model, rxnName, grRule, geneNameList, systNameList, addRxnGeneMat)Inputs
- model – COBRA Toolbox model structure
- rxnName – Name of the new reaction
- grRule – Gene-reaction rule in boolean format (and/or allowed)
Optional inputs
- geneNameList – List of gene names (used only for translation from common gene names to systematic gene names)
- systNameList – List of systematic names
- addRxnGeneMat – adds rxnGeneMat to model structure (default = true)
Output
- model – COBRA Toolbox model structure with new gene reaction associations
-
changeRxnMets
(model, Mets2change, NewMets, Rxn, NewStoich)[source]¶ Changes metabolites in a specified reaction, or randomly chosen reactions.
Usage
[model ModifiedRxns] = changeRxnMets(model, Mets2change, NewMets, Rxn, NewStoich)Inputs
- model – COBRA model structure
- Mets2change – Cell array of metabolites to change
- NewMets – Cell array of replacement metabolites (must be in order of those that will be replaced
- Rxn – reaction to change (string) or cell array, or if a number is put here, that number of reactions (with Mets2change) will be randomly chosen and the metabolites will be swapped
Optional input
NewStoich – Stoichiometry of new metabs (conserved from old mets by default). If multiple reactions are being changed, this must be a mets x rxns matrix,
e.g. for 2 new reactions: Rxn = {‘r1’, ‘r2’},
- r1: 2 A + 3 B -> 1 C
- r2: 4 A + 3 B -> 3 C
where A and C are the new metabolites, NewMets = {‘A’, ‘C’} NewStoich = [ 2 4; 1 3]
Outputs
- model – COBRA model structure with changed reaction
- ModifiedRxns – Rxns which were modified
-
checkIDsForTypeExist
(model, ids, basefield)[source]¶ Check whether the given IDs exist for the given type of base field. Base fields include rxns, mets, genes, comps, proteins, ctrs, evars. ctrs/mets as well as rxns/evars will be considered as a combined field.
Usage
[tf,existing] = checkIDsForTypeExist(model,ids,basefield)Inputs
- model – model structure
- ids – cell array of reaction names
- basefield – Any base field defined.
Outputs
- tf – Whether any of the IDs exists.
- existing – the already existing IDs for this base field.
-
convertIrrevFluxDistribution
(vIrrev, matchRev)[source]¶ Converts irreversible flux distribution to reversible
Usage
vRev = covertIrrevFluxDistribution(vIrrev, matchRev)Inputs
- vIrrev – Irreversible flux distribution
- matchRev – Vector mapping irreversible fluxes to reversible fluxes (Generated by convertToIrreversible)
Output
- vRev – Reversible flux distribution
-
convertToIrreversible
(model, varargin)[source]¶ Converts model to irreversible format, either for the entire model or for a defined list of reversible reactions.
Usage
[modelIrrev, matchRev, rev2irrev, irrev2rev] = convertToIrreversible(model, varargin)Input
- model – COBRA model structure
Optional input
- varargin –
Additional Options as ParameterName/Value pairs.
Allowed Parameters are:
- sRxns: List of specific reversible reactions to convert to irreversible (Default = model.rxns)
- flipOrientation: Alter reactions that can only carry negative flux by flipping and marking them with ‘_r’ (Default = true)
- orderReactions: Order Reactions such that reverse reactions directly follow their forward reaction.
Outputs
- modelIrrev – Model in irreversible format
- matchRev – Matching of forward and backward reactions of a reversible reaction
- rev2irrev – Matching from reversible to irreversible reactions
- irrev2rev – Matching from irreversible to reversible reactions
Example
% To convert a whole model to an irreversible model: [modelIrrev, matchRev, rev2irrev, irrev2rev] = convertToIrreversible(model) % To Convert only Reactions R1, R2 and R15: reactionsToRevert = {'R1', 'R2', 'R15'}; [modelIrrev, matchRev, rev2irrev, irrev2rev] = convertToIrreversible(model, 'sRxns', reactionsToRevert) % To order the reactions such that backward follows forward reaction: [modelIrrev, matchRev, rev2irrev, irrev2rev] = convertToIrreversible(model, 'orderReactions', true)
Note
Uses the reversible list to construct a new model with reversible reactions separated into forward and backward reactions. Separated reactions are appended with ‘_f’ and ‘_b’ and the reversible list tracks these changes with a ‘1’ corresponding to separated forward reactions. Reactions entirely in the negative direction will be reversed and appended with ‘_r’.
-
convertToReversible
(model)[source]¶ Converts a model structure from irreversible format to reversible format
Usage
modelRev = convertToReversible(model)Input
- model – COBRA model in irreversible format (forward/backward reactions separated) forward reactions have to be marked with an _f in the id, backward with an _b. reverse reactions (i.e. reactions which were originally only allowed to carry negative flux must have a _r tag at the end of the reaction id. It is further assumed, that there is an exact 1:1 match between _f and _b reactions.
Output
- modelRev – Model in reversible format
-
createModel
(varargin)[source]¶ Create a COBRA model from inputs or an empty model structure if no inputs are provided.
Usage
model = createModel(rxnAbrList, rxnNameList, rxnList, revFlagList, lowerBoundList, upperBoundList, subSystemList, grRuleList, geneNameList, systNameList)Inputs
- rxnAbrList – List of names of the new reactions
- rxnNameList – List of names of the new reactions
- rxnList – List of reactions: format: {A -> B + 2 C} If the compartment of a metabolite is not specified, it is assumed to be cytoplasmic, i.e. [c]
Optional inputs
- revFlagList – List of reversibility flag (opt, default = 1)
- lowerBoundList – List of lower bound (Default = 0 or -vMax)
- upperBoundList – List of upper bound (Default = vMax)
- subSystemList – List of subsystem (Default = {‘’})
- grRuleList – List of gene-reaction rule in boolean format (and/or allowed) (Default = ‘’);
- geneNameList – List of gene names (used only for translation from common gene names to systematic gene names)
- systNameList – List of systematic names
- printLevel – Verbosity (0 - no outputs, except warnings, 1- normal printout (default))
Output
- model – COBRA model structure
Example
1) Create A model with two Reactions (R1 : 'A -> B + C', R2: 'C -> D') model = createModel({'R1','R2'},{'Reaction 1','Reaction 2'},{'A -> B + C', 'C -> D'}); 2) Also set the subSystems of the two Reactions (R1: Sub1, R2: Sub2): model = createModel({'R1','R2'},{'Reaction 1','Reaction 2'},{'A -> B + C', 'C -> D'},... 'subSystemList', {'Sub1','Sub2'}); 3) Also set upper and lower bounds: model = createModel({'R1','R2'},{'Reaction 1','Reaction 2'},{'A -> B + C', 'C -> D'},... 'subSystemList', {'Sub1','Sub2'}, 'lowerBoundList',[-3 -1000],'upperBoundList',[120 17]);
-
createXMatrix
(compoundsIn, transport, compartment)[source]¶ Creates a matrix full of exchange reactions based on the input list (creates an exchange reaction for each of the metabolites present in the model)
Usage
ExchangeRxnMatrix = createXMatrix(compoundsIn, transport, compartment)Inputs
- compoundsIn – SU matrix
- transport – if 1, transport reactions will be defined as well for every compound (default: 0, which corresponds to only exchange reactions (from the specified compartment)
- compartment – (default = ‘[c]’) –> transport from cytoplasm [c] to extracellular space [e] (or sink) any other compartment (except ‘[e]’ creates transport from [c] to the compartment, from the compartment to the external compartment and an exchanger in the external compartment.
Output
- ExchangeRxnMatrix – model containing all exchange reactions for all compounds in compoundsIn
-
extendModelFieldsForType
(model, type, varargin)[source]¶ Extend all existing fields relevant for the given type to the size of the field of the given type, or a specified size. Usage
model = extendModelFieldsForType(model, type, varargin)Inputs
- model – the model to update
- type – the Type of field to update one of (‘rxns’,’mets’,’comps’,’genes’,’evars’,’ctrs’)
Optional input
- varargin –
Additional Options as ‘ParameterName’, Value pairs. Options are:
- ‘originalSize’, the original size of the field, this is used to determine fields which have to be adjusted (default length of field type - 1).
- ‘targetSize’, the target size to which the field should be extended. Default values will be used as defined in the ModelFieldDefinitions to fill empty entries (default length of field type).
- ‘excludeFields’, fields that should be ignored during update.
Output
- model – A model with the requested fields associated to the given type updated. Associated fields are determined by size, and if multiple base fields have the same size, the Model Field definition along with checks for field Names (e.g. rxnXYZ is associated with rxns) is used. Added values are either default values (if defined in the ModelFieldDefinitions), or {‘’} for cell arrays, NaN for numeric arrays and false for logical arrays. Char Arrays will be ignored.
-
extractCompModel
(model, compSymbol, intOnlyFlag, updateGenes)[source]¶ Creates model for a cellular compartment
Usage
compModel = extractCompModel(model, compSymbol, intOnlyFlag)Inputs
- model – COBRA model structure
- compSymbol – Compartment symbol
Optional inputs
- intOnlyFlag – Include only non-transport reactions (Default = true)
- updateGenes – Update the GPR rules removing all unassociated genes. This can take some time on larger models.(default false)
Output
- compModel – COBRA model for a cellular compartment
-
extractMetModel
(model, metabNames, nLayers, allCompFlag, nRxnsMetThr)[source]¶ Creates a subnetwork model around one or more metabolites
Usage
metabModel = extractMetModel(model, metabNames, nLayers, allCompFlag, nRxnsMetThr)Inputs
- model – COBRA model structure
- metabNames – Metabolites to build subnetwork model around
- nLayers – Number of layers
- allCompFlag – Use all metabolites regardless of compartment
Optional input
- nRxnsMetThr – Ignore metabolites which appear in more than nRxnMetThr (Default = 100)
Output
- metabModel – COBRA model around one or more metabolites
-
extractSubNetwork
(model, rxnList, metList, updateGenes)[source]¶ Extract subnetwork model Usage
subModel = extractSubNetwork(model, rxnList, metList)Inputs
- model – COBRA model structure
- rxnList – Reaction list for the subnetwork to be extracted
Optional inputs
- metNames – Metabolite list for the subnetwork to be extracted
- updateGenes – Also remove unused genes (can take some time on large networks)
Output
- subModel – COBRA model of subnetwork
-
extractSubSysModel
(model, subSysNames)[source]¶ Creates model for one of more model subsystems
Usage
subSysModel = extractSubSysModel(model, subSysNames)Inputs
- model – COBRA model structure
- subSysNames – List of subsystems to extract
Output
- subSysModel – COBRA model of selected subsystems
-
flipRxnOrientation
(model, rxnList)[source]¶ flips the directionality of the given reactions and adjusts the bounds and objective coefficients accordingly.
Usage
model = flipRxnDirectionality(model, rxnList)Inputs
- model – A COBRA Style model structure
- rxnList – A List of reactions or a single reaction
Output
- model – The model with the specified reactions flipped.
-
generateRules
(model, printLevel)[source]¶ If a model does not have a model.rules field but has a model.grRules field, can be regenerated using this script
Usage
[model] = generateRules(model)Inputs
- model – COBRA model with model.grRules
- printLevel – optional variable to print out all new genes (default = TRUE), can be zero if not needed
Output
- model – same model but with model.rules added
-
getEmptyConstraints
(model)[source]¶ Get a list of empty constraints (i.e. constraints that have no non-zero values. Usage
emptyConstraints = getEmptyConstraints(model)Input
- model – model structure
Output
- emptyConstraints – A list of IDs of empty constraints.
- Author:
- Thomas Pfau - Sep 2018
-
getIDPositions
(model, ids, basefield)[source]¶ Get the positions of the IDs for the given basefield. This function will currently only work for rxns and mets and also checks the associated ctrs (for mets) and evars (for rxns) fields for the given IDs. elements from evars / ctrs will have positions nRxns/nMets + position respectively.
Usage
[pos,pres] = getIDPositions(model,ids,basefield)Inputs
- model – model structure
- ids – cell array of reaction names
- basefield – Either ‘rxns’, or ‘mets’
Output
- pos – The positions of the given ids in the [rxns;evars] or [mets;ctrs] vectors for rxns and mets , respectively.
-
getModelFieldsForType
(model, type, varargin)[source]¶ Get the fields in the model which are associated with the given type. Usage
matchingFields = getModelFieldsForType(model, type, varargin)Inputs
- model – the model to update
- type – the Type of field to update one of (‘rxns’,’mets’,’comps’,’genes’,’ctrs’,’evars’)
Optional input
- varargin –
Additional Options as ‘ParameterName’, Value pairs. Options are:
- ‘fieldSize’, the original size of the field (if mets was already adjusted, this size will be used to determine matching fields.
Outputs
- matchingfields – A cell array of fields associated with the given type. The initial check is for the size of the field, if multiple base fields have the same size, it is assumed, that fields named e.g. rxnXYZ are associated with rxns, and only those fields are adapted along with fields which are specified in the Model FieldDefinitions.
- dimensions – The dimension associated with the given type in the given field. matchingField(X) is matching to type in dimenion(X)
-
isSameCobraModel
(model1, model2, printLevel)[source]¶ Checks if two COBRA models are the same
Usage
[isSame, nDiff, commonFields] = isSameCobraModel(model1, model2, printLevel)Inputs
- model1 – COBRA model structure 1
- model2 – COBRA model structure 2
Optional input
- printLevel – Whether to provide additional output (0 - no output (default), 1 - output).
Outputs
- isSame – True if all common fields are identical, else false
- nDiff – Number of differences between the two models for each field
- commonFields – List of common fields
-
keepCompartment
(model, compartments)[source]¶ This function removes reactions in all compartments except those specified by the cell array “compartments”
Usage
model = keepCompartment(model, compartments)Inputs
- model – COBRA model structure
- compartments – cell array of strings (e.g., to discard all reactions except those in the mitochondria and cytosol, compartments = {‘[m]’, ‘[c]’};
Output
- model – COBRA model with reactions in the specified compartmetns
-
mergeModelFieldPositions
(model, type, positions, mergeFunctions)[source]¶ Usage
[modelNew] = mergeModelFieldPositions(model,type,positions)Inputs
- model – The model with the fields to merge
- type – the field type to merge ( rxns, mets, comps or genes)
- positions – The positions in the given field type to merge either as indices or as logical array.
Optional input
mergeFunctions – A cell array of fieldNames and functions that can be called on a larger array of the type used for the field. e.g.
- {‘metCharges’,@(x) x(1); ‘grRules’, @(x) strjoin(x,’ or ‘);
- by default, all numeric fields are added up, all unique entries in cell arrays are concatenated with ‘;’,
- grRules and rules are assumed to be merged with and (i.e. a batch reaction is assumed to need all associated GPRs)
Output
- modelNew – merged model with the positions merged into one. Unique entries in Related String fields will be concatenated with ‘;’ matrices will be summed up.
-
mergeTwoModels
(model1, model2, objrxnmodel, mergeGenes)[source]¶ Merge two models. If fields conflict, the data from fields in model1 will be used. Usage
[modelNew] = mergeTwoModels(model1,model2,objrxnmodel)Inputs
- model1 – model 1
- model2 – model 2
Optional inputs
- objrxnmodel – Set as 1 or 2 to set objective reaction from desired model
- mergeGenes – Do merge the gene associated data, if false the genes field and the rules field will be cleared and other fields associated with genes will not be merged. GPR rules can be reconstructed using the grRules field.(Default = true)
Output
- modelNew – merged model
-
moveRxn
(model, startspot, endspot)[source]¶ The function moves a reaction from one spot in the network to another, useful for placing important reactions at the beginning of the network to easier follow certain reactions.
Usage
[model] = moveRxn(model, startspot, endspot)Inputs
- model – COBRA model structure
- startspot – The reaction number to move
- endspot – The spot where the reaction is moving to
Output
- model – COBRA toolbox model structure with moved reaction
-
orderModelFields
(model)[source]¶ Orders the fields in a model according to the field definitions. Defined first, Remaining fields in alphabetical order.
Usage
orderedModel = orderModelFields(model)Input
- model – a model structure in COBRA format
Output
- orderedModel – a model with fields ordered according to the field definitions.
-
reassignFwBwMatch
(match, selVec)[source]¶ Reassings forward-backward matches when modifying an irreversible model
Usage
matchNew = reassignFwBwMatch(match, selVec)Inputs
- match – Forward-backwards mapping vector
- selVec – Selection vector marking reactions to remap
Output
- matchNew – Modified forward-backwards mapping vector
-
reduceModel
(model, tol, irrevFlag, verbFlag, negFluxAllowedFlag, checkConsistencyFlag, changeBoundsFlag)[source]¶ Removes from the model all of the reactions that are never used (max and min are < tol). Finds the minimal bounds for the flux through each reaction. Also returns the results for flux variability analysis (maxes, mins).
Usage
[modelRed, hasFlux, maxes, mins] = reduceModel(model, tol, irrevFlag, verbFlag, negFluxAllowedFlag, checkConsistencyFlag, changeBoundsFlag)Input
- model – COBRA model structure
Optional inputs
- tol – Tolerance for non-zero bounds - bounds smaller in absolute value than this value will be set to zero (Default = 1e-6)
- irrevFlag – Determines if the models should be treated using the irreversible form. (Default = false)
- verbFlag – Verbose output (Default = false)
- negFluxAllowedFlag – Allow negative fluxes through irrev reactions (Default = false)
- checkConsistencyFlag – Do a consistency check of the optimal solution (Default = true)
- changeBoundsFlag – Change upper/lower bounds to the minimal bounds (Default = true)
Outputs
- modelRed – Reduced model
- hasFlux – The indexes of the reactions that are not blocked in the model
- maxes – Maximum fluxes
- mins – Minimum fluxes
-
removeCOBRAConstraints
(model, constraintsToRemove)[source]¶ Remove the specified Non Metabolic Constraints. Usage
model = removeCOBRAConstraint(model, constraintsToRemove)Inputs
- model – model structure
- constraintsToRemove – cell array of Constraint IDs, or Constraint Positions to remove, or a boolean vector of positions to remove.
Output
- model – the model with the constraints removed.
- Author:
- Thomas Pfau - Nov 2017
-
removeFieldEntriesForType
(model, indicesToRemove, type, fieldSize, varargin)[source]¶ Remove field entries at the specified indices from all fields associated with the given type Usage
model = removeFieldEntriesForType(model, indicesToRemove, type, varargin)Inputs
- model – the model to update
- indicesToRemove – indices which should be removed (either a logical array or double indices)
- type – the Type of field to update. one of (‘rxns’,’mets’,’comps’,’genes’)
- fieldSize – The size of the original field before modification. This is necessary to identify fields from which entries have to be removed.
Optional input
varargin – Additional Options as ‘ParameterName’, Value pairs. Options are: - ‘excludeFields’, fields which should not be
adjusted but kkept how they are.
Output
- modelNew – the model in which all fields associated with the given type have the entries indicated removed. The initial check is for the size of the field, if multiple base fields have the same size, it is assumed, that fields named e.g. rxnXYZ are associated with rxns, and only those fields are adapted along with fields which are specified in the Model FieldDefinitions.
-
removeGenesFromModel
(model, geneList, varargin)[source]¶ Removes the given genes from the model. GPR rules will be adjusted to reflect the removal. By default, the rules are converted to DNF and all clauses containing any of the given genes are removed. Note, that this function is not supposed to be used to model single gene deletions.
Usage
[model, affectedRxns, originalGPRs, deletedReactions] = removeGenesFromModel(model, geneList)Inputs
- model – COBRA model with the appropriate constrains for a particular condition
- geneList – List of genes to be deleted
Optional input
varargin – Additional Parameter/value pairs or a parameter struct with the following parameter names:
- keepReactions - Whether to keep reactions if its GPR is changed to an empty GPR, i.e. all complexes catalyzing it are removed. (default: true)
- keepClauses - Do not remove clauses containing the gene, but instead just remove the gene from the clause (default: false).
Outputs
- model – COBRA model with the selected genes deleted
- affectedRxns – A list of reactions which have their rules altered
- originalGPRs – The original GPR rules for the affected reactions
- deletedReactions – The list of reactions removed from the model (if keepReaction was false).
-
removeMetabolites
(model, metaboliteList, removeRxnFlag)[source]¶ Removes metabolites from a model
Usage
model = removeMetabolites(model, metaboliteList, removeRxnFlag)Inputs
- model – COBRA model structure
- metaboliteList – List of metabolites to be removed
Optional input
- removeRxnFlag – Remove reactions with no metabolites (Default = true)
Output
- model – COBRA model with removed metabolites
-
removeRxns
(model, rxnRemoveList, varargin)[source]¶ Removes reactions from a model
Usage
model = removeRxns(model, rxnRemoveList, varargin)Inputs
- model – COBRA model structure
- rxnRemoveList – Cell array of reaction names to be removed
Optional input
- varargin –
Parameters in ParameterName, Value pair representation.
Available parameters are:
- irrevFlag: Irreverseble (true) or reversible (false) reaction format (Default = false)
- metFlag: Remove unused metabolites (Default = true)
Output
- model – COBRA model w/o selected reactions
Optional inputs are used as parameter value pairs
Example
1) Remove the reactions 'ATPM' and 'TKT1' from the given model model = removeRxns(model,{'ATPM','TKT1'}); 2) Remove the same reactions but keep any metabolites which would now be not present in any reaction: model = removeRxns(model,{'ATPM','TKT1'}, 'metFlag', false);
-
removeSubSystemsFromRxns
(model, reactions, subSystems)[source]¶ Adds the subSystem to the specified reaction
Usage
[model] = addSubSystemToReaction(model,reaction,subSystem)Inputs
- model – A COBRA model struct with at least rxns and subSystems fields
- reactions – Either a string identifying a reaction, or a cell array of strings identifying multiple reactions, or a double vector or boolean vector identifying positions.
- subSystems – A String identifying a subsystem, or a cell array of strings to assign multiple subSystems. If multiple strings are present, an empty string will be removed
Output
- model – The model with the subSystems set to the respective reactions (old values will be removed).
Example
%Remove TCA as subSystem from a set of reactions [model] = removeSubSystemsFromRxns(model,{'ACONTa';'ACONTb';'AKGDH';'CS';'FUM';'ICDHyr';'MDH';'SUCOAS'},'TCA') %Remove Glycolysis/Gluconeogenesis from reaction 18 of the model [model] = removeSubSystemsFromRxns(model,18,{'Glycolysis','Gluconeogenesis'})
-
removeTrivialStoichiometry
(model)[source]¶ Removes metabolites and reactions corresponding to zero rows and columns
Usage
modelOut=removeTrivialStoichiometry(model)Input
- model – Model with metabolites and reactions to remove
Output
- modelOut – Obtained model with removed metabolites and reactions
-
removeUnusedGenes
(model)[source]¶ Updates the rules, genes, and rxnGeneMat fields based on the grRules field for reactions in the model.
Usage
modelNew = removeUnusedGenes(model)Input
- model – COBRA structure
Output
- modelNew – COBRA model structure with updated gene field reflecting only content present in the model
-
setRxnSubSystems
(model, reactions, subSystems)[source]¶ Sets the subSystems of the specified reactions to the specified subSystems
Usage
[model] = addSubSystemToReaction(model,reaction,subSystem)Inputs
- model – A COBRA model struct with at least rxns and subSystems fields
- reactions – Either a string identifying a reaction, or a cell array of strings identifying multiple reactions, or a double vector or boolean vector identifying positions.
- subSystems – A String identifying a subsystem, or a cell array of strings to assign multiple subSystems. If multiple strings are present, an empty string will be removed
Output
- model – The model with the subSystems set to the respective reactions (old values will be removed).
Example
% Set TCA as subSystem for a set of reactions [model] = setRxnSubSystems(model, {'ACONTa';'ACONTb';'AKGDH';'CS';'FUM';'ICDHyr';'MDH';'SUCOAS'}, 'TCA') % Set Glycolysis/Gluconeogenesis to reaction 18 of the model [model] = setRxnSubSystems(model, 18, {'Glycolysis','Gluconeogenesis'})
-
updateFieldOrderForType
(model, type, newOrder)[source]¶ Reorder the fields associated with the provided type to the new order. Usage
matchingFields = updateFieldOrderForType(model, type, newOrder)Inputs
- model – the model to update
- type – the Type of field to update one of (‘rxns’,’mets’,’comps’,’genes’)
- newOrder – The new Order. must be of the same size as the requested model.(type) field.
Output
- model – The model with all field associated with type reordered
-
updateGenes
(model)[source]¶ Update the model genes field (if it does not exist, generate it from the grRules field, if it exists, remove Unused genes and remove duplicate genes.
Usage
[modelNew] = updateGenes(model);Input
- model – COBRA model structure
Output
- modelNew – COBRA model structure with corrected genes
Note
The gene order will be changed to sorted. You should probably use buildRxnGeneMat to make sure the order matches in all relevant fields.
-
updateMetNames
(referenceModel, modelToUpdate, wipeExisting)[source]¶ Updates model.metNames in a new model, using metNames of a reference model.
Usage
[updatedModel] = updateMetNames(referenceModel, modelToUpdate, wipeExisting);Inputs
- referenceModel – COBRA model structure with correct model.metNames
- modelToUpdate – COBRA model structure that needs to have its model.metNames updated
Optional input
- wipeExisting – true: remove all existing model.metNames in modelToUpdate, especially when model.metNames is wrong.
Output
- updatedModel – COBRA model structure with corrected metNames