combinePeaks | R Documentation |
In addition to aggregating content of spectra variables (describe in
combineSpectra()
) it is also possible to aggregate and combine mass peaks
data from individual spectra within a Spectra
. These combinePeaks()
function combines mass peaks within each spectrum with a difference in
their m/z values that is smaller than the maximal acceptable difference
defined by ppm
and tolerance
. Parameters intensityFun
and mzFun
allow to define functions to aggregate the intensity and m/z values for
each such group of peaks. With weighted = TRUE
(the default), the m/z
value of the combined peak is calculated using an intensity-weighted mean
and parameter mzFun
is ignored. The MsCoreUtils::group()
function is
used for the grouping of mass peaks. Parameter msLevel.
allows to define
selected MS levels for which peaks should be combined. This function
returns a Spectra
with the same number of spectra than the input object,
but with possibly combined peaks within each spectrum.
Additional peak variables (other than "mz"
and "intensity"
) are
dropped (i.e. their values are replaced with NA
) for combined peaks
unless they are constant across the combined peaks. See also
reduceSpectra()
for a function to select a single representative
mass peak for each peak group.
## S4 method for signature 'Spectra'
combinePeaks(
object,
tolerance = 0,
ppm = 20,
intensityFun = base::mean,
mzFun = base::mean,
weighted = TRUE,
msLevel. = uniqueMsLevels(object),
...
)
object |
A |
tolerance |
|
ppm |
|
intensityFun |
Function to aggregate intensities for all peaks in each peak group into a single intensity value. |
mzFun |
Function to aggregate m/z values for all mass peaks within
each peak group into a single m/z value. This parameter is ignored if
|
weighted |
|
msLevel. |
|
... |
ignored. |
Sebastian Gibb, Johannes Rainer, Laurent Gatto
combineSpectra()
for functions to combine or aggregate Spectra
's
spectra data.
combinePeaksData()
for the function to combine the mass peaks data.
reduceSpectra()
and similar functions to filter mass peaks data.
Spectra for a general description of the Spectra
object.
## Create a Spectra from mzML files and use the `MsBackendMzR` on-disk
## backend.
sciex_file <- dir(system.file("sciex", package = "msdata"),
full.names = TRUE)
sciex <- Spectra(sciex_file, backend = MsBackendMzR())
## Combine mass peaks per spectrum with a difference in their m/z value
## that is smaller than 20 ppm. The intensity values of such peaks are
## combined by summing their values, while for the m/z values the median
## is reported
sciex_comb <- combinePeaks(sciex, ppm = 20,
intensityFun = sum, mzFun = median)
## Comparing the number of mass peaks before and after aggregation
lengths(sciex) |> head()
lengths(sciex_comb) |> head()
## Plotting the first spectrum before and after aggregation
par(mfrow = c(1, 2))
plotSpectra(sciex[2L])
plotSpectra(sciex_comb[2L])
## Using `reduceSpectra()` to keep for each group of mass peaks with a
## difference in their m/z values < 20ppm the one with the highest intensity.
sciex_red <- reduceSpectra(sciex, ppm = 20)
## Comparing the number of mass peaks before and after the operation
lengths(sciex) |> head()
lengths(sciex_red) |> head()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.