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 dfea07f3..c591dd10 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 = "median", software_colors: Dict[str, str] = { "MaxQuant": "#377eb8", "AlphaPept": "#4daf4a", @@ -107,6 +108,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 @@ -123,6 +125,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]}
" @@ -162,15 +165,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) @@ -205,7 +220,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 6b114dc4..d7cfbee3 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: