BiocStyle::markdown()

Preparation

Load required packages and functions.

library("MSnbase")
library("MSnbaseBoxCar")
library("ggplot2")

Read a small dataset composed of 16 MS1 spectra as an MSnExp:

f <- dir(system.file("extdata", package = "MSnbaseBoxCar"),
         pattern = "boxcar.mzML",
         full.names = TRUE)
basename(f)
x <- readMSData(f, mode = "onDisk")
x

Define boxcar groups

Define boxcar groups based on the filterString metadata variable: full scans are encoded as "FTMS + p NSI Full ms [375.0000-1800.0000]" while their respective Boxcar scans reflect the provide adjacent m/z segments "FTMS + p NSI SIM msx ms [299.0000-1701.0000, 299.0000-351.0000, ...]"

fData(x)$filterString[1:4]

The bc_groups function identifies full (noted NA) and BoxCar spectra and groups the latter:

x <- bc_groups(x)
fData(x)$bc_groups

Keep only BoxCar spectra

The next filter BoxCar spectra, as defined above.

xbc <- filterBoxCar(x)
fData(xbc)$bc_groups
bc_plot(xbc[1:3]) +
    xlim(440, 510)

Combine BoxCar spectra

Remove any peaks outside of the BoxCar segments.

xbc <- bc_zero_out_box(xbc, offset = 0.5)
xbc
bc_plot(xbc[1:3]) +
    xlim(440, 510)

Combine BoxCar spectra to reconstitute the full scan and coerce result back to an MSnExp object containing 4 spectra.

res <- combineSpectra(xbc,
                      fcol = "bc_groups",
                      method = boxcarCombine)
res
plot(res[[1]])

The above steps can also be piped into a single command.

library("magrittr")
res <- x %>%
    bc_groups() %>%
    filterBoxCar() %>%    
    bc_zero_out_box(offset = 0.5) %>%
    combineSpectra(fcol = "groups",
                   method = boxcarCombine)

The processed data can also be written to a new mzML file.

writeMSData(res, "boxcar_processed.mzML")

References

Session information

sessionInfo()


lgatto/MSnbaseBoxCar documentation built on May 14, 2020, 9:12 p.m.