Description Usage Arguments Value Author(s) See Also Examples
combineSpectra
combines spectra in a MSnExp, OnDiskMSnExp
or MSpectra object applying the summarization function fun
to sets
of spectra defined by a factor (fcol
parameter). The resulting combined
spectrum for each set contains metadata information (present in mcols
and
all spectrum information other than mz
and intensity
) from the first
spectrum in each set.
Combining of spectra for MSnExp or OnDiskMSnExp objects is performed by default for each file separately, combining of spectra across files is thus not possible. See examples for details.
1 2 3 4 5 6 7 8 9 10 11 | ## S4 method for signature 'MSnExp'
combineSpectra(
object,
fcol = "fileIdx",
method = meanMzInts,
...,
BPPARAM = bpparam()
)
## S4 method for signature 'MSpectra'
combineSpectra(object, fcol, method = meanMzInts, fun, ...)
|
object |
A MSnExp or MSpectra |
fcol |
For |
method |
|
... |
additional arguments for |
BPPARAM |
For |
fun |
Deprecated use |
A MSpectra
or MSnExp
object with combined spectra. Metadata
(mcols
) and all spectrum attributes other than mz
and intensity
are taken from the first Spectrum
in each set.
Johannes Rainer, Laurent Gatto
meanMzInts()
for a function to combine spectra.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | set.seed(123)
mzs <- seq(1, 20, 0.1)
ints1 <- abs(rnorm(length(mzs), 10))
ints1[11:20] <- c(15, 30, 90, 200, 500, 300, 100, 70, 40, 20) # add peak
ints2 <- abs(rnorm(length(mzs), 10))
ints2[11:20] <- c(15, 30, 60, 120, 300, 200, 90, 60, 30, 23)
ints3 <- abs(rnorm(length(mzs), 10))
ints3[11:20] <- c(13, 20, 50, 100, 200, 100, 80, 40, 30, 20)
## Create the spectra.
sp1 <- new("Spectrum1", mz = mzs + rnorm(length(mzs), sd = 0.01),
intensity = ints1, rt = 1)
sp2 <- new("Spectrum1", mz = mzs + rnorm(length(mzs), sd = 0.01),
intensity = ints2, rt = 2)
sp3 <- new("Spectrum1", mz = mzs + rnorm(length(mzs), sd = 0.009),
intensity = ints3, rt = 3)
spctra <- MSpectra(sp1, sp2, sp3,
elementMetadata = DataFrame(idx = 1:3, group = c("b", "a", "a")))
## Combine the spectra reporting the maximym signal
res <- combineSpectra(spctra, mzd = 0.05, intensityFun = max)
res
## All values other than m/z and intensity are kept from the first spectrum
rtime(res)
## Plot the individual and the merged spectrum
par(mfrow = c(2, 1), mar = c(4.3, 4, 1, 1))
plot(mz(sp1), intensity(sp1), xlim = range(mzs[5:25]), type = "h", col = "red")
points(mz(sp2), intensity(sp2), type = "h", col = "green")
points(mz(sp3), intensity(sp3), type = "h", col = "blue")
plot(mz(res[[1]]), intensity(res[[1]]), type = "h",
col = "black", xlim = range(mzs[5:25]))
## Combine spectra in two sets.
res <- combineSpectra(spctra, fcol = "group", mzd = 0.05)
res
rtime(res)
## Plot the individual and the merged spectra
par(mfrow = c(3, 1), mar = c(4.3, 4, 1, 1))
plot(mz(sp1), intensity(sp1), xlim = range(mzs[5:25]), type = "h", col = "red")
points(mz(sp2), intensity(sp2), type = "h", col = "green")
points(mz(sp3), intensity(sp3), type = "h", col = "blue")
plot(mz(res[[1]]), intensity(res[[1]]), xlim = range(mzs[5:25]), type = "h",
col = "black")
plot(mz(res[[2]]), intensity(res[[2]]), xlim = range(mzs[5:25]), type = "h",
col = "black")
## Combining spectra of an MSnExp/OnDiskMSnExp objects
## Reading data from 2 mzML files
sciex <- readMSData(dir(system.file("sciex", package = "msdata"),
full.names = TRUE), mode = "onDisk")
## Filter the file to a retention time range from 2 to 20 seconds (to reduce
## execution time of the example)
sciex <- filterRt(sciex, rt = c(2, 20))
table(fromFile(sciex))
## We have thus 64 spectra per file.
## In the example below we combine spectra measured in one second to a
## single spectrum. We thus first define the grouping variable and add that
## to the `fData` of the object. For combining, we use the
## `consensusSpectrum` function that combines the spectra keeping only peaks
## that were found in 50% of the spectra; by defining `mzd = 0.01` all peaks
## within an m/z of 0.01 are evaluated for combining.
seconds <- round(rtime(sciex))
head(seconds)
fData(sciex)$second <- seconds
res <- combineSpectra(sciex, fcol = "second", mzd = 0.01, minProp = 0.1,
method = consensusSpectrum)
table(fromFile(res))
## The data was reduced to 19 spectra for each file.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.