cobra.core.gene Module Contents

cobra.core.gene.ast2str(expr, level=0, names=None)[source]

convert compiled ast to gene_reaction_rule str

  • expr (str) – string for a gene reaction rule, e.g “a and b”
  • level (int) – internal use only
  • names (dict) – Dict where each element id a gene identifier and the value is the gene name. Use this to get a rule str which uses names instead. This should be done for display purposes only. All gene_reaction_rule strings which are computed with should use the id.

The gene reaction rule

Return type:


cobra.core.gene.eval_gpr(expr, knockouts)[source]

evaluate compiled ast of gene_reaction_rule with knockouts

  • expr (Expression) – The ast of the gene reaction rule
  • knockouts (DictList, set) – Set of genes that are knocked out

True if the gene reaction rule is true with the given knockouts otherwise false

Return type:


class cobra.core.gene.GPRCleaner[source]

Parses compiled ast of a gene_reaction_rule and identifies genes

Parts of the tree are rewritten to allow periods in gene ID’s and bitwise boolean operations


parse gpr into AST

Parameters:str_expr (string) – string with the gene reaction rule to parse
Returns:elements ast_tree and gene_ids as a set
Return type:tuple
class cobra.core.gene.Gene(id=None, name="", functional=True)[source]

A Gene in a cobra model

  • id (string) – The identifier to associate the gene with
  • name (string) – A longer human readable name for the gene
  • functional (bool) – Indicates whether the gene is functional. If it is not functional then it cannot be used in an enzyme complex nor can its products be used.
__init__(id=None, name="", functional=True)[source]

A flag indicating if the gene is functional.

Changing the flag is reverted upon exit if executed within the model as context.


Knockout gene by marking it as non-functional and setting all associated reactions bounds to zero.

The change is reverted upon exit if executed within the model as context.

remove_from_model(model=None, make_dependent_reactions_nonfunctional=True)[source]

Removes the association

  • model (cobra model) – The model to remove the gene from
  • make_dependent_reactions_nonfunctional (bool) – If True then replace the gene with ‘False’ in the gene association, else replace the gene with ‘True’

Deprecated since version 0.4: Use cobra.manipulation.delete_model_genes to simulate knockouts and cobra.manipulation.remove_genes to remove genes from the model.