Inspect controls and acquisition order
The selected injections span a larger acquisition sequence. Their original counters preserve gaps between selected files, while their timestamps measure elapsed acquisition time. Replacing that sequence with row numbers would obscure both facts.
Pooled QC, blanks, and MM8 standards answer different questions. The pooled QC measures repeatability in a complex extract. The blanks reveal procedural background. The standard mixture supplies known material for a declared set of mass channels. None of these injections adds a biological plant to the species comparison.
Verify time before fitting drift
Section titled “Verify time before fitting drift”The preparation reads acquisition timestamps from every complete mzML file and checks them against the original source selection. Both examples below recalculate elapsed time from those timestamps. They also require every biological injection to lie between the first and last selected pooled QC.
That cohort-wide condition is necessary but insufficient for feature correction. A feature can be absent from an early or late QC. The drift lesson checks the observed QC interval separately for each feature.
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", "standard_chromatograms.tsv.gz", "standard_summary.tsv", "standard_extraction.json"))
metadata <- read.delim("/fixtures/sample_metadata.tsv", stringsAsFactors = FALSE)metadata <- metadata[order(metadata$acquisition_counter), ]timestamp_text <- sub("([+-][0-9]{2}):([0-9]{2})$", "\\1\\2", metadata$acquisition_timestamp)timestamp <- as.POSIXct(timestamp_text, format = "%Y-%m-%dT%H:%M:%OS%z", tz = "UTC")stopifnot(!anyNA(timestamp), all(diff(as.numeric(timestamp)) > 0))stopifnot(all(diff(metadata$acquisition_counter) > 0))elapsed <- as.numeric(difftime(timestamp, timestamp[1], units = "hours"))stopifnot(max(abs(elapsed - metadata$elapsed_hours)) < 1e-8)qc_time <- elapsed[metadata$role == "pooled_qc"]plant_time <- elapsed[metadata$role == "biological"]stopifnot(all(plant_time > min(qc_time)), all(plant_time < max(qc_time)))chronology <- data.frame(injection_id = metadata$injection_id, acquisition_counter = metadata$acquisition_counter, elapsed_hours = elapsed, role = metadata$role)write.csv(chronology, "outputs/chronology_r.csv", row.names = FALSE)channels <- read.delim(gzfile("/fixtures/standard_chromatograms.tsv.gz"))standards <- read.delim("/fixtures/standard_summary.tsv")stopifnot(!anyDuplicated(standards[c("injection_id", "standard_name")]))stopifnot(nrow(standards) == 24L)stopifnot(length(unique(standards$injection_id)) == 8L)standard_ids <- metadata$injection_id[metadata$role == "system_suitability"]stopifnot(setequal(unique(standards$injection_id), standard_ids))stopifnot(all(is.finite(channels$intensity)), all(channels$intensity >= 0))stopifnot(all(channels$retention_time_seconds >= 0.6))stopifnot(all(channels$retention_time_seconds < 1080))recomputed <- numeric(nrow(standards))for (index in seq_len(nrow(standards))) { selected <- channels$injection_id == standards$injection_id[index] & channels$standard_name == standards$standard_name[index] values <- channels[selected, ] values <- values[order(values$retention_time_seconds), ] widths <- diff(values$retention_time_seconds) stopifnot(length(widths) > 0L, all(widths > 0)) averages <- (head(values$intensity, -1) + tail(values$intensity, -1)) / 2 recomputed[index] <- sum(widths * averages)}relative_error <- abs(recomputed - standards$whole_window_area) / pmax(standards$whole_window_area, 1)stopifnot(max(relative_error) < 1e-6)standards$recomputed_area <- recomputedwrite.csv(standards, "outputs/standard_areas_r.csv", row.names = FALSE)metrics <- list(injections = nrow(metadata), standard_injections = length(unique(standards$injection_id)), mass_channels = length(unique(standards$standard_name)), channel_profiles = nrow(standards), span_hours = max(elapsed), max_area_relative_error = max(relative_error))write_json(metrics, "outputs/metrics_r.json", auto_unbox = TRUE, digits = 16)cat(sprintf("Selected injections: %d\n", nrow(metadata)))cat(sprintf("Standard injections and mass channels: %d %d\n", metrics$standard_injections, metrics$mass_channels))cat(sprintf("Elapsed acquisition span: %.6f hours\n", max(elapsed)))cat(sprintf("Complete standard channel profiles: %d\n", nrow(standards)))Selected injections: 38Standard injections and mass channels: 8 3Elapsed acquisition span: 37.142175 hoursComplete standard channel profiles: 24role_order <- c("process_blank", "system_suitability", "pooled_qc", "biological")metadata$role <- factor(metadata$role, levels = role_order)order_plot <- ggplot(metadata, aes(elapsed_hours, role, color = role)) + geom_point(size = 3) + geom_vline(xintercept = range(qc_time), linetype = "dotted", color = "#87919c") + scale_color_manual(values = c("#87919c", "#9c6930", "#3c8c75", "#286b86")) + labs(x = "Hours from the first selected acquisition", y = NULL, title = "Original acquisition times preserve omitted intervals") + theme_minimal(base_size = 12) + theme(legend.position = "none")ggsave("outputs/run_order_r.png", order_plot, width = 9, height = 3.6, dpi = 160, bg = "white")channel_plot <- ggplot(channels, aes(retention_time_seconds / 60, intensity, color = injection_id)) + geom_line(linewidth = 0.35, alpha = 0.8) + facet_wrap(~ standard_name, scales = "free_y", ncol = 1) + scale_color_viridis_d() + labs(x = "Retention time in minutes", y = "Ion signal", color = "Standard injection", title = "Three mass channels across eight MM8 injections") + theme_minimal(base_size = 11)ggsave("outputs/standard_channels_r.png", channel_plot, width = 9, height = 7.4, 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", "standard_chromatograms.tsv.gz", "standard_summary.tsv", "standard_extraction.json"])
metadata = pd.read_csv("/fixtures/sample_metadata.tsv", sep="\t")metadata = metadata.sort_values("acquisition_counter").reset_index(drop=True)timestamp = pd.to_datetime(metadata["acquisition_timestamp"], utc=True, format="ISO8601")assert timestamp.notna().all()assert timestamp.diff().iloc[1:].gt(pd.Timedelta(0)).all()assert metadata["acquisition_counter"].diff().iloc[1:].gt(0).all()elapsed = (timestamp - timestamp.iloc[0]).dt.total_seconds() / 3600np.testing.assert_allclose( elapsed, metadata["elapsed_hours"], rtol=0, atol=1e-8)qc_time = elapsed.loc[metadata["role"].eq("pooled_qc")]plant_time = elapsed.loc[metadata["role"].eq("biological")]assert plant_time.gt(qc_time.min()).all()assert plant_time.lt(qc_time.max()).all()chronology = metadata[["injection_id", "acquisition_counter", "role"]].copy()chronology["elapsed_hours"] = elapsedchronology = chronology[["injection_id", "acquisition_counter", "elapsed_hours", "role"]]chronology.to_csv("outputs/chronology_python.csv", index=False)r_chronology = pd.read_csv("outputs/chronology_r.csv")pd.testing.assert_frame_equal(chronology, r_chronology, check_dtype=False, rtol=0, atol=1e-8)channels = pd.read_csv("/fixtures/standard_chromatograms.tsv.gz", sep="\t")standards = pd.read_csv("/fixtures/standard_summary.tsv", sep="\t")assert not standards.duplicated(["injection_id", "standard_name"]).any()assert len(standards) == 24 and standards["injection_id"].nunique() == 8assert set(standards["injection_id"]) == set(metadata.loc[ metadata["role"].eq("system_suitability"), "injection_id"])assert np.isfinite(channels["intensity"]).all()assert channels["intensity"].ge(0).all()assert channels["retention_time_seconds"].ge(0.6).all()assert channels["retention_time_seconds"].lt(1080).all()recomputed = []for row in standards.to_dict("records"): selected = channels["injection_id"].eq(row["injection_id"]) selected &= channels["standard_name"].eq(row["standard_name"]) values = channels.loc[selected].sort_values("retention_time_seconds") times = values["retention_time_seconds"].to_numpy() assert len(times) > 1 and np.all(np.diff(times) > 0) recomputed.append(float(np.trapezoid(values["intensity"], times)))relative_error = np.abs(recomputed - standards["whole_window_area"])relative_error /= np.maximum(standards["whole_window_area"], 1)assert relative_error.max() < 1e-6standards["recomputed_area"] = recomputedstandards.to_csv("outputs/standard_areas_python.csv", index=False)r_standards = pd.read_csv("outputs/standard_areas_r.csv")pd.testing.assert_frame_equal(standards, r_standards, check_dtype=False, rtol=1e-6, atol=1e-8)metrics = { "injections": len(metadata), "standard_injections": int(standards["injection_id"].nunique()), "mass_channels": int(standards["standard_name"].nunique()), "channel_profiles": len(standards), "span_hours": float(elapsed.max()), "max_area_relative_error": float(relative_error.max()),}Path("outputs/metrics_python.json").write_text(json.dumps(metrics, indent=2))print(f"Selected injections: {len(metadata)}")print("Standard injections and mass channels:", metrics["standard_injections"], metrics["mass_channels"])print(f"Elapsed acquisition span: {elapsed.max():.6f} hours")print(f"Complete standard channel profiles: {len(standards)}")Selected injections: 38Standard injections and mass channels: 8 3Elapsed acquisition span: 37.142175 hoursComplete standard channel profiles: 24role_order = ["process_blank", "system_suitability", "pooled_qc", "biological"]colors = ["#87919c", "#9c6930", "#3c8c75", "#286b86"]figure, axis = plt.subplots(figsize=(9, 3.6))for index, role in enumerate(role_order): selected = metadata["role"].eq(role) axis.scatter(elapsed.loc[selected], [index] * int(selected.sum()), color=colors[index], s=45)for boundary in [qc_time.min(), qc_time.max()]: axis.axvline(boundary, color="#87919c", linestyle=":", linewidth=0.9)axis.set_yticks(range(len(role_order)), role_order)axis.set_xlabel("Hours from the first selected acquisition")axis.set_title("Original acquisition times preserve omitted intervals")figure.tight_layout()figure.savefig("outputs/run_order_python.png", dpi=160, facecolor="white")plt.close(figure)names = sorted(channels["standard_name"].unique())injections = sorted(channels["injection_id"].unique())colors = plt.get_cmap("viridis")(np.linspace(0, 1, len(injections)))figure, axes = plt.subplots(3, 1, figsize=(9, 7.4), sharex=True)for axis, name in zip(axes, names, strict=True): for index, injection in enumerate(injections): selected = channels["standard_name"].eq(name) selected &= channels["injection_id"].eq(injection) values = channels.loc[selected] axis.plot(values["retention_time_seconds"] / 60, values["intensity"], color=colors[index], alpha=0.8, linewidth=0.6, label=injection) axis.set_title(name, fontsize=11) axis.set_ylabel("Ion signal")axes[-1].set_xlabel("Retention time in minutes")axes[0].legend(title="Standard injection", ncol=4, fontsize=7, loc="upper right")figure.suptitle("Three mass channels across eight MM8 injections")figure.tight_layout()figure.savefig("outputs/standard_channels_python.png", dpi=160, facecolor="white")plt.close(figure)

Interpret the standard channels at their supported resolution
Section titled “Interpret the standard channels at their supported resolution”The source protocol lists kinetin, rutin, and phlorizin in the MM8 mixture. The extraction preserves PubChem properties for those three selected constituents. Each channel uses the deprotonated exact mass with a 10 ppm window.
The interval includes scans from 0.6 seconds and excludes scans at or after 1,080 seconds. The source protocol places lithium-formate infusion at 18 minutes. Complete source files remain available, so this analytical boundary does not erase the calibration data.
Each reported area integrates the whole selected mass channel. It does not isolate one chromatographic peak, establish absolute concentration, or identify a biological feature. Extra peaks and changes in peak shape remain visible in the chromatograms. The identification lesson explains the additional evidence required for a compound assignment.
Further reading
Section titled “Further reading”-
Broadhurst and colleagues on analytical controls
The authors distinguish system suitability, process blanks, and pooled QC samples. Their guidance explains why acquisition order and repeated controls need separate records.
-
PubChem properties for the three MM8 constituents
The original response gives compound identifiers, formulas, and exact masses for kinetin, rutin, and phlorizin. Those properties define mass channels without identifying every observed peak.