changeset 270:4617f8a3ab28 draft

Uploaded
author luca_milaz
date Sun, 04 Aug 2024 16:36:03 +0000
parents 3671d7cb4eaf
children d879c594013d
files marea_2/flux_to_map.py
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/marea_2/flux_to_map.py	Sun Aug 04 16:02:16 2024 +0000
+++ b/marea_2/flux_to_map.py	Sun Aug 04 16:36:03 2024 +0000
@@ -818,20 +818,22 @@
     """Convert an RGBA color to HEX format."""
     return '#{:02x}{:02x}{:02x}'.format(int(rgba[0] * 255), int(rgba[1] * 255), int(rgba[2] * 255))
 
-def reds_cmap(value):
-    """Map a normalized value to RGB color using the Reds colormap."""
-    # Assumi che 'value' sia scalare e tra 0 e 1
-    r = value
-    g = 0
-    b = 0
+def gray_to_red_cmap(value):
+    """Map a normalized value to RGB color transitioning from gray to red."""
+    # Ensure value is in the range [0, 1]
+    value = abs(value)
+    r = value + 0.5
+    g = 0.5 - 0.5 * value
+    b = 0.5 - 0.5 * value
+    
     return (r, g, b)
 
-def computeEnrichmentMedoids(metabMap :ET.ElementTree, class_pat :Dict[str, List[List[float]]], ids :List[str]) -> None:
+def computeEnrichmentMeanMedian(metabMap :ET.ElementTree, class_pat :Dict[str, List[List[float]]], ids :List[str]) -> None:
 
     metabMap_mean = copy.deepcopy(metabMap)
     metabMap_median = copy.deepcopy(metabMap)
     
-    medians = {} # dict , for each class an array (the median)
+    medians = {} # dict, for each class an array (the median)
     means = {}
     for key, value in class_pat.items():
         values = np.array(class_pat[key])
@@ -854,27 +856,27 @@
         colors_median={}
         i=0
         for rxn_id in ids:
-             colors_median[rxn_id] = rgba_to_hex(reds_cmap(medians[key][i]))
+             colors_median[rxn_id] = rgba_to_hex(gray_to_red_cmap(medians[key][i]))
              i+=1
 
         colors_mean={}
         i=0
         for rxn_id in ids:
-             colors_mean[rxn_id] = rgba_to_hex(reds_cmap(means[key][i]))
+             colors_mean[rxn_id] = rgba_to_hex(gray_to_red_cmap(means[key][i]))
              i+=1
 
         for rxn_id in ids:
             arrow = Arrow(width=5, col=colors_median[rxn_id])
             arrow.applyTo(arrow.getMapReactionId(rxn_id, mindReactionDir=False), metabMap_median, arrow.toStyleStr())
             # Now we style the arrow head(s):
-            idOpt1, idOpt2 = getArrowHeadElementId(arrow.getMapReactionId(rxn_id, mindReactionDir=False))
+            idOpt1, idOpt2 = getArrowHeadElementId(arrow.getMapReactionId(rxn_id, mindReactionDir=True))
             arrow.applyTo(idOpt1, metabMap_median, arrow.toStyleStr(downSizedForTips = True))
             if idOpt2: arrow.applyTo(idOpt2, metabMap_median, arrow.toStyleStr(downSizedForTips = True))
 
             arrow = Arrow(width=5, col=colors_mean[rxn_id])
             arrow.applyTo(arrow.getMapReactionId(rxn_id, mindReactionDir=False), metabMap_mean, arrow.toStyleStr())
             # Now we style the arrow head(s):
-            idOpt1, idOpt2 = getArrowHeadElementId(arrow.getMapReactionId(rxn_id, mindReactionDir=False))
+            idOpt1, idOpt2 = getArrowHeadElementId(arrow.getMapReactionId(rxn_id, mindReactionDir=True))
             arrow.applyTo(idOpt1, metabMap_mean, arrow.toStyleStr(downSizedForTips = True))
             if idOpt2: arrow.applyTo(idOpt2, metabMap_mean, arrow.toStyleStr(downSizedForTips = True))
 
@@ -911,7 +913,7 @@
 
     ids, class_pat = getClassesAndIdsFromDatasets(ARGS.input_datas_fluxes, ARGS.input_data_fluxes, ARGS.input_class_fluxes, ARGS.names_fluxes)
 
-    computeEnrichmentMedoids(core_map, class_pat, ids)
+    computeEnrichmentMeanMedian(core_map, class_pat, ids)
 
     computeEnrichment(core_map, class_pat, ids)