\HeaderA{identifyMajorPeaks}{Identify peaks based on the ridges in 2-D CWT coefficient matrix}{identifyMajorPeaks}
\keyword{methods}{identifyMajorPeaks}
\begin{Description}\relax
Indentify the peaks based on the ridge list (returned by \code{\LinkA{getRidge}{getRidge}}) in 2-D CWT coefficient matrix and estimated Signal to Noise Ratio (SNR)
\end{Description}
\begin{Usage}
\begin{verbatim}
identifyMajorPeaks(ridgeList, wCoefs, scales = as.numeric(colnames(wCoefs)), SNR.Th = 3, peakScaleRange = 5, ridgeLength = 32, nearbyPeak = FALSE, nearbyWinSize = 100, winSize.noise = 500, SNR.method = "quantile", minNoiseLevel = 0.001)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{ridgeList}] returned by \code{\LinkA{getRidge}{getRidge}}
\item[\code{wCoefs}] 2-D CWT coefficients 
\item[\code{scales}] scales of CWT, by default it is the colnames of wCoefs 
\item[\code{SNR.Th}] threshold of SNR 
\item[\code{peakScaleRange}] the CWT scale range of the peak. 
\item[\code{ridgeLength}] the maximum ridge scale of the major peaks. 
\item[\code{nearbyPeak}] determine whether to include the small peaks close to large major peaks 
\item[\code{nearbyWinSize}] the window size to determine the nearby peaks. Only effective when nearbyPeak is true.
\item[\code{winSize.noise}] the local window size to estimate the noise level. 
\item[\code{SNR.method}] method to estimate noise level. Currently, only 95 percentage quantile is supported. 
\item[\code{minNoiseLevel}] the minimum noise level used in calculating SNR, i.e., if the estimated noise level is less than "minNoiseLevel", it will use "minNoiseLevel" instead. If the noise level is less than 0.5, it will be treated as the ratio to the maximum amplitude of the spectrum. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The determination of the peaks is based on three rules:
Rule 1: The maximum ridge scale of the peak should larger than a certain threshold
Rule 2: Based on the scale of the peak (corresponding to the maximum value of the peak ridge) should be within certain range
Rule 3: Based on the peak SNR
\end{Details}
\begin{Value}
Return a list with following elements:
\begin{ldescription}
\item[\code{peakIndex}] the m/z indexes of the identified peaks
\item[\code{peakCenterIndex}] the m/z indexes of peak centers, which correspond to the maximum on the ridge. peakCenterIndex includes all the peaks, not just the identified major peaks.
\item[\code{peakCenterValue}] the CWT coefficients (the maximum on the ridge) corresponding to peakCenterIndex
\item[\code{peakSNR}] the SNR of the peak, which is the ratio of peakCenterValue  and noise level
\item[\code{peakScale}] the estimated scale of the peak, which corresponds to the peakCenerIndex
\item[\code{potentialPeakIndex}] the m/z indexes of all potential peaks, which satisfy all requirements of a peak without considering its SNR. Useful, if you want to change to a lower SNR threshold later.
\item[\code{allPeakIndex}] the m/z indexes of all the peaks, whose order is the same as peakCenterIndex, peakCenterValue, peakSNR and peakScale.
\end{ldescription}


All of these return elements have peak names, which are the same as the corresponding peak ridges. see \code{\LinkA{getRidge}{getRidge}} for details.
\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{peakDetectionCWT}{peakDetectionCWT}}, \code{\LinkA{tuneInPeakInfo}{tuneInPeakInfo}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
        data(exampleMS)
        scales <- seq(1, 64, 3)
        wCoefs <- cwt(exampleMS, scales=scales, wavelet='mexh')
        
        localMax <- getLocalMaximumCWT(wCoefs)
        ridgeList <- getRidge(localMax)
        
        SNR.Th <- 3
        majorPeakInfo <- identifyMajorPeaks(ridgeList, wCoefs, SNR.Th=SNR.Th)
        ## Plot the identified peaks
        peakIndex <- majorPeakInfo$peakIndex
        plotPeak(exampleMS, peakIndex, main=paste('Identified peaks with SNR >', SNR.Th)) 
        
\end{ExampleCode}
\end{Examples}

