Skip to content

Review sample quality and normalization

Normalization changes the reference against which abundance differences are measured. A sample median shift can remove a loading difference, but the same shift can remove biology when many measured proteins move together. We preserve the offsets and examine the assumption before fitting a model.

This lesson starts from the verified OpenMS abundance table. The primary workflow explains why the refined QPX peptide sums are a separate export.

Review the measurement before the transformation

Section titled “Review the measurement before the transformation”

The review connects each complete raw run to its culture and condition. It examines spectrum counts, identification yield, mass error, feature intensity, missingness, and the number of protein groups with usable abundance.

No single measure establishes acceptable quality. A low identification count can reflect sample composition or a technical failure. A large total signal can reflect loading or a few abundant peptides. The review uses several measurements from the same run and records the evidence for each concern.

The cohort has no separate blank or pooled QC series. We therefore cannot use blank subtraction or a pooled reference to establish contamination or acquisition drift. Potential contaminant flags and run diagnostics remain useful, with that limit stated.

We inspect the exporter before converting absent values. A structural zero that means no quantified feature becomes missing for the log transformation. A finite positive measurement remains a measurement. Invalid negative values and nonfinite values cause an input failure.

The canonical matrix keeps one row per protein group and one column per culture. It preserves sample order and all member accessions. An absent measurement never becomes zero after log transformation.

Estimate offsets from one declared reference set

Section titled “Estimate offsets from one declared reference set”

The normalization reference contains accepted noncontaminant target groups with two group-unique peptide sequences and measured abundance in all six cultures. Using the same rows in every sample prevents a different missing subset from defining each median.

We transform positive abundance to log2 units. For each culture, we calculate its median over the reference set, then subtract the difference from the median of those six medians. The resulting offset table records the adjustment applied to every observed value in that culture.

The implementation stops if fewer than twenty accepted complete groups define the reference. This declared minimum prevents an adjustment from depending on only a few groups. The review still examines the reference distribution and the consequences of the offsets.

The figures show distributions before and after the adjustment, sample correlations, and a PCA of complete protein groups. The PCA uses the same rows across samples and does not fill missing entries for a better-looking projection.

The differential lesson compares normalized and unnormalized effects. It also reports the offset range, because a large global adjustment changes the interpretation of the contrast. The result remains relative to the measured reference distribution rather than an absolute protein concentration.

An unusual sample is not excluded because it weakens a condition difference. Exclusion requires a specific technical reason, a recorded sample identity, and a new description of the resulting design. The missing-value lesson then separates absent measurements from evidence of biological absence.

Inspect the common reference and all six cultures

Section titled “Inspect the common reference and all six cultures”

The executable comparison preserves every normalized value and checks it across languages. The correlation matrix and PCA use the common complete reference. Their displayed coordinates are exploratory summaries, while the separate run table preserves acquisition totals and the final supported identification counts.

The run diagnostics count distinct spectra in the final PSM export, divided by the raw MS2 count. This fraction describes the retained identification evidence after the complete workflow. It does not recover matches removed by earlier filters.

The mass-error intervals span the fifth through ninety-fifth percentiles of the final PSM errors. They use the exported experimental and calculated precursor masses without isotope correction. Their width is a diagnostic, not a replacement for the executed search tolerance.

Resistant cultures have lower identification yield and more missing measurements than parental cultures. The review retains all six cultures because no single run has a demonstrated technical failure.

The resulting comparison concerns observed protein groups under the declared reference normalization. It cannot establish an absolute change in total protein amount.

The displayed mass intervals use the unadjusted fields exported by OpenMS. They include the allowed isotope offset and the neutral hydrogen convention in the pinned pepXML importer.

The companion audit checks native selected-ion m/z values against the executed search settings. Do not interpret the unadjusted percentile range as calibration error after isotope adjustment.

