n <- 200
freq <- 1:n
theory <- sin(freq/n*4*pi)*cos(freq/n*3*pi)
spec <- theory + 0.1*rnorm(n)
plot(spec,ty="b")
lines(theory,col="blue",lwd=3)
pts <- peaks(spec, minPH=0.7)
abline(v=pts$x,col="blue",lwd=3)
## peaks after smoothing the spectrum
spec.sm <- loess.smooth(freq, spec, span=0.2,
degree = 2, evaluation = 100)
lines(spec.sm$x, spec.sm$y, col="orange", lwd=2)
pts <- peaks(spec.sm, minPH=0.4)
abline(v=pts$x,col="orange", lwd=2)
## Analyses of Mass Spectrum between 12000 and 100'000
## without smoothing, without baseline substraction
data(MS)
MS <- log10(MS[MS$mz>12000&MS$mz<1e5,])
P <- peaks(MS, minPH=0.02, minPW=0.001)
plot(MS, ty="l")
abline(v=P$x,col="blue")
## compare to
if (require(PROcess)) { ## V 1.8.0
ii <- peaks(MS$I,300)
detach("package:PROcess")
plot(MS, ty="l")
abline(v=MS$mz[ii],col="orange")
} else print("Package Process not available!")
## or to
if (require(ppc)) { ## V 1.01
ii <- ppc.peaks(MS$I,400/nrow(MS))
detach("package:ppc")
plot(MS, ty="l")
abline(v=MS$mz[ii],col="red")
} else print("Package ppc not available!")
Run the code above in your browser using DataLab