7.1.1.1.1.6. cobramod.core.pathway¶
COBRApy Group-child class extension
The new class cobramod.pathway.Pathway is child derived from
cobra.core.group.Group. It extends some functionalities such as:
solution: Obtain the solution for the specific members.
visualize: get a
escher.Builderfor that specific Pathway.
7.1.1.1.1.6.1. Attributes¶
7.1.1.1.1.6.2. Exceptions¶
Simple Error that should be raised when a value is missing as key in a |
7.1.1.1.1.6.3. Classes¶
Added in version 1.3.0. |
|
Added in version 1.3.0. |
|
Create a JsonDictionary object which can be used to parse information into |
|
A Sub-class from the original COBRApy |
7.1.1.1.1.6.4. Functions¶
|
Converts all Group objects in the given model to proper cobramod |
7.1.1.1.1.6.5. Module Contents¶
- class cobramod.core.pathway.EscherIntegration(map_name=None, map_json=None, reaction_data=None, reaction_scale=None, reaction_styles=None, never_ask_before_quit=False)¶
Bases:
anywidget.AnyWidgetAdded in version 1.3.0.
An alternative Python integration for Escher .
- Parameters:
- map_name¶
- map_json¶
- reaction_scale¶
- never_ask_before_quit¶
- property model_data¶
- property embedded_css¶
- property options¶
- save_html(filepath)¶
This method creates a standalone HTML file that contains all the data of the Escher map and loads it automatically when it is opened.
- Parameters:
filepath (Union[str, pathlib.Path]) – The file in which the HTML file is to be saved.
- class cobramod.core.pathway.ForceGraphIntegration¶
Bases:
anywidget.AnyWidgetAdded in version 1.3.0.
Widget for displaying a
cobra.core.group.Grouporcobra.Reactionas a force directed graph.- property model: Type[cobra.core.Group] | Type[cobra.Reaction] | None¶
The Model to be represented. It can ether be a
cobra.core.group.Grouporcobra.Reaction. It is set to None upon initialization.- Return type:
Optional[Union[Type[cobra.core.Group], Type[cobra.Reaction]]]
- property solution: Type[cobra.Solution] | dict[str, float] | None¶
The flux values to be taken into account when creating the graph. These scale the stoichiometry of the respective reaction. If a reaction is not found in this object, a flux of 1 is assumed. The flux values can either be passed as cobra.Solution or as dict, where the key is the reaction ID and the value is the flux value. It is set to None upon initialization.
- Return type:
Optional[Union[Type[cobra.Solution], dict[str, float]]]
- save_layout(file)¶
Method to save the layout of the current display. The resulting file is a CSV containing the ID of the metabolite and its X, Y and Z position in the other columns.
- Parameters:
file (Union[str, pathlib.Path]) – The path where the layout is to be saved.
- load_layout(file)¶
Method to restore the layout that was saved using
save_layout().- Parameters:
file (Union[str, pathlib.Path]) – Path to the file containing the saved layout.
- cobramod.core.pathway.debug_log¶
- exception cobramod.core.pathway.GraphKeyError¶
Bases:
ExceptionSimple Error that should be raised when a value is missing as key in a graph
- class cobramod.core.pathway.JsonDictionary¶
Bases:
collections.UserDictCreate a JsonDictionary object which can be used to parse information into JSON files to be later read by Escher. When creating the object, some keyword arguments may be passed.
- Keyword Arguments:
head (dict, optional) – General information of the JSON. Keys included: map_name, map_id, map_description, homepage, schema.
reactions (dict, optional) – Dictionary with multiple
cobramod.visualization.items.Reactionwhere the key is the number of the reaction and the value the object. Defaults to empty dictionary.nodes (PairDictionary) – Dictionary with multiple
cobramod.visualization.items.Nodewhere the key is the number of the Node and the value the corresponding object. Defaults to empty dictionary.text_labels (dict, optional) – Dictionary with the custom text inside the canvas.
canvas (dict, optional) – x and y position, width and height of the white area in Escher.
- reaction_data¶
Dictionary with the solution to be visualized. Default to empty dictionary.
- json_dump(indent=None)¶
Returns a string that is the JSON representation of this class.
- add_metabolite(x, y, label_x, label_y, bigg_id, name, node_is_primary)¶
Add a metabolite-type node into the JsonDictionary. The key will be always the last node number.
- Parameters:
x (float) – Position in x-axis for the node.
y (float) – Position in y-axis fot the node.
label_x (float) – Position of the label in the x-axis.
label_y (float) – Position of the label in the y-axis.
bigg_id (str) – Identifier of the metabolite. It does not have to be from BIGG.
name (str) – Name of the label for the metabolite.
node_is_primary (bool) – True if node should represent a primary metabolite, i.e. Node is visually larger.
- add_marker(x, y, node_type)¶
Add a marker-type node into the JsonDictionary. Node can be a midmarker or a multimarker. These markers are located in the middle of the reaction. A midmarker is located between two multimarkers.
- map_metabolites(metabolite_dict, reaction, top_edge, left_edge, vertical)¶
Creates the metabolites from given dictionary and complements the
cobramod.visualization.items.Reaction. Moreover, it creates the corresponding metabolites-nodes for the JsonDictionary class.- Parameters:
metabolite_dict (dict) – Dictionary with metabolites and their coefficients.
reaction (Reaction) – Reaction that will include the metabolite.
top_edge (float) – Position for the top edge of the reaction-box.
left_edge (float) – Position for the left edge of the reaction-box.
vertical (bool) – Defines if metabolite should be map vertically.
- add_segments(reaction, metabolite_dict)¶
Add the segments to given Reaction. This will make the visuals in Escher. The information about the nodes of metabolites in located in the JsonDictionary. A reaction will have 2 + number of metabolite as its number of segments.
- add_reaction(row, column, string, name, identifier, vertical)¶
Parses and add given reaction string as a reaction for the JsonDictionary. It will automatically create all the necessary nodes and segments for the JSON.
- Parameters:
string (str) – Reaction string to be parsed.
identifier (str) – Identifier for the reaction.
row (int) – Row number from the visualization matrix.
column (int) – Column number of the visualization matrix.
name (str) – The name of the reaction.
vertical (bool) – If reaction should be displayed vertically.
- color_grading(color, min_max=None, quantile=False, max_steps=100, n_steps=None)¶
Function that creates a color scale between two predefined colors. The number of color gradations corresponds to the number of fluxes.
- Parameters:
color (list of str or list of list of int) – list of two colors. The first color defines the endpoint for positive values, the second for negative values. The colors must be passed in their rgb representation.
min_max (list of float,optional) – List consisting of two floats. The first int describes the minimum, the second the maximum. These two values are additionally added as data values and at the same time ensure that all values greater or less than these are ignored when creating the gradient.
quantile (bool, optional) – Defines whether quantiles are to be used for the creation of the gradient. Otherwise, the steps are equally distributed between the minimum and maximum.
n_steps (int, optional) – Sets the number of color steps.
max_steps (int, optional) – Sets the maximum number of color steps.
- visualize(filepath, vertical=False, color=None, min_max=None, quantile=False, max_steps=100, n_steps=None, custom_integration=False, never_ask_before_quit=False)¶
Saves the visualization of the JsonDictionary in given path as a HTML. Returns the builder for the JsonDictionary. If method is called in Jupyter or Qtconsole, it will show the embedded builder of the escher visualization. Else, it will open the default browser of the operating system and will load the previously saved HTML.
Blank spaces are removed from the reactions.
- Parameters:
filepath (Union[str, pathlib.Path]) – Path, optional Path for the HTML. Defaults to “pathway.html” in the current working directory
vertical (bool) – bool, optional Defines if pathway should be illustrated vertically. Defaults to False.
color (Optional[List[Union[str, List[int], None]]]) – list of str or list of lost of int, optional A list consisting of two entries. These define the endpoints for a color gradient. The entries can either be the colors as a list with three elements that define the RGB values or a string that defines the color name according to the css standard. If None is used here, no gradient will be generated. Defaults to None. Example: [“orange”, “green”] or [[255, 165, 0], [0, 128, 0]]
min_max (Optional[List[float]]) – list of float, optional List consisting of two ints. The first int describes the minimum, the second the maximum. These two values are additionally added as data values and at the same time ensure that all values greater or less than these are ignored when creating the gradient. With Quantile = False, a data-independent gradient is created.
quantile (bool) – bool, optional Defines whether quantiles are to be used for the creation of the gradient. Otherwise, the steps are equally distributed between the minimum and maximum.
max_steps (int) – int, optional Sets the maximum number of color steps.
n_steps (Optional[int]) – int, optional Sets the maximum number of color steps.
custom_integration (bool)
never_ask_before_quit (bool)
- Returns:
Escher builder object for the visualization
- Return type:
Builder
See also
Color names according to the css standard: https://www.w3schools.com/cssref/css_colors.asp
- class cobramod.core.pathway.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]
- cobramod.core.pathway.model_convert(model)¶
Converts all Group objects in the given model to proper cobramod
cobramod.pathway.Pathway- Parameters:
model (cobra.core.Model)