Skip to content

Commit

Permalink
Merge pull request #498 from Proteobench/fix-key-plot_metric
Browse files Browse the repository at this point in the history
Fixes mean plotting
  • Loading branch information
rodvrees authored Dec 16, 2024
2 parents 2c535e4 + 1397bb1 commit 072a0af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions proteobench/datapoint/quant_datapoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import proteobench


def filter_df_numquant_median_abs_epsilon(row: Dict[str, Any], min_quant: int = 3) -> float | None:
def filter_df_numquant_epsilon(row: Dict[str, Any], min_quant: int = 3, metric: str = "median") -> float | None:
"""
Extract the 'median_abs_epsilon' value from a row (assumed to be a dictionary).
Expand All @@ -27,7 +27,7 @@ def filter_df_numquant_median_abs_epsilon(row: Dict[str, Any], min_quant: int =
if isinstance(list(row.keys())[0], str):
min_quant = str(min_quant)
if isinstance(row, dict) and min_quant in row and isinstance(row[min_quant], dict):
return row[min_quant].get("median_abs_epsilon")
return row[min_quant].get("{}_abs_epsilon".format(metric))

return None

Expand Down
9 changes: 7 additions & 2 deletions proteobench/modules/quant/quant_base/quant_base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from proteobench.datapoint.quant_datapoint import (
Datapoint,
filter_df_numquant_median_abs_epsilon,
filter_df_numquant_epsilon,
filter_df_numquant_nr_prec,
)
from proteobench.github.gh import GithubProteobotRepo
Expand Down Expand Up @@ -185,7 +185,12 @@ def filter_data_point(all_datapoints: pd.DataFrame, default_val_slider: int = 3)
A DataFrame containing the filtered data points.
"""
all_datapoints["median_abs_epsilon"] = [
filter_df_numquant_median_abs_epsilon(v, min_quant=default_val_slider) for v in all_datapoints["results"]
filter_df_numquant_epsilon(v, min_quant=default_val_slider) for v in all_datapoints["results"]
]

all_datapoints["mean_abs_epsilon"] = [
filter_df_numquant_epsilon(v, min_quant=default_val_slider, metric="mean")
for v in all_datapoints["results"]
]

all_datapoints["nr_prec"] = [
Expand Down
12 changes: 6 additions & 6 deletions proteobench/plotting/plot_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "median",
metric: str = "Median",
software_colors: Dict[str, str] = {
"MaxQuant": "#377eb8",
"AlphaPept": "#4daf4a",
Expand Down Expand Up @@ -165,18 +165,18 @@ def plot_metric(
benchmark_metrics_df["hover_text"] = hover_texts
benchmark_metrics_df["scatter_size"] = scatter_size

if metric == "median":
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,
max(all_median_abs_epsilon) + max(all_median_abs_epsilon) * 0.05,
]
layout_xaxis_title = (
"Median absolute difference between measured and expected log2-transformed fold change."
)
elif metric == "mean":
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,
max(all_mean_abs_epsilon) + max(all_mean_abs_epsilon) * 0.05,
]
layout_xaxis_title = "Mean absolute difference between measured and expected log2-transformed fold change."

Expand Down Expand Up @@ -205,7 +205,7 @@ def plot_metric(
# tmp_df["enable_match_between_runs"] = tmp_df["enable_match_between_runs"].astype(str)
fig.add_trace(
go.Scatter(
x=tmp_df["median_abs_epsilon"],
x=tmp_df["{}_abs_epsilon".format(metric.lower())],
y=tmp_df["nr_prec"],
mode="markers" if label == "None" else "markers+text",
hovertext=tmp_df["hover_text"],
Expand Down
3 changes: 1 addition & 2 deletions webinterface/pages/base_pages/quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ def display_existing_results(self) -> None:
fig_metric = PlotDataPoint.plot_metric(
data_points_filtered,
label=st.session_state[st.session_state[self.variables_quant.selectbox_id_uuid]],
metric=metric,
key="placeholder", # TODO: add to variables
metric=metric
)
st.plotly_chart(fig_metric, use_container_width=True)
except Exception as e:
Expand Down

0 comments on commit 072a0af

Please sign in to comment.