---
title: "Benchmark results"
author: "Witold E. Wolski"
date: today
format:
fgczQuartoTemplate-html: default
vignette: >
%\VignetteIndexEntry{Benchmark results}
%\VignetteEngine{quarto::format}
%\VignetteEncoding{UTF-8}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, fig.width = 9, fig.height = 5)
options(knitr.kable.NA = "")
```
```{r read}
# The tables of the installed package: `make install` after `make benchmark`
extdata <- function(name, col_classes = NA) {
path <- system.file("extdata", name, package = "prolfquabenchmark", mustWork = TRUE)
utils::read.delim(path, stringsAsFactors = FALSE, colClasses = col_classes)
}
scores <- extdata("benchmark_scores.tsv", col_classes = c(tool_version = "character"))
curves <- extdata("benchmark_curves.tsv")
methods <- extdata("benchmark_methods.tsv", col_classes = c(tool_version = "character"))
datasets <- extdata("benchmark_datasets.tsv")
preprocessing <- extdata("benchmark_preprocessing.tsv")
same_pairs <- extdata("benchmark_same_pairs.tsv")
```
```{r method-style}
# Colour by model family, shape and line type by model within the family: the same in every figure of both vignettes
method_style <- function(method) {
list(
prolfquabenchmark::method_scales(method),
ggplot2::theme_bw(),
ggplot2::theme(legend.key.width = grid::unit(2.5, "lines"))
)
}
# Prints a plot from inside a results = "asis" loop, in order with the text, with its own height and caption
print_with_height <- function(plot, height, caption) {
header <- paste0(
"```{r, fig.height = ", height, ", fig.cap = ", paste(deparse(caption, width.cutoff = 500L), collapse = ""), "}"
)
cat(knitr::knit_child(text = c(header, "print(plot)", "```"), envir = environment(), quiet = TRUE))
}
# Prints a table as an interactive DT table from inside a results = "asis" chunk, decimal columns rounded to 1 digit;
# `container`: an HTML table with its own header rows
print_table <- function(table, caption, page_length = 15, container = NULL) {
widget <- do.call(DT::datatable, c(
list(table, rownames = FALSE, caption = caption, options = list(pageLength = page_length, scrollX = TRUE)),
if (!is.null(container)) list(container = container)
))
decimal_columns <- names(table)[vapply(table, is.double, logical(1))]
if (length(decimal_columns) > 0) {
widget <- DT::formatRound(widget, decimal_columns, digits = 1)
}
cat(knitr::knit_child(text = c("```{r}", "widget", "```"), envir = environment(), quiet = TRUE))
}
```
::::: {.panel-tabset}
# Overview
The benchmark pipeline (`make benchmark`; `workflow/Snakefile`, `config/config.yaml`) prepares each dataset once, fits every method to the input it needs, and scores how well each method ranks proteins with a known change above unchanged ones: E. coli spiked into a human background in IonStar, UPS1 spiked into yeast in CPTAC. The tables and figures come from the files the pipeline exports to `inst/extdata`, so this page renders without data downloads. **Methods** lists the methods and defines the scores, **Summary** compares the methods across datasets, and **Benchresults** has one tab per dataset.
```{r datasets-table}
datasets |>
dplyr::transmute(
.data$dataset,
input = .data$input_file,
changed = .data$positive,
unchanged = .data$negative
) |>
knitr::kable(caption = paste0(
"The ", nrow(datasets), " datasets: the input file and the species of the changed and unchanged proteins. ",
"The Data tab of each dataset in Benchresults lists its preprocessing steps."
))
```
# Methods
:::: {.panel-tabset}
## Methods
```{r methods, results = "asis"}
methods_url <- "https://github.com/prolfqua/prolfquabenchmark/blob/main/inst/extdata/benchmark_methods.tsv"
methods |>
dplyr::summarise(datasets = dplyr::n(), .by = c("method", "tool", "tool_version", "level", "input", "description")) |>
dplyr::arrange(.data$tool != "prolfqua", .data$level, .data$method) |>
dplyr::select("method", "tool_version", "level", "input", "datasets", "description") |>
print_table(
caption = paste0(
"The ", dplyr::n_distinct(methods$method), " methods, with tool version, model level, the input the method ",
"fits, the number of datasets it ran on (every dataset that provides its input, of ",
dplyr::n_distinct(methods$dataset), ") and a short description."
),
page_length = 20
)
cat("\n\nPer dataset and with the wall time of each fit: [benchmark_methods.tsv](", methods_url, ").\n\n", sep = "")
```
## Scores and figures
- Ranking scores: fold change (`log_fc`), p-value signed by the fold change (`scaled.p_value`), t statistic (`t_statistic`)
- AUC, pAUC_5, pAUC_10: area under the ROC curve, and partial area up to a false positive rate of 0.05 or 0.1, on a 0 to 100 scale, with all contrasts of a dataset pooled
- Contrasts computed: protein and contrast pairs with a result for the ranking score, all contrasts together. Each method is scored on the pairs it computes, so pAUC_5 is plotted against this count
- Pareto front (red): the methods no other method beats on both pAUC_5 and contrasts computed
- Same pairs: a method may be on the front because it tests fewer, easier proteins. The methods that test all its protein and contrast pairs (the same or more) are scored again on exactly these pairs (`same_pairs_scores()`; tab Pareto front of each dataset, below the front, ranking by scaled p-value; `benchmark_same_pairs.tsv` has pAUC_5 and pAUC_10 for all three ranking scores)
- Level: `protein` (model fitted to protein abundances), `peptide` (model fitted to peptides, one result per protein), `protein + peptide` (hurdle: intensity on proteins, detection on peptides)
- FDP vs FDR: the false discovery proportion at each nominal FDR; a calibrated FDR lies on the diagonal
- Encoding: colour is the model family of the [prolfqua factory figure](https://github.com/fgcz/prolfqua#readme) (linear models, limma, limpa, LOD imputation, peptide level, hurdle); point shape and line type tell the models of a family apart; external tools are dark grey with open shapes. A method looks the same in every figure here and in the vignette `Score_history` (`method_scales()`, styles from prolfqua's `facade_styles.tsv`)
## Report provenance
```{r provenance}
data.frame(
Field = c("Report", "prolfquabenchmark", "Benchmarked", "Benchmark tables", "Datasets", "Methods", "Rendered"),
Value = c(
"Benchmark results",
as.character(utils::packageVersion("prolfquabenchmark")),
paste(sort(unique(methods$tool_version)), collapse = ", "),
"inst/extdata/benchmark_*.tsv of the installed prolfquabenchmark, exported by make benchmark",
as.character(nrow(datasets)),
as.character(dplyr::n_distinct(methods$method)),
format(Sys.time(), "%Y-%m-%d %H:%M %Z")
)
) |>
knitr::kable()
```
## R session info
```{r session-info}
sessionInfo()
```
::::
# Summary
```{r summary, results = "asis"}
# one score of every method (rows) on every dataset (columns), all contrasts pooled, ranking by scaled p-value; next to
# each score the contrasts computed (protein and contrast pairs with a p-value) the score is computed on
summary_datasets <- intersect(datasets$dataset, scores$dataset)
summary_table <- function(metric) {
scores |>
dplyr::filter(.data$contrast == "all", .data$score == "scaled.p_value") |>
dplyr::select(method = "model_name", "dataset", dplyr::all_of(metric), contrasts = "n_total") |>
tidyr::pivot_wider(names_from = "dataset", values_from = c(dplyr::all_of(metric), "contrasts")) |>
dplyr::select("method", dplyr::all_of(as.vector(outer(c(metric, "contrasts"), summary_datasets, paste, sep = "_"))))
}
# two header rows: each dataset over its score and its contrasts computed
summary_header <- function(metric) {
htmltools::withTags(table(thead(
tr(
th(rowspan = 2, "method"),
lapply(summary_datasets, function(d) th(colspan = 2, d)),
th(rowspan = 2, "median")
),
tr(lapply(summary_datasets, function(d) list(th(metric), th("contrasts computed"))))
)))
}
cat("::: {.panel-tabset}\n\n")
for (metric in c("pAUC_10", "pAUC_5")) {
cat("\n\n## ", metric, "\n\n", sep = "")
summary_scores <- summary_table(metric)
summary_scores$median <- apply(summary_scores[paste0(metric, "_", summary_datasets)], 1, stats::median, na.rm = TRUE)
print_table(
summary_scores[order(summary_scores$median, decreasing = TRUE), ],
caption = paste0(
metric, " of every method on every dataset, ranking by p-value signed by the fold change (scaled.p_value), ",
"all contrasts of a dataset pooled; empty where the dataset does not provide the method's input. Sorted by the ",
"median over the datasets the method ran on. ", metric, ": partial area under the ROC curve up to a false ",
"positive rate of ", if (metric == "pAUC_10") "0.1" else "0.05", ". Next to each score, contrasts computed: the ",
"protein and contrast pairs with a p-value, which the method is scored on; the Pareto front tab of each dataset ",
"compares the methods on the same pairs."
),
page_length = 20,
container = summary_header(metric)
)
}
cat("\n\n:::\n\n")
```
# Benchresults
:::: {.panel-tabset}
```{r datasets, results = "asis"}
# one tab per dataset, each with the same sub-tabs
for (dataset_name in datasets$dataset) {
cat("\n\n## ", dataset_name, "\n\n::: {.panel-tabset}\n\n### Data\n\n", sep = "")
cat(datasets$description[datasets$dataset == dataset_name], "; input: ",
datasets$input_file[datasets$dataset == dataset_name], ".\n\n", sep = "")
cat(paste0("- ", preprocessing$step[preprocessing$dataset == dataset_name], "\n"), "\n", sep = "")
dataset_scores <- dplyr::filter(scores, .data$dataset == dataset_name)
positive <- datasets$positive[datasets$dataset == dataset_name]
negative <- datasets$negative[datasets$dataset == dataset_name]
n_contrasts <- length(setdiff(unique(dataset_scores$contrast), "all"))
pooled <- if (n_contrasts == 1) "one contrast" else paste("all", n_contrasts, "contrasts pooled")
cat("\n\n### Scores\n\n")
computed <- dataset_scores |>
dplyr::filter(.data$contrast == "all", .data$score == "scaled.p_value") |>
dplyr::select(model = "model_name", `contrasts computed` = "n_total")
dataset_scores |>
dplyr::filter(.data$contrast == "all") |>
tidyr::pivot_longer(c("AUC", "pAUC_10"), names_to = "metric", values_to = "value") |>
tidyr::unite("column", "metric", "score", sep = " / ") |>
dplyr::select(model = "model_name", "level", "column", "value") |>
tidyr::pivot_wider(names_from = "column", values_from = "value", names_sort = TRUE) |>
dplyr::left_join(computed, by = "model") |>
dplyr::relocate("contrasts computed", .after = "level") |>
dplyr::arrange(dplyr::desc(.data$`pAUC_10 / scaled.p_value`)) |>
print_table(
caption = paste0(
"Ranking scores on ", dataset_name, ", ", pooled, ", sorted by pAUC_10 of scaled.p_value. AUC is the ",
"area under the ROC curve and pAUC_10 the partial area up to a false positive rate of 0.1, both on a 0 to ",
"100 scale, for ranking by fold change, scaled p-value and t statistic. Contrasts computed: protein and ",
"contrast pairs with a p-value."
),
page_length = 20
)
cat("\n\n### Pareto front\n\n")
pauc_5 <- dataset_scores |>
dplyr::filter(.data$contrast == "all") |>
dplyr::select("model_name", "score", "pAUC_5", contrasts = "n_total") |>
dplyr::mutate(method = .data$model_name)
front <- pauc_5 |>
dplyr::filter(prolfquabenchmark::pareto_optimal(.data$pAUC_5, .data$contrasts), .by = "score") |>
dplyr::arrange(.data$score, .data$pAUC_5)
print_with_height(
ggplot2::ggplot(pauc_5, ggplot2::aes(x = pAUC_5, y = contrasts, colour = method, shape = method)) +
ggplot2::geom_step(data = front, ggplot2::aes(x = pAUC_5, y = contrasts), direction = "vh",
colour = "#e34948", linewidth = 1, inherit.aes = FALSE) +
ggplot2::geom_point(size = 3) +
ggrepel::geom_text_repel(
ggplot2::aes(label = method),
colour = "grey20",
size = 3,
segment.colour = "grey60",
min.segment.length = 0,
box.padding = 0.6,
force = 6,
max.overlaps = Inf,
show.legend = FALSE,
seed = 1
) +
ggplot2::scale_y_continuous(expand = ggplot2::expansion(mult = c(0.15, 0.4))) +
ggplot2::facet_wrap(~score, ncol = 1) +
ggplot2::labs(x = "pAUC_5 (all contrasts pooled)", y = "contrasts computed (protein and contrast pairs)",
title = paste(dataset_name, "pAUC_5 vs contrasts computed")) +
method_style(pauc_5$method),
height = 11,
caption = paste0(
"Ranking accuracy against the number of contrasts computed on ", dataset_name, ". Each point is one method. ",
"x: pAUC_5, the partial area under the ROC curve up to a false positive rate of 0.05 (0 to 100), ", pooled,
"; the ROC curve separates ", positive, " proteins (changed) from ", negative, " proteins (unchanged). ",
"y: contrasts computed, the protein and contrast pairs with a result. Panels rank proteins by fold change ",
"(log_fc), by p-value signed by the fold change (scaled.p_value) and by t statistic. Colour: model family as ",
"in the prolfqua factory figure; shape: model within its family; grey open shapes: external tools. ",
"The red staircase is the Pareto front: ",
"no other method has both a higher pAUC_5 and more contrasts computed."
)
)
dataset_same <- dplyr::filter(same_pairs, .data$dataset == dataset_name, .data$score == "scaled.p_value")
if (nrow(dataset_same) > 0) {
# one panel per set of contrasts, each with its own x axis; labels alternate above and below the line
dataset_same <- dataset_same |>
dplyr::mutate(panel = paste0(.data$front_method, ": ", .data$contrasts, " contrasts")) |>
dplyr::arrange(dplyr::desc(.data$contrasts), .data$pAUC_5) |>
dplyr::mutate(panel = factor(.data$panel, levels = unique(.data$panel)), y = 0) |>
dplyr::mutate(label_y = ifelse(seq_along(.data$pAUC_5) %% 2 == 1, 0.55, -0.55), .by = "panel")
lines <- dataset_same |>
dplyr::summarize(from = min(.data$pAUC_5), to = max(.data$pAUC_5), .by = "panel")
front_points <- dplyr::filter(dataset_same, .data$method == .data$front_method)
print_with_height(
ggplot2::ggplot(dataset_same, ggplot2::aes(x = pAUC_5, y = y, colour = method, shape = method)) +
ggplot2::geom_segment(data = lines, ggplot2::aes(x = from, xend = to, y = 0, yend = 0),
colour = "grey40", linetype = "dashed", inherit.aes = FALSE) +
ggplot2::geom_point(size = 3) +
ggplot2::geom_point(data = front_points, ggplot2::aes(x = pAUC_5, y = y),
shape = 21, size = 5.5, stroke = 1.2, colour = "#e34948", inherit.aes = FALSE) +
ggrepel::geom_text_repel(
ggplot2::aes(label = method),
nudge_y = dataset_same$label_y,
direction = "x",
colour = "grey20",
size = 3,
segment.colour = "grey60",
min.segment.length = 0,
max.overlaps = Inf,
show.legend = FALSE,
seed = 1
) +
ggplot2::scale_y_continuous(limits = c(-1, 1), breaks = NULL) +
ggplot2::facet_wrap(~panel, ncol = 1, scales = "free_x") +
ggplot2::labs(x = "pAUC_5 on the panel's contrasts (all contrasts pooled)", y = NULL,
title = paste(dataset_name, "same contrasts, ranking by scaled.p_value")) +
method_style(dataset_same$method),
height = 1 + 1.6 * dplyr::n_distinct(dataset_same$panel),
caption = paste0(
"Ranking accuracy on the same contrasts on ", dataset_name, ", ranking by scaled p-value. Each panel is one ",
"set of contrasts: those computed by a method on the Pareto front of the figure above (red circle), with ",
"their number in the panel title. On the dashed line are the methods that compute all these contrasts, the ",
"same or more, scored on these contrasts only (pAUC_5, ", pooled, "); each panel has its own x axis. A method ",
"to the right of the red circle ranks these contrasts better: the front method's position then comes from ",
"computing fewer, easier contrasts rather than from ranking them better."
)
)
}
cat("\n\n### ROC\n\n")
dataset_curves <- dplyr::filter(curves, .data$dataset == dataset_name)
print_with_height(
ggplot2::ggplot(dplyr::filter(dataset_curves, .data$curve == "ROC"),
ggplot2::aes(x = x, y = y, colour = method, linetype = method)) +
ggplot2::geom_step() +
ggplot2::coord_cartesian(xlim = c(0, 0.2)) +
ggplot2::facet_wrap(~score) +
ggplot2::labs(x = "false positive rate", y = "true positive rate", title = paste(dataset_name, "ROC")) +
method_style(dataset_curves$method),
height = 4.5,
caption = paste0(
"ROC curves on ", dataset_name, ", ", pooled, ". y: fraction of ", positive, " proteins (changed) ranked ",
"above a threshold, the true positive rate; x: fraction of ", negative, " proteins (unchanged) above it, ",
"the false positive rate, shown up to 0.2. One curve per method; panels rank by fold change, scaled ",
"p-value and t statistic. Colour: model family as in the prolfqua factory figure; line type: model within its ",
"family; grey: external tools."
)
)
cat("\n\n### Calibration\n\n")
print_with_height(
ggplot2::ggplot(dplyr::filter(dataset_curves, .data$curve == "FDP"),
ggplot2::aes(x = x, y = y, colour = method, linetype = method)) +
ggplot2::geom_abline(colour = "grey60") +
ggplot2::geom_step() +
ggplot2::labs(x = "nominal FDR", y = "false discovery proportion", title = paste(dataset_name, "FDP vs FDR")) +
method_style(dataset_curves$method),
height = 4.5,
caption = paste0(
"Calibration of the FDR each method reports on ", dataset_name, ", ", pooled, ". x: nominal FDR threshold; ",
"y: fraction of ", negative, " proteins (unchanged) among the proteins called significant at that ",
"threshold, the false discovery proportion. One curve per method, colours and line types as in the ROC figure. ",
"A calibrated FDR lies on the grey diagonal; curves above it are anti-conservative, with more false ",
"discoveries than the FDR promises."
)
)
cat("\n\n:::\n\n")
}
```
::::
:::::