From 45bbe0bfaf77b98222c4e55240e86238c382ab29 Mon Sep 17 00:00:00 2001 From: rodvrees Date: Wed, 4 Dec 2024 09:16:50 +0100 Subject: [PATCH 1/2] New toggle for metrics --- proteobench/datapoint/quant_datapoint.py | 5 ++++- proteobench/plotting/plot_quant.py | 25 +++++++++++++++++++----- webinterface/pages/base_pages/quant.py | 19 +++++++++++++++++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/proteobench/datapoint/quant_datapoint.py b/proteobench/datapoint/quant_datapoint.py index 60bb5615..3db8a30e 100644 --- a/proteobench/datapoint/quant_datapoint.py +++ b/proteobench/datapoint/quant_datapoint.py @@ -185,7 +185,9 @@ def get_metrics(df: pd.DataFrame, min_nr_observed: int = 1) -> Dict[int, Dict[st nr_prec = len(df_slice) # Calculate the median absolute epsilon (insensitive to outliers) - median_abs_epsilon = df_slice["epsilon"].abs().mean() + median_abs_epsilon = df_slice["epsilon"].abs().median() + # Calculate the mean absolute epsilon (sensitive to outliers) + mean_abs_epsilon = df_slice["epsilon"].abs().mean() # Calculate the variance of epsilon (sensitive to outliers) variance_epsilon = df_slice["epsilon"].var() @@ -199,6 +201,7 @@ def get_metrics(df: pd.DataFrame, min_nr_observed: int = 1) -> Dict[int, Dict[st return { min_nr_observed: { "median_abs_epsilon": median_abs_epsilon, + "mean_abs_epsilon": mean_abs_epsilon, "variance_epsilon": variance_epsilon, "nr_prec": nr_prec, "CV_median": cv_median, diff --git a/proteobench/plotting/plot_quant.py b/proteobench/plotting/plot_quant.py index 0ec9fb15..f6a23e3b 100644 --- a/proteobench/plotting/plot_quant.py +++ b/proteobench/plotting/plot_quant.py @@ -71,6 +71,7 @@ def plot_fold_change_histogram(result_df: pd.DataFrame, species_ratio: Dict[str, @staticmethod def plot_metric( benchmark_metrics_df: pd.DataFrame, + metric: str, software_colors: Dict[str, str] = { "MaxQuant": "#377eb8", "AlphaPept": "#4daf4a", @@ -106,6 +107,7 @@ def plot_metric( all_median_abs_epsilon = [ v2["median_abs_epsilon"] for v in benchmark_metrics_df["results"] for v2 in v.values() ] + all_mean_abs_epsilon = [v2["mean_abs_epsilon"] for v in benchmark_metrics_df["results"] for v2 in v.values()] all_nr_prec = [v2["nr_prec"] for v in benchmark_metrics_df["results"] for v2 in v.values()] # Add hover text with detailed information for each data point @@ -122,6 +124,7 @@ def plot_metric( datapoint_text + f"Comment (private submission): {benchmark_metrics_df.comments[idx]}" ) else: + # TODO: Determine parameters based on module datapoint_text = ( f"ProteoBench ID: {benchmark_metrics_df.id[idx]}
" + f"Software tool: {benchmark_metrics_df.software_name[idx]} {benchmark_metrics_df.software_version[idx]}
" @@ -161,15 +164,27 @@ def plot_metric( benchmark_metrics_df["hover_text"] = hover_texts benchmark_metrics_df["scatter_size"] = scatter_size + if metric == "median": + layout_xaxis_range = [ + min(all_median_abs_epsilon) - min(all_median_abs_epsilon) * 0.05, + max(all_median_abs_epsilon) + min(all_median_abs_epsilon) * 0.05, + ] + layout_xaxis_title = ( + "Median absolute difference between measured and expected log2-transformed fold change." + ) + elif metric == "mean": + layout_xaxis_range = [ + min(all_mean_abs_epsilon) - min(all_mean_abs_epsilon) * 0.05, + max(all_mean_abs_epsilon) + min(all_mean_abs_epsilon) * 0.05, + ] + layout_xaxis_title = "Mean absolute difference between measured and expected log2-transformed fold change." + fig = go.Figure( layout_yaxis_range=[ min(all_nr_prec) - min(max(all_nr_prec) * 0.05, 2000), max(all_nr_prec) + min(max(all_nr_prec) * 0.05, 2000), ], - layout_xaxis_range=[ - min(all_median_abs_epsilon) - min(all_median_abs_epsilon) * 0.05, - max(all_median_abs_epsilon) + min(all_median_abs_epsilon) * 0.05, - ], + layout_xaxis_range=layout_xaxis_range, ) # Get all unique color-software combinations (necessary for highlighting) @@ -202,7 +217,7 @@ def plot_metric( width=700, height=700, xaxis=dict( - title="Mean absolute difference between measured and expected log2-transformed fold change", + title=layout_xaxis_title, gridcolor="white", gridwidth=2, linecolor="black", diff --git a/webinterface/pages/base_pages/quant.py b/webinterface/pages/base_pages/quant.py index ef24e9ca..09801890 100644 --- a/webinterface/pages/base_pages/quant.py +++ b/webinterface/pages/base_pages/quant.py @@ -129,9 +129,17 @@ def display_submitted_results(self) -> None: self.initialize_submitted_data_points() data_points_filtered = self.filter_data_submitted_slider() + metric = st.radio( + "Select metric to plot", + options=["Median", "Mean"], + help="Toggle between median and mean absolute difference metrics.", + key="placeholder2", # TODO: add to variables + ) + try: fig_metric = PlotDataPoint.plot_metric( data_points_filtered, + metric=metric, label=st.session_state[st.session_state[self.variables_quant.selectbox_id_submitted_uuid]], ) st.plotly_chart(fig_metric, use_container_width=True) @@ -155,9 +163,18 @@ def display_existing_results(self) -> None: self.initialize_main_data_points() data_points_filtered = self.filter_data_main_slider() + metric = st.radio( + "Select metric to plot", + options=["Median", "Mean"], + help="Toggle between median and mean absolute difference metrics.", + ) + try: fig_metric = PlotDataPoint.plot_metric( - data_points_filtered, label=st.session_state[st.session_state[self.variables_quant.selectbox_id_uuid]] + data_points_filtered, + label=st.session_state[st.session_state[self.variables_quant.selectbox_id_uuid]], + metric=metric, + key="placeholder", # TODO: add to variables ) st.plotly_chart(fig_metric, use_container_width=True) except Exception as e: From a6914bf2cf4b984bafb01add1fda6d8b879a0694 Mon Sep 17 00:00:00 2001 From: rodvrees Date: Mon, 9 Dec 2024 15:48:58 +0100 Subject: [PATCH 2/2] Provide default metric value to plot_metric --- proteobench/plotting/plot_quant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proteobench/plotting/plot_quant.py b/proteobench/plotting/plot_quant.py index ee2a730a..c591dd10 100644 --- a/proteobench/plotting/plot_quant.py +++ b/proteobench/plotting/plot_quant.py @@ -71,7 +71,7 @@ def plot_fold_change_histogram(result_df: pd.DataFrame, species_ratio: Dict[str, @staticmethod def plot_metric( benchmark_metrics_df: pd.DataFrame, - metric: str, + metric: str = "median", software_colors: Dict[str, str] = { "MaxQuant": "#377eb8", "AlphaPept": "#4daf4a",