From f62ffd70a263b30ccca985d9410ba73d8b870649 Mon Sep 17 00:00:00 2001 From: johaGL Date: Mon, 5 Oct 2026 18:34:22 +0200 Subject: [PATCH 1/4] updates `src/dimet/visualization/abundance_bars.py`: solves issue #33 xaxis and barcolor being the same generate no legend --- src/dimet/visualization/abundance_bars.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/dimet/visualization/abundance_bars.py b/src/dimet/visualization/abundance_bars.py index 7e3bdbb..f0468ec 100644 --- a/src/dimet/visualization/abundance_bars.py +++ b/src/dimet/visualization/abundance_bars.py @@ -69,6 +69,9 @@ def plot_one_metabolite(df: pd.DataFrame, ) if do_stripplot: np.random.seed(123) # to force the jitter not to randomly change + dodge_bool = True + if axisx_var == hue_var: + dodge_bool = False try: sns.stripplot( ax=curr_ax, @@ -77,7 +80,7 @@ def plot_one_metabolite(df: pd.DataFrame, hue=str(hue_var), data=df, palette=palette_choice, - dodge=True, + dodge=dodge_bool, edgecolor="black", linewidth=1.5, alpha=1, @@ -132,7 +135,10 @@ def plot_abundance_bars_no_grid( axs_k = apply_advanced_param_custom_x_labs(cfg, axs_k) if k == 0: # collect the legend, which is same for any plot thehandles, thelabels = axs_k.get_legend_handles_labels() - axs_k.legend_.remove() + try: + axs_k.legend_.remove() + except AttributeError: + pass # no legend is generated when xaxis and barcolor are equal plt.tight_layout(pad=0.01, w_pad=-2, h_pad=0.1) plt.savefig(output_path_k, bbox_inches="tight", @@ -141,6 +147,8 @@ def plot_abundance_bars_no_grid( plt.legend(handles=thehandles, labels=thelabels, loc="upper right") plt.axis("off") + if hue_var == axisx_var: + plt.figtext(0.1, 0.7, "No legend:\n xaxis equal to barcolor") plt.savefig(os.path.join( output_directory, f"legend.{cfg.analysis.method.figure_format}"), @@ -198,7 +206,10 @@ def plot_as_grid_of_bars( thehandles, thelabels = axs[-1].get_legend_handles_labels() for i in range(len(selected_metabolites)): - axs[i].legend_.remove() + try: + axs[i].legend_.remove() + except AttributeError: + pass # no legend is generated when xaxis and barcolor are equal plt.subplots_adjust(left=0.2, top=0.76, bottom=0.2, hspace=corrector_factor) @@ -211,7 +222,10 @@ def plot_as_grid_of_bars( plt.close() plt.legend(handles=thehandles, labels=thelabels, loc="upper right") + if hue_var == axisx_var: + plt.figtext(0.1, 0.7, "No legend:\n xaxis equal to barcolor") plt.axis("off") + plt.savefig(os.path.join( output_directory, f"legend.{cfg.analysis.method.figure_format}"), From 59a3adac2aa68397870c831ce16140dbe9f453bf Mon Sep 17 00:00:00 2001 From: johaGL Date: Mon, 5 Oct 2026 19:00:57 +0200 Subject: [PATCH 2/4] updates `src/dimet/visualization` modules: solves issue #31: svg files have now editable text instead "paths" --- src/dimet/visualization/abundance_bars.py | 1 + src/dimet/visualization/isotopologue_proportions.py | 2 ++ src/dimet/visualization/mean_enrichment_line_plot.py | 2 ++ src/dimet/visualization/metabologram.py | 2 ++ src/dimet/visualization/pca_plot.py | 3 +++ 5 files changed, 10 insertions(+) diff --git a/src/dimet/visualization/abundance_bars.py b/src/dimet/visualization/abundance_bars.py index f0468ec..fc8662e 100644 --- a/src/dimet/visualization/abundance_bars.py +++ b/src/dimet/visualization/abundance_bars.py @@ -21,6 +21,7 @@ cs = ConfigStore.instance() +matplotlib.rcParams['svg.fonttype'] = 'none' def pile_up_abundance(df: pd.DataFrame, metada_sel: pd.DataFrame) -> pd.DataFrame: diff --git a/src/dimet/visualization/isotopologue_proportions.py b/src/dimet/visualization/isotopologue_proportions.py index 0372434..c6c1227 100644 --- a/src/dimet/visualization/isotopologue_proportions.py +++ b/src/dimet/visualization/isotopologue_proportions.py @@ -22,6 +22,8 @@ cs = ConfigStore.instance() +matplotlib.rcParams['svg.fonttype'] = 'none' + def isotopologue_proportions_2piled_df( compartment_df: pd.DataFrame, diff --git a/src/dimet/visualization/mean_enrichment_line_plot.py b/src/dimet/visualization/mean_enrichment_line_plot.py index b9035a7..048d101 100644 --- a/src/dimet/visualization/mean_enrichment_line_plot.py +++ b/src/dimet/visualization/mean_enrichment_line_plot.py @@ -16,6 +16,8 @@ cs = ConfigStore.instance() +matplotlib.rcParams['svg.fonttype'] = 'none' + def melt_data_metadata_2df(compartment_df: pd.DataFrame, metadata_co_df: pd.DataFrame) -> pd.DataFrame: diff --git a/src/dimet/visualization/metabologram.py b/src/dimet/visualization/metabologram.py index 40b863b..8e9b5c2 100644 --- a/src/dimet/visualization/metabologram.py +++ b/src/dimet/visualization/metabologram.py @@ -28,6 +28,8 @@ logger = logging.getLogger(__name__) +matplotlib.rcParams['svg.fonttype'] = 'none' + def get_differential_results_dict(file_name: str, data_integration: DataIntegration, diff --git a/src/dimet/visualization/pca_plot.py b/src/dimet/visualization/pca_plot.py index 6747d12..e698e90 100644 --- a/src/dimet/visualization/pca_plot.py +++ b/src/dimet/visualization/pca_plot.py @@ -5,6 +5,7 @@ import os from typing import List, Union +import matplotlib import matplotlib.figure as figure import matplotlib.pyplot as plt import numpy as np @@ -18,6 +19,8 @@ cs = ConfigStore.instance() +matplotlib.rcParams['svg.fonttype'] = 'none' + def variance_expl_plot(var_explained_df: pd.DataFrame) -> figure.Figure: """ From 201ec0401640ba17dcf7fbd21ebd31b4d0f60963 Mon Sep 17 00:00:00 2001 From: johaGL Date: Mon, 5 Oct 2026 19:30:15 +0200 Subject: [PATCH 3/4] updates pca plot: legend outside plot area solving issue #32 (`src/dimet/visualization`) & adds figsize params in `src/dimet/config/analysis/method/pca_plot.yaml` --- .../config/analysis/method/pca_plot.yaml | 3 +++ src/dimet/visualization/pca_plot.py | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/dimet/config/analysis/method/pca_plot.yaml b/src/dimet/config/analysis/method/pca_plot.yaml index c138b3d..4cff1d9 100644 --- a/src/dimet/config/analysis/method/pca_plot.yaml +++ b/src/dimet/config/analysis/method/pca_plot.yaml @@ -20,3 +20,6 @@ impute_values: # how to impute zeroes mean_enrichment: "min" isotopologues: "min" isotopologue_proportions: "min" + +width: !!float 6.2 +height: !!float 4.0 \ No newline at end of file diff --git a/src/dimet/visualization/pca_plot.py b/src/dimet/visualization/pca_plot.py index e698e90..e6e03ee 100644 --- a/src/dimet/visualization/pca_plot.py +++ b/src/dimet/visualization/pca_plot.py @@ -50,11 +50,12 @@ def pca_scatter_plot(pc_df: pd.DataFrame, var_explained_df: pd.DataFrame, col1: str, col2: str, labels_column: str, - ellipses_column: Union[str, None]) -> figure.Figure: + ellipses_column: Union[str, None], + width: float=6.0, height: float=4.0) -> figure.Figure: """ returns the scatter plot (a seaborn matplotlib figure) """ - fig, ax = plt.subplots() + fig, ax = plt.subplots(figsize=(width, height)) sns.scatterplot(x="PC1", y="PC2", ax=ax, data=pc_df, @@ -62,6 +63,15 @@ def pca_scatter_plot(pc_df: pd.DataFrame, style=col2, legend=True, s=80, zorder=3) + handles, labels = ax.get_legend_handles_labels() + ax.legend( + handles, + labels, + bbox_to_anchor=(1.05, 1), # Places legend outside the top-right corner + loc='upper left', + borderaxespad=0.0 + ) + plt.tight_layout() # Ensures the legend is not clipped ax.axhline(0, ls="--", color="gray", zorder=1) ax.axvline(0, ls="--", color="gray", zorder=1) if labels_column != "": @@ -152,6 +162,7 @@ def run_pca_plot(pca_results_dict: dict, cfg: DictConfig, color_dot = cfg.analysis.method.color style_dot = cfg.analysis.method.style + options_labels = {'label-y': "name_to_plot", 'label-n': ""} # when empty string, no dot labels @@ -162,7 +173,10 @@ def run_pca_plot(pca_results_dict: dict, cfg: DictConfig, scatter_fig: figure.Figure = pca_scatter_plot( pc_df, var_explained_df, color_dot, style_dot, labels_column, - ellipses_column=cfg.analysis.method.draw_ellipses) + ellipses_column=cfg.analysis.method.draw_ellipses, + width=cfg.analysis.method.width, + height=cfg.analysis.method.height + ) pca_scatter_2_file(scatter_fig, name_elements, out_plot_dir, cfg.analysis.method.figure_format) plt.close() From 77f323684e6c165a883b75d6909e113c975ab1af Mon Sep 17 00:00:00 2001 From: johaGL Date: Mon, 5 Oct 2026 19:50:29 +0200 Subject: [PATCH 4/4] updates (`src/dimet/processing/differential_analysis.py`): solves bug of span computation (issue #30) --- src/dimet/processing/differential_analysis.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dimet/processing/differential_analysis.py b/src/dimet/processing/differential_analysis.py index 77fc14b..a2a94be 100644 --- a/src/dimet/processing/differential_analysis.py +++ b/src/dimet/processing/differential_analysis.py @@ -40,9 +40,13 @@ def compute_span_incomparison(df: pd.DataFrame, groups: List) -> pd.DataFrame: the computed differences. """ for i in df.index.values: - all_values = list(df.loc[i, groups[0]]) + list(df.loc[i, groups[1]]) + group1_values = df.loc[i, groups[0]].to_numpy() + group2_values = df.loc[i, groups[1]].to_numpy() + + all_values = np.concatenate([group1_values, group2_values]) + + interval = np.nanmax(all_values) - np.nanmin(all_values) - interval = max(all_values) - min(all_values) df.loc[i, "span_allsamples"] = interval return df