## ----style, echo = FALSE, results = 'asis', message=FALSE--------------------- BiocStyle::markdown() ##---- echo = false,消息= false ------------------------------------------------------------------------------------------------------------------------------库(spectra)knitr :: opts_chunk $ set(echo = true,message = false)库(biocStyle)## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------库(Spectra)库(msbackendmassbank)fls <-dir(system.file(“ extdata”,package =“ msbackendmassbank”),full.names = true,pattern =“ txt $”)fls ## ---- import--------------------------------------------------------------------------------------------------------- sps <- Spectra(fls[1], source = MsBackendMassbank(), backend = MsBackendDataFrame()) ## ----spectravars-------------------------------------------------------------- spectraVariables(sps) ## ----import2------------------------------------------------------------------ sps <- Spectra(fls[-1], source = MsBackendMassbank(), backend = MsBackendDataFrame()) spectraVariables(sps) ## ----metadata----------------------------------------------------------------- # create data frame to indicate with metadata blocks shall be read. metaDataBlocks <- data.frame(metadata = c("ac", "ch", "sp", "ms", "record", "pk", "comment"), read = rep(TRUE, 7)) sps <- Spectra(fls[-1], source = MsBackendMassbank(), backeend = MsBackendDataFrame(), metaBlock = metaDataBlocks) # all spectraVariables possible in MassBank are read spectraVariables(sps) # all NA columns can be dropped spectraVariables(dropNaSpectraVariables(sps)) ## ----instrument--------------------------------------------------------------- sps$rtime sps$title ## ----mz----------------------------------------------------------------------- mz(sps) intensity(sps) ## ----all-import, eval = FALSE------------------------------------------------- # sps <- Spectra(fls, source = MsBackendMassbank(), nonStop = TRUE) ## ----mysql, eval = FALSE------------------------------------------------------ # library(RMariaDB) # con <- dbConnect(MariaDB(), host = "localhost", user = "massbank", # dbname = "MassBank") ## ----sqlite------------------------------------------------------------------- library(RSQLite) con <- dbConnect(SQLite(), system.file("sql", "minimassbank.sqlite", package = "MsBackendMassbank")) ## ----------------------------------------------------------------------------- mb <- Spectra(con, source = MsBackendMassbankSql()) mb ## ----------------------------------------------------------------------------- spectraVariables(mb) ## ----------------------------------------------------------------------------- head(msLevel(mb)) ## ----------------------------------------------------------------------------- head(mb$msLevel) ## ----------------------------------------------------------------------------- mz(mb) ## ----------------------------------------------------------------------------- table(mb$instrument_type) ## ----------------------------------------------------------------------------- mb <- mb[mb$ionization == "ESI"] length(mb) ## ----------------------------------------------------------------------------- library(MsCoreUtils) sims <- compareSpectra(mb[11], mb[-11], FUN = ndotproduct, ppm = 40) max(sims) ## ----------------------------------------------------------------------------- plotSpectraMirror(mb[11], mb[(which.max(sims) + 1)], ppm = 40) ## ----------------------------------------------------------------------------- mb_match <- mb[c(11, which.max(sims) + 1)] compounds(mb_match) ## ----------------------------------------------------------------------------- sessionInfo()