Skip to content

Inspect detected and aligned ion features

A feature links an ion’s mass trace to a chromatographic peak. The primary workflow detects those features in each injection, aligns their retention times, and links corresponding observations across injections. Each operation adds a different assumption. A smooth chromatogram cannot establish correct correspondence across every sample.

The examples use the same accepted OpenMS feature maps. R and Python independently check the exported matrix and calculate the diagnostic summaries. They do not repeat peak detection with two unrelated algorithms.

The matrix contains one row per linked ion feature and one column per quantification injection. A positive value represents an observed integrated area. NA means that the linked feature has no observation in that injection. The preparation verifies each observed area against its original FeatureFinderMetabo record before these examples read it.

The upstream pyOpenMS 2.9.1 table fills absent observations with 0.0. The complete audit checks those entries against the consensus handles. The teaching matrix derives its missing values from absent handles, so an export placeholder never becomes a measured zero.

The analysis interval starts at 0.6 seconds and excludes 1,080 seconds and later. The deposited protocol places lithium-formate calibration at 18 minutes. The preparation excludes a linked feature when its consensus apex or any original observed apex falls outside this interval. It preserves every excluded identifier and the original time range in a separate table. The complete source spectra remain intact.

Alignment changes the time coordinate, so an early original apex can acquire a negative aligned time. The audit checks each transformed value against its original apex and saved transformation. A negative aligned value does not mean that the instrument recorded a negative acquisition time.

The source data are Dietz and colleagues’ MTBLS865 deposit, released publicly by MetaboLights in 2020 under EMBL-EBI Terms of Use. The repository’s public data policy permits reuse, and its data guide permits modification. The source notice identifies the authors, original files, and this analysis’s selection and transformations.

library(ggplot2)
library(jsonlite)
source("/shared/validate_fixtures.R")
ValidateFixtures(c("sample_metadata.tsv", "features.tsv.gz",
"feature_intensities.tsv.gz", "feature_observations.tsv.gz",
"excluded_features.tsv.gz",
"representative_chromatograms.tsv.gz"))
metadata <- read.delim("/fixtures/sample_metadata.tsv")
features <- read.delim(gzfile("/fixtures/features.tsv.gz"),
colClasses = c(feature_id = "character"))
area_table <- read.delim(gzfile("/fixtures/feature_intensities.tsv.gz"),
colClasses = c(feature_id = "character"),
check.names = FALSE)
observations <- read.delim(gzfile("/fixtures/feature_observations.tsv.gz"),
colClasses = c(feature_id = "character",
source_feature_id = "character",
adduct_group = "character"))
excluded <- read.delim(gzfile("/fixtures/excluded_features.tsv.gz"),
colClasses = c(feature_id = "character"))
selected_ids <- metadata$injection_id[metadata$role != "system_suitability"]
stopifnot(identical(area_table$feature_id, features$feature_id))
stopifnot(identical(names(area_table)[-1], selected_ids))
stopifnot(!anyDuplicated(features$feature_id))
stopifnot(!anyDuplicated(observations[c("feature_id", "injection_id")]))
stopifnot(!anyDuplicated(observations[c("injection_id", "source_feature_id")]))
areas <- as.matrix(area_table[, -1])
positions <- cbind(match(observations$feature_id, features$feature_id),
match(observations$injection_id, selected_ids))
stopifnot(!anyNA(positions), sum(is.finite(areas)) == nrow(observations))
relative_error <- abs(areas[positions] - observations$intensity) /
observations$intensity
stopifnot(all(is.finite(relative_error)), max(relative_error) < 1e-6)
stopifnot(all(areas[is.finite(areas)] > 0))
stopifnot(!any(excluded$feature_id %in% features$feature_id))
stopifnot(all(observations$original_retention_time_seconds >= 0.6))
stopifnot(all(observations$original_retention_time_seconds < 1080))
qc_ids <- metadata$injection_id[metadata$role == "pooled_qc"]
qc <- observations[observations$injection_id %in% qc_ids, ]
frequency <- table(qc$feature_id)
qc <- qc[qc$feature_id %in% names(frequency)[frequency >= 2L], ]
stopifnot(nrow(qc) > 0L)
qc$before_residual_seconds <- qc$original_retention_time_seconds -
ave(qc$original_retention_time_seconds, qc$feature_id, FUN = median)
qc$after_residual_seconds <- qc$aligned_retention_time_seconds -
ave(qc$aligned_retention_time_seconds, qc$feature_id, FUN = median)
residuals <- qc[, c("feature_id", "injection_id", "before_residual_seconds",
"after_residual_seconds")]
write.csv(residuals, "outputs/retention_residuals_r.csv", row.names = FALSE)
metrics <- list(features = nrow(features), observations = nrow(observations),
missing_cells = sum(is.na(areas)),
excluded_features = nrow(excluded),
qc_residuals = nrow(residuals),
before_rms = sqrt(mean(qc$before_residual_seconds^2)),
after_rms = sqrt(mean(qc$after_residual_seconds^2)))
write_json(metrics, "outputs/metrics_r.json", auto_unbox = TRUE, digits = 16)
cat(sprintf("Retained features: %d\n", metrics$features))
cat(sprintf("Observed areas and absent observations: %d %d\n",
metrics$observations, metrics$missing_cells))
cat(sprintf("Features outside the analysis interval: %d\n",
metrics$excluded_features))
cat(sprintf("QC retention RMS before and after alignment: %.6f %.6f s\n",
metrics$before_rms, metrics$after_rms))
Retained features: 96101
Observed areas and absent observations: 219881 2663149
Features outside the analysis interval: 15097
QC retention RMS before and after alignment: 8.285782 8.274222 s
chromatograms <- read.delim(
gzfile("/fixtures/representative_chromatograms.tsv.gz"),
colClasses = c(feature_id = "character")
)
stopifnot(length(unique(chromatograms$feature_id)) == 1L)
stopifnot(setequal(unique(chromatograms$injection_id), qc_ids))
stopifnot(all(is.finite(chromatograms$intensity)))
stopifnot(all(chromatograms$intensity >= 0))
chromatogram_plot <- ggplot(
chromatograms, aes(aligned_retention_time_seconds, intensity,
color = injection_id)
) +
geom_line(linewidth = 0.6) + scale_color_viridis_d() +
labs(x = "Aligned retention time in seconds", y = "Ion signal",
color = "QC injection", title = "One mass channel across eight QCs") +
theme_minimal(base_size = 12)
ggsave("outputs/feature_chromatograms_r.png", chromatogram_plot,
width = 8.5, height = 5, dpi = 160, bg = "white")
residual_plot <- ggplot(qc, aes(before_residual_seconds,
after_residual_seconds)) +
geom_point(size = 0.7, alpha = 0.25, color = "#286b86") +
geom_abline(slope = 1, intercept = 0, linetype = "dotted") +
geom_hline(yintercept = 0, color = "#87919c") +
geom_vline(xintercept = 0, color = "#87919c") +
labs(x = "Original QC deviation in seconds",
y = "Aligned QC deviation in seconds",
title = "Each deviation uses its feature's median QC time") +
theme_minimal(base_size = 12)
ggsave("outputs/retention_residuals_r.png", residual_plot, width = 6.5,
height = 5.5, dpi = 160, bg = "white")

