cobra.manipulation.delete#

Provide functions for pruning reactions, metabolites and genes.

Attributes#

Classes#

_GeneRemover

Class to represent a gene set remover.

Functions#

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.

knock_out_model_genes(→ List[cobra.Reaction])

Disable the genes in gene_list.

delete_model_genes(→ None)

Temporarily remove the effect of genes in gene_list.

remove_genes(→ None)

Remove genes entirely from the model.

Module Contents#

cobra.manipulation.delete.logger#
cobra.manipulation.delete.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.delete.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.delete.knock_out_model_genes(model: cobra.Model, gene_list: Iterable[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.delete.delete_model_genes(model: cobra.Model, gene_list: 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

class cobra.manipulation.delete._GeneRemover(target_genes: Set[cobra.Gene], **kwargs)[source]#

Bases: ast.NodeTransformer

Class to represent a gene set remover.

Parameters:

target_genes (list or set of cobra.Gene) – A set of genes to be removed.

target_genes#
visit_Name(node: ast.Name) ast.Name | None[source]#

Remove a gene.

Parameters:

node (ast.Name) – The gene to remove.

Returns:

None if gene object is in target_genes.

Return type:

cobra.Gene or None

visit_BoolOp(node: ast.BoolOp) ast.BoolOp | ast.Name | None[source]#

Rules for boolean operations.

Parameters:

node (ast.Name) – The gene to apply rules to.

Returns:

None if size of Or node values is zero after applying rule, or size of And node values is lower after applying rule.

Return type:

ast.Name or None

cobra.manipulation.delete.remove_genes(model: cobra.Model, gene_list: List[cobra.Gene] | Set[cobra.Gene] | List[str] | 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).