17.1.1.1.1.4. cobra.core.gene

17.1.1.1.1.4.1. Module Contents

17.1.1.1.1.4.1.1. Classes

GPRCleaner

Parses compiled ast of a gene_reaction_rule and identifies genes

Gene

A Gene in a cobra model

17.1.1.1.1.4.1.2. Functions

ast2str(expr, level=0, names=None)

convert compiled ast to gene_reaction_rule str

eval_gpr(expr, knockouts)

evaluate compiled ast of gene_reaction_rule with knockouts

parse_gpr(str_expr)

parse gpr into AST

cobra.core.gene.keywords[source]
cobra.core.gene.keyword_re[source]
cobra.core.gene.number_start_re[source]
cobra.core.gene.replacements = [['.', '__COBRA_DOT__'], ["'", '__COBRA_SQUOTE__'], ['"', '__COBRA_DQUOTE__'], [':', '__COBRA_COLON__'], ['/', '__COBRA_FSLASH__'], ['\\', '__COBRA_BSLASH'], ['-', '__COBRA_DASH__'], ['=', '__COBRA_EQ__']][source]
cobra.core.gene.ast2str(expr, level=0, names=None)[source]

convert compiled ast to gene_reaction_rule str

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

Returns

The gene reaction rule

Return type

string

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

evaluate compiled ast of gene_reaction_rule with knockouts

Parameters
  • expr (Expression) – The ast of the gene reaction rule

  • knockouts (DictList, set) – Set of genes that are knocked out

Returns

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

Return type

bool

class cobra.core.gene.GPRCleaner[source]

Bases: ast.NodeTransformer

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

visit_Name(self, node)[source]
visit_BinOp(self, node)[source]
cobra.core.gene.parse_gpr(str_expr)[source]

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]

Bases: cobra.core.species.Species

A Gene in a cobra model

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

property functional(self)[source]

A flag indicating if the gene is functional.

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

knock_out(self)[source]

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(self, model=None, make_dependent_reactions_nonfunctional=True)[source]

Removes the association

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

_repr_html_(self)[source]