17.1.5. cobra.manipulation

Submodules

Package Contents

Functions

add_SBO(→ None)

Add SBO terms for demands and exchanges.

delete_model_genes(→ None)

Temporarily remove the effect of genes in gene_list.

knock_out_model_genes(→ List[cobra.Reaction])

Disable the genes in gene_list.

prune_unused_metabolites(→ Tuple[cobra.Model, ...)

Remove metabolites not involved in any reactions.

prune_unused_reactions(→ Tuple[cobra.Model, ...)

Remove reactions with no assigned metabolites, returns pruned model.

remove_genes(→ None)

Remove genes entirely from the model.

escape_ID(→ None)

Make all model component object IDs SBML compliant.

rename_genes(→ None)

Rename genes in a model from the rename_dict.

check_mass_balance(→ Dict[cobra.Reaction, ...)

Check mass balance for reactions of model and return unbalanced ones.

check_metabolite_compartment_formula(→ List[str])

Check metabolite formulae of model.

cobra.manipulation.add_SBO(model: cobra.Model) None[source]

Add SBO terms for demands and exchanges.

This works for models which follow the standard convention for constructing and naming these reactions.

The reaction should only contain the single metabolite being exchanged, and the id should be EX_<met_id> or DM_<met_id> .

Parameters

model (cobra.Model) – The model whose demand and exchange reactions need to be annotated.

cobra.manipulation.delete_model_genes(model: cobra.Model, gene_list: Union[List[cobra.Gene], Set[cobra.Gene], List[str], Set[str]], cumulative_deletions: bool = True, disable_orphans: bool = False) None[source]

Temporarily remove the effect of genes in gene_list.

It sets the bounds to “zero” for reactions catalysed by the genes in gene_list if deleting the genes stops the reactions from proceeding.

Parameters
  • model (cobra.Model) – The model whose reaction bounds are to be set.

  • gene_list (list of cobra.Gene) – The list of genes to knock-out.

  • cumulative_deletions (bool, optional) – If True, then any previous deletions will be maintained in the model (default True). Unused, ignored.

  • disable_orphans (bool, optional) – If True, then orphan reactions will be disabled. Currently, this is not implemented (default False). Unused, ignored.

  • : (.. deprecated) – 0.25: Use cobra.manipulation.knock_out_model_genes to simulate knockouts and cobra.manipulation.remove_genes to remove genes from the model.

See also

knock_out_model_genes, remove_model_genes

cobra.manipulation.knock_out_model_genes(model: cobra.Model, gene_list: Iterable[Union[cobra.Gene, int, str]]) List[cobra.Reaction][source]

Disable the genes in gene_list.

It sets the bounds to “zero” for reactions catalysed by the genes in gene_list if deleting the genes would stop the reactions from proceeding.

The changes are reverted upon exit if executed within the model as context.

Parameters
  • model (cobra.Model) – The model whose reaction bounds are to be set.

  • gene_list (list of cobra.Gene) – The list of genes to knock-out.

Returns

A list of cobra.Reactions that had the bounds turned to zero.

Return type

list[cobra.Reaction]

cobra.manipulation.prune_unused_metabolites(model: cobra.Model) Tuple[cobra.Model, List[cobra.Metabolite]][source]

Remove metabolites not involved in any reactions.

Parameters

model (cobra.Model) – The model to remove unused metabolites from.

Returns

  • cobra.Model – Input model with unused metabolites removed.

  • list of cobra.Metabolite – List of metabolites that were removed.

cobra.manipulation.prune_unused_reactions(model: cobra.Model) Tuple[cobra.Model, List[cobra.Reaction]][source]

Remove reactions with no assigned metabolites, returns pruned model.

Parameters

model (cobra.Model) – The model to remove unused reactions from.

Returns

  • cobra.Model – Input model with unused reactions removed.

  • list of cobra.Reaction – List of reactions that were removed.

cobra.manipulation.remove_genes(model: cobra.Model, gene_list: Union[List[cobra.Gene], Set[cobra.Gene], List[str], Union[str]], remove_reactions: bool = True) None[source]

Remove genes entirely from the model.

This will also simplify all gene-reaction rules with the genes inactivated.

Parameters
  • model (cobra.Model) – The model to remove genes from.

  • gene_list (list of cobra.Gene or gene ids) – The list of gene objects to remove.

  • remove_reactions (bool, optional) – Whether to remove reactions associated with genes in gene_list (default True).

cobra.manipulation.escape_ID(model: cobra.Model) None[source]

Make all model component object IDs SBML compliant.

Parameters

model (cobra.Model) – The model to operate on.

cobra.manipulation.rename_genes(model: cobra.Model, rename_dict: Dict[str, str]) None[source]

Rename genes in a model from the rename_dict.

Parameters
  • model (cobra.Model) – The model to operate on.

  • rename_dict (dict of {str: str}) – The dictionary having keys as old gene names and value as new gene names.

cobra.manipulation.check_mass_balance(model: cobra.Model) Dict[cobra.Reaction, Dict[cobra.Metabolite, float]][source]

Check mass balance for reactions of model and return unbalanced ones.

Parameters

model (cobra.Model) – The model to perform check on.

Returns

dict of {cobra.Reaction – Returns an empty dict if all components are balanced.

Return type

dict of {cobra.Metabolite: float}}

cobra.manipulation.check_metabolite_compartment_formula(model: cobra.Model) List[str][source]

Check metabolite formulae of model.

Parameters

model (cobra.Model) – The model to perform check on.

Returns

Returns an empty list if no errors are found.

Return type

list of str