Low level functions to convert between Spectra and matchms Spectrum
Source:R/conversion.R
rspec_to_pyspec.Rd
The rspec_to_pyspec()
and pyspec_to_rspec()
functions allow to convert
R Spectra()
objects into matchms
Python Spectrum
objects. These functions are designed for
advanced users or developers who want/need to integrate Python/matchms
functionality into R using reticulate. All other users should use the
dedicated R functions within this package that take care of running the
Python code in the correct Python environment.
Parameter mapping
allows to define which spectra variables (metadata)
should be copied between the R and Python spectra. Only provided spectra
variables will be copied to R respectively Python. mapping
also defines
the mapping between the Spectra
's spectra variables and the Spectrum
metadata. The names of the character vector mapping
are the R spectra
variables and the values the corresponding names in the Python's Spectrum
metadata. See the output of the spectraVariableMapping()
function for the
default variables and the mapping of the names.
The spectraVariableMapping()
function provides a default mapping of some
core Spectra
variables based on this definition in matchms.
The function returns a named vector that can be directly used as parameter
mapping
in the rspec_to_pyspec()
and pyspec_to_rspec()
functions.
Usage
# S4 method for class 'missing'
spectraVariableMapping(object, ...)
rspec_to_pyspec(
x,
mapping = spectraVariableMapping(),
reference = import("matchms"),
BPPARAM = SerialParam(),
.check = TRUE
)
pyspec_to_rspec(
x,
mapping = spectraVariableMapping(),
BPPARAM = SerialParam(),
.check = TRUE
)
Arguments
- object
ignored.
- ...
ignored.
- x
For
rspec_to_pyspec()
:Spectra
object. Forpyspec_to_rspec()
: a Python list of matchms Spectrum objects.- mapping
Named
character
providing the spectra variable names (metadata) to convert. Names are expected to be the spectra variable names and values the corresponding names of the Python Spectrum metadata fields. See description above for more details.- reference
Optional reference to Python environment
matchms
.- BPPARAM
Optional parallel processing setup.
- .check
Optionally disable input parameter checking. Input parameter checking should only disabled for very good reasons.
Value
For rspec_to_pyspec()
: Python array of Spectrum objects, same
length than x
. For pyspec_to_rspec()
: Spectra()
with the converted
spectra. For spectraVariableMapping()
: named character
vector with
names being Spectra
variable names and values the corresponding names
in matchms
.
Examples
## List the default spectra variables and their mapping.
spectraVariableMapping()
#> precursorMz precursorIntensity
#> "precursor_mz" "precursor_intensity"
#> precursorCharge rtime
#> "charge" "retention_time"
#> collisionEnergy isolationWindowTargetMz
#> "collision_energy" "isolation_window_target_mz"
#> msLevel
#> "ms_level"