17.1.1.4.1.2. cobra.manipulation.delete

Provide functions for pruning reactions, metabolites and genes.

17.1.1.4.1.2.1. Module Contents

17.1.1.4.1.2.1.1. Classes

_GeneRemover

Class to represent a gene set remover.

17.1.1.4.1.2.1.2. Functions

prune_unused_metabolites(model: Model) → Tuple[‘Model’, List[‘Metabolite’]]

Remove metabolites not involved in any reactions.

prune_unused_reactions(model: Model) → Tuple[‘Model’, List[‘Reaction’]]

Remove reactions with no assigned metabolites, returns pruned model.

undelete_model_genes(model: Model) → None

Undo the effects of a call to delete_model_genes in place.

get_compiled_gene_reaction_rules(model: Model) → Dict[‘Reaction’, Module]

Generate a dictionary of compiled gene-reaction rules.

find_gene_knockout_reactions(model: Model, gene_list: List[‘Gene’], compiled_gene_reaction_rules: Optional[Dict[‘Reaction’, Module]] = None) → List[‘Reaction’]

Identify reactions which will be disabled when genes are knocked out.

delete_model_genes(model: Model, gene_list: Union[List[‘Gene’], Set[‘Gene’], List[str], Set[str]], cumulative_deletions: bool = True, disable_orphans: bool = False) → None

Temporarily remove the effect of genes in gene_list.

remove_genes(model: Model, gene_list: Union[List[‘Gene’], Set[‘Gene’], List[str], Union[str]], remove_reactions: bool = True) → None

Remove genes entirely from the model.

cobra.manipulation.delete.prune_unused_metabolites(model: Model) → Tuple['Model', List['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: Model) → Tuple['Model', List['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.undelete_model_genes(model: Model) → None[source]

Undo the effects of a call to delete_model_genes in place.

Parameters

model (cobra.Model) – The model which will be modified in place.

cobra.manipulation.delete.get_compiled_gene_reaction_rules(model: Model) → Dict['Reaction', Module][source]

Generate a dictionary of compiled gene-reaction rules.

Any gene-reaction rule expression which cannot be compiled or do not evaluate after compiling will be excluded. The result can be used in the find_gene_knockout_reactions function to speed up evaluation of these rules.

Parameters

model (cobra.Model) – The model to get gene-reaction rules for.

Returns

  • dict of cobra.Reaction, ast.Module – The dictionary of cobra.Reaction objects as keys and ast.Module objects as keys.

  • .. deprecated:: – Internal function that has outlived its purpose.

cobra.manipulation.delete.find_gene_knockout_reactions(model: Model, gene_list: List['Gene'], compiled_gene_reaction_rules: Optional[Dict['Reaction', Module]] = None) → List['Reaction'][source]

Identify reactions which will be disabled when genes are knocked out.

Parameters
  • model (cobra.Model) – The model for which to find gene knock-out reactions.

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

  • compiled_gene_reaction_rules (dict of {reaction: compiled_string},) – optional If provided, this gives pre-compiled gene-reaction rule strings. The compiled rule strings can be evaluated much faster. If a rule is not provided, the regular expression evaluation will be used. Because not all gene-reaction rule strings can be evaluated, this dict must exclude any rules which can not be used with eval (default None).

Returns

  • list of cobra.Reaction – The list of cobra.Reaction objects which will be disabled.

  • .. deprecated:: 0.22.1 – Internal function that has outlived its purpose.

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

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

class cobra.manipulation.delete._GeneRemover(target_genes: Set['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.

visit_Name(self, node: Name) → Optional['Name'][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(self, node: BoolOp) → Optional[Union['BoolOp', 'Name']][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: Model, gene_list: Union[List['Gene'], Set['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).