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.
Check every observed area
Section titled “Check every observed area”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$intensitystopifnot(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: 96101Observed areas and absent observations: 219881 2663149Features outside the analysis interval: 15097QC retention RMS before and after alignment: 8.285782 8.274222 schromatograms <- 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")

import jsonimport sysfrom pathlib import Path
import matplotlib.pyplot as pltimport numpy as npimport pandas as pd
sys.path.insert(0, "/shared")from validate_fixtures import validate_fixtures
validate_fixtures([ "sample_metadata.tsv", "features.tsv.gz", "feature_intensities.tsv.gz", "feature_observations.tsv.gz", "excluded_features.tsv.gz", "representative_chromatograms.tsv.gz",])metadata = pd.read_csv("/fixtures/sample_metadata.tsv", sep="\t")features = pd.read_csv("/fixtures/features.tsv.gz", sep="\t", dtype={"feature_id": str})area_table = pd.read_csv("/fixtures/feature_intensities.tsv.gz", sep="\t", dtype={"feature_id": str})observations = pd.read_csv( "/fixtures/feature_observations.tsv.gz", sep="\t", dtype={"feature_id": str, "source_feature_id": str, "adduct_group": str})excluded = pd.read_csv("/fixtures/excluded_features.tsv.gz", sep="\t", dtype={"feature_id": str})selected_ids = metadata.loc[metadata["role"].ne("system_suitability"), "injection_id"].tolist()assert area_table["feature_id"].tolist() == features["feature_id"].tolist()assert area_table.columns[1:].tolist() == selected_idsassert features["feature_id"].is_uniqueassert not observations.duplicated(["feature_id", "injection_id"]).any()assert not observations.duplicated(["injection_id", "source_feature_id"]).any()areas = area_table.iloc[:, 1:].to_numpy(dtype=float)row_index = pd.Index(features["feature_id"]).get_indexer( observations["feature_id"])column_index = pd.Index(selected_ids).get_indexer(observations["injection_id"])assert np.all(row_index >= 0) and np.all(column_index >= 0)assert np.isfinite(areas).sum() == len(observations)np.testing.assert_allclose(areas[row_index, column_index], observations["intensity"], rtol=1e-6, atol=0)assert np.all(areas[np.isfinite(areas)] > 0)assert not set(excluded["feature_id"]) & set(features["feature_id"])assert observations["original_retention_time_seconds"].ge(0.6).all()assert observations["original_retention_time_seconds"].lt(1080).all()qc_ids = metadata.loc[metadata["role"].eq("pooled_qc"), "injection_id"].tolist()qc = observations.loc[observations["injection_id"].isin(qc_ids)].copy()frequency = qc.groupby("feature_id")["injection_id"].transform("size")qc = qc.loc[frequency.ge(2)].copy()assert len(qc) > 0for before, after in [ ("original_retention_time_seconds", "before_residual_seconds"), ("aligned_retention_time_seconds", "after_residual_seconds"),]: centers = qc.groupby("feature_id")[before].transform("median") qc[after] = qc[before] - centersresiduals = qc[["feature_id", "injection_id", "before_residual_seconds", "after_residual_seconds"]].reset_index(drop=True)residuals.to_csv("outputs/retention_residuals_python.csv", index=False)r_residuals = pd.read_csv("outputs/retention_residuals_r.csv", dtype={"feature_id": str})pd.testing.assert_frame_equal(residuals, r_residuals, check_dtype=False, rtol=1e-8, atol=1e-8)metrics = { "features": len(features), "observations": len(observations), "missing_cells": int(np.isnan(areas).sum()), "excluded_features": len(excluded), "qc_residuals": len(residuals), "before_rms": float(np.sqrt(np.mean(qc["before_residual_seconds"] ** 2))), "after_rms": float(np.sqrt(np.mean(qc["after_residual_seconds"] ** 2))),}Path("outputs/metrics_python.json").write_text(json.dumps(metrics, indent=2))print(f"Retained features: {metrics['features']}")print("Observed areas and absent observations:", metrics["observations"], metrics["missing_cells"])print(f"Features outside the analysis interval: {metrics['excluded_features']}")print("QC retention RMS before and after alignment:", f"{metrics['before_rms']:.6f} {metrics['after_rms']:.6f} s")Retained features: 96101Observed areas and absent observations: 219881 2663149Features outside the analysis interval: 15097QC retention RMS before and after alignment: 8.285782 8.274222 schromatograms = pd.read_csv( "/fixtures/representative_chromatograms.tsv.gz", sep="\t", dtype={"feature_id": str})assert chromatograms["feature_id"].nunique() == 1assert set(chromatograms["injection_id"]) == set(qc_ids)assert np.isfinite(chromatograms["intensity"]).all()assert chromatograms["intensity"].ge(0).all()figure, axis = plt.subplots(figsize=(8.5, 5))colors = plt.get_cmap("viridis")(np.linspace(0, 1, len(qc_ids)))for index, identifier in enumerate(qc_ids): selected = chromatograms.loc[chromatograms["injection_id"].eq(identifier)] axis.plot(selected["aligned_retention_time_seconds"], selected["intensity"], color=colors[index], linewidth=0.8, label=identifier)axis.set_xlabel("Aligned retention time in seconds")axis.set_ylabel("Ion signal")axis.set_title("One mass channel across eight QCs")axis.legend(title="QC injection", fontsize=8)figure.tight_layout()figure.savefig("outputs/feature_chromatograms_python.png", dpi=160, facecolor="white")plt.close(figure)figure, axis = plt.subplots(figsize=(6.5, 5.5))axis.scatter(qc["before_residual_seconds"], qc["after_residual_seconds"], s=4, alpha=0.25, color="#286b86")limits = [min(qc["before_residual_seconds"].min(), qc["after_residual_seconds"].min()), max(qc["before_residual_seconds"].max(), qc["after_residual_seconds"].max())]axis.plot(limits, limits, color="#87919c", linestyle=":", linewidth=0.8)axis.axhline(0, color="#87919c", linewidth=0.8)axis.axvline(0, color="#87919c", linewidth=0.8)axis.set_xlabel("Original QC deviation in seconds")axis.set_ylabel("Aligned QC deviation in seconds")axis.set_title("Each deviation uses its feature's median QC time")figure.tight_layout()figure.savefig("outputs/retention_residuals_python.png", dpi=160, facecolor="white")plt.close(figure)

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.
Read alignment as a correspondence check
Section titled “Read alignment as a correspondence check”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.
Further reading
Section titled “Further reading”-
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.