CompDb-based MS spectrum backend
Source:R/MsBackendCompDb-functions.R
, R/MsBackendCompDb.R
MsBackendCompDb.Rd
The MsBackendCompDb
represents MS2 spectra data from a CompDb()
object/database. The object keeps only the primary keys of the spectra,
the associated compound IDs and the precursor m/z values in memory and
has thus only a very low memory footprint. All spectra variables, including
m/z and intensity values are retrieved from the database on-demand. By
extending the MsBackendCached()
class directly, MsBackendCompDb
supports
adding/replacing spectra variables. These values are however only cached
within the object and not propagated (written) to the database.
It is not intended that users create or use instances of this class directly,
the Spectra()
call on CompDb()
will return a Spectra
object that uses
this backend.
The MsBackendCompDb
does not support parallel processing because the
database connection stored within the object can not be used across
multiple parallel processes. The backendBpparam()
method for
MsBackendCompDb
thus returns always SerialParam
and hence any
function that uses this method to check for parallel processing capability
of a MsBackend
will by default disable parallel processing.
Usage
MsBackendCompDb()
# S4 method for class 'MsBackendCompDb'
backendInitialize(object, x, filter, ...)
# S4 method for class 'MsBackendCompDb'
show(object)
# S4 method for class 'MsBackendCompDb'
peaksData(object, columns = c("mz", "intensity"))
# S4 method for class 'MsBackendCompDb'
peaksVariables(object)
# S4 method for class 'MsBackendCompDb'
dataStorage(object)
# S4 method for class 'MsBackendCompDb'
intensity(object) <- value
# S4 method for class 'MsBackendCompDb'
mz(object) <- value
# S4 method for class 'MsBackendCompDb'
spectraData(object, columns = spectraVariables(object))
# S4 method for class 'MsBackendCompDb'
spectraNames(object)
# S4 method for class 'MsBackendCompDb'
spectraNames(object) <- value
# S4 method for class 'MsBackendCompDb,ANY'
x[i, j, ..., drop = FALSE]
# S4 method for class 'MsBackendCompDb,ANY'
extractByIndex(object, i)
# S4 method for class 'MsBackendCompDb'
x$name <- value
# S4 method for class 'MsBackendCompDb'
precScanNum(object)
# S4 method for class 'MsBackendCompDb'
tic(object, initial = TRUE)
# S4 method for class 'MsBackendCompDb'
backendBpparam(object, BPPARAM = bpparam())
Arguments
- object
an
MsBackendCompDb
instance.- x
an
MsBackendCompDb
instance.- filter
for
backendInitialize()
: optional filter expression to specify which elements to retrieve from the database.- ...
ignored.
- columns
for
spectraData()
:character
with names of columns/spectra variables that should be returned. Defaults tospectraVariables(object)
. Database columns"ms_level"
,"precursor_mz"
,"precursor_intensity"
,"precursor_charge"
are mapped to the coreSpectra
variablesmsLevel
,precursorMz
,precursorIntensity
andprecursorCharge
, respectively. ForpeaksData
:character
with the names of the peaks columns to return. UsepeaksVariables
for supported values.- value
for
$<-
: the replacement values.- i
For
[
:integer
,logical
orcharacter
to subset the object.- j
For
[
: not supported.- drop
For
[
: not considered.- name
for
$<-
: the name of the spectra variable to replace.- initial
for
tic()
:logical(1)
whether original total ion current values should be returned or if the values should be calculated based on the actual intensity values of each spectrum.- BPPARAM
for
backendBpparam()
:BiocParallel
parallel processing setup. Seebpparam()
for more information.
Note
For higher performance it is suggested to change the backend of the
Spectra()
object to an MsBackendMemory()
backend with the
setBackend()
method of Spectra
objects.
Methods implemented for MsBackendCompDb
The methods listed here are implemented for the MsBackendCompDb
. All other
methods are inherited directly from the parent MsBackendCached()
class.
See the help of MsBackend()
in the Spectra
package for a
complete listing of methods.
peaksData()
: gets the full list of peak matrices. Returns alist()
, length equal to the number of spectra and each element being amatrix
with columns"mz"
and"intensity"
with the spectra's m/z and intensity values.peaksVariables()
: lists the available peaks variables in the backend (database). These can be used for parametercolumns
ofpeaksData()
.intensity<-
: not supported.mz<-
: not supported.spectraData()
: returns the complete spectrum data including m/z and intensity values as aDataFrame()
.$<-
: replace or add a spectrum variable. Note thatmz
,intensity
andspectrum_id
variables can not be replaced.
Examples
## MsBackendCompDb are not expected to be created/instanciated by users
## directly. Users also almost never directly interact with this type of
## object, as it is intented as a pure data backend for the `Spectra` object.
## Users will thus access MS data through such `Spectra` object, which can
## be created for `CompDb` objects using the `Spectra` method (see help
## of the `CompDb` object for more information. This examples shows how
## a `MsBackendCompDb` could be created purely from an SQLite database
## with data from a CompoundDb database.
## Connect to the SQLite database of a `CompDb` distributed via this package
library(RSQLite)
library(Spectra)
cdb <- CompDb(system.file("sql/CompDb.MassBank.sql", package = "CompoundDb"))
be <- backendInitialize(MsBackendCompDb(), cdb)
be
#> MsBackendCompDb with 70 spectra
#> msLevel precursorMz polarity
#> <integer> <numeric> <integer>
#> 1 2 179.07 1
#> 2 2 179.07 1
#> 3 2 179.07 1
#> 4 2 179.07 1
#> 5 2 179.07 1
#> ... ... ... ...
#> 66 2 337.091 1
#> 67 2 337.091 1
#> 68 2 337.091 1
#> 69 2 337.091 1
#> 70 2 337.091 1
#> ... 46 more variables/columns.
#> Use 'spectraVariables' to list all of them.
#> data source: MassBank
#> version: 2020.09
#> organism: NA
## Accessing m/z values
mz(be)
#> NumericList of length 70
#> [[1]] 133.0648 151.0754 155.9743 161.0597 179.0703
#> [[2]] 133.0648 151.0754 155.9745 161.0597 179.0703
#> [[3]] 105.0699 133.0648 151.0754 161.0597 179.0703
#> [[4]] 105.0699 133.0648 151.0754 161.0597 179.0703
#> [[5]] 105.0699 115.0542 133.0648 151.0754 161.0597 179.0703
#> [[6]] 506.3324
#> [[7]] 276.2686 294.2792 312.287 330.2976 470.3112 488.3218 506.3324
#> [[8]] 56.0502 57.0706 60.045 69.0699 ... 312.287 330.2976 488.3218 506.3324
#> [[9]] 56.0502 57.0706 60.045 67.0542 ... 242.2115 276.2686 294.2792 312.287
#> [[10]] 56.0502 57.0706 60.045 67.0542 ... 159.0288 224.2009 276.2686 294.2792
#> ...
#> <60 more elements>