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.") diff --git a/lastplot/graph_constructor.py b/lastplot/graph_constructor.py index 3613598..d396a05 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 @@ -62,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/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 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