rformassspectrometry / Spectra

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

Pass arbitrary spectraVariables to the function applied by `addProcessing` #182

Closed jorainer closed 3 years ago

jorainer commented 3 years ago

Using the addProcessing function it is possible to apply any user-provided function to the peak matrix. Currently, this is used by methods like smooth etc. This allows to manipulate m/z and intensity values of spectra on any backend (even if we have only a read-only backend).

Thus far we automatically pass also the spectra variables msLevel and centroided to the function which will be applied to each peak matrix. This is hardcoded into the function since most functions so far (smooth, pickPeaks etc) needed these parameters. It is however at present not possible to pass arbitrary spectra variables to the function (which would e.g. be needed for issue #181 ).

I think however I have a solution to this: I suggest that the user has the possibility to define with addProcessing which spectra variables should be made available the the function that should be applied to each peak matrix. These are then extracted and passed to the function on demand. This could be implemented with the following changes:

The biggest change will be the addition of a new slot - we would have to provide a updateObject function that adds this slot if an old Spectra is loaded and we need to check for the presence of this slot in the .peaksapply and addProcessing functions.

I will implement this and compare its performance - but I don't expect a big loss in performance. I think however that this will improve the flexibility of Spectra considerably (and it will be easier for the user to provide custom functions).

@lgatto @sgibb I would really like to get your thoughts (and concerns?) about this.

lgatto commented 3 years ago

Sounds good to me.

jorainer commented 3 years ago

I've added some examples to the vignette describing this in detail.

jorainer commented 3 years ago

Implemented and merged into master.