changeset 164:929104dceba8 draft

Uploaded
author luca_milaz
date Mon, 18 Nov 2024 17:17:02 +0000
parents 0a043d85070e
children 2be342a25cdb
files COBRAxy/flux_to_map.py
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/COBRAxy/flux_to_map.py	Mon Nov 18 17:13:28 2024 +0000
+++ b/COBRAxy/flux_to_map.py	Mon Nov 18 17:17:02 2024 +0000
@@ -891,7 +891,7 @@
 def computeEnrichmentMeanMedian(metabMap: ET.ElementTree, class_pat: Dict[str, List[List[float]]], ids: List[str], colormap: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 given colormap.
+    The fluxes are normalized across classes/datasets and visualized using the given colormap.
 
     Args:
         metabMap (ET.ElementTree): An XML tree representing the metabolic map.
@@ -907,17 +907,17 @@
 
     # Compute medians and means
     medians = {key: np.round(np.median(np.array(value), axis=1), 6) for key, value in class_pat.items()}
-    means = {key: np.round(np.mean(np.array(value), axis=1),6) for key, value in class_pat.items()}
+    means = {key: np.round(np.mean(np.array(value), axis=1), 6) for key, value in class_pat.items()}
 
     # Normalize medians and means
     max_flux_medians = max(np.max(np.abs(arr)) for arr in medians.values())
     max_flux_means = max(np.max(np.abs(arr)) for arr in means.values())
 
-    min_flux_medians = min(min_nonzero_abs(arr) for arr in medians.values())
-    min_flux_means = min(min_nonzero_abs(arr) for arr in means.values())
+    min_flux_medians = min(np.min(arr) for arr in medians.values())
+    min_flux_means = min(np.min(arr) for arr in means.values())
 
-    medians = {key: median/max_flux_medians for key, median in medians.items()}
-    means = {key: mean/max_flux_means for key, mean in means.items()}
+    max_flux_medians = max(np.max(arr) for arr in medians.values())
+    max_flux_means = max(np.max(arr) for arr in means.values())
 
     save_colormap_image(min_flux_medians, max_flux_medians, utils.FilePath("Color map median", ext=utils.FileFormat.PNG, prefix=ARGS.output_path), colormap)
     save_colormap_image(min_flux_means, max_flux_means, utils.FilePath("Color map mean", ext=utils.FileFormat.PNG, prefix=ARGS.output_path), colormap)
@@ -927,12 +927,12 @@
     for key in class_pat:
         # Create color mappings for median and mean
         colors_median = {
-            rxn_id: rgb_to_hex(cmap(abs(medians[key][i]))) if medians[key][i] != 0 else '#bebebe'  #grey blocked
+            rxn_id: rgb_to_hex(cmap((medians[key][i] - min_flux_medians) / (max_flux_medians - min_flux_medians))) if medians[key][i] != 0 else '#bebebe'  #grey blocked
             for i, rxn_id in enumerate(ids)
         }
 
         colors_mean = {
-            rxn_id: rgb_to_hex(cmap(abs(means[key][i]))) if means[key][i] != 0 else '#bebebe'  #grey blocked
+            rxn_id: rgb_to_hex(cmap((means[key][i] - min_flux_means) / (max_flux_means - min_flux_means))) if means[key][i] != 0 else '#bebebe'  #grey blocked
             for i, rxn_id in enumerate(ids)
         }