Skip to content

Test pathways with a defensible protein background

A pathway test depends on which proteins could have entered its foreground. The whole genome is not the sampling background for a filtered proteomics experiment. We use the eligible tested protein groups that also meet a declared annotation rule.

This lesson uses the accepted differential table and a preserved human membership file from Reactome release 98. The source contains memberships at all levels of the pathway hierarchy.

A protein group contributes at most one observation to a pathway. Expanding a shared group into several gene names would count one measured signal several times and alter the test’s denominator.

The mapping retains every member accession. A group is eligible only when every member has a reviewed human UniProt accession and the same nonempty Reactome membership set. Groups with incompatible or missing member annotations remain in an exclusion table with their membership and reason. This conservative rule can discard useful measurements, but it prevents an arbitrary representative accession from deciding the pathway assignment.

We apply the same mapping rule to the foreground and background. Keeping an ambiguous group only when it appears significant would bias the test toward the desired conclusion.

The join reports the number of tested groups, mapped groups, excluded groups, and pathway memberships before enrichment. Those losses describe the part of the measured proteome that the interpretation can represent.

The foreground uses the declared differential threshold among mapped tested groups. The background contains all mapped eligible tested groups, including the foreground. Both sets use protein-group identifiers rather than duplicated accessions.

For each pathway, a one-sided hypergeometric test asks whether the foreground contains more members than expected under sampling from that background. The family contains every pathway with 5 to 500 background groups, including pathways with no foreground hits. The analysis applies BH once across that complete family.

The R and Python examples use the same memberships, foreground, background, size limits, and alternative hypothesis. Their overlap counts, p-values, and adjusted p-values must agree within the recorded tolerances.

Reactome pathways overlap and include parent-child relationships. Several small adjusted p-values can arise from the same group of proteins. They do not establish several independent mechanisms.

An enrichment result also lacks a direct activity measurement. Higher abundance of pathway members does not prove higher pathway flux or signaling activity. We inspect the contributing groups, their effect directions, and their culture-level measurements before attaching a biological interpretation.

The figure reports pathway size, foreground overlap, and the adjusted p-value. Its companion table retains the exact contributing groups. The source and license are available through Reactome’s download documentation and data license.

The foreground contains mapped tested groups with a moderated differential BH value below 0.05, regardless of effect direction. The test therefore concerns an excess of differential groups, not increased pathway activity. The contributor table retains each group’s signed effect for interpretation.

R regenerates the declared primary limma model from the accepted fixtures. Python verifies the ordinary model and then reads that fresh moderated table to define exactly the same foreground. It independently calculates all pathway overlaps, hypergeometric probabilities, and pathway BH values.

The measured background contains 406 mapped tested groups, and the foreground contains 150 differential groups. The complete family contains 448 pathways and produces 0 adjusted findings.

These tests support no pathway enrichment claim for this contrast under the declared mapping and background rules.

The display orders pathways by adjusted p-value, then foreground overlap. In this cohort, the displayed categories describe membership overlap without an adjusted enrichment finding.

