View source: R/ChromBackendSpectra.R
ChromBackendSpectra | R Documentation |
The ChromBackendSpectra
class extends ChromBackendMemory
, inheriting
all its slots and methods while providing additional functionality for
summarizing chromatographic data from Spectra::Spectra()
objects.
It can be initialized with a Spectra
object, which is stored in the
spectra
slot of the backend. Users can also provide a data.frame
containing chromatographic metadata, stored in chromData
. This metadata
filters the Spectra
object and generates peaksData
. If chromData
is
not provided, a default data.frame
is created from the Spectra
data.
An "rtmin", "rtmax", "mzmin", and "mzmax" column will be created by
condensing the Spectra
data corresponding to each unique combination of
the factorize.by
variables.
The dataOrigin core chromatogram variable should reflect the dataOrigin
of the Spectra
object. The factorize.by
parameter defines the variables
for grouping Spectra
data into chromatographic data. The default is
c("msLevel", "dataOrigin")
, which will define separate chromatograms for
each combination of msLevel
and dataOrigin
. These variables must be in
both Spectra
and chromData
(if provided).
The summarize.method
parameter defines how spectral data intensity is
summarized:
"sum": Sums intensity to create a Total Ion Chromatogram (TIC).
"max": Takes max intensity for a Base Peak Chromatogram (BPC).
If chromData
or its factorization columns are modified, the factorize()
method must be called to update chromSpectraIndex
.
ChromBackendSpectra()
## S4 method for signature 'ChromBackendSpectra'
backendInitialize(
object,
spectra = Spectra::Spectra(),
factorize.by = c("msLevel", "dataOrigin"),
summarize.method = c("sum", "max"),
chromData = fillCoreChromVariables(),
...
)
chromSpectraIndex(object)
object |
A |
spectra |
A |
factorize.by |
A |
summarize.method |
A |
chromData |
A |
... |
Additional parameters. |
No peaksData
is stored until the user calls a function that generates it
(e.g., rtime()
, peaksData()
, intensity()
). The peaksData
slot
replacement is unsupported — modifications are temporary to optimize memory.
The inMemory
slot indicates this with TRUE
.
ChromBackendSpectra
should reuse ChromBackendMemory
methods whenever
possible to keep implementations simple.
ensure that it returns a factor
Philippine Louail, Johannes Rainer.
library(Spectra)
library(MsBackendMetaboLights)
## Get Spectra data from MetaboLights
be <- backendInitialize(MsBackendMetaboLights(),
mtblsId = "MTBLS39",
filePattern = c("63B.cdf")
)
s <- Spectra(be)
## Initialize ChromBackendSpectra
be_empty <- new("ChromBackendSpectra")
be <- backendInitialize(be_empty, s)
## replace the msLevel data
msLevel(be) <- c(1L, 2L, 3L)
## re-factorize the data
be <- factorize(be)
## Create BPC : we summarize the intensity present in the Spectra object
## by the maximum value, thus creating a Base Peak Chromatogram.
be <- backendInitialize(be_empty, s, summarize.method = "max")
## Can now see the details of this bpc by looking at the chromData of our
## object
chromData(be)
## Another possibilities is to create eics from the Spectra object.
## Here we create an EIC with a specific m/z and retention time window.
df <- data.frame(mzmin = 100.01, mzmax = 100.02 , rtmin = 50, rtmax = 100)
be <- backendInitialize(be_empty, s, summarize.method = "sum")
chromData(be) <- cbind(chromData(be), df)
## now when we call the peaksData function, we will get the intensity
## of the spectra object that are in the m/z and retention time window
## defined in the chromData.
peaksData(be)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.