{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Metabolic network modeling with COBRA\n", "\n", "## Databases of models\n", "1. Biomodels https://www.ebi.ac.uk/biomodels-main/publmodels\n", "2. BiGG http://bigg.ucsd.edu/\n", "3. HMA http://www.metabolicatlas.org\n", "\n", "## Documentation of cobrapy and cobra toolbox\n", "1. https://cobrapy.readthedocs.io/en/stable/index.html\n", "2. https://opencobra.github.io/cobratoolbox/stable/\n", "\n", "## Solvers\n", "1. Gurobi http://www.gurobi.com\n", "2. cplex https://www.ibm.com/products/ilog-cplex-optimization-studio\n", "3. glpk\n", "\n", "To install `cobrapy`, run the following code below (requires pip):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# install cobrapy\n", "# !pip install cobra\n", "# !pip install pytest" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# load modules\n", "import cobra\n", "from cobra.io import load_model" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# check cobra version\n", "cobra.__version__" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model = load_model(\"textbook\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### You can also load a exist model by using io functions like load_matlab_model, read_sbml_model ..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "## io functions\n", "\n", "# cobra.io.read_sbml_model\n", "# cobra.io.load_json_model\n", "# cobra.io.load_matlab_model\n", "# cobra.io.load_yaml_model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Components of model\n", "### Model (`cobra.core.model.Model`)\n", "\n", "-------------\n", "\n", "#### attribute:\n", "\n", "
Attribute | \n", "Type | \n", "Description | \n", "
---|---|---|
reactions | \n", "DictList | \n", "A DictList where the key is the reaction identifier and the value a Reaction | \n", "
metabolites | \n", "DictList | \n", "A DictList where the key is the metabolite identifier and the value a Metabolite | \n", "
genes | \n", "DictList | \n", "A DictList where the key is the gene identifier and the value a Gene | \n", "
solution | \n", "cobra.Solution | \n", "The last obtained solution from optimizing the model. | \n", "
boundary | \n", "DictList | \n", "Boundary reactions in the model. Reactions that either have no substrate or product. | \n", "
exchanges | \n", "DictList | \n", "Exchange reactions in model. Reactions that exchange mass with the exterior. Uses annotations and heuristics to exclude non-exchanges such as sink reactions. | \n", "
demands | \n", "DictList | \n", "Demand reactions in model. Irreversible reactions that accumulate or consume a metabolite in the inside of the model. | \n", "
sinks | \n", "DictList | \n", "Sink reactions in model. Reversible reactions that accumulate or consume a metabolite in the inside of the model. | \n", "
objective | \n", "optlang.interface.Objective | \n", "Before introduction of the optlang based problems, this function returned the objective reactions as a list. With optlang, the objective is not limited a simple linear summation of individual reaction fluxes, making that return value ambiguous. Henceforth, use cobra.util.solver.linear_reaction_coefficients to get a dictionary of reactions with their linear coefficients (empty if there are none) \n", "The set value can be dictionary (reactions as keys, linear coefficients as values), string (reaction identifier), int (reaction index), Reaction or problem.Objective or sympy expression directly interpreted as objectives. | \n",
"
Method | \n", "Parameters | \n", "Return type | \n", "Description | \n", "
---|---|---|---|
copy | \n", "None | \n", "cobra.Model | \n", "Provides a partial ‘deepcopy’ of the Model. All of the Metabolite, Gene, and Reaction objects are created anew but in a faster fashion than deepcopy | \n", "
add_metabolites | \n", "metabolite_list (list) | \n", "None | \n", "Will add a list of metabolites to the model object and add new constraints accordingly. | \n", "
remove_metabolites | \n", "metabolite_list (list) \n", " destructive (bool)\n", " | \n",
" None | \n", "Remove a list of metabolites from the the object. | \n", "
add_boundary | \n", "metabolite (cobra.Metabolite) \n", " type (str, {\"exchange\", \"demand\", \"sink\"}) \n", " reaction_id (str, optional) \n", " lb (float, optional) \n", " ub (float, optional) \n", " sbo_term (str, optional) | \n",
" cobra.Reaction | \n", "Add a boundary reaction for a given metabolite. \n", "There are three different types of pre-defined boundary reactions: exchange, demand, and sink reactions. An exchange reaction is a reversible, unbalanced reaction that adds to or removes an extracellular metabolite from the extracellular compartment. A demand reaction is an irreversible reaction that consumes an intracellular metabolite. A sink is similar to an exchange but specifically for intracellular metabolites. \n", "If you set the reaction type to something else, you must specify the desired identifier of the created reaction along with its upper and lower bound. The name will be given by the metabolite name and the given type. | \n",
"
add_reactions | \n", "reaction_list (list) | \n", "None | \n", "Add reactions to the model. \n", " Reactions with identifiers identical to a reaction already in the model are ignored. | \n",
"
remove_reactions | \n", "reaction_list (list) \n", " remove_orphans (bool)\n", " | \n",
" None | \n", "Remove reactions from the model. | \n", "
slim_optimize | \n", "error_value (float, None) \n", " message (string)\n", " | \n",
" float | \n", "Optimize model without creating a solution object. | \n", "
optimize | \n", "objective_sense ({None, 'maximize' 'minimize'}, optional) \n", " raise_error (bool)\n", " | \n",
" cobra.Solution | \n", "Optimize the model using flux balance analysis. | \n", "
summary | \n", "solution (cobra.Solution, optional) \n", " threshold (float, optional) \n", " fva (pandas.DataFrame or float, optional) \n", " names (bool, optional) \n", " float_format (callable, optional)\n", " | \n",
" cobra.ModelSummary | \n", "Create a summary of the exchange fluxes of the model. | \n", "
Attribute | \n", "Type | \n", "Description | \n", "
---|---|---|
id | \n", "string | \n", "The identifier to associate with this reaction | \n", "
name | \n", "string | \n", "A human readable name for the reaction | \n", "
reaction | \n", "string | \n", "Human readable reaction string | \n", "
lower_bound | \n", "float | \n", "The lower flux bound | \n", "
upper_bound | \n", "float | \n", "The upper flux bound | \n", "
bounds | \n", "tupple | \n", "The upper and the lower flux bounds | \n", "
subsystem | \n", "string | \n", "Subsystem where the reaction is meant to occur | \n", "
objective_coefficient | \n", "float | \n", "The coefficient for this reaction in a linear objective | \n", "
flux_expression | \n", "sympy expression | \n", "Forward flux expression | \n", "
flux | \n", "float | \n", "The flux value in the most recent solution. | \n", "
reduced_cost | \n", "float | \n", "The reduced cost in the most recent solution. | \n", "
metabolites | \n", "dict (cobra.metabolite: float) | \n", "The dict of metabolites involved in the reaction. | \n", "
genes | \n", "frozenset (cobra.gene) | \n", "The frozenset of genes involved in the reaction. | \n", "
gene_reaction_rule | \n", "string | \n", "The boolean representation of the gene requirements for the reaction to be active. | \n", "
Method | \n", "Parameters | \n", "Return type | \n", "Description | \n", "
---|---|---|---|
remove_from_model | \n", "remove_orphans=False (bool) | \n", "None | \n", "Removes the reaction from a model. | \n", "
get_coefficient | \n", "metabolite_id (str or cobra.Metabolite) | \n", "float | \n", "Return the stoichiometric coefficient of a metabolite. | \n", "
get_coefficients | \n", "metabolite_ids (iterable) | \n", "map | \n", "Return the stoichiometric coefficients for a list of metabolites. | \n", "
add_metabolites | \n", " metabolites_to_add (dict)\n",
" combine (bool)\n", " reversibly (bool) | \n",
" None | \n", "Add metabolites and stoichiometric coefficients to the reaction. If the final coefficient for a metabolite is 0 then it is removed from the reaction. | \n", "
subtract_metabolites | \n", " metabolites (dict) \n", " combine (bool) \n", " reversibly (bool) | \n",
" None | \n", " Subtract metabolites from a reaction. \n", " That means add the metabolites with -1*coefficient. If the final coefficient for a metabolite is 0 then the metabolite is removed from the reaction. | \n",
"
build_reaction_string | \n", "use_metabolite_names=False (bool) | \n", "str | \n", "Generate a human readable reaction string | \n", "
build_reaction_from_string | \n", " reaction_str (string) \n", " verbose (bool) \n", " fwd_arrow (re.compile) \n", " rev_arrow (re.compile) \n", " reversible_arrow (re.compile) \n", " term_split (string)\n", " | \n",
" None | \n", " Builds reaction from reaction equation reaction_str using parser \n", " Takes a string and using the specifications supplied in the optional arguments infers a set of metabolites, metabolite compartments and stoichiometries for the reaction. It also infers the reversibility of the reaction from the reaction arrow. | \n",
"
knock_out | \n", "None | \n", "None | \n", "Knockout reaction by setting its bounds to zero. | \n", "
Attribute | \n", "Type | \n", "Description | \n", "
---|---|---|
id | \n", "str | \n", "the identifier to associate with the metabolite | \n", "
formula | \n", "str | \n", "Chemical formula (e.g. H2O) | \n", "
name | \n", "str | \n", "A human readable name. | \n", "
charge | \n", "float | \n", "The charge number of the metabolite | \n", "
compartment | \n", "str or None | \n", "Compartment of the metabolite. | \n", "
elements | \n", "dict | \n", "Dictionary of elements as keys and their count in the metabolite as integer. | \n", "
shadow_price | \n", "float | \n", "The shadow price in the most recent solution. | \n", "
Method | \n", "Parameters | \n", "Return type | \n", "Description | \n", "
---|---|---|---|
remove_from_model | \n", "destructive (bool) | \n", "None | \n", "Removes the association from self.model | \n", "
summary | \n", "solution=None (cobra.Solution) \n", " threshold=0.01 (float) \n", " fva=None (pandas.DataFrame or float) \n", " names=False (bool) \n", " float_format='{:.3g}'.format (callable) | \n",
" cobra.MetaboliteSummary | \n", "Create a summary of the producing and consuming fluxes. \n", " This method requires the model for which this metabolite is a part to be solved. | \n",
"
Attribute | \n", "Type | \n", "Description | \n", "
---|---|---|
id | \n", "str | \n", "The identifier to associate the gene with | \n", "
name | \n", "str | \n", "A longer human readable name for the gene | \n", "
functional | \n", "bool | \n", "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. | \n", "
Method | \n", "Parameters | \n", "Return type | \n", "Description | \n", "
---|---|---|---|
knock_out | \n", "None | \n", "None | \n", "Knockout gene by marking it as non-functional and setting all associated reactions bounds to zero. | \n", "