The representative mass channel preserves separate signals from all eight pooled QC injections.

Original and aligned QC retention deviations describe the accepted linked observations.

Interpret the chromatogram before its area

Section titled “Interpret the chromatogram before its area”

The representative feature appears in all eight pooled QCs and has room for a 30-second window on either side of every original apex. The selection ranks eligible features by median raw QC area, then mass, retention time, and identifier. It does not use biological effect estimates or p-values.

Each trace sums centroid signals within 10 ppm of that injection’s feature mass and within the fixed time window. The workflow’s actual retention transformation places the traces on the shared axis. These traces reveal peak shape, multiple nearby peaks, and inconsistent correspondence. Their unsmoothed channel signal does not reproduce FeatureFinderMetabo’s smoothed mass-trace area by definition.

The executed channel contains more than one nearby peak. Its repeated shape across QCs does not establish a single compound or prove correspondence across the biological samples.

MapAlignerPoseClustering fits retention transformations to a shared reference. The residual figure centers each feature on its median observed QC time before and after transformation. It describes the dispersion of the linked observations.

The executed FeatureLinkerUnlabeledKD also enables internal LOWESS warping before linking. Its linking parameters use 30 seconds and 10 ppm. The OpenMS 3.0.0 implementation preserves the input feature times in its reported consensus, while it uses separate warped coordinates internally. Here those input times already include the MapAligner transformation.

The residual figure therefore describes the exported MapAligner coordinates, not the linker’s internal LOWESS coordinates. Its near-diagonal pattern shows little change in those exported deviations. It is not an independent benchmark of correct identity. The primary review also inspects transformation landmarks, chromatographic overlays, missing observations, and proposed adduct groups. Background and reproducibility then determine which features enter the quality filters.

  • OpenMS 3.0.0 MapAlignerPoseClustering source

    The original implementation selects a reference, estimates transformations, and writes aligned feature maps and transformation files. It identifies which coordinate change occurs before feature linking.

  • OpenMS 3.0.0 feature-linking implementation

    The pinned source applies internal LOWESS warping but inserts original feature handles into its consensus output. This distinction explains the limits of exported retention-time residuals.