7.1.1.1.1.3. cobramod.core.extension¶
Pathway extension
This module handles the addition of reactions as a pathway into a model and the corresponding test that comes with it.
Most important functions: - add_pathway: Adds a pathway or multiple reactions into a model. - test_non_zero_flux: Checks that the given reaction in a model is active and
gives a non-zero flux.
7.1.1.1.1.3.1. Attributes¶
7.1.1.1.1.3.2. Classes¶
7.1.1.1.1.3.3. Functions¶
|
Produces the short summary and another one in the defined format. |
|
Yields a Reaction from given list of identifiers . |
|
Return a List with the metabolite identifiers that must have a sink |
|
Main part of the non-zero flux test. It is a recursive function. Firstly, |
|
Performs non-zero flux test. In this test, a reaction is tested to make |
|
Performs non-zero flux test. In this test, a reaction is tested to make |
|
From a sequence of Reaction objects, add each Reaction into given model. It |
|
Updates the given sequence taking into consideration reactions to avoid |
|
Adds a Pathway into given model. The reactions are created from: |
|
Adds a pathway into given model from a dictionary with the information of |
|
Adds a sequence of identifiers to given model. It will automatically test |
|
Adds a pathway from the given database into a model. The argument 'pathway' |
7.1.1.1.1.3.4. Module Contents¶
- class cobramod.core.extension.Pathway(id, name='', members=None, kind=None)¶
Bases:
cobra.core.GroupA Sub-class from the original COBRApy
cobra.Group, which inherits all attributes and adds the method solution, to get a Solution for the members of this Class.- Attributes
- vertical (bool, optional):
Variable that determines whether the display should be vertical or horizontal using Escher. Defaults to False.
- color_negative (str or list of int, optional) :
The color to use as the endpoint for the negative fluxes during the creation of the color gradient. All colors of the CSS standard can be used here or their RGB representation.
- color_positive (str or list of int, optional) :
The color to use as the endpoint for the positive fluxes during the creation of the color gradient. All colors of the CSS standard can be used here or their RGB representation.
- color_min_max (list of float, optional) :
The maximum and minimum to be taken into account when creating the color gradient. This creates these two values artificially to allow the creation of a data-independent color gradient. Fluxes larger or smaller are ignored accordingly.
- color_quantile (bool, optional) :
Attribute that defines whether the color gradient should be determined through quantiles or equally distributed between the maximum and the minimum. Defaults to False which means that the gradations are evenly distributed.
- color_n_steps (int, optional) :
The number of steps used when creating the color gradient. Uses the number of fluxes by default. The default value is None.
- color_max_steps (int, optional) :
The maximum number of steps to use when creating the color gradient. Default value is 100.
See also
Color names according to the css standard: https://www.w3schools.com/cssref/css_colors.asp
- Parameters:
id (str)
name (str)
members (Optional[set[cobra.core.Object]])
kind (Optional[str])
- add_members(new_members)¶
Add given list of
cobra.core.reaction.Reactioninto the Pathway.
- solution(solution)¶
Returns a
cobra.Solutionwith only the members of the pathway.- Parameters:
solution (Solution) – Original COBRApy
cobra.Solutionto filter.- Returns:
- Filtered solution containing only members of the Pathway
class.
- Return type:
Solution
- modify_graph(reaction, next_reaction)¶
Modifies the order of the graph. This is useful when merging multiple pathways or joining reactions. In the graph, the selected reaction will be forced to show “next_reaction” as its successor.
- Parameters:
- Raises:
GraphKeyError – If the reaction or the next_reaction does not appear
in the graph of the pathway. –
- visualize(solution_fluxes=None, filename=None, vis='escher', never_ask_before_quit=False)¶
Changed in version 1.3.0: The ‘vis’ parameter has been added. This allows one to choose between different visualization tools.
Returns a
escher.Builder, which can be used to create visual representations of the pathway.- Parameters:
solution_fluxes (Optional[Union[cobra.core.Solution, dict[str, float]]]) – Series or Dictionary with fluxes. The values will be then showed in the Builder. Defaults to None.
filename (Optional[Union[str, pathlib.Path]]) – Path for the HTML. Defaults to “pathway.html” in the current working directory.
vis (Literal['escher', 'escher-custom', '3d-force']) –
Added in version 1.3.0.
Parameter that determines the visualization tool used. It is possible to choose between the original Escher integration [escher], the one embedded in CobraMod [escher-custom] and a 3-dimensional force directed graph visualization [3d-force].
Deprecated since version 1.3.0: The original python integration of Escher will be removed in a future version due to dependency conflicts with Jupyter. The integration embedded in CobraMod will take its place in the future. This can already be used by setting ‘vis’ to “escher-custom”.
never_ask_before_quit (bool) –
Added in version 1.3.0.
Option to control whether a warning dialog is displayed when the Escher Builder window is closed. Only has an effect when using Escher for visualization.
- Return type:
Union[escher.Builder, cobramod.visualization.escher.EscherIntegration, cobramod.visualization.force_graph.ForceGraphIntegration, None]
- class cobramod.core.extension.DataModel(lists)¶
A class that can create a snapshot of a model and generates the summary based on those snapshots. Contains methods to identify differences and save them in multiple formats.
- classmethod from_model(model)¶
Method to create a DataModel object based on a model object.
- Parameters:
model (Model) – Model based on which a DataModel object is to be created.
- diff(other)¶
Creates a new DataModel object consisting of the differences between the original and the passed DataModel object.
- Parameters:
other (DataModel) – DataModel to be compared with this one.
- to_excl(path, model=None, additions=None, deletions=None)¶
Method to save a DataModel as an Excel file. Can also be used to save the changes between two points in time, in an Excel file format. For other formats see
cobramod.summary.DataModel.to_csv()orcobramod.summary.DataModel.to_txt().
- to_csv(path, model=None, additions=None, deletions=None)¶
Method to save a DataModel as a CSV file. Can also be used to save the changes between two points in time, as a CSV. For other formats see
cobramod.summary.DataModel.to_excl()orcobramod.summary.DataModel.to_txt().- Parameters:
path (Path) – Location where the file is to be saved.
model (cobra.Model)
model (Model): Model for the extraction of model id and name. additions (DataModel): DataModel that contains the new entities in
the model.
- deletions (DataModel): DataModel that contains the remote entities
in the model.
- to_txt(path, model=None, additions=None, deletions=None)¶
Method to save a DataModel as a txt file. Can also be used to save the changes between two points in time, as a txt. For other formats see
cobramod.summary.DataModel.to_excl()orcobramod.summary.DataModel.to_csv().
- cobramod.core.extension.summarize(model, original, filename)¶
Produces the short summary and another one in the defined format.
- Parameters:
model (Model) – model with recent changes.
original (DataModel) – Object with data from the previous model. Use method
cobramod.summary.DataModel().filename (Path) – Location where the summary should be stored. The file format is determined by the suffix of the filename. Thus, ‘.txt’, ‘.csv’ or ‘.xlsx’ can be used.
- cobramod.core.extension.debug_log¶
- cobramod.core.extension.yield_reaction_from_list(sequence, compartment, directory, database, show_imbalance, stop_imbalance, replacement, model, model_id, genome)¶
Yields a Reaction from given list of identifiers .
Hint
Hyphens will become underscores. Double hyphens become single underscores.
- Parameters:
sequence (list) – Identifiers for the reactions.
directory (Path) – Path to directory where data is located.
database (Optional[str]) – Name of the database. Check
cobramod.available_databasesfor a list of names.compartment (str) – Location of the reaction.
replacement (dict) – Original identifiers to be replaced. Values are the new identifiers. This applies to metabolites.
stop_imbalance (bool) – If unbalanced reaction is found, stop process.
show_imbalance (bool) – If unbalanced reaction is found, show output.
model_id (str) – Exclusive for BIGG. Retrieve object from specified model.
genome (str, optional) – Exclusive for KEGG. Abbreviation for the specie involved. Genes will be obtained for this specie.
model (cobra.core.Model)
- Returns:
New Reactions objects
- Return type:
Generator
- cobramod.core.extension.find_problem(model, identifier)¶
Return a List with the metabolite identifiers that must have a sink reaction to make the reaction carry a non-zero flux.
- Parameters:
model (cobra.core.Model)
identifier (str)
- Return type:
- cobramod.core.extension.recursive_flux_test(model, identifier, times=0)¶
Main part of the non-zero flux test. It is a recursive function. Firstly, the function checks if there a non-zero flux. If not, it will create the necessary sink reactions and rerun the test. This function warns the user if sink reactions were created.
- Parameters:
- Returns:
optimization value
- Return type:
Optional[float]
- Raises:
OptimizationError – Whenever a reaction needs manual intervention
- cobramod.core.extension.non_zero_core(model, identifier)¶
Performs non-zero flux test. In this test, a reaction is tested to make sure it can carry a flux. If necessary, CobraMod creates sink reactions to simulate turnover of metabolites that participate in the reaction. Warnings will be shown for these cases.
- cobramod.core.extension.test_non_zero_flux(model, reaction)¶
Performs non-zero flux test. In this test, a reaction is tested to make sure it can carry a flux. If necessary, CobraMod creates sink reactions to simulate turnover of metabolites that participate in the reaction. Warnings will be shown for these cases.
- Parameters:
model (Model) – Model that contains the reaction
reaction (str) – identifier of the reaction
- Raises:
OptimizationError – If given reaction needs manual curation
- cobramod.core.extension.add_reactions_to_Pathway(model, pathway, sequence, ignore_list)¶
From a sequence of Reaction objects, add each Reaction into given model. It checks if new reactions do not break the optimized value. All reactions are added to a common CobraMod Pathway.
- Parameters:
model (Model) – Model to expand.
pathway (Pathway) – Common Pathway to add the reaction.
sequence (list) – List with
cobra.core.reaction.Reactionobjectsignore_list (list, optional) – A sequence of reactions that should be added but not tested for a non-zero-flux.
- Raises:
TypeError – if reactions are not valid Reaction objects
- cobramod.core.extension.remove_avoid_reactions(sequence, avoid_list)¶
Updates the given sequence taking into consideration reactions to avoid in the sequence
- cobramod.core.extension.add_pathway_from_file(model, file, identifier, database, replacement, ignore_list, stop_imbalance, show_imbalance, directory, genome, model_id)¶
Adds a Pathway into given model. The reactions are created from:
- Path or str: A file with components. E. g. : Path.cwd().joinpath("file_with_names.txt") or "./file_with_names.txt" This applies for both options : :code:`reaction_identifier, compartment` For custom reactions :code:`reaction_identifier, reaction_name | coefficient metabolite <-> coefficient metabolite- Parameters:
model (Model) – Model to expand.
path (Union[str, Path]) – Location of the file.
database (str) – Name of the database. Check
cobramod.available_databasesfor a list of names.identifier (str) – Common
cobramod.pathway.Pathwayidentifierfile (Union[str, pathlib.Path])
replacement (dict)
ignore_list (list)
stop_imbalance (bool)
show_imbalance (bool)
directory (pathlib.Path)
genome (Optional[str])
model_id (str)
- Argument for complex pathways:
- avoid_list (list, optional): A sequence of reactions identifiers to
avoid adding to the model.
- replacement (dict, optional): Original identifiers to be replaced.
Values are the new identifiers. This applies to metabolites as well. User can rename or replace identifiers using this argument.
- ignore_list (list, optional): A sequence of reactions that should be
added but not tested for a non-zero-flux.
- Arguments for utilities:
- 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_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
- cobramod.core.extension.add_pathway_from_data(model, data, group, directory, database, compartment, avoid_list, replacement, ignore_list, stop_imbalance, show_imbalance, model_id, genome)¶
Adds a pathway into given model from a dictionary with the information of the pathway into given model from a dictionary with the information of the model.
- Parameters:
model (Model) – Model to expand.
data_dict (dict) – Dictionary with the information for the pathway.
directory (Path) – Path for directory to stored and retrieve data.
database (str) – Name of the database to search for reactions and metabolites. Check
cobramod.available_databasesfor a list of names.compartment (str) – Location of the reactions.
data (cobramod.retrieval.Data)
group (Optional[str])
avoid_list (list)
replacement (dict)
ignore_list (list)
stop_imbalance (bool)
show_imbalance (bool)
model_id (str)
genome (Optional[str])
- Arguments for complex pathways:
- avoid_list (list, optional): A sequence of reactions identifiers to
avoid adding to the model.
- replacement (dict, optional): Original identifiers to be replaced.
Values are the new identifiers. This applies to metabolites as well. User can rename or replace identifiers using this argument.
- ignore_list (list, optional): A sequence of reactions that should be
added but not tested for a non-zero-flux.
- Arguments for utilities:
stop_imbalance (bool): If unbalanced reaction is found, stop process. show_imbalance (bool): If unbalanced reaction is found, show output. model_id (str, optional): Exclusive for BIGG. Retrieve object from
specified model. Pathway are not available. Defaults to: “universal”
- genome (str, optional): Exclusive for KEGG. Abbreviation for the
specie involved. Genes will be obtained from this specie. List available at https://www.genome.jp/kegg/catalog/org_list.html
- cobramod.core.extension.add_pathway_from_strings(model, identifier, sequence, database, compartment, directory, avoid_list, replacement, ignore_list, stop_imbalance, show_imbalance, model_id, genome)¶
Adds a sequence of identifiers to given model. It will automatically test for valid optimized values.
- Parameters:
model (Model) – Model to expand.
identifier (str) – Common
cobramod.pathway.Pathwayidentifier.sequence (list) – List reaction identifiers.
database (Optional[str]) – Name of the database. Check
cobramod.available_databasesfor a list of names.compartment (str) – Location of the reactions.
directory (Path) – Path for directory to store and retrieve data.
stop_imbalance (bool)
show_imbalance (bool)
model_id (str)
genome (Optional[str])
- Arguments for complex pathways:
- avoid_list (list, optional): A sequence of reactions identifiers to
avoid adding to the model.
- replacement (dict, optional): Original identifiers to be replaced.
Values are the new identifiers. This applies to metabolites as well. User can rename or replace identifiers using this argument.
- ignore_list (list, optional): A sequence of reactions that should be
added but not tested for a non-zero-flux.
- Arguments for utilities:
stop_imbalance (bool): If unbalanced reaction is found, stop process. show_imbalance (bool): If unbalanced reaction is found, show output. model_id (str, optional): Exclusive for BIGG. Retrieve object from
specified model. Pathway are not available.
- genome (str): Exclusive for KEGG. Abbreviation for the
specie involved. Genes will be obtained from this specie. List available at https://www.genome.jp/kegg/catalog/org_list.html
- cobramod.core.extension.add_pathway(model, pathway, directory, compartment, database=None, group=None, avoid_list=[], replacement={}, ignore_list=[], filename=None, stop_imbalance=False, show_imbalance=True, model_id='', genome=None)¶
Adds a pathway from the given database into a model. The argument ‘pathway’ can be a list of reactions identifiers or explicitly a pathway identifier. A group of reactions will be included in a custom group. The data will be downloaded and structured according to the database.
- Parameters:
model (Model) – Model to expand.
pathway (list, str) – Sequence of reaction identifiers or a single identifier for a pathway. Examples: [“RXN-2206”, “RXN-207”], (Reaction to download from a database) “PWY-886”, (Pathway to download from a database) [“ACALDt, RXN_2206_c”], (which are reactions already in the model)
directory (Path) – Path for the directory to store and retrieve data.
database (str, Optional) – Name of the database. Check
cobramod.available_databasesfor a list of names. When adding reactions of the model, this argument is not necessary Defaults to None.compartment (str) – Location of the reactions. If adding reaction already in the model, this argument will not change the reaction’s compartment.
group (str, optional) – Common
cobramod.pathway.Pathwayidentifier. This will overwrite the name of the pathway.replacement (dict)
filename (Optional[Union[str, pathlib.Path]])
stop_imbalance (bool)
show_imbalance (bool)
model_id (str)
genome (Optional[str])
- Arguments for complex pathways:
- avoid_list (list, optional): A sequence of reactions identifiers to
avoid adding to the model.
- replacement (dict, optional): Original identifiers to be replaced.
Values are the new identifiers. This applies to metabolites as well. User can rename or replace identifiers using this argument.
- ignore_list (list, optional): A sequence of reactions that should be
added but not tested for a non-zero-flux.
- Arguments for summary:
- filename (Path, optional): Location for the summary. Defaults to
“summary” in the current working directory. The file format is defined by the suffix. The suffixes ‘.txt’, ‘.csv’ and ‘.xlsx’ can be used. If the filename is set to None, no summary will be created.
- Arguments for utilities:
- 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_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