Package 'CentroidR'

Title: Centroid Profile Mass Spectrometry Data
Description: CentroidR provides the infrastructure to centroid profile mass spectrometry spectra (mzML) with independent MS1 and MS2 tolerances, 1D Morse-Smale topological prominence valley splitting, weighted log-quadratic Gaussian and power-weighted m/z centroiding, overlapping multiplet deconvolution, and analyzer-specific m/z domain scaling.
Authors: Adriano Rutz [aut, cre] (ORCID: <https://orcid.org/0000-0003-0443-9902>), Johannes Rainer [aut] (ORCID: <https://orcid.org/0000-0002-6977-7147>)
Maintainer: Adriano Rutz <[email protected]>
License: AGPL (>= 3)
Version: 0.0.0.9005
Built: 2026-11-20 22:55:24 UTC
Source: https://github.com/adafede/CentroidR

Help Index


Centroid an mzML file with configurable parameters

Description

Processes an mzML file containing profile-mode mass spectra and writes centroided MS1 and MS2 spectra to a new mzML file.

Usage

centroid_one_file(
  file,
  pattern,
  replacement,
  min_datapoints_ms1 = 5L,
  min_datapoints_ms2 = 1L,
  mz_tol_da_ms1 = 0.0025,
  mz_tol_da_ms2 = 0.0025,
  mz_tol_ppm_ms1 = 5,
  mz_tol_ppm_ms2 = 5,
  mz_fun_ms1 = base::mean,
  mz_fun_ms2 = base::mean,
  int_fun_ms1 = base::max,
  int_fun_ms2 = base::max,
  mz_weighted = TRUE,
  time_domain = TRUE,
  intensity_exponent = 3,
  centroid_method = c("weighted", "gaussian", "func"),
  intensity_method = c("func", "gaussian_apex", "gaussian_area", "trapezoid"),
  deconvolve = FALSE,
  valley_ratio = 0.2,
  valley_hws = 2L,
  baseline_subtract = FALSE,
  domain_scaling = c("legacy", "linear", "tof", "orbitrap", "fticr"),
  mz_ref = 100
)

Arguments

file

character(1). Path to the input mzML file (EDAM:format_3244). Must be a valid, accessible mzML format file.

pattern

character(1). Regular expression pattern to match in the input file path, used for modifying the output file path.

replacement

character(1). Replacement string for altering the output file path based on the pattern.

min_datapoints_ms1

integer(1). Minimum datapoints to be considered for MS1 data. Must be at least 1. Default: 5L.

min_datapoints_ms2

integer(1). Minimum datapoints to be considered for MS2 data. Must be at least 1. Default: 1L.

mz_tol_da_ms1

numeric(1). m/z tolerance in Daltons for MS1 data. Default: 0.0025.

mz_tol_da_ms2

numeric(1). m/z tolerance in Daltons for MS2 data. Default: 0.0025.

mz_tol_ppm_ms1

numeric(1). m/z tolerance in parts per million (ppm) for MS1. Default: 5.

mz_tol_ppm_ms2

numeric(1). m/z tolerance in parts per million (ppm) for MS2. Default: 5.

mz_fun_ms1

function. Function to aggregate m/z values within each peak group (MS1). Ignored if mz_weighted = TRUE. Default: base::mean.

mz_fun_ms2

function. Function to aggregate m/z values within each peak group (MS2). Ignored if mz_weighted = TRUE. Default: base::mean.

int_fun_ms1

function. Function to aggregate peak intensities within each peak group (MS1). Default: base::max.

int_fun_ms2

function. Function to aggregate peak intensities within each peak group (MS2). Default: base::max.

mz_weighted

logical(1). If TRUE, uses intensity-weighted mean for m/z value aggregation. Default: TRUE.

time_domain

logical(1). If TRUE, uses square root for m/z weighting (TRUE for TOF). Default: TRUE.

intensity_exponent

numeric(1). If mz_weighted=TRUE, the exponent of the intensity for m/z weighting. Default: 3.

centroid_method

character(1). Mathematical estimator for peak m/z when mz_weighted = TRUE: "weighted" (power-weighted mean, default), "gaussian" (apex-centered weighted log-quadratic Guo-Caruana Gaussian fit with automatic fallback to power-weighted mean on < 3 points or non-concave profiles), or "func" (applies mz_fun_ms1 / mz_fun_ms2 directly). When mz_weighted = FALSE, ⁠mz_fun_ms*⁠ is always used regardless of centroid_method.

intensity_method

character(1). Mathematical estimator for peak abundance: "func" (applies int_fun_ms1 / int_fun_ms2, default), "gaussian_apex" (interpolated continuous Gaussian apex height to eliminate picket-fence sampling attenuation), "gaussian_area" (analytical Gaussian integral Aσ2πA \sigma \sqrt{2\pi}), or "trapezoid" (numerical trapezoidal integration over m/z).

deconvolve

logical(1). If TRUE, applies 2-pass Gauss-Seidel Gaussian tail subtraction across split sub-peaks within overlapping multiplet groups before estimating centroids and intensities. Default: FALSE.

valley_ratio

numeric(1). Maximum ratio of valley intensity to the topological basin barrier height (1D Morse-Smale persistence) at which a group is split into separate peaks. Must be in ⁠[0, 1]⁠. Default: 0.2.

valley_hws

integer(1). Half-window size for local maxima detection during valley splitting. Must be at least 1. Default: 2L.

baseline_subtract

logical(1). If TRUE, subtracts the local edge baseline floor of each peak group prior to valley splitting and centroid estimation. Default: FALSE.

domain_scaling

character(1). Mass analyzer spacing scaling model used when grouping adjacent profile points: "legacy" (honours time_domain via sqrt(mz) transformation, default), "linear" (constant Da + ppm in m/z space), "tof" (local Jacobian Δm∝m1/2\Delta m \propto m^{1/2}), "orbitrap" (local Jacobian Δm∝m3/2\Delta m \propto m^{3/2}), or "fticr" (local Jacobian Δm∝m2\Delta m \propto m^2).

mz_ref

numeric(1). Reference m/z (in Daltons) at which ⁠mz_tol_da_*⁠ is calibrated when domain_scaling is "tof", "orbitrap", or "fticr". Default: 100.

Details

MS1 and MS2 spectra are processed separately with their own tolerances so the two levels can be tuned independently. Spectra of any other msLevel (such as MS3+) are preserved unmodified with their original centroided flag, and all spectra retain their original chronological scan acquisition order in the exported mzML.

Within a spectrum, profile points are first grouped by m/z tolerance using either the legacy sqrt(mz) transformation (domain_scaling = "legacy") or an exact local Jacobian analyzer spacing law (domain_scaling in "linear", "tof", "orbitrap", or "fticr"). Each group is then recursively split at deep valleys evaluated via 1D Morse-Smale topological basin prominence (valley_ratio, valley_hws, and optional baseline_subtract) so that closely spaced peaks are not merged even when small noise ripples sit inside a valley.

Peak centroids are estimated via power-weighted mean (centroid_method = "weighted"), apex-centered weighted log-quadratic Guo-Caruana Gaussian fitting (centroid_method = "gaussian"), or custom aggregation ("func"), while peak abundances can be reported via ⁠int_fun_ms*⁠ (intensity_method = "func"), interpolated Gaussian apex ("gaussian_apex"), analytical Gaussian area ("gaussian_area"), or numerical trapezoidal integration ("trapezoid"). Setting deconvolve = TRUE performs 2-pass Gauss-Seidel Gaussian tail subtraction across split sub-peaks prior to centroid and intensity estimation.

A group is only reduced when it holds at least ⁠min_datapoints_ms*⁠ points of non-zero intensity; below that it is reported as zero intensity and filtered out. Spectra left without any peak by this step are restored from the input, so no spectrum is lost.

File path modifications are supported via pattern and replacement. pattern is a regular expression, as in sub().

Value

logical(1). TRUE if the file was centroided, or TRUE if it was skipped because the output file already existed; FALSE if the input was missing, if pattern/replacement resolved to the input file itself (preventing in-place overwrite), or if centroiding failed. Invalid argument types raise an error instead of returning FALSE.

EDAM Ontology

  • Topics: ⁠http://edamontology.org/topic_3172⁠ (Metabolomics), ⁠http://edamontology.org/topic_0153⁠ (Lipids), ⁠http://edamontology.org/topic_0154⁠ (Small molecules), ⁠http://edamontology.org/topic_3370⁠ (Analytical chemistry)

  • Operations: ⁠http://edamontology.org/operation_3215⁠ (Peak detection / Peak picking / Centroiding), ⁠http://edamontology.org/operation_3214⁠ (Spectral analysis), ⁠http://edamontology.org/operation_3695⁠ (Data filtering)

  • Input/Output Data: ⁠http://edamontology.org/data_0943⁠ (Mass spectrum), ⁠http://edamontology.org/data_2536⁠ (Mass spectrometry data)

  • Input/Output Format: ⁠http://edamontology.org/format_3244⁠ (mzML)

Author(s)

Johannes Rainer, Adriano Rutz

Examples

## Not run: 
# Example usage (requires an mzML file):
# centroid_one_file(
#   file = "raw_data.mzML",
#   pattern = "\.mzML$",
#   replacement = "_centroided.mzML",
#   min_datapoints_ms1 = 5L,
#   min_datapoints_ms2 = 1L
# )

## End(Not run)