cobramod.core.creation ====================== .. py:module:: cobramod.core.creation .. autoapi-nested-parse:: Object creation This module handles the creation of COBRApy's objects :class:`cobra.core.metabolite.Metabolite` and :class:`cobra.core.reaction.Reaction`. Dictionaries containing the data of a given database are used. Attributes ---------- .. autoapisummary:: cobramod.core.creation.debug_log Functions --------- .. autoapisummary:: cobramod.core.creation.build_metabolite cobramod.core.creation.metabolite_from_string cobramod.core.creation.metabolite_from_data cobramod.core.creation.convert_string_metabolite cobramod.core.creation.get_file_metabolites cobramod.core.creation.get_reaction cobramod.core.creation.reaction_from_string cobramod.core.creation.string_to_reaction cobramod.core.creation.get_file_reactions cobramod.core.creation.create_object cobramod.core.creation.add_metabolites cobramod.core.creation.find_replacements cobramod.core.creation.add_reactions Module Contents --------------- .. py:data:: debug_log .. py:function:: build_metabolite(identifier, formula, name, charge, compartment) Returns a basic :class:`cobra.Metabolite`. LOG level: Debug :param identifier: Short name for Metabolite :type identifier: str :param formula: Chemical formula :type formula: str :param name: Long name for Metabolite :type name: name :param charge: Charge of the metabolite :type charge: float :param compartment: Location :type compartment: str :returns: Metabolite .. py:function:: metabolite_from_string(line_string, replacement, model) Creates a Metabolite object based on a string. Function will try to find the metabolite in the model or cross-reference and return it if possible. The string must follow the syntax: :code:`formatted identifier, name , compartment, chemical_formula, molecular_charge` :param line_string: string with information :type line_string: str :param replacement: Dictionary with either the new identifier and/or the identifier of an object inside the model :type replacement: dict[str, str] :param model: Model to search for cross-references :type model: Model :raises WrongSyntax: if format is does not follow syntax :returns: Metabolite .. py:function:: metabolite_from_data(data, compartment, model = cobra_core.Model()) Parses the metabolite information from a Data object and creates a Metabolite in given compartment. This function will try to figure out if the metabolite is already in the model :returns: Metabolite .. py:function:: convert_string_metabolite(line, model, replacement, directory, database, model_id) Transform a string into a Metabolite and returns it. This object can be either manually-curated or from a database. If the compound if found under a different name (cross-reference), this will be returned instead. Custom metabolite syntax: :code:`formatted_identifier, name, compartment, chemical_formula, molecular_charge` Metabolite from database: :code:`metabolite_identifier, compartment` :param line: string with information of metabolite :type line: str :param model: Model to check for cross-references :type model: Model :param replacement: Dictionary with either the new identifier and/or the identifier of an object inside the model :type replacement: dict[str, str] :param directory: Path to directory where data is located :type directory: Path :param database: Name of database. Check :obj:`cobramod.retrieval.available_databases` for a list of names. The argument can be None ONLY for manually curated metabolites :type database: str, optional :param model_id: Exclusive for BIGG. Name of model :type model_id: str, optional :returns: Metabolite .. py:function:: get_file_metabolites(model, filename, replacement, directory, database, model_id) Return a list with Metabolites from a file. If a metabolite is found in model under a different name (cross-reference), it will be included in the list instead. Custom metabolite syntax: :code:`formatted_identifier, name, compartment, chemical_formula, molecular_charge` Metabolite from database: :code:`metabolite_identifier, compartment` :param model: Model to get metabolites if available :type model: Model :param filename: location of the file with metabolites :type filename: Path :param replacement: Dictionary with either the new identifier and/or the identifier of object inside the model. :type replacement: dict[str, str] :param directory: Path to directory where data is located. :type directory: Path :param database: Name of database. Check :obj:`cobramod.retrieval.available_databases` for a list of names. The argument can be None ONLY for manually curated metabolites :type database: str, optional :param model_id: Bigg-specific argument. Name of the model :type model_id: str, optional :raises FileNotFoundError: If given file is not found :returns: list[Metabolite] .. py:function:: get_reaction(data, compartment, replacement, show_imbalance, stop_imbalance, model) Creates a :class:`cobra:Reaction` from reaction Data. Location of the reaction can be set with the argument 'compartment'. This function searchs if the reaction and their metabolites are already in the model and will use them instead. Additionally, genes will be created and linked to the reaction. :param data_dict: Biochemical information of the reaction :type data_dict: Data :param compartment: Locations of the reaction :type compartment: str :param replacement: Original identifiers to be replaced Values are the new identifiers. :type replacement: dict[str, str] :param model: Model to search for duplicates and cross-references :type model: Model :param stop_imbalance: If unbalanced reaction is found, stop process :type stop_imbalance: bool :param show_imbalance: If unbalanced reaction is found, show output :type show_imbalance: bool :returns: Reaction .. py:function:: reaction_from_string(line_string, directory, database, stop_imbalance, show_imbalance, replacement, model_id, model = cobra_core.Model()) Returns a custom reaction from a string that includes the information of the reaction and its metabolites. If the metabolites are not in inside the model, they will be retrieved from the specified database. This Function will also search for cross-references in the model. Syntax: :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`** Else, include a model to retrieve identifiers from it. Reversibility will depend on the type of arrow. Options are: **`<--, -->, <=>, <->`** :param line_string: string with information :type line_string: str :param directory: Path to directory where data is located :type directory: Path :param database: Name of database. Check :obj:`cobramod.retrieval.available_databases` for a list of names. The argument can be None ONLY for manually curated metabolites :type database: str, optional :param stop_imbalance: If unbalanced reaction is found, stop process :type stop_imbalance: bool :param show_imbalance: If unbalanced reaction is found, show output :type show_imbalance: bool :param replacement: Dictionary with either the new identifier and/or the identifier of an object inside the model :type replacement: dict :param model_id: Bigg-specific argument. Name of the model :type model_id: optional, str :param model: A model to obtain metabolite objects from. Defaults to an empty Model :type model: Model, optional :raises NoDelimiter: If no delimiter "|" is found. :returns: Reaction .. py:function:: string_to_reaction(line, model, directory, database, stop_imbalance, show_imbalance, replacement, model_id, genome) Returns a :class:`cobra.Reaction` from a string. It can be either manually-curated, or the identifier for a reaction in a database. The function will search for cross-references of the reaction and its metabolites if the database provides that information Syntax: :code:`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`** Else, include a model to retrieve identifiers from it. Reversibility will depend on the type of arrow that. Options are **`<--, -->, <=>, <->`** :param line: String with custom reaction or identifier of reaction :type line: str :param model: Model to search for cross-references :type model: Model :param directory: Path to directory, where data is located :type directory: Path :param database: Name of database. Check :obj:`cobramod.retrieval.available_databases` for a list of names. This argument can be empty ONLY for manually-curated reactions :type database: str, optional :param stop_imbalance: If unbalanced reaction is found, stop process :type stop_imbalance: bool :param show_imbalance: If unbalanced reaction is found, show output :type show_imbalance: bool :param replacement: Dictionary with either the new identifier and/or the identifier of an object inside the model. :type replacement: dict[str, str] :param genome: Exclusive for KEGG. Abbreviation for the specie involved. Genes will be obtained from this specie :type genome: str, optional :param model_id: Exclusive for BIGG. Retrieve object from specified model :type model_id: str, optional :returns: Reaction .. py:function:: get_file_reactions(model, filename, directory, stop_imbalance, show_imbalance, replacement, database, model_id, genome) Returns list with reactions from file. All reactions can be either created manually or retrieved from a database. For each reactions, its always checks for mass balance. 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`** Else, include a model to retrieve identifiers from it. Reversibility will depend on the type of arrow that. Options are: **`<--, -->, <=>, <->`** From database: :code:`original_identifier, compartment` :param model: model to check for cross-references :type model: Model :param filename: location of the file with reaction information :type filename: Path, str :param directory: Path to directory where data is located :type directory: Path :param stop_imbalance: If unbalanced reaction is found, stop process :type stop_imbalance: bool :param show_imbalance: If unbalanced reaction is found, show output :type show_imbalance: bool :param replacement: Dictionary with either the new identifier and/or the identifier of an object inside the model :type replacement: dict[str, str] :param database: Name of database. Check :obj:`cobramod.retrieval.available_databases` for a list of names. This argument can be empty ONLY for manually-curated reactions :type database: str, optional :param model_id: Exclusive for BIGG. Retrieve object from specified model :type model_id: str, optional :param genome: Exclusive for KEGG. Abbreviation for the specie involved. Genes will be obtained from this specie :type genome: str, optional :raises FileNotFoundError: If file does not exists :returns: list[Reaction] .. py:function:: create_object(identifier, directory, database, compartment, replacement = {}, show_imbalance = True, stop_imbalance = False, model = cobra_core.Model(), model_id = None, genome = None) Creates and returns a COBRApy object based on given identifier and database. Identifier names will be formatted. .. hint:: Hyphens will become underscores. :param identifier: Original identifier of the database. :type identifier: str :param directory: Path to directory where data is stored. :type directory: Path :param database: Name of database. Check :obj:`cobramod.retrieval.available_databases` for a list of names. :type database: Optional[str] :param compartment: Location of the object. In case of reaction, all metabolites will be included in the same location. :type compartment: str :param replacement: Dictionary with either the new identifier and/or the identifier of an object inside the model. :type replacement: dict[str, str] :Arguments for 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. * **model** (*Model*) -- Model in which cross-references for reaction and metabolites might be found and used. If nothing is specified, it uses an empty model by default :Special arguments for databases: * **model_id** (*str, optional*) -- Exclusive for BIGG. Retrieve object from specified model. Internal functions use the default: "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 :rtype: cobra.core.Object .. py:function:: add_metabolites(model, obj, directory = Path.cwd().joinpath('data'), database = None, **kwargs) Adds given object into the model. The options are: - Path or str: A file with the metabolites. E. g: Path.cwd().joinpath("file_with_names.txt") or "./file_with_names.txt" - List[Metabolites]: A list with multiple Metabolite objects. Custom metabolite syntax: :code:`formatted_identifier, name, compartment, chemical_formula, molecular_charge` Metabolite from database: :code:`metabolite_identifier, compartment` - List[str]: A list with multiple str with the mentioned syntax. CobraMod will try to download the biochemical information and create instead custom metabolites if not found in the database. In case of only custom metabolites, it is recommended to use None for the argument database :param model: Model to be expanded and searched for metabolites. :type model: Model :param obj: A Path; a list with either strings or Metabolite objects, or a single string. See syntax above. :param database: Name of database. Check :obj:`cobramod.available_databases` for a list of names. Defaults to None (This is useful for custom metabolites). :type database: str :param directory: Path to directory where the data is located. If nothing is specified, then it defaults to the directory "data" in the current working directory. :type directory: Path :keyword replacement: Dictionary with either the new identifier and/or the identifier of an object inside the model. :kwtype replacement: dict :keyword include_metanetx_specific_ec: Determines whether MetaNetX specific EC numbers should be taken over. These are generally not found in other databases. Furthermore, this could result in non-existing Brenda IDs being created. The default value is False. :raises WrongSyntax (from str): If the syntax is not followed correctly as mentioned above. :raises ValueError: If Keyword Arguments are missing. :raises FileNotFoundError (from Path): if file does not exists .. py:function:: find_replacements(identifier, obj_type, replace_dict, model) Returns either a COBRApy object if found in the model or a string with the new identifier, which can be used to create a new object or retrieve data. The replace_dict has two options for keys. One can be the unmodified identifier given by a database, or a formated identifier. E.g: "WATER_c": "C00001_c" or "ACETALD-DEHYDROG-RXN" : "R00228_c" :param identifier: Original identifier to replace or rename. :type identifier: str :param obj_type: Type of object to search for. Only options are "reactions" or "metabolites". :type obj_type: str :param replace_dict: Dictionary with either the new identifier and or the identifier of object inside the model. :type replace_dict: dict :param model: :type model: Model :returns: A COBRApy Object if replacement is found in the model. Otherwise nothing is returned .. py:function:: add_reactions(model, obj, directory, database = None, stop_imbalance = False, show_imbalance = 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 - List[str]: Either the identifier with its corresponding compartment or a string with all components. This applies for the Path option. E.g. : :code:`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. CobraMod will try to use the same metabolites and reactions inside of the model. If not found, then CobraMod will try to download its biochemical information or create custom objects. :param model: Model to expand and search for reactions. :type model: Model :param obj: A Path; a list with either strings or Reaction objects, or a single string. See syntax above. :param database: Name of database. Check :obj:`cobramod.available_databases` for a list of names. Defaults to None (Useful for custom reactions). :type database: str :param directory: Path to directory where data is located. :type directory: Path :param stop_imbalance: If an unbalanced reaction is found, stop the process. Defaults to False. :type stop_imbalance: bool :param show_imbalance: If an unbalanced reaction is found, print output. Defaults to True. :type show_imbalance: bool :keyword replacement: Dictionary with either the new identifier and/or the identifier of an object inside the model. :kwtype replacement: dict :keyword genome: Exclusive for KEGG. Abbreviation for the species involved. Genes will be obtained for this species. :kwtype genome: str :keyword consider_sub_elements: Specifies whether additional cross-references should also be added to the subelements. For example, you can specify whether only the reaction or also its metabolites should be expanded. Defaults to True :keyword include_metanetx_specific_ec: Determines whether MetaNetX specific EC numbers should be taken over. These are generally not found in other databases. Furthermore, this could result in non-existing Brenda IDs being created. The default value is False. :raises WrongSyntax (from str): If the syntax is not followed correctly as mentioned above. :raises ValueError: If Keyword Arguments are missing. :raises FileNotFoundError (from Path): If the file does not exists.