library(ggplot2)
library(jsonlite)
source("/shared/ms_common.R")
data <- PrepareMsAnalysis(LoadMsData())
samples <- data$samples
quality <- read.delim("/fixtures/run_qc.tsv", check.names = FALSE)
stopifnot(identical(quality$sample_id, samples$sample_id))
stopifnot(all(quality$ms1_spectra > 0), all(quality$ms2_spectra > 0))
psms <- read.delim(gzfile("/fixtures/psm_evidence.tsv.gz"),
check.names = FALSE)
stopifnot(setequal(psms$sample_id, samples$sample_id),
all(is.finite(psms$precursor_error_ppm_unadjusted)),
all(psms$final_psm_q_value >= 0 & psms$final_psm_q_value <= 0.01))
quality$precursor_error_q05 <- NA_real_
quality$precursor_error_q95 <- NA_real_
for (index in seq_len(nrow(samples))) {
selected <- psms[psms$sample_id == samples$sample_id[index], ]
errors <- selected$precursor_error_ppm_unadjusted
stopifnot(nrow(selected) == quality$final_supported_psms[index],
length(unique(selected$spectra_ref)) ==
quality$final_supported_spectra[index],
abs(median(errors) -
quality$median_precursor_error_ppm_unadjusted[index]) < 1e-10)
quality$precursor_error_q05[index] <- quantile(errors, 0.05, names = FALSE)
quality$precursor_error_q95[index] <- quantile(errors, 0.95, names = FALSE)
}
quality$supported_spectrum_fraction <- quality$final_supported_spectra /
quality$ms2_spectra
quality$measured_candidate_groups <- colSums(
is.finite(data$log_abundance[data$candidate, , drop = FALSE])
)
quality$candidate_missing_fraction <- 1 - quality$measured_candidate_groups /
sum(data$candidate)
stopifnot(all(quality$supported_spectrum_fraction <= 1),
all(quality$quantified_groups == colSums(is.finite(data$abundance))))
write.csv(quality, "outputs/run_diagnostics_r.csv", row.names = FALSE)
offsets <- data.frame(sample_id = samples$sample_id,
median_offset_log2 = unname(data$offsets))
write.csv(offsets, "outputs/median_offsets_r.csv", row.names = FALSE)
normalized <- data.frame(group_id = data$groups$group_id,
data$normalized, check.names = FALSE)
write.csv(normalized, "outputs/normalized_abundance_r.csv", row.names = FALSE,
na = "NA")
reference <- data$normalized[data$reference, , drop = FALSE]
correlations <- cor(reference)
stopifnot(all(is.finite(correlations)))
write.csv(correlations, "outputs/sample_correlations_r.csv")
distances <- as.matrix(dist(t(reference)))
write.csv(distances, "outputs/sample_distances_r.csv")
pca <- prcomp(t(reference), center = TRUE, scale. = FALSE)
variance <- pca$sdev^2 / sum(pca$sdev^2)
stopifnot(all(is.finite(variance)))
scores <- data.frame(samples[, c("sample_id", "condition")],
PC1 = pca$x[, 1], PC2 = pca$x[, 2])
metrics <- list(
reference_groups = sum(data$reference),
offset_range_log2 = diff(range(data$offsets)),
pc1_variance = variance[1], pc2_variance = variance[2],
minimum_sample_correlation = min(correlations[upper.tri(correlations)])
)
write_json(metrics, "outputs/metrics_r.json", auto_unbox = TRUE, digits = 16)
cat("Complete groups in the normalization reference:",
metrics$reference_groups, "\n")
cat(sprintf("Range of sample offsets: %.6f log2 units\n",
metrics$offset_range_log2))
cat(sprintf("Minimum sample correlation: %.6f\n",
metrics$minimum_sample_correlation))
Complete groups in the normalization reference: 341
Range of sample offsets: 0.989848 log2 units
Minimum sample correlation: 0.528431
run_diagnostics <- data.frame(
sample_id = rep(samples$sample_id, 3),
measurement = rep(c("Supported MS2 fraction", "Candidate missing fraction",
"Unadjusted precursor error, ppm"), each = 6),
value = c(quality$supported_spectrum_fraction,
quality$candidate_missing_fraction,
quality$median_precursor_error_ppm_unadjusted),
lower = c(rep(NA_real_, 12), quality$precursor_error_q05),
upper = c(rep(NA_real_, 12), quality$precursor_error_q95)
)
run_diagnostics$sample_id <- factor(run_diagnostics$sample_id,
levels = samples$sample_id)
diagnostic_plot <- ggplot(run_diagnostics, aes(sample_id, value)) +
geom_point(color = "#286b86", size = 2.5) +
geom_linerange(aes(ymin = lower, ymax = upper), na.rm = TRUE) +
facet_wrap(~measurement, scales = "free_y", nrow = 1) +
labs(x = "Culture", y = NULL, title = "Complete runs and retained evidence") +
theme_minimal(base_size = 10) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggsave("outputs/run_diagnostics_r.png", diagnostic_plot,
width = 12, height = 4.7, dpi = 160, bg = "white")
raw <- data$log_abundance[data$reference, , drop = FALSE]
distributions <- data.frame(
sample_id = rep(samples$sample_id, each = nrow(raw), times = 2),
log2_abundance = c(as.vector(raw), as.vector(reference)),
scale = rep(c("Raw log2", "Median adjusted"), each = length(raw))
)
distributions$sample_id <- factor(distributions$sample_id,
levels = samples$sample_id)
boxplot <- ggplot(distributions, aes(sample_id, log2_abundance)) +
geom_boxplot(fill = "#c6dce5", outlier.size = 0.4) +
facet_wrap(~scale, nrow = 1) +
labs(x = "Culture", y = "Log2 abundance",
title = "The same complete reference groups before and after scaling") +
theme_minimal(base_size = 10) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggsave("outputs/reference_distributions_r.png", boxplot,
width = 11, height = 4.7, dpi = 160, bg = "white")
score_plot <- ggplot(scores, aes(PC1, PC2, color = condition)) +
geom_point(size = 3) +
ggrepel::geom_text_repel(aes(label = sample_id), size = 3, seed = 73,
box.padding = 0.4, show.legend = FALSE) +
scale_color_manual(values = c("#286b86", "#b85c38")) +
scale_x_continuous(expand = expansion(mult = 0.12)) +
scale_y_continuous(expand = expansion(mult = 0.12)) +
labs(x = sprintf("PC1, %.1f%%", variance[1] * 100),
y = sprintf("PC2, %.1f%%", variance[2] * 100),
color = "Condition", title = "Complete reference groups after scaling") +
theme_minimal(base_size = 11)
ggsave("outputs/sample_pca_r.png", score_plot,
width = 8, height = 5, dpi = 160, bg = "white")
correlation_data <- as.data.frame(as.table(correlations))
correlation_plot <- ggplot(correlation_data, aes(Var1, Var2, fill = Freq)) +
geom_tile() + geom_text(aes(label = sprintf("%.2f", Freq)), size = 3) +
scale_fill_gradient(low = "#edf3f5", high = "#4489a4") +
labs(x = NULL, y = NULL, fill = "Correlation",
title = "Pearson correlation across the common reference") +
theme_minimal(base_size = 10) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggsave("outputs/sample_correlations_r.png", correlation_plot,
width = 7, height = 6, dpi = 160, bg = "white")

The panels show supported spectra, missing abundance, and unadjusted precursor error for each culture.

The boxplots compare log2 abundance before and after sample median normalization.

The PCA plot shows the cultures in the first two components.

The heatmap shows culture correlations across the common reference.

The pinned OpenMS PepXML reader shows how precursor neutral masses enter the identification records. Read it when checking the mass-error calculation against the source format.

The pinned OpenMS ProteomicsLFQ implementation describes feature normalization and protein quantification settings. It provides the source definition needed before applying the downstream normalization shown here.