rformassspectrometry / Spectra

Low level infrastructure to handle MS spectra
https://rformassspectrometry.github.io/Spectra/
34 stars 24 forks source link

pickPeaks, halfWindowSize #167

Closed ococrook closed 3 years ago

ococrook commented 3 years ago

From the docs it says the following:

`halfWindowSize` controls the window size of the peak picking algorithm.
The resulting window size is 2 * halfWindowSize + 1.
 The size should be nearly (or slightly larger) the FWHM (full width at half maximum).

It seems it's also required to be an integer > 0. However, my FWHM are quite a bit smaller than this. My question is in this case should I set halfWindowSize to be as small as possible? I'm guessing 1 here, in which case a small comment in the docs would be useful. Or should we be doing something else?

FWHMhist

jorainer commented 3 years ago

If I'm not wrong the halfWindowSize refers to the number of scans/spectra (that's also why it's an integer). I don't quite understand the unit of the FWHM in your graph? Could it be that that's in seconds or minutes?

sgibb commented 3 years ago

The algorithm was originally part of the MALDIquant package and the fact that

The size should be nearly (or slightly larger) the FWHM (full width at half maximum).

refers to the resolution of MALDI-MS devices 10 years ago.

In the implementation halfWindowSize is the number of elements left and right to the current index in the vector (a local maximum that could be a peak has to be higher than its halfWindowSize neighbors on the left/right). That's why it could just be an integer number. In line with the documentation (that I wrote 10 years ago) I would recommend to look how many elements in your m/z vector a typical FWHM is covering. In the old days we often start with diff(range(mz))/length(mz) / FHWM. Could be that in your case it is roughly diff(range(mz))/length(mz) / 0.125 (but 0.15 wouldn't hurt).

ococrook commented 3 years ago

Great thanks guys, relaly appreciate it. Just to clarify for me FWHM is \Delta M at 50% height of the peak.

I appreciate the documentation and resolution refers to a while ago, which I thought I would double check so that everything is still making sense! Seb your formulae makes sense having a quick play around - cheers for the suggestion!