changeset 297:df022575a39c draft

Uploaded
author luca_milaz
date Mon, 05 Aug 2024 10:21:48 +0000
parents 3e24934edf12
children 5418a59697a3
files marea_2/flux_to_map.py
diffstat 1 files changed, 23 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/marea_2/flux_to_map.py	Mon Aug 05 10:06:01 2024 +0000
+++ b/marea_2/flux_to_map.py	Mon Aug 05 10:21:48 2024 +0000
@@ -395,6 +395,16 @@
         self.applyTo(idOpt1, metabMap, self.toStyleStr(downSizedForTips = True))
         if idOpt2: self.applyTo(idOpt2, metabMap, self.toStyleStr(downSizedForTips = True))
 
+    def styleReactionElements_custom(self, metabMap :ET.ElementTree, reactionId :str, isNegative:bool) -> None:
+
+        self.applyTo(getArrowBodyElementId(reactionId), metabMap, self.toStyleStr())
+        idOpt1, idOpt2 = getArrowHeadElementId(reactionId)
+
+        if(isNegative):
+            self.applyTo(idOpt2, metabMap, self.toStyleStr(downSizedForTips = True))
+        else:
+            self.applyTo(idOpt1, metabMap, self.toStyleStr(downSizedForTips = True))
+
 
     
     def getMapReactionId(self, reactionId :str, mindReactionDir :bool) -> str:
@@ -926,23 +936,26 @@
         colors_mean = {rxn_id: rgb_to_hex(jet_colormap(means[key][i])) for i, rxn_id in enumerate(ids)}
 
         for i, rxn_id in enumerate(ids):
-            new_rxn_id=""
-            if(medians[key][i] < 0):
-                new_rxn_id = "B_" +  rxn_id 
-            else:
-                new_rxn_id = "F_" +  rxn_id 
+
+            isNegative = False
+
+            if(medians[key][i] <0):
+                isNegative = True
 
             # Apply median arrows
-            apply_arrow(metabMap_median, new_rxn_id, colors_median[rxn_id])
+            apply_arrow(metabMap_median, rxn_id, colors_median[rxn_id], isNegative)
 
             # Apply mean arrows
-            apply_arrow(metabMap_mean, new_rxn_id, colors_mean[rxn_id])
+            apply_arrow(metabMap_mean, rxn_id, colors_mean[rxn_id], isNegative)
 
         # Save and convert the SVG files
         save_and_convert(metabMap_mean, "mean", key)
         save_and_convert(metabMap_median, "median", key)
 
-def apply_arrow(metabMap, rxn_id, color):
+
+
+
+def apply_arrow(metabMap, rxn_id, color, isNegative):
     """
     Apply an arrow to a specific reaction in the metabolic map with a given color.
 
@@ -955,7 +968,8 @@
         None
     """
     arrow = Arrow(width=5, col=color)
-    arrow.styleReactionElements(metabMap, rxn_id, mindReactionDir=False)
+    arrow.styleReactionElements_custom(metabMap, rxn_id, isNegative)
+
     idOpt1, idOpt2 = getArrowHeadElementId(rxn_id)
     arrow.applyTo(idOpt1, metabMap, arrow.toStyleStr(downSizedForTips=True))
     if idOpt2: