Mercurial > repos > bimib > marea_2
changeset 249:a2adb47e630d draft
Uploaded
author | luca_milaz |
---|---|
date | Sun, 04 Aug 2024 13:52:05 +0000 |
parents | 419c6bfad590 |
children | a88909fb1c68 |
files | marea_2/flux_to_map.py |
diffstat | 1 files changed, 23 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/marea_2/flux_to_map.py Sun Aug 04 13:29:55 2024 +0000 +++ b/marea_2/flux_to_map.py Sun Aug 04 13:52:05 2024 +0000 @@ -14,6 +14,7 @@ import os import argparse import pyvips +import matplotlib.pyplot as plt from typing import Tuple, Union, Optional, List, Dict ERRORS = [] @@ -813,7 +814,15 @@ dataset = dataset.drop(dataset.columns[0], axis = "columns").to_dict("list") return { id : list(map(utils.Float("Dataset values, not an argument"), values)) for id, values in dataset.items() }, IDs +def rgba_to_hex(rgba): + """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 computeEnrichmentMedoids(metabMap :ET.ElementTree, class_pat :Dict[str, List[List[float]]], ids :List[str]) -> None: + + metabMap_mean = metabMap.copy() + metabMap_median = metabMap.copy() + #class_pat 462 * cellule utils.logWarning( ids, @@ -827,8 +836,8 @@ medians[key] = median means[key] = means - max_flux_medians = max(medians.values(), key=abs) - max_flux_means = max(means.values(), key=abs) + 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()) for key, value in medians.items(): medians[key] = medians[key] / max_flux_medians @@ -836,9 +845,21 @@ for key, value in means.items(): means[key] = means[key] / max_flux_means + cmap = plt.cm.Reds + norm = plt.Normalize(vmin=0, vmax=1) + colors_median_rgb = {k: cmap(norm(v)) for k, v in medians.items()} + colors_median = {k: rgba_to_hex(c) for k, c in colors_median_rgb.items()} + colors_mean_rgb = {k: cmap(norm(v)) for k, v in means.items()} + colors_mean = {k: rgba_to_hex(c) for k, c in colors_mean_rgb.items()} + for rxn_id in ids: + arrow = Arrow(width=5, col=colors_median[rxn_id]) + arrow.applyTo(rxn_id, metabMap_median, arrow.toStyleStr()) + + svgFilePath = utils.FilePath(details = "SVG Map median", ext = utils.FileFormat.SVG, prefix="result") + utils.writeSvg(svgFilePath, metabMap_median) pass