peak_detection2d: Detect peaks in 2D NMR spectra

View source: R/read_NMR_spectra.R

peak_detection2dR Documentation

Detect peaks in 2D NMR spectra

Description

Detects local maxima in each spectrum of a 2D NMR dataset and converts the detected peaks into a 1D specmine dataset suitable for downstream analysis.

Usage

peak_detection2d(
  specmine_2d_dataset,
  baseline_thresh = NULL,
  noiseFilt = 0,
  negatives = FALSE,
  verbose = TRUE
)

Arguments

specmine_2d_dataset

A specmine 2D dataset containing one numeric matrix per sample.

baseline_thresh

Optional numeric threshold used as the minimum intensity for peak detection. If NULL, a threshold is estimated from the positive values of each spectrum.

noiseFilt

Integer noise filter level: 0 for no filter, 1 for a mild filter, and 2 for a strong filter.

negatives

Logical indicating whether variables with negative ppm values should be kept.

verbose

Logical indicating whether progress messages should be shown.

Value

A specmine dataset object as a list. The data element is a numeric matrix where rows correspond to detected 2D peak coordinates encoded as combined F1/F2 positions and columns correspond to samples. Matrix entries contain peak intensities, with missing values indicating that a given peak was not detected in a sample. The returned object also includes the original sample metadata, the dataset description, the dataset type set to "nmr-peaks", and labels describing the x-axis and data values. This output represents a reduced 1D peak table derived from the input 2D NMR spectra.

Examples

m <- matrix(c(0, 5, 0, 0), nrow = 2)
rownames(m) <- c("1.0", "1.1")
colnames(m) <- c("2.0", "2.1")
x <- list(data = list(s1 = m), metadata = data.frame(), description = "Toy")
try(peak_detection2d(x, baseline_thresh = 1, negatives = TRUE, verbose = FALSE))


specmine documentation built on Aug. 5, 2026, 5:06 p.m.