From a545cefb6dd461a239e8594c91f10e59aef84a94 Mon Sep 17 00:00:00 2001 From: Robin De Schepper Date: Thu, 18 Jul 2024 21:38:20 -0400 Subject: [PATCH 1/5] added MIN_BAR_GAP global const --- lastplot/graph_constructor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lastplot/graph_constructor.py b/lastplot/graph_constructor.py index 3613598..42d1ead 100644 --- a/lastplot/graph_constructor.py +++ b/lastplot/graph_constructor.py @@ -1,9 +1,11 @@ import numpy as np from matplotlib.axes import Axes +MIN_BAR_GAP = 0.005 + def mpl_calc_series( - n_groups, n_bars, group_width, bar_width, bar_gap, min_bar_gap=0.01 + n_groups, n_bars, group_width, bar_width, bar_gap, min_bar_gap=MIN_BAR_GAP ): # IMPORTANT: This algorithm only produces correct bar widths when the # figure's width is determined exclusively by the n_groups given. @@ -42,7 +44,7 @@ def mpl_calc_bar_width(n_bars, group_width, gap): def mpl_debug_series( - n_groups, n_bars, group_width, bar_width, bar_gap, ax: Axes, min_bar_gap=0.03 + n_groups, n_bars, group_width, bar_width, bar_gap, ax: Axes, min_bar_gap=MIN_BAR_GAP ): debug = f"Input: w{bar_width:.2f}, g{bar_gap:.2f};" bar_gap *= n_groups From ec8900248a8d47139a33ef5a43c3d3665fa1dfdb Mon Sep 17 00:00:00 2001 From: Robin De Schepper Date: Thu, 18 Jul 2024 21:39:51 -0400 Subject: [PATCH 2/5] fixed issue with additional invalid_df return value --- lastplot/workflows.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lastplot/workflows.py b/lastplot/workflows.py index db953b3..0bdd6c3 100644 --- a/lastplot/workflows.py +++ b/lastplot/workflows.py @@ -3,7 +3,9 @@ from lastplot.saving import * -def data_workflow(file_path, data_sheet, mice_sheet, output_path, control_name, experimental_name): +def data_workflow( + file_path, data_sheet, mice_sheet, output_path, control_name, experimental_name +): """ Automatically processes lipidomics data. @@ -18,8 +20,12 @@ def data_workflow(file_path, data_sheet, mice_sheet, output_path, control_name, df, df_mice = load_data( datapath=file_path, sheet_name=data_sheet, mice_sheet=mice_sheet ) - df_clean = data_cleanup(df=df, df_mice=df_mice, output_path=output_path) - statistics = statistics_tests(df_clean=df_clean, control_name=control_name, experimental_name=experimental_name) + df_clean, _ = data_cleanup(df=df, df_mice=df_mice, output_path=output_path) + statistics = statistics_tests( + df_clean=df_clean, + control_name=control_name, + experimental_name=experimental_name, + ) df_final = z_scores(df_clean=df_clean, statistics=statistics) save_values(df_final=df_final, output_path=output_path) save_zscores(df_final=df_final, output_path=output_path) From 3cb74f0b75c68654bb8d5c1bda37aef4fe445e2c Mon Sep 17 00:00:00 2001 From: Robin De Schepper Date: Thu, 18 Jul 2024 21:40:12 -0400 Subject: [PATCH 3/5] fixed bar width issue --- lastplot/log10_graphs.py | 64 ++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lastplot/log10_graphs.py b/lastplot/log10_graphs.py index e8a2a56..8e0e26d 100644 --- a/lastplot/log10_graphs.py +++ b/lastplot/log10_graphs.py @@ -18,16 +18,16 @@ # Graphs by log10 values def log_values_graph_lipid( - df_final, - control_name, - experimental_name, - output_path, - palette, - xlabel=None, - ylabel=None, - title=None, - show=True, - debug=False, + df_final, + control_name, + experimental_name, + output_path, + palette, + xlabel=None, + ylabel=None, + title=None, + show=True, + debug=False, ): """ The `log_values_graph_lipid` function generates boxplots and statistical annotations to visualize the distribution of log 10 transformed values of single lipids across regions. It performs the following tasks: @@ -198,16 +198,16 @@ def log_values_graph_lipid( def log_values_graph_lipid_class( - df_final, - control_name, - experimental_name, - output_path, - palette, - xlabel=None, - ylabel=None, - title=None, - show=True, - debug=False, + df_final, + control_name, + experimental_name, + output_path, + palette, + xlabel=None, + ylabel=None, + title=None, + show=True, + debug=False, ): """ The `log_values_graph_lipid_class` function generates boxplots to visualize the distribution of log 10 transformed values across different lipid classes within each region. It performs the following tasks: @@ -277,12 +277,12 @@ def log_values_graph_lipid_class( for g, genotype in enumerate(genotype_labels): values = data[ (data["Lipids"] == lipid) & (data["Genotype"] == genotype) - ]["Log10 Values"] + ]["Log10 Values"] bp = ax.boxplot( values, positions=[positions[j][g]], - widths=bar_width, + widths=width, patch_artist=True, boxprops=dict(facecolor=palette[g], color="k"), medianprops=dict(color="k"), @@ -334,16 +334,16 @@ def log_values_graph_lipid_class( def log_values_graph_class_average( - df_final, - control_name, - experimental_name, - output_path, - palette, - xlabel=None, - ylabel=None, - title=None, - show=True, - debug=False, + df_final, + control_name, + experimental_name, + output_path, + palette, + xlabel=None, + ylabel=None, + title=None, + show=True, + debug=False, ): """ The `log_values_graph_class_average average` function generates boxplots and statistical annotations for visualizing average log 10 values of lipids classes From 6d9d567b6d4c8147dc99c335d948608d0f067aa2 Mon Sep 17 00:00:00 2001 From: Robin De Schepper Date: Thu, 18 Jul 2024 21:47:05 -0400 Subject: [PATCH 4/5] fixed dropped code --- lastplot/data_cleanup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lastplot/data_cleanup.py b/lastplot/data_cleanup.py index 693a96f..3fa7053 100644 --- a/lastplot/data_cleanup.py +++ b/lastplot/data_cleanup.py @@ -102,7 +102,7 @@ def replace_zero_values(row, data): & (data["Regions"] == row["Regions"]) & (data["Genotype"] == row["Genotype"]) & (data["Values"] != 0) - ] + ] if not group_df.empty: min_value = group_df["Values"].min() if min_value != 0: @@ -119,9 +119,9 @@ def replace_zero_values(row, data): os.makedirs(output_path + "/output") try: - with pd.ExcelWriter( - output_path + "/output/Output file.xlsx", engine="openpyxl", mode="a" - ) as writer: + with pd.ExcelWriter(output_path + "/output/Output file.xlsx") as writer: + df_eliminated.to_excel(writer, sheet_name="Eliminated Lipids") + print("Saving data to new Excel file") except PermissionError: print("Close the Excel file and try again.") From 541bdcdcbe4e3fb85586fad3b635e709e48ecf38 Mon Sep 17 00:00:00 2001 From: Robin De Schepper Date: Thu, 18 Jul 2024 21:51:03 -0400 Subject: [PATCH 5/5] fixed input bar_width being used as output width --- lastplot/graph_constructor.py | 1 - lastplot/zscores_graphs.py | 64 +++++++++++++++++------------------ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/lastplot/graph_constructor.py b/lastplot/graph_constructor.py index 42d1ead..d396a05 100644 --- a/lastplot/graph_constructor.py +++ b/lastplot/graph_constructor.py @@ -64,7 +64,6 @@ def mpl_debug_series( else: algorithm = "gapped" debug += f" Calc: w{bar_width:.2f}, g{bar_gap:.2f}, {algorithm};" - mpl_calc_series(n_groups, n_bars, group_width, bar_width, bar_gap) ax.axhline(0, linestyle="--", color="k") for x in range(n_groups): ax.axvline(x, color="gray", linewidth=0.5) diff --git a/lastplot/zscores_graphs.py b/lastplot/zscores_graphs.py index 3146e69..141bf8c 100644 --- a/lastplot/zscores_graphs.py +++ b/lastplot/zscores_graphs.py @@ -18,16 +18,16 @@ # Graphs by Z scores def zscore_graph_lipid( - df_final, - control_name, - experimental_name, - output_path, - palette, - xlabel=None, - ylabel=None, - title=None, - show=True, - debug=False, + df_final, + control_name, + experimental_name, + output_path, + palette, + xlabel=None, + ylabel=None, + title=None, + show=True, + debug=False, ): """ The `zscore_graph_lipid` function generates boxplots and statistical annotations for visualizing Z scores of lipids @@ -200,16 +200,16 @@ def zscore_graph_lipid( def zscore_graph_lipid_class( - df_final, - control_name, - experimental_name, - output_path, - palette, - xlabel=None, - ylabel=None, - title=None, - show=True, - debug=False, + df_final, + control_name, + experimental_name, + output_path, + palette, + xlabel=None, + ylabel=None, + title=None, + show=True, + debug=False, ): """ The `zscore_graph_lipid_class` function generates boxplots to visualize the distribution of Z scores across different lipid classes within each region. It performs the following tasks: @@ -278,12 +278,12 @@ def zscore_graph_lipid_class( for g, genotype in enumerate(genotype_data): experimental_values = data[ (data["Lipids"] == lipid) & (data["Genotype"] == genotype) - ]["Z Scores"] + ]["Z Scores"] bp = ax.boxplot( experimental_values, positions=[positions[j][g]], - widths=bar_width, + widths=width, patch_artist=True, boxprops=dict(facecolor=palette[g], color="k"), medianprops=dict(color="k"), @@ -333,16 +333,16 @@ def zscore_graph_lipid_class( def zscore_graph_class_average( - df_final, - control_name, - experimental_name, - output_path, - palette, - xlabel=None, - ylabel=None, - title=None, - show=True, - debug=False, + df_final, + control_name, + experimental_name, + output_path, + palette, + xlabel=None, + ylabel=None, + title=None, + show=True, + debug=False, ): """ The `zscore_graph_class average` function generates boxplots and statistical annotations for visualizing average Z scores of lipids classes