5.1.1.1.1. cobramod.core.creation

Object creation

This module handles the creation of COBRApy’s objects cobra.core.metabolite.Metabolite and cobra.core.reaction.Reaction. Dictionaries containing the data of a given database are used. Important functions are:

  • create_object: Creates and Returns a COBRApy object.

  • add_reactions: Add reactions from multiple sources.

  • add_metabolites: Add reactions from multiple sources.

These functions are a mix of multiple simpler functions:

  • _metabolite_from_string, _reaction_from_string: create objects from strings.

  • _get_metabolite, _get_reaction: create objects from dictionary.

  • _convert_string_reaction, _convert_string_metabolite: create objects from files.

5.1.1.1.1.1. Module Contents

5.1.1.1.1.1.1. Functions

create_object(identifier: str, directory: pathlib.Path, database: str, compartment: str, replacement: dict = {}, show_imbalance: bool = True, stop_imbalance: bool = False, model: cobra.Model = Model(0), model_id: str = 'universal', genome: str = None) → Union[cobra.Reaction, cobra.Metabolite, dict]

Creates and returns a COBRApy object based on given identifier and

add_metabolites(model: cobra.Model, obj: Any, database=None, **kwargs)

Adds given object into the model. The options are:

add_reactions(model: cobra.Model, obj: Any, database=None, stop_imbalance: bool = False, show_imbalance: bool = True, **kwargs)

Adds given object into the model. The options are:

cobramod.core.creation.create_object(identifier: str, directory: pathlib.Path, database: str, compartment: str, replacement: dict = {}, show_imbalance: bool = True, stop_imbalance: bool = False, model: cobra.Model = Model(0), model_id: str = 'universal', genome: str = None) Union[cobra.Reaction, cobra.Metabolite, dict]

Creates and returns a COBRApy object based on given identifier and database. Identifier names will be formatted.

Hint

Hyphens will become underscores. Double hyphens become single underscores.

Parameters
  • identifier (str) – Original identifier of the database.

  • directory (Path) – Path to directory where data is stored.

  • database (str) – Name of database. Check cobramod.available_databases for a list of names.

  • compartment (str) – Location of the object. In case of reaction, all metabolites will be included in the same location.

  • replacement (dict, optional) – original identifiers to be replaced. Values are the new identifiers. Defaults to {}. Does not apply to pathways.

Arguments for reactions

stop_imbalance (bool, optional): If an unbalanced reaction is found,

stop the process. Defaults to False.

show_imbalance (bool, optional): If an unbalanced reaction is found,

print output. Defaults to True.

model (Model, optional): Model to add search for translated metabolites

or reactions. Defaults to an empty model.

Special arguments for databases

model_id (str, optional): Exclusive for BIGG. Retrieve object from

specified model. Pathways are not available. Defaults to: “universal”

genome (str, optional): Exclusive for KEGG. Abbreviation for the

species involved. Genes will be obtained for this species. List available at https://www.genome.jp/kegg/catalog/org_list.html

Returns

A Reaction or Metabolite object; or the

information for a pathway.

Return type

Union[Reaction, Metabolite]

cobramod.core.creation.add_metabolites(model: cobra.Model, obj: Any, database=None, **kwargs)

Adds given object into the model. The options are:

  • Path: A file with components. E. g:

    Path.cwd().joinpath(“file_with_names.txt”)

  • Metabolite: A single Metabolite.

  • List[Metabolites]: A list with multiple Metabolite objects.

  • str: Either the identifier with its corresponding compartment or a

string with the whole attributes. This applies for the Path option. E.g:

Custom metabolite syntax:

formatted_identifier, name, compartment, chemical_formula, molecular_charge

Metabolite from database:

metabolite_identifier, compartment

  • List[str]: A list with multiple str with the mentioned syntax.

Parameters
  • model (Model) – Model to be expanded and searched for metabolites.

  • obj – A Path; a list with either strings or Metabolite objects, or a single string. See syntax above.

  • database (str) – Name of database. Check cobramod.available_databases for a list of names. Defaults to None (This is useful for custom metabolites).

Keyword Arguments

directory (Path) – Path to directory where the data is located.

Raises
  • WrongSyntax (from str) – If the syntax is not followed correctly as mentioned above.

  • ValueError – If Keyword Arguments are missing.

  • FileNotFoundError (from Path) – if file does not exists

cobramod.core.creation.add_reactions(model: cobra.Model, obj: Any, database=None, stop_imbalance: bool = False, show_imbalance: bool = True, **kwargs)

Adds given object into the model. The options are:

  • Path: A file with components. E. g. :

    Path.cwd().joinpath(“file_with_names.txt”)

  • List[Reactions]: A list with regular Reactions

  • str: Either the identifier with its corresponding compartment or a

string with all components. This applies for the Path option. E.g. :

reaction_identifier, compartment

For custom reactions

:code:`reaction_identifier, reaction_name | coefficient metabolite <-> coefficient metabolite

Identifiers of metabolites have to end with an underscore and a compartment:

E.g. `4 OXYGEN-MOLECULE_c`

  • List[str]: A list with multiple str with the mentioned syntax.

Parameters
  • model (Model) – Model to expand and search for reactions.

  • obj – A Path; a list with either strings or Reaction objects, or a single string. See syntax above.

  • database (str) – Name of database. Check cobramod.available_databases for a list of names. Defaults to None (Useful for custom reactions).

  • stop_imbalance (bool) – If an unbalanced reaction is found, stop the process. Defaults to False.

  • show_imbalance (bool) – If an unbalanced reaction is found, print output. Defaults to True.

Keyword Arguments
  • directory (Path) – Path to directory where data is located.

  • replacement (dict) – Original identifiers to be replaced. Values are the new identifiers. Defaults to {}.

  • genome (str) – Exclusive for KEGG. Abbreviation for the species involved. Genes will be obtained for this species.

Raises
  • WrongSyntax (from str) – If the syntax is not followed correctly as mentioned above.

  • ValueError – If Keyword Arguments are missing.

  • FileNotFoundError (from Path) – If the file does not exists.