library(ggplot2)
library(jsonlite)
source("/shared/ms_common.R")
source("/shared/ms_models.R")
data <- PrepareMsAnalysis(LoadMsData())
primary <- FitMsLimma(data)
WriteMsModelProvenance("outputs/model_provenance_r.json")
primary$members <- data$groups$members
write.csv(primary, "outputs/primary_limma_r.csv", row.names = FALSE,
na = "NA")
write.csv(FitMsOrdinary(data), "outputs/ordinary_r.csv", row.names = FALSE,
na = "NA")
mapping <- read.delim("/fixtures/pathway_mapping.tsv",
colClasses = "character", quote = "")
membership <- read.delim("/fixtures/pathway_membership.tsv",
colClasses = "character", quote = "")
stopifnot(identical(mapping$group_id, primary$group_id))
pathways <- TestMsPathways(primary, mapping, membership)
result <- pathways$results
write.csv(result, "outputs/pathway_tests_r.csv", row.names = FALSE)
write.csv(data.frame(group_id = pathways$background),
"outputs/pathway_background_r.csv", row.names = FALSE)
write.csv(data.frame(group_id = pathways$selected),
"outputs/pathway_foreground_r.csv", row.names = FALSE)
statuses <- sort(unique(mapping$mapping_status))
mapping_summary <- data.frame(
mapping_status = statuses, all_groups = integer(length(statuses)),
tested_groups = integer(length(statuses))
)
for (index in seq_along(statuses)) {
same_status <- mapping$mapping_status == statuses[index]
mapping_summary$all_groups[index] <- sum(same_status)
mapping_summary$tested_groups[index] <- sum(same_status & primary$tested)
}
write.csv(mapping_summary, "outputs/mapping_summary_r.csv", row.names = FALSE)
contributors <- membership[membership$group_id %in% pathways$selected &
membership$pathway_id %in% result$pathway_id, ]
contributors <- merge(contributors,
primary[c("group_id", "members", "log2_fold_change",
"adjusted_p_value")], by = "group_id")
contributors <- contributors[order(contributors$pathway_id,
contributors$group_id), ]
write.csv(contributors, "outputs/pathway_contributors_r.csv", row.names = FALSE)
metrics <- list(
tested_groups = sum(primary$tested),
background_groups = length(pathways$background),
foreground_groups = length(pathways$selected),
tested_pathways = nrow(result),
significant_pathways = sum(result$adjusted_p_value < 0.05)
)
write_json(metrics, "outputs/metrics_r.json", auto_unbox = TRUE)
cat("Tested protein groups:", metrics$tested_groups, "\n")
cat("Mapped background groups:", metrics$background_groups, "\n")
cat("Mapped differential groups:", metrics$foreground_groups, "\n")
cat("Pathways in the BH family:", metrics$tested_pathways, "\n")
cat("Pathways below BH 0.05:", metrics$significant_pathways, "\n")
Tested protein groups: 463
Mapped background groups: 406
Mapped differential groups: 150
Pathways in the BH family: 448
Pathways below BH 0.05: 0
display <- result[order(result$adjusted_p_value, -result$selected_hits,
result$pathway_id), ]
display <- head(display, 12L)
if (nrow(display)) {
display$label <- paste(display$pathway_id,
substr(display$pathway_name, 1, 50))
display$label <- factor(display$label, levels = rev(display$label))
display$score <- -log10(pmax(display$adjusted_p_value,
.Machine$double.xmin))
enrichment <- ggplot(display,
aes(selected_hits, label,
size = pathway_background_groups,
color = score)) +
geom_point() + scale_size_area(max_size = 8) +
scale_color_gradient(low = "#b9d4dc", high = "#1c6377") +
labs(x = "Differential protein groups", y = NULL,
size = "Background groups", color = "-log10 BH") +
theme_minimal(base_size = 9)
} else {
enrichment <- ggplot() +
annotate("text", x = 0, y = 0,
label = "No pathways meet the declared background size filter") +
theme_void()
}
ggsave("outputs/pathway_enrichment_r.png", enrichment, width = 11,
height = 6.5, dpi = 160, bg = "white")
mapping_plot <- ggplot(
mapping_summary, aes(tested_groups, reorder(mapping_status, tested_groups))
) +
geom_col(fill = "#287c8e") +
labs(x = "Tested protein groups", y = "Annotation decision") +
theme_minimal(base_size = 10)
ggsave("outputs/pathway_mapping_r.png", mapping_plot, width = 10,
height = 4.5, dpi = 160, bg = "white")

The plot shows pathway tests within the declared measured background.

The bars show protein group counts for each pathway mapping decision.

The pathway table retains zero-hit tests and the mapping table retains excluded groups. When the differential foreground is empty, every tested pathway has a hypergeometric p-value of one. That result remains a valid output rather than a reason to change the foreground threshold.

Reactome’s license agreement assigns CC0 to database data and CC BY 4.0 to its pathway illustrations. The membership file used here is data. These terms differ from the licenses for Reactome software.

The Reactome data agreement distinguishes its database data from illustrations and software. It identifies the terms that apply to the pathway membership table used here.

The R p-value adjustment reference explains BH correction. Read it alongside the declared pathway family and the observed protein universe; the adjustment cannot repair a biased universe.