rformassspectrometry / Spectra

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

New feature: group and summarised Spectra #295

Open lgatto opened 1 year ago

lgatto commented 1 year ago

The filterPrecursorMaxIntensity() (see #290) conceptually works as follows:

  1. Group spectra based on a given criterion, here those that have the same precursor MZ,
  2. Group these or filter one of them, here the one with the highest precursor intensity.

This could be generalised with groupSpectra() and summarizedSpectra() functions. But before embarking on something like this, we should rework the documentation (see #288) to clarify which functions would fall under this paradigm.

jorainer commented 1 year ago

If I understood correctly, the idea of the grouping function would that it adds a special spectra variable to the input object with the spectra groups (e.g. a factor). The summarize spectra will then use that grouping to summarize the spectra in each group to a single spectrum.

So, summarizeSpectra could thus be defined as

summarizeSpectra <- function(x, f = spectraGroups(x), ...)

which would allow to either use predefined spectra groups or allow the user to define their own factor.

lgatto commented 1 year ago

Yes. The typical usage/paradigm would be

sp |>
  groupSpectraByPrecursorMz(...) |>
  summarizeSpectraByMaxPrecursorInt(...)

or

sp |>
  groupSpectra(fun = groupByPrecursorMz, ...) |>
  summarizeSpectra(fun = summarizeByMaxPrecursotIn, ...)