if (requireNamespace("MALDIquant", quietly = TRUE)) {
# Two toy spectra with peaks near 1000, 1500, 2000 Da
mass <- seq(900, 2100, by = 1)
make_spectrum <- function(shift) {
inten <- dnorm(mass, 1000 + shift, 2) * 50 +
dnorm(mass, 1500 - shift, 2) * 80 +
dnorm(mass, 2000 + shift, 2) * 40 +
rnorm(length(mass), 0, 0.2)
MALDIquant::createMassSpectrum(mass = mass, intensity = inten)
}
spectra <- list(make_spectrum(0.3), make_spectrum(-0.3))
# Detect peaks without averaging; align in strict bins
peaks <- PeakDetection(
x = spectra,
averageMassSpec = FALSE,
SNRdetection = 3,
PeakDetectionMethod = "MAD",
binPeaks = TRUE,
AlignMethod = "strict",
Tolerance = 0.5,
verbose = TRUE
)
# Build an intensity matrix (rows = spectra, cols = aligned m/z bins)
X <- MALDIquant::intensityMatrix(peaks)
dim(X)
}
Run the code above in your browser using DataLab