filterSpectriPy | R Documentation |
The filterSpectriPy()
function allows to filter/process a Spectra
object
using the select_by_intensity()
, select_by_mz()
,
remove_peaks_around_precursor_mz()
, and normalize_intensities()
functions of the Python
matchms.filtering
module.
Selection and configuration of the algorithm can be performed with one of the parameter objects (equivalent to matchms' function names):
select_by_intensity()
: Keeps only the peaks within defined intensity
range (keep if intensity_from
>= intensity >= intensity_to
). See also
the respective documentation in matchms.
select_by_mz()
: Keeps only the peaks between mz_from
and mz_to
(keep if mz_from
>= m/z >= mz_to
). See also the respective
documentation in matchms.
remove_peaks_around_precursor_mz()
: Removes the peaks that are within
mz_tolerance
(in Da) of the precursor mz, excluding the precursor peak.
normalize_intensities()
: Normalizes the intensities of peaks
(and losses) to unit height.
select_by_intensity(intensity_from = 10, intensity_to = 200)
select_by_mz(mz_from = 0, mz_to = 1000)
remove_peaks_around_precursor_mz(mz_tolerance = 17)
normalize_intensities()
## S4 method for signature 'Spectra,filter_param'
filterSpectriPy(object, param, mapping = spectraVariableMapping(), ...)
intensity_from |
|
intensity_to |
|
mz_from |
|
mz_to |
|
mz_tolerance |
|
object |
A |
param |
one of parameter classes listed above (such as
|
mapping |
named |
... |
ignored. |
filterSpectriPy()
returns a Spectra
object on which the
filtering/processing function has been applied
The first call to the filterSpectriPy()
function can take longer because
the Python environment needs to be first set up.
filterSpectriPy()
first translates the Spectra
to Python, applies the
filter functions from the matchms Python libraries and then translates
the filtered data back to a Spectra
object. Thus, any spectra variables
other than those that are translated between R and Python will be lost
during the processing. Use setSpectraVariableMapping()
to define which
spectra variables should be transferred/converted between R and Python.
See also examples below for more information.
The Spectra::Spectra()
object returned by filterSpectriPy()
will
always use an in-memory backend (i.e. the Spectra::MsBackendMemory()
),
independently of the backend used by the backend used by the input
Spectra
.
Thomas Naake
Spectra::filterIntensity()
, Spectra::filterMzRange()
,
Spectra::scalePeaks()
in the Spectra
package for pure R
implementations of filtering/processing calculations.
rspec_to_pyspec()
or pyspec_to_rspec()
for the functions used to
translated the MS data between R and Python.
library(Spectra)
## create some example Spectra
DF <- DataFrame(
msLevel = c(2L, 2L, 2L),
name = c("Caffeine", "Caffeine", "1-Methylhistidine"),
precursorMz = c(195.0877, 195.0877, 170.0924)
)
DF$intensity <- list(
c(340.0, 416, 2580, 412),
c(388.0, 3270, 85, 54, 10111),
c(3.407, 47.494, 3.094, 100.0, 13.240))
DF$mz <- list(
c(135.0432, 138.0632, 163.0375, 195.0880),
c(110.0710, 138.0655, 138.1057, 138.1742, 195.0864),
c(109.2, 124.2, 124.5, 170.16, 170.52))
sps <- Spectra(DF)
## Filter: select_by_intensity
res <- filterSpectriPy(
sps, select_by_intensity(intensity_from = 15, intensity_to = 300))
## Only mass peaks with intensities between the specified limits are
## retained
intensity(res)
## Compared to the original intensities
intensity(sps)
## Note that the spectra variable `"name"` was lost during conversion of
## the MS data between R and Python:
sps$name
any(spectraVariables(res) == "name")
## Only spectra variables defined by `spectraVariableMapping()` are
## converted and thus retained:
spectraVariableMapping()
## We can also pass a custom *spectra variable mapping* with the `mapping`
## parameter to the `filterSpectriPy()` function. Below we create such
## a mapping by adding the translation of a spectra variable `"name"` to
## a metadata name `"compound_name"` to the default spectra variable
## mapping `defaultSpectraVariableMapping()`.
map <- c(defaultSpectraVariableMapping(), name = "compound_name")
map
## Repeat the filtering operation passing this mapping information:
res <- filterSpectriPy(
sps, select_by_intensity(intensity_from = 15, intensity_to = 300),
mapping = map)
res$name
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.