sgibb / MALDIquant

Quantitative Analysis of Mass Spectrometry Data
https://strimmerlab.github.io/software/maldiquant/
60 stars 25 forks source link

Peak binning on reference peaks #69

Closed ndevln closed 3 years ago

ndevln commented 3 years ago

Hi Sebastian,

thank you for this great package.

I have a small question / feature request. I used reference data to define reference peaks. Now I can align new data to these reference peaks (alignSpectra()).

But to get the final data, I have to set the intensity of the reference peaks object to NA and pass this as the peaks list to the intensityMatrix() function. This works but feels like quite a hack and I never perform peak detection on the new data. Also, the peaks are sometime still minimally miss aligned, so the returned intensity is a little bit smaller than the peak value.

If I could pass the reference peaks to binPeaks() and intensityMatrix() the peaks could be binned on the reference instead of the mean of all peaks. And intensityMatrix() could use the reference to provide data on locations which are not detected as peaks in the new data.

To work with the new data, the new intensity matrix should ideally have the same number of columns as the reference intensity matrix. And it would be a bonus if the column names match, since I like to transform the matrix into a data.frame.

What do you think? Or am I doing it wrong?

Greetings, Alex

sgibb commented 3 years ago

Dear Alex thanks for your suggestion.

I add a new method to the binPeaks function that allows you to use the first MassPeaks object as reference. I hope this is what you need:

## create a peak list
p <- c(createMassPeaks(mass=c(1, 1.01, 3), intensity=c(2, 1, 1)),
       createMassPeaks(mass=c(0.99, 3), intensity=rep(1, 2)),
       createMassPeaks(mass=c(1.02, 3), intensity=rep(1, 2)))

## create a reference
ref <- createMassPeaks(mass=c(1, 3), intensity=rep(1, 2))

## drop the reference
intensityMatrix(
    binPeaks(c(ref, p), method="reference", tolerance=0.05)[-1]
)
## you could use `filterPeaks` to remove the peaks that are not binned

This new feature is available in the reference branch. Could you please install MALDIquant from this branch and test the feature:

remotes::install_github("sgibb/MALDIquant@reference")
library("MALDIquant")

If you are satisfied with it I will merge it into the master branch and upload it to CRAN.

Best wishes,

Sebastian

sgibb commented 3 years ago

on CRAN now