17.1.1.4.1.3. cobra.manipulation.modify

Provide functions to modify model components.

17.1.1.4.1.3.1. Module Contents

17.1.1.4.1.3.1.1. Classes

_GeneEscaper

Class to represent a gene ID escaper.

_Renamer

Class to represent a gene renamer.

17.1.1.4.1.3.1.2. Functions

_escape_str_id(id_str: str) → str

Make a single string ID SBML compliant.

escape_ID(model: Model) → None

Make all model component object IDs SBML compliant.

rename_genes(model: Model, rename_dict: Dict[str, str]) → None

Rename genes in a model from the rename_dict.

cobra.manipulation.modify._renames = [['.', '_DOT_'], ['(', '_LPAREN_'], [')', '_RPAREN_'], ['-', '__'], ['[', '_LSQBKT'], [']', '_RSQBKT'], [',', '_COMMA_'], [':', '_COLON_'], ['>', '_GT_'], ['<', '_LT'], ['/', '_FLASH'], ['\\', '_BSLASH'], ['+', '_PLUS_'], ['=', '_EQ_'], [' ', '_SPACE_'], ["'", '_SQUOT_'], ['"', '_DQUOT_']][source]
cobra.manipulation.modify._escape_str_id(id_str: str) → str[source]

Make a single string ID SBML compliant.

Parameters

id_str (str) – The ID string to operate on.

Returns

The SBML compliant ID string.

Return type

str

class cobra.manipulation.modify._GeneEscaper[source]

Bases: ast.NodeTransformer

Class to represent a gene ID escaper.

visit_Name(self, node: Gene) → 'Gene'[source]

Escape string ID.

Parameters

node (cobra.Gene) – The gene object to work on.

Returns

The gene object whose ID has been escaped.

Return type

cobra.Gene

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

Make all model component object IDs SBML compliant.

Parameters

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

class cobra.manipulation.modify._Renamer(rename_dict: Dict[str, str], **kwargs)[source]

Bases: ast.NodeTransformer

Class to represent a gene renamer.

Parameters

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

visit_Name(self, node: Gene) → 'Gene'[source]

Rename a gene.

Parameters

node (cobra.Gene) – The gene to rename.

Returns

The renamed gene object.

Return type

cobra.Gene

cobra.manipulation.modify.rename_genes(model: 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.