changeset 284:90185e1784ab draft

Uploaded
author luca_milaz
date Sun, 04 Aug 2024 18:38:11 +0000
parents 33e499061029
children 7a098cb82865
files marea_2/flux_to_map.py
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/marea_2/flux_to_map.py	Sun Aug 04 18:37:57 2024 +0000
+++ b/marea_2/flux_to_map.py	Sun Aug 04 18:38:11 2024 +0000
@@ -815,6 +815,15 @@
     return { id : list(map(utils.Float("Dataset values, not an argument"), values)) for id, values in dataset.items() }, IDs
 
 def jet_colormap(value):
+    """
+    Generate an RGB color based on a single numeric value using a colormap similar to MATLAB's 'jet'.
+
+    Args:
+        value (float): A numeric value to be mapped to a color.
+
+    Returns:
+        numpy.ndarray: An array of RGB color components (in the range [0, 1]).
+    """
     # Ensure value is a single numeric value
     value = abs(value)
     
@@ -829,12 +838,33 @@
     return rgb
 
 def rgb_to_hex(rgb):
+    """
+    Convert RGB values (0-1 range) to hexadecimal color format.
+
+    Args:
+        rgb (numpy.ndarray): An array of RGB color components (in the range [0, 1]).
+
+    Returns:
+        str: The color in hexadecimal format (e.g., '#ff0000' for red).
+    """
     # Convert RGB values (0-1 range) to hexadecimal format
     rgb = (rgb * 255).astype(int)
     return '#{:02x}{:02x}{:02x}'.format(rgb[0], rgb[1], rgb[2])
     
 
 def computeEnrichmentMeanMedian(metabMap: ET.ElementTree, class_pat: Dict[str, List[List[float]]], ids: List[str]) -> None:
+    """
+    Compute and visualize the metabolic map based on mean and median of the input fluxes.
+    The fluxes are normalised across classes/datasets and visualised using the jet colormap.
+
+    Args:
+        metabMap (ET.ElementTree): An XML tree representing the metabolic map.
+        class_pat (Dict[str, List[List[float]]]): A dictionary where keys are class names and values are lists of enrichment values.
+        ids (List[str]): A list of reaction IDs to be used for coloring arrows.
+    
+    Returns:
+        None
+    """
     # Create copies only if they are needed
     metabMap_mean = copy.deepcopy(metabMap)
     metabMap_median = copy.deepcopy(metabMap)
@@ -867,6 +897,17 @@
         save_and_convert(metabMap_median, "median", key)
 
 def apply_arrow(metabMap, rxn_id, color):
+    """
+    Apply an arrow to a specific reaction in the metabolic map with a given color.
+
+    Args:
+        metabMap (ET.ElementTree): An XML tree representing the metabolic map.
+        rxn_id (str): The ID of the reaction to which the arrow will be applied.
+        color (str): The color of the arrow in hexadecimal format.
+
+    Returns:
+        None
+    """
     arrow = Arrow(width=5, col=color)
     arrow.styleReactionElements(metabMap, rxn_id, mindReactionDir=False)
     idOpt1, idOpt2 = getArrowHeadElementId(rxn_id)
@@ -875,6 +916,17 @@
         arrow.applyTo(idOpt2, metabMap, arrow.toStyleStr(downSizedForTips=True))
 
 def save_and_convert(metabMap, map_type, key):
+    """
+    Save the metabolic map as an SVG file and optionally convert it to PNG and PDF formats.
+
+    Args:
+        metabMap (ET.ElementTree): An XML tree representing the metabolic map.
+        map_type (str): The type of map ('mean' or 'median').
+        key (str): The key identifying the specific map.
+
+    Returns:
+        None
+    """
     svgFilePath = utils.FilePath(f"SVG Map {map_type} - {key}", ext=utils.FileFormat.SVG, prefix="result")
     utils.writeSvg(svgFilePath, metabMap)
     if ARGS.generate_pdf: