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 with fields:

    • .rxns - n x 1 reaction identifiers, used to resolve idList entries and to size the reaction block of a new constraint row

    • .ctrs - ctrs x 1 constraint identifiers (created if absent, checked for duplicates otherwise)

    • .C - ctrs x n constraint coefficient matrix (created if absent)

    • .E - m x evars extra variable matrix, read only to determine whether additional-variable constraint coefficients (.D) need to be built

    • .D - ctrs x evars coupling matrix between extra variables and constraints (read and extended when .E is present)

  • 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;

OPTIONAL INPUTS:

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:

model – 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

  • .D - Optional: the matrix containing 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.

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 with fields:

    • .rxns - n x 1 reaction identifiers, checked so that new variable IDs do not clash with reaction IDs

    • .evars - evars x 1 extra variable identifiers (created if absent, checked for duplicates otherwise)

    • .E - m x evars extra variable coefficient matrix, read to determine the current number of variables

    • .evarlb - evars x 1 lower bounds of extra variables

    • .evarub - evars x 1 upper bounds of extra variables

    • .evarc - evars x 1 objective coefficients of extra variables

    • .evarNames - evars x 1 extra variable names (created only if not already present and Names was supplied)

  • idList – cell array of ids

OPTIONAL INPUTS:

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

  • .evarNames - The variable names (if provided or already present)

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.

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, rxnNames] = addDemandReaction (model, metaboliteNameList, printLevel)

INPUTS:
  • model – COBRA model structure with fields:

    • .mets - m x 1 metabolite identifiers, used to detect entries of metaboliteNameList that are missing from the model

  • metaboliteNameList – List of metabolite names (cell array)

OPTIONAL INPUT:

printLevel – If > 0 will print out the reaction formulas (Default: 0).

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, AddedExchRxn] = addExchangeRxn (model, metList, lb, ub)

INPUTS:
  • model – Cobra model structure with fields:

    • .mets - m x 1 metabolite identifiers, used to find entries of metList missing from the model

    • .lb - n x 1 reaction lower bounds, used to build the default lower bound when lb is not supplied

    • .ub - n x 1 reaction upper bounds, used to build the default upper bound when ub is not supplied

  • metList – List of metabolites

OPTIONAL INPUTS:
  • lb – Array of lower bounds

  • ub – Array of upper bounds

OUTPUTS:
  • newModel – COBRA model with added exchange reactions

  • AddedExchRxn – List of exchange reaction identifiers that were added

addGenes(model, geneIDs, varargin)[source]

Add Genes (or a single gene) to the model

USAGE:

newmodel = addGenes (model, geneIDs, varargin)

INPUT:
  • model – The model to add the Metabolite batch to, with fields:

    • .genes - g x 1 gene identifiers, checked for duplicates against geneIDs and extended with the newly added gene IDs

  • geneIDs – The IDs of the genes that shall be added.

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):

  • 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 = addMIRIAMAnnotations (model, elementIDs, databases, ids, varargin)

INPUTS:
  • model – A COBRA Style model struct

  • elementIDs – 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 INPUTS:

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, varargin)

INPUTS:
  • model – Cobra model structure

  • metID – The ID(s) of the metabolite(s) (will be the identifier in model.mets)

OPTIONAL INPUTS:

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)

Examples

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, with fields:

    • .mets - m x 1 metabolite identifiers, checked for duplicates against metIDs and extended with the newly added metabolite IDs

  • metIDs – The metabolite IDs to add. No duplicate IDs may be provided and no ID may be present in the supplied model.

OPTIONAL INPUTS:

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]

OUTPUTS:

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, with fields:

    • .mets - m x 1 metabolite identifiers, used to locate the positions of metList in the model

    • .rxns - n x 1 reaction identifiers, checked for duplicates against rxnIDs and extended with the newly added reaction IDs

  • 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 INPUTS:

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.

OUTPUTS:

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’})

addMultipleReactionsIT(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, with fields:

    • .mets - m x 1 metabolite identifiers, used to locate the positions of metList in the model

    • .rxns - n x 1 reaction identifiers, checked for duplicates against rxnIDs and extended with the newly added reaction IDs

  • 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 INPUTS:

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.

OUTPUTS:

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 with fields:

    • .rxns - n x 1 reaction identifiers, checked for an existing reaction with the same ID and extended with the new reaction ID

    • .lb - n x 1 lower bounds, read to compute default bounds/reversibility and set for the new/modified reaction

    • .ub - n x 1 upper bounds, read to compute the default upper bound and set for the new/modified reaction

    • .mets - m x 1 metabolite identifiers, used to determine which of the reaction’s metabolites are already in the model

    • .S - m x n stoichiometric matrix, read and extended with the new reaction’s column

    • .subSystems - n x 1 subsystem assignments, created if absent and set for the new/modified reaction

    • .subSystem - legacy singular subsystem field, read (if present) to seed the default subsystem when modifying an existing reaction

    • .grRules - n x 1 GPR rule strings, read (if present) to seed the default gene rule when modifying an existing reaction

    • .rxnNames - n x 1 reaction names, read (if present) to seed the default reaction name and set for the new/modified reaction

  • rxnID – Reaction name abbreviation (i.e. ‘ACALD’)

OPTIONAL INPUTS:

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 = 0

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.

Examples

%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 with fields:

    • .rxns - n x 1 reaction identifiers, used to determine the current number of reactions

    • .mets - m x 1 metabolite identifiers, used to determine the current number of metabolites

    • .lb - n x 1 lower bounds, used to derive the default value of nRxn when it is not supplied

    • .S - m x n stoichiometric matrix, used to determine whether a metabolite already participates in the reactions being replaced

    • .subSystems - n x 1 subsystem assignments, initialized to ‘’ for every reaction if the field is not yet present

    • .grRules - n x 1 GPR rule strings, initialized to ‘’ for every reaction if the field is not yet present

    • .genes - g x 1 gene identifiers, checked with isfield to determine whether the model already has a gene list

  • 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

  • nRxn – The reaction index at which to start adding the new reactions (default: length(model.lb) + 1)

  • 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

[newmodel] = addReactionGEM(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, rxnsInModel] = addSinkReactions (model, metabolites, lb, ub)

INPUTS:
  • model – COBRA model structure with fields:

    • .mets - m x 1 metabolite identifiers, checked against metabolites

    • .lb - n x 1 reaction lower bounds, used to build the default lower bound when lb is not supplied

    • .ub - n x 1 reaction upper bounds, used to build the default upper bound when ub is not supplied

    • .rxns - n x 1 reaction identifiers, used to locate the newly added sink reaction when setting its name

  • 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] = addSubSystemsToReactions (model, reactions, subSystems)

INPUT:
  • model – A COBRA model struct with fields:

    • .rxns - n x 1 reaction identifiers, used to resolve reactions when it is given as name(s) rather than positions

    • .subSystems - n x 1 subsystem annotations, created if absent and extended with the new subsystem(s)

  • 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 supplied 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 with fields:

  • .rxns - n x 1 reaction identifiers, sorted and used to reorder all reaction-associated fields

  • .mets - m x 1 metabolite identifiers, sorted and used to reorder all metabolite-associated fields

  • .genes - g x 1 gene identifiers (if present), sorted and used to reorder all gene-associated fields

  • .comps - c x 1 compartment symbols (if present), sorted and used to reorder all compartment-associated fields

OUTPUT:

abcModel – the alphabetized model

annotateSBOTerms(model)[source]

Add SBO terms to model entities

USAGE:

model = annotateSBOTerms (model)

INPUT:

model – model structure with fields:

  • .mets - m x 1 metabolite identifiers, iterated to set .metSBOTerms

  • .genes - g x 1 gene identifiers, iterated to set .geneSBOTerms

  • .rxns - n x 1 reaction identifiers, iterated to classify each reaction and set .rxnSBOTerms

OUTPUT:

model – updated model structure with fields:

  • .metSBOTerms - m x 1 SBO terms for metabolites, set to SBO:0000247 for every metabolite

  • .geneSBOTerms - g x 1 SBO terms for genes, set to SBO:0000243 for every gene

  • .rxnSBOTerms - n x 1 SBO terms for reactions, classified by reaction-ID pattern or compartment usage

assignGPRA(model, gpraFile)[source]

Assigns each reaction a Gene-protein-reaction association

USAGE:

model = assignGPRA (model, gpraFile)

INPUTS:
  • model – COBRA model structure with fields:

    • .rxns - n x 1 reaction identifiers, intersected with the reactions parsed from gpraFile

    • .genes - overwritten with the gene list parsed from gpraFile

    • .rxnGeneMat - n x g reaction-gene incidence matrix, rebuilt from the parsed GPRA file

  • 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 with fields:

    • .rxns - n x 1 reaction identifiers, matched against the reactions parsed from gpraFile

    • .subSystems - n x 1 subsystem assignments, overwritten for every reaction (looked up from gpraFile, or set to ‘Exchange’ if not found)

  • gpraFile – SimPheny GPRA file

OUTPUT:

model – COBRA model structure with subsystem assignment

buildRxn2subSystem(model, removeSubSystems)[source]

Generates reaction-subSystem matrix for a COBRA model This function adds two fields to the COBRA model: 1) rxnSubsystemMat and 2)subSystemsNames and removes the old subSystems field(optional and can be set to false)

USAGE:

[modelOut, rxn2subSystem, subSystemNames, nestedCells] = buildRxn2subSystem (model, removeSubSystems)

INPUTS:

model – COBRA model structure with fields:

  • .rxns - n x 1 reaction identifiers

  • .subSystems - n x 1 subsystem assignments (removed from the output model if removeSubSystems is true)

OPTIONAL INPUTS:

removeSubSystems – Binary variable, if equals to 1 (or true) subSystems field will be removed from the model default:true

OUTPUTS:
  • modelOut – COBRA model structure containing two added fields of “rxn2subSystem” and “subSystemsNames”

  • rxn2subSystem – Matrix of reactions vs subSystems

  • subSystemNames – Unique sub-system names in the model with order corrosponding to the matrix

  • nestedCells – logical variable, True if sub-system field is a nested cell vector and False if it’s not

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 – COBRA model structure with fields:

    • .S - m x n stoichiometric matrix, read to size the reaction block

    • .ctrs - constraint identifiers, used to resolve constraintID

    • .evars - additional (non-reaction) variables, checked to size the extra-variable block

    • .C - ctrs x n constraint coefficient matrix on the reactions (updated)

    • .D - ctrs x evars coupling matrix between constraints and additional variables (read and updated)

    • .d - constraint right hand side values (updated)

    • .dsense - constraint senses (‘L’, ‘G’, ‘E’), updated per constraint

    • .ctrNames - descriptive constraint names, created if absent then updated

  • constraintID – The ID of the constraint (or the index in the ctrs field)

OPTIONAL INPUTS:

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!

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 – COBRA model structure with fields:

    • .evars - additional (non-reaction) variable identifiers, used to resolve variableID; the matching evar<Property> fields (e.g. evarlb, evarub, evarc) are updated in place

  • variableID – The ID of the variable (or the index in the evars field)

OPTIONAL INPUTS:

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

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 with fields:

    • .rxns - n x 1 cell array of reaction identifiers

    • .genes - g x 1 cell array of gene identifiers

    • .rules - n x 1 cell array of evaluatable GPR rules

    • .rxnGeneMat - (optional) n x g reaction-gene incidence matrix

  • 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 ModifiedRxns – Combined output pair (space-separated in the signature):

  • 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:

[bool, existing] = checkIDsForTypeExist (model, ids, basefield)

INPUTS:
  • model – model structure with fields:

    • .rxns - n x 1 cell array of reaction identifiers

    • .evars - (if present) evars x 1 cell array of extra variable identifiers, combined with .rxns when basefield is rxns or evars

    • .mets - m x 1 cell array of metabolite identifiers

    • .ctrs - (if present) ctrs x 1 cell array of constraint identifiers, combined with .mets when basefield is mets or ctrs

  • ids – cell array of identifiers

  • basefield – Any base field defined.

OUTPUT:
  • bool – Boolean vector true if any of the IDs exist.

  • existing – Unique set of pre-existing IDs for this base field.

Example

[bool,existing] = checkIDsForTypeExist(model,’atp[c]’,’mets’)

convertIrrevFluxDistribution(vIrrev, matchRev)[source]

Converts irreversible flux distribution to reversible

USAGE:

vRev = convertIrrevFluxDistribution (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 with fields:

  • .rxns - n x 1 cell array of reaction identifiers

  • .lb - n x 1 lower flux bounds

  • .ub - n x 1 upper flux bounds

  • .S - m x n stoichiometric matrix

  • .c - n x 1 objective coefficients

Any other field associated with rxns (as returned by getModelFieldsForType) is extended and reordered alongside these.

OPTIONAL INPUTS:

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. Fields used:

  • .rxns - n x 1 cell array of reaction identifiers

  • .lb - n x 1 lower flux bounds

  • .ub - n x 1 upper flux bounds

  • .S - m x n stoichiometric matrix

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 descriptive 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

Examples

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

dispStoichAsTable(model, printLevel)[source]

Display the stoichiometric matrix as a table

USAGE:

T = dispStoichAsTable (model, printLevel)

INPUTS:

model – COBRA model structure with fields:

  • .S - m x n stoichiometric matrix

  • .rxns - n x 1 cell array of reaction identifiers

  • .mets - m x 1 cell array of metabolite identifiers

OPTIONAL INPUTS:

printLevel – Verbose level (0 = silent, 1 = display the table (default))

OUTPUT:

T – Table representation of the stoichiometric matrix, with reactions as variables and metabolites as row names

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 INPUTS:

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 with fields:

    • .mets - m x 1 cell array of metabolite identifiers

    • .S - m x n stoichiometric matrix

    • .rxns - n x 1 cell array of reaction identifiers

  • compSymbol – Compartment symbol

OPTIONAL INPUT:
  • 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 with fields:

    • .S - m x n stoichiometric matrix

    • .mets - m x 1 cell array of metabolite identifiers

    • .rxns - n x 1 cell array of reaction identifiers

    • .c - (if present) n x 1 objective coefficients

  • 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 with fields:

    • .rxns - n x 1 cell array of reaction identifiers

    • .mets - m x 1 cell array of metabolite identifiers

    • .S - m x n stoichiometric matrix

    • .genes - (if updateGenes is used) g x 1 cell array of gene identifiers

  • rxnList – Reaction list for the subnetwork to be extracted

OPTIONAL INPUTS:
  • metList – 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 with fields:

    • .rxns - n x 1 cell array of reaction identifiers

    • .subSystems - n x 1 cell array of subsystem annotations

  • 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 = flipRxnOrientation (model, rxnList)

INPUTS:
  • model – A COBRA Style model structure with fields:

    • .rxns - n x 1 cell array of reaction identifiers

    • .S - m x n stoichiometric matrix (rows for the flipped reactions are negated)

    • .c - n x 1 objective coefficients (negated for the flipped reactions)

    • .lb - n x 1 lower flux bounds (swapped/negated for the flipped reactions)

    • .ub - n x 1 upper flux bounds (swapped/negated for the flipped reactions)

  • rxnList – A List of reactions or a single reaction

OUTPUTS:

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)

INPUT:
  • model – COBRA model structure with fields:

    • .grRules - n x 1 cell array of gene-protein-reaction rules (required)

    • .genes - (if present) g x 1 cell array of gene identifiers

  • 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)

INPUTS:

model – model structure with fields:

  • .C - ctrs x n additional constraints matrix

  • .D - ctrs x evars coupling matrix between extra variables and constraints

  • .ctrs - ctrs x 1 cell array of constraint identifiers

OUTPUT:

emptyConstraints – A list of IDs of empty constraints.

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 with fields:

    • .rxns - n x 1 cell array of reaction identifiers

    • .evars - (if present) evars x 1 cell array of extra variable identifiers

    • .mets - m x 1 cell array of metabolite identifiers

    • .ctrs - (if present) ctrs x 1 cell array of constraint identifiers

  • ids – cell array of reaction names

  • basefield – Either ‘rxns’, or ‘mets’

OUTPUTS:
  • pos – The positions of the given ids in the [rxns;evars] or [mets;ctrs] vectors for rxns and mets , respectively.

  • pres – Logical vector, true where the corresponding entry in ids was found in the searched vector.

getMetAbbr(mets)[source]

Gets the abbreviation for each metabolite, and the unique abbreviations, from metabolite abbreviation(s), each of which must have compartment symbol concatentated on the right hand side (i.e. metAbbr[*]).

USAGE:

[metAbbr, uniqueMetAbbrs] = getMetAbbr (mets)

INPUT:

mets – char array with a single metabolite abbreviation (with compartment, e.g. metAbbr[c]), or m x 1 cell array of such metabolite abbreviations

OUTPUTS:
  • metAbbr – char array with a single metabolite abbreviation (compartment symbol removed), or m x 1 cell array of metabolite abbreviations

  • uniqueMetAbbrs – char array with a single metabolite abbreviation or cell array of unique metabolite abbreviations

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’,’rxnName’,’specName’)

OPTIONAL INPUTS:

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.

OUTPUT:
  • 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 INPUTS:

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

Note: Notice that this function checks if two models are the same, two same models does not necessary mean two same structures. use structeq.m to compare two structures

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 with fields:

    • .S - m x n stoichiometric matrix

    • .mets - m x 1 metabolite identifiers

    • .rxns - n x 1 reaction identifiers

  • 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 compartments

mergeModelFieldPositions(model, type, positions, mergeFunctions)[source]

Merges the entries of all fields associated with a given index type (rxns, mets, comps or genes) at the specified positions into a single entry, using field-specific merge functions where provided.

USAGE:

modelNew = mergeModelFieldPositions (model, type, positions, mergeFunctions)

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 INPUTS:

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, with fields:

  • .rules - n x 1 GPR rules, gene indices remapped to the kept position when type is genes

  • .grRules - n x 1 readable GPR rules, gene names remapped to the kept position when type is genes

Unique entries in Related String fields will be concatenated with ‘;’ matrices will be summed up.

mergeTwoModels(model1, model2, objrxnmodel, mergeGenes, rmDuplRxns)[source]

Merge two models. If fields conflict, the data from fields in model1 will be used.

USAGE:

[modelNew] = mergeTwoModels (model1, model2, objrxnmodel, mergeGenes, rmDuplRxns)

INPUTS:
  • model1 – model 1, with fields:

    • .c - n x 1 objective coefficients (reset to 0 if objrxnmodel selects model2’s objective)

    • .osenseStr - objective sense (max/min), kept if objrxnmodel selects model1’s objective

    • .genes - g x 1 gene identifiers

    • .comps - c x 1 compartment symbols

    • .mets - m x 1 metabolite identifiers

    • .rxns - n x 1 reaction identifiers

    • .S - m x n stoichiometric matrix

  • model2 – model 2, with the same fields as model1 (.c, .osenseStr, .genes, .comps, .mets, .S), used analogously

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)

  • rmDuplRxns – Boolean indicating whether duplicate reactions should be removed (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 with field:

    • .rxns - n x 1 reaction identifiers, used to size and locate all reaction-indexed fields that are moved

  • startspot – The reaction number to move

  • endspot – The spot where the reaction is moving to

OUTPUTS:

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 with fields:

  • .S - m x n stoichiometric matrix

  • .rxns - n x 1 reaction identifiers

  • .lb - n x 1 lower flux bounds

  • .ub - n x 1 upper flux bounds

  • .c - n x 1 objective coefficients, read indirectly through optimizeCbModel when checking consistency of the reduced model

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 = removeCOBRAConstraints (model, constraintsToRemove)

INPUTS:
  • model – model structure with fields:

    • .C - ctrs x n additional constraints matrix

    • .ctrs - ctrs x 1 constraint identifiers

  • 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.

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, fieldSize, varargin)

INPUTS:
  • model – the model to update, with fields:

    • .rules - n x 1 evaluatable GPR rules, updated when type is genes

    • .genes - g x 1 gene identifiers, read to map removed gene positions to gene names when type is genes

  • 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’,’ctrs’,’evars’,’rxnName’,’specName’,’molAlias’)

  • fieldSize – The size of the original field before modification. This is necessary to identify fields from which entries have to be removed.

OPTIONAL INPUTS:

varargin – Additional Options as ‘ParameterName’, Value pairs. Options are: - ‘excludeFields’, fields which should not be

adjusted but kept how they are.

OUTPUT:

model – 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.

Note

rxnName, specName, and molAlias refer to a map field, see https://github.com/opencobra/cobratoolbox/blob/master/docs/source/notes/simpleMATLABStructure.md

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. Instead, use deleteModelGenes.m for that.

USAGE:

[model, affectedRxns, originalGPRs, deletedReactions] = removeGenesFromModel (model, geneList)

INPUT:
  • model – COBRA model with the appropriate constrains for a particular condition, with fields:

    • .genes - g x 1 gene identifiers

    • .rules - n x 1 evaluatable GPR rules, updated to remove the deleted genes

    • .rxns - n x 1 reaction identifiers (read if keepReactions is false)

    • .grRules - n x 1 readable GPR rules, updated if present

    • .rxnGeneMat - n x g reaction-gene incidence matrix, used to find affected reactions if present

  • geneList – List of genes to be deleted as cell array, or a single gene as char

OPTIONAL INPUTS:

varargin – Additional Parameter/value pairs or a parameter struct with the following parameter names:

  • keepReactions - Whether to keep reactions if its GPR is hanged 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 in grRules format.

  • deletedReactions – The list of reactions removed from the model (if keepReaction was false).

removeMetabolites(model, metRemoveList, removeRxnFlag, rxnRemoveMethod)[source]

Removes metabolites from a model

USAGE:

[model, rxnRemovedList] = removeMetabolites (model, metRemoveList, removeRxnFlag, rxnRemoveMethod)

INPUTS:
  • model – COBRA model structure with fields:

    • .S - m x n stoichiometric matrix

    • .mets - m x 1 metabolite identifiers

    • .genes - g x 1 gene identifiers (read if present, to determine the number of genes)

  • metRemoveList – List of metabolites to be removed

OPTIONAL INPUT:
  • removeRxnFlag – Remove reactions with no metabolites (Default = true)

  • rxnRemoveMethod – {(‘inclusive’),’exclusive’,’legacy’}, to remove reactions in a stoichiometrically consistent manner, or possibly not consistently if either of the last options are chosen.

OUTPUT:
  • model – COBRA model with removed metabolites

  • rxnRemovedList – Cell array of reaction abbreviations that were removed as a consequence of the metabolite removal

removeRxns(model, rxnRemoveList, varargin)[source]

Removes reactions from a model

USAGE:

[modelOut, metRemovedList, ctrsRemovedList] = removeRxns (model, rxnRemoveList, varargin)

INPUTS:
  • model – COBRA model structure with fields:

    • .S - m x n stoichiometric matrix

    • .rxns - n x 1 reaction identifiers

    • .mets - m x 1 metabolite identifiers

    • .genes - g x 1 gene identifiers (read if present, to determine the number of genes)

    • .lb - n x 1 lower flux bounds

    • .ub - n x 1 upper flux bounds

    • .match - n x 1 forward-backward reaction mapping vector (read/reassigned if irrevFlag)

    • .C - ctrs x n additional constraints matrix (read if present)

    • .d - ctrs x 1 right-hand side of the additional constraints (read if present)

    • .dsense - ctrs x 1 constraint senses (read if present)

    • .ctrs - ctrs x 1 constraint identifiers (read if present)

    • .ctrNames - ctrs x 1 constraint names (read if present)

  • rxnRemoveList – Cell array of reaction abbreviations to be removed

OPTIONAL INPUTS:

varargin – Parameters in ParameterName, Value pair representation. Available parameters are: * metRemoveMethod

‘exclusive’ = remove metabolites exclusively involved in removed reactions (default) ‘inclusive’ = remove any metabolite involved in one or more removed reactions (can cause stoichiometric inconsistency)

  • ctrsRemoveMethod ‘exclusive’ = only remove constraints exclusively involved in removed reactions (default) ‘inclusive’ = any constraint involved in a removed reaction is to be removed ‘infeasible’ = if a removed reaction involves any constraint then remove that constraint, unless the constraint is still feasible. ‘legacy’ = remove empty constraints, it seems equivalent to ‘exclusive’, but kept for completeness

  • irrevFlag: Irreverseble (true) or reversible (false) reaction format (Default = false)

  • metFlag: Remove unused metabolites (Default = true)

OUTPUT:
  • modelOut – COBRA model w/o selected reactions

  • metRemovedList – Cell array of metabolite abbreviations that were removed

  • ctrsRemovedList – Cell array of model.ctrs that were removed Alternatively, if model.ctrs did not exist, then a boolean vector displaying the rows of C*v <=d that were removed.

Optional inputs are used as parameter value pairs

Examples

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] = removeSubSystemsFromRxns (model, reactions, subSystems)

INPUT:
  • model – A COBRA model struct with fields:

    • .rxns - n x 1 reaction identifiers

    • .subSystems - n x 1 cell array of cell arrays of subSystem names for each reaction (created if not already present)

  • 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, with field:

  • .S - m x n stoichiometric matrix

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, unusedGenes] = removeUnusedGenes (model)

INPUTS:

model – COBRA structure

OUTPUT:
  • modelNew – COBRA model structure with updated gene field reflecting only content present in the model

  • unusedGenes – Cell array of gene identifiers that were removed because they are not associated with any reaction (i.e. all-zero columns of modelNew.rxnGeneMat)

setRxnSubSystems(model, reactions, subSystems)[source]

Sets the subSystems of the specified reactions to the specified subSystems

USAGE:

[model] = setRxnSubSystems (model, reactions, subSystems)

INPUT:
  • model – A COBRA model struct with fields:

    • .rxns - n x 1 reaction identifiers

    • .subSystems - n x 1 cell array of cell arrays of subSystem names for each reaction (created if not already present)

  • 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:

model = updateFieldOrderForType (model, type, newOrder)

INPUTS:
  • model – the model to update, with fields:

    • .genes - g x 1 gene identifiers (read if type is genes, to size the reorder loop)

    • .rules - n x 1 evaluatable GPR rules, remapped if type is genes

  • 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, with fields:

    • .mets - m x 1 metabolite identifiers

    • .metNames - m x 1 metabolite names

  • modelToUpdate – COBRA model structure that needs to have its model.metNames updated, with field:

    • .mets - m x 1 metabolite identifiers

OPTIONAL INPUTS:

wipeExisting – true: remove all existing model.metNames in modelToUpdate, especially when model.metNames is wrong.

OUTPUT:

updatedModel – COBRA model structure with corrected metNames