## load library
library("MALDIquant");
## load example data
data("spectra", package="MALDIquant");
## choose only a subset
spectra <- spectra[1:2];
## show some information
spectra
## running typical workflow
## transform intensities
t <- lapply(spectra, transformIntensity, fun=sqrt);
## smoothing function
movingAvg <- function(y) {
ma <- rep(1, 5)/5;
return(filter(y, ma, sides=2));
}
## smooth spectra
s <- lapply(t, transformIntensity, fun=movingAvg);
## baseline correction
b <- lapply(s, removeBaseline);
## detect peaks
p <- lapply(b, detectPeaks);
## plot results
par(mfcol=c(3, length(spectra)));
for (i in seq(along=spectra)) {
plot(spectra[[i]], main="raw spectrum");
plot(s[[i]], main="transformed (sqrt) and smoothed (ma5)");
plot(b[[i]], main="baseline removed and peaks detected");
points(p[[i]], pch=4, col=2);
}
par(mfrow=c(1, 1));
## bin peaks
bp <- binPeaks(p);
## show intensity matrix
intensityMatrix(bp);Run the code above in your browser using DataLab