Skip to content

Commit

Permalink
Merge pull request #489 from Proteobench/mean_median_plot
Browse files Browse the repository at this point in the history
Change median or mean quant error viz depending on user's choice
  • Loading branch information
RobbinBouwmeester authored Dec 16, 2024
2 parents 4fdb82b + 0fb6c04 commit 2c535e4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
5 changes: 4 additions & 1 deletion proteobench/datapoint/quant_datapoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand Down
25 changes: 20 additions & 5 deletions proteobench/plotting/plot_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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]}<br>"
+ f"Software tool: {benchmark_metrics_df.software_name[idx]} {benchmark_metrics_df.software_version[idx]}<br>"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
19 changes: 18 additions & 1 deletion webinterface/pages/base_pages/quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 2c535e4

Please sign in to comment.