\HeaderA{peakDetectionCWT}{The main function of peak detection by CWT based pattern matching}{peakDetectionCWT}
\keyword{methods}{peakDetectionCWT}
\begin{Description}\relax
This function is a wrapper of \code{\LinkA{cwt}{cwt}}, \code{\LinkA{getLocalMaximumCWT}{getLocalMaximumCWT}}, \code{\LinkA{getRidge}{getRidge}}, \code{\LinkA{identifyMajorPeaks}{identifyMajorPeaks}}
\end{Description}
\begin{Usage}
\begin{verbatim}
peakDetectionCWT(ms, scales = c(1, seq(2, 30, 2), seq(32, 64, 4)), SNR.Th = 3, nearbyPeak = TRUE, peakScaleRange = 5, amp.Th = 0.01, minNoiseLevel = amp.Th/SNR.Th, ridgeLength = 24, peakThr=NULL, tuneIn = FALSE, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{ms}] the mass spectrometry spectrum 
\item[\code{scales}] scales of CWT 
\item[\code{SNR.Th}] SNR (Signal to Noise Ratio) threshold
\item[\code{nearbyPeak}] Determine whether to include the nearby small peaks of major peaks. TRUE by default
\item[\code{peakScaleRange}] the scale range of the peak. larger than 5 by default. 
\item[\code{amp.Th}] the minimum required relative amplitude of the peak (ratio to the maximum of CWT coefficients) 
\item[\code{minNoiseLevel}] the minimum noise level used in computing the SNR 
\item[\code{ridgeLength}] the minimum highest scale of the peak in 2-D CWT coefficient matrix 
\item[\code{peakThr}] Minimal absolute intensity (above the baseline) of peaks to be picked. If this value is provided, then the smoothing function \code{\LinkA{sav.gol}{sav.gol}} will be called to estimate the local intensity.(added based on the suggestion and code of Steffen Neumann)
\item[\code{tuneIn}] determine whether to tune in the parameter estimation of the detected peaks 
\item[\code{...}] other parameters used by \code{\LinkA{identifyMajorPeaks}{identifyMajorPeaks}} and smoothing function \code{\LinkA{sav.gol}{sav.gol}} 
\end{ldescription}
\end{Arguments}
\begin{Value}
\begin{ldescription}
\item[\code{majorPeakInfo}] return of \code{\LinkA{identifyMajorPeaks}{identifyMajorPeaks}}
\item[\code{ridgeList}] return of \code{\LinkA{getRidge}{getRidge}}
\item[\code{localMax}] return of \code{\LinkA{getLocalMaximumCWT}{getLocalMaximumCWT}} 
\item[\code{wCoefs}] 2-D CWT coefficient matrix, see \code{\LinkA{cwt}{cwt}} for details.
\end{ldescription}
\end{Value}
\begin{Author}\relax
Pan Du, Simon Lin
\end{Author}
\begin{References}\relax
Du, P., Kibbe, W.A. and Lin, S.M. (2006) Improved peak detection in mass spectrum by incorporating continuous wavelet transform-based pattern matching, Bioinformatics, 22, 2059-2065.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{cwt}{cwt}}, \code{\LinkA{getLocalMaximumCWT}{getLocalMaximumCWT}}, \code{\LinkA{getRidge}{getRidge}}, \code{\LinkA{identifyMajorPeaks}{identifyMajorPeaks}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
        data(exampleMS)
        SNR.Th <- 3
        peakInfo <- peakDetectionCWT(exampleMS, SNR.Th=SNR.Th)
        majorPeakInfo = peakInfo$majorPeakInfo
        peakIndex <- majorPeakInfo$peakIndex
        plotPeak(exampleMS, peakIndex, main=paste('Identified peaks with SNR >', SNR.Th)) 
        
        ## In some cases, users may want to add peak filtering based on the absolute peak amplitude
        peakInfo <- peakDetectionCWT(exampleMS, SNR.Th=SNR.Th, peakThr=500)
        majorPeakInfo = peakInfo$majorPeakInfo
        peakIndex <- majorPeakInfo$peakIndex
        plotPeak(exampleMS, peakIndex, main=paste('Identified peaks with SNR >', SNR.Th))       
\end{ExampleCode}
\end{Examples}

