fluxpy.illustrations.build_escher_map¶
JSON creator
This module handles the convertion of strings into a proper object that can be used to create a JSON string, which can be later used in Escher.
The main class of this module is
cobramod.visualization.converter.JsonDictionary. This class is able to
parse and store data as JSON objects. To check the attributes for each
JSON object, please read the documentation of
cobramod.visualization.items.
Important methods:
json_dump: The data can be parsed into a JSON. (str)
add_metabolite: Add metabolite-node into the JsonDictionary.
add_marker: Add a marker-node into the JsonDictionary.
add_reaction: Parses a reaction string and add the information into the JsonDictionary.
add_blank: Adds a empty reaction. This is useful for the extra space in the
visualizations. - visualize: Saves Escher visualization as a HTML and return the Escher Builder.
Classes¶
Create a JsonDictionary object which can be used to parse information into |
Functions¶
|
Converts a |
|
This function translates the rgb or string representation into a numpy |
|
This function divides a list into two, one consisting of the positive |
|
Return a set for the keys of either the reactions, the nodes or |
|
Returns the largest number of the keys from either reactions, nodes, or |
|
Add the corresponding midmarker and multimarkers into the |
|
|
|
|
|
Module Contents¶
- fluxpy.illustrations.build_escher_map._convert_string(string: str) dict[source]¶
Converts a
cobra.Reactionreaction-string into a dictionary, and returns a dictionary with the corresponding participants and their coefficients.Examples: ‘C00001_c + 2 C00002_c –> C00009_c + C00080_c + G11113_c’ ‘C00002_c + C00033_c <=> C00227_c + G11113_c’ ‘C00002_c + C00033_c <– C00227_c + G11113_c’
- fluxpy.illustrations.build_escher_map._color2np_rgb(color: str | List[int] | None) numpy.ndarray[source]¶
This function translates the rgb or string representation into a numpy array. The string representation must follow the css standard.
- Parameters:
color – The color to be translated.
- Returns:
Numpy array with the rgb representation of the color or with the values [220,220,220] as standard return for incorrect inputs.
- fluxpy.illustrations.build_escher_map._divide_values(flux: List[float], min_max: List[float] | None = None) Tuple[List[float], List[float], bool, bool][source]¶
This function divides a list into two, one consisting of the positive values and one of the negative values.
- Parameters:
- Returns:
- This function returns two lists and two bools. The first return is the
list consisting of positive values. The second return is the list with negative values. The third return is a bool that indicates whether min_max consists of two positive values. The fourth return describes whether min_max consists of two negative values.
- class fluxpy.illustrations.build_escher_map.JsonDictionary[source]¶
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: int | None = None) str[source]¶
Returns a string that is the JSON representation of this class.
- Parameters:
indent (int) – Defines the indentation for the JSON. Defaults to None.
- _get_set(item: str) set[source]¶
Return a set for the keys of either the reactions, the nodes or segments for all reactions. Options for item: “nodes”, “segments”, “reactions”.
- _get_last_number(item: str) int[source]¶
Returns the largest number of the keys from either reactions, nodes, or segments from each reaction. Options for item: “nodes”, “segments”, “reactions”.
- add_metabolite(x: float, y: float, label_x: float, label_y: float, bigg_id: str, name: str, node_is_primary: bool)[source]¶
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: float, y: float, node_type: str)[source]¶
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.
- _add_reaction_markers(identifier: str, top_edge: float, left_edge: float, vertical: bool)[source]¶
Add the corresponding midmarker and multimarkers into the JsonDictionary. Nodes will be added to the corresponding reaction data. Number for the nodes will not repeat themselves. If vertical is passed, then the reaction markers will be created in order to represent a vertical pathway.
- _get_matrix_reactions(vertical: bool, position: int) list[source]¶
Return a List with the names of the reactions, which are located in given position. The position can be from a column or a row. Vertical defines the orientation.
- _get_products(reactions: list) Dict[str, list][source]¶
Returns a dictionary where keys are the reactions of given list and the values the products of the reactions.
Returns the node number of the metabolite and the reaction involved if found in given dictionary with products.
- map_metabolites(metabolite_dict: dict, reaction: cobramod.visualization.items.Reaction, top_edge: float, left_edge: float, vertical: bool)[source]¶
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: cobramod.visualization.items.Reaction, metabolite_dict: dict)[source]¶
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.
- Parameters:
metabolite_dict (dict) – Dictionary with metabolites and their coefficients.
reaction (Reaction) – Reaction to extend.
- add_reaction(row: int, column: int, string: str, name: str, identifier: str, vertical: bool)[source]¶
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.
- _reset()[source]¶
Resets the data of JsonDictionary to its initial state. This helps when calling the function multiple times.
- color_grading(color: List[str | List[int] | None], min_max: List[float] | None = None, quantile: bool = False, max_steps: int = 100, n_steps: int | None = None)[source]¶
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: str | pathlib.Path, vertical: bool = False, color: List[str | List[int] | None] | None = None, min_max: List[float] | None = None, quantile: bool = False, max_steps: int = 100, n_steps: int | None = None, custom_integration: bool = False, never_ask_before_quit: bool = False)[source]¶
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 – Path, optional Path for the HTML. Defaults to “pathway.html” in the current working directory
vertical – bool, optional Defines if pathway should be illustrated vertically. Defaults to False.
color – 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 – 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, 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, optional Sets the maximum number of color steps.
n_steps – int, optional Sets the maximum number of color steps.
- 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
- fluxpy.illustrations.build_escher_map._get_set(self, item: str) set[source]¶
Return a set for the keys of either the reactions, the nodes or segments for all reactions. Options for item: “nodes”, “segments”, “reactions”.
- fluxpy.illustrations.build_escher_map._get_last_number(self, item: str) int[source]¶
Returns the largest number of the keys from either reactions, nodes, or segments from each reaction. Options for item: “nodes”, “segments”, “reactions”.
- fluxpy.illustrations.build_escher_map._add_reaction_markers(self, identifier: str, top_edge: float, left_edge: float, vertical: bool)[source]¶
Add the corresponding midmarker and multimarkers into the JsonDictionary. Nodes will be added to the corresponding reaction data. Number for the nodes will not repeat themselves. If vertical is passed, then the reaction markers will be created in order to represent a vertical pathway.