Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change median or mean quant error viz depending on user's choice #489

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading