# HG changeset patch # User luca_milaz # Date 1722853308 0 # Node ID df022575a39c3faaa0e1006d400595d373573e70 # Parent 3e24934edf1273a432ad88f650b204dbcd1ec4d5 Uploaded diff -r 3e24934edf12 -r df022575a39c marea_2/flux_to_map.py --- 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: