RMassBank: Non-standard usage

Introduction

## 
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
## 
##     lowess

This vignette assumes you are familiar with the standard usage of RMassBank, which is documented in

vignette("RMassBank")

Skipping recalibration

For instances where recalibration is not wanted, e.g. there is not enough data, or the user wants to use non-recalibrated data, recalibration can be deactivated. To do this, the recalibrator entry in the settings must be set to recalibrate.identity. This can be done in the settings file directly (preferred):

recalibrator:
    MS1: recalibrate.identity
    MS2: recalibrate.identity

Or, alternatively, the settings can be adapted directly via R code.

RmbDefaultSettings()
rmbo <- getOption("RMassBank")
rmbo$recalibrator <- list(
        "MS1" = "recalibrate.identity",
        "MS2" = "recalibrate.identity"
    )
options("RMassBank" = rmbo)

To show the results of using a non-recalibrated workflow, we load a workspace with pre-processed data:

w <- loadMsmsWorkspace(system.file("results/pH_narcotics_RF.RData", 
                package="RMassBankData"))
## Warning in .updateObject.RmbWorkspace.1to2(w, ..., verbose): You are
## loading an archive from an old RMassBank version. The aggregate tables
## are not loaded from the original object, but recomputed.
## Warning in .updateObject.RmbWorkspace.1to2(w, ..., verbose): If you
## hand-edited any aggregate table, the information might not be retained in
## the new object.
## Warning in .updateObject.RmbWorkspace.1to2(w, ..., verbose): You are
## loading an archive from an old RMassBank version. The aggregate tables
## are not loaded from the original object, but recomputed.
## Warning in .updateObject.RmbWorkspace.1to2(w, ..., verbose): If you
## hand-edited any aggregate table, the information might not be retained in
## the new object.
## Warning in .updateObject.RmbWorkspace.1to2(w, ..., verbose): You are
## loading an archive from an old RMassBank version. The multiplicity
## filtering results are not loaded from the original object, but
## recomputed.
## Warning in .updateObject.RmbWorkspace.1to2(w, ..., verbose): If you
## hand-edited any multiplicity filtering results, the information might not
## be retained in the new object.

The recalibration curve:

recal <- makeRecalibration(w@parent,
                recalibrateBy = rmbo$recalibrateBy,
                recalibrateMS1 = rmbo$recalibrateMS1,
                recalibrator = list(MS1="recalibrate.loess",MS2="recalibrate.loess"),
                recalibrateMS1Window = 15)

w@rc <- recal$rc
w@rc.ms1 <- recal$rc.ms1
w@parent <- w
plotRecalibration(w)

Some example peaks to show the effect of recalibration:

w@spectra[[1]]@parent@mz[30:32]
## [1] 133.0346 133.0381 133.9772
w@spectra[[1]]@children[[1]]@mz[15:17]
## [1] 87.00286 88.13592 97.10767

Now reprocess the recalibration step with the above set recalibration.identity:

w <- msmsWorkflow(w, steps=4)

The recalibration graph shows that the recalibration “curve” will do no recalibration. To verify, we can show the same peaks as before:

w@spectra[[1]]@parent@mz[30:32]
## [1] 133.0346 133.0381 133.9772
w@spectra[[1]]@children[[1]]@mz[15:17]
## [1] 87.00286 88.13592 97.10767

Combining multiplicities

Standard multiplicity filtering, which is configurable in the settings, eliminates peaks which are observed only once for a compound. This eliminates spurious formula matches for random noise efficiently. It works well if either many spectra are recorded per compound, or if the same collision energy is present twice (e.g. with different resolutions). It sometimes fails for spectra on the “outer end” of the recorded collision energies when that spectrum is only present once – peaks which appear only in the highest or only in the lowest recorded energy can be erroneously deleted. To prevent this, one can re-run the workflow, read a second set of spectra for every compound (the second most intense) and combine the peak multiplicities of the two analyzed runs. (Mutiplicity filtering can also be switched off completely.)

Example:

RmbDefaultSettings()
getOption("RMassBank")$multiplicityFilter
## [1] 2
# to make processing faster, we only use 3 spectra per compound
rmbo <- getOption("RMassBank")
rmbo$spectraList <- list(
    list(mode="CID", ces = "35%", ce = "35 % (nominal)", res = 7500),
    list(mode="HCD", ces = "15%", ce = "15 % (nominal)", res = 7500),
    list(mode="HCD", ces = "30%", ce = "30 % (nominal)", res = 7500)
)
options(RMassBank = rmbo)

loadList(system.file("list/NarcoticsDataset.csv", 
        package="RMassBankData"))


w <- newMsmsWorkspace()
files <- list.files(system.file("spectra", package="RMassBankData"),
        ".mzML", full.names = TRUE)
w@files <- files[1:2]

First, the spectra are read and processed until reanalysis (step 7) normally:

w1 <- msmsWorkflow(w, mode="pH", steps=c(1))
# Here we artificially cut spectra out to make the workflow run faster for the vignette:
w1@spectra <- as(lapply(w1@spectra, function(s)
    {
        s@children <- s@children[1:3]
        s
    }),"SimpleList")
w1 <- msmsWorkflow(w1, mode="pH", steps=c(2:7))

Subsequently, we re-read and process the “confirmation spectra”, i.e. the second-best spectra from the files. Therefore, we will have two sets of spectra for each compound and every real peak should in theory occur twice.

w2 <- msmsWorkflow(w, mode="pH", steps=c(1), confirmMode = 1)
# Here we artificially cut spectra out to make the workflow run faster for the vignette:

w2@spectra <- as(lapply(w2@spectra, function(s)
    {
        s@children <- s@children[1:3]
        s
    }),"SimpleList")
w2 <- msmsWorkflow(w2, mode="pH", steps=c(2:7))

Finally, we combine the two workspaces for multiplicity filtering, and apply the last step in the workflow (multiplicity filtering).

wTotal <- combineMultiplicities(c(w1, w2))
wTotal <- msmsWorkflow(wTotal, steps=8, mode="pH", archivename = "output")

Subsequently, we can proceed as usual with mbWorkflow:

mb <- newMbWorkspace(wTotal)
# [...] load lists, execute workflow etc.

Session information

sessionInfo()
## R version 4.4.2 (2024-10-31)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C                 
##  [3] LC_TIME=en_US.UTF-8           LC_COLLATE=C                 
##  [5] LC_MONETARY=en_US.UTF-8       LC_MESSAGES=en_US.UTF-8      
##  [7] LC_PAPER=en_US.UTF-8          LC_NAME=en_US.UTF-8          
##  [9] LC_ADDRESS=en_US.UTF-8        LC_TELEPHONE=en_US.UTF-8     
## [11] LC_MEASUREMENT=en_US.UTF-8    LC_IDENTIFICATION=en_US.UTF-8
## 
## time zone: Etc/UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] gplots_3.2.0         RMassBankData_1.44.0 RMassBank_3.17.0    
## [4] Rcpp_1.0.13-1        BiocStyle_2.35.0    
## 
## loaded via a namespace (and not attached):
##   [1] sys_3.4.3                   jsonlite_1.8.9             
##   [3] MultiAssayExperiment_1.33.0 magrittr_2.0.3             
##   [5] MALDIquant_1.22.3           rmarkdown_2.29             
##   [7] zlibbioc_1.52.0             vctrs_0.6.5                
##   [9] RCurl_1.98-1.16             base64enc_0.1-3            
##  [11] htmltools_0.5.8.1           S4Arrays_1.7.1             
##  [13] itertools_0.1-3             curl_6.0.1                 
##  [15] SparseArray_1.7.2           mzID_1.45.0                
##  [17] sass_0.4.9                  KernSmooth_2.23-24         
##  [19] bslib_0.8.0                 htmlwidgets_1.6.4          
##  [21] plyr_1.8.9                  httr2_1.0.6                
##  [23] impute_1.81.0               cachem_1.1.0               
##  [25] buildtools_1.0.0            igraph_2.1.1               
##  [27] lifecycle_1.0.4             iterators_1.0.14           
##  [29] pkgconfig_2.0.3             Matrix_1.7-1               
##  [31] R6_2.5.1                    fastmap_1.2.0              
##  [33] GenomeInfoDbData_1.2.13     MatrixGenerics_1.19.0      
##  [35] clue_0.3-66                 digest_0.6.37              
##  [37] pcaMethods_1.99.0           rsvg_2.6.1                 
##  [39] colorspace_2.1-1            S4Vectors_0.45.2           
##  [41] GenomicRanges_1.59.0        fansi_1.0.6                
##  [43] httr_1.4.7                  abind_1.4-8                
##  [45] compiler_4.4.2              withr_3.0.2                
##  [47] bit64_4.5.2                 doParallel_1.0.17          
##  [49] BiocParallel_1.41.0         DBI_1.2.3                  
##  [51] logger_0.4.0                fingerprint_3.5.7          
##  [53] R.utils_2.12.3              MASS_7.3-61                
##  [55] ChemmineR_3.59.0            rappdirs_0.3.3             
##  [57] DelayedArray_0.33.2         rjson_0.2.23               
##  [59] caTools_1.18.3              gtools_3.9.5               
##  [61] mzR_2.41.0                  tools_4.4.2                
##  [63] PSMatch_1.11.0              R.oo_1.27.0                
##  [65] webchem_1.3.0               glue_1.8.0                 
##  [67] QFeatures_1.17.0            grid_4.4.2                 
##  [69] cluster_2.1.6               readJDX_0.6.4              
##  [71] reshape2_1.4.4              generics_0.1.3             
##  [73] gtable_0.3.6                rcdk_3.8.1                 
##  [75] tzdb_0.4.0                  R.methodsS3_1.8.2          
##  [77] preprocessCore_1.69.0       tidyr_1.3.1                
##  [79] data.table_1.16.2           hms_1.1.3                  
##  [81] xml2_1.3.6                  utf8_1.2.4                 
##  [83] XVector_0.47.0              BiocGenerics_0.53.3        
##  [85] foreach_1.5.2               pillar_1.9.0               
##  [87] stringr_1.5.1               vroom_1.6.5                
##  [89] limma_3.63.2                rJava_1.0-11               
##  [91] dplyr_1.1.4                 lattice_0.22-6             
##  [93] bit_4.5.0                   tidyselect_1.2.1           
##  [95] maketools_1.3.1             knitr_1.49                 
##  [97] gridExtra_2.3               IRanges_2.41.1             
##  [99] ProtGenerics_1.39.0         SummarizedExperiment_1.37.0
## [101] stats4_4.4.2                xfun_0.49                  
## [103] Biobase_2.67.0              statmod_1.5.0              
## [105] MSnbase_2.33.2              matrixStats_1.4.1          
## [107] DT_0.33                     stringi_1.8.4              
## [109] UCSC.utils_1.3.0            lazyeval_0.2.2             
## [111] yaml_2.3.10                 evaluate_1.0.1             
## [113] codetools_0.2-20            data.tree_1.1.0            
## [115] rcdklibs_2.9                MsCoreUtils_1.19.0         
## [117] tibble_3.2.1                BiocManager_1.30.25        
## [119] cli_3.6.3                   affyio_1.77.0              
## [121] munsell_0.5.1               jquerylib_0.1.4            
## [123] GenomeInfoDb_1.43.1         png_0.1-8                  
## [125] XML_3.99-0.17               parallel_4.4.2             
## [127] ggplot2_3.5.1               readr_2.1.5                
## [129] assertthat_0.2.1            AnnotationFilter_1.31.0    
## [131] bitops_1.0-9                scales_1.3.0               
## [133] affy_1.85.0                 ncdf4_1.23                 
## [135] purrr_1.0.2                 crayon_1.5.3               
## [137] rlang_1.1.4                 rvest_1.0.4                
## [139] vsn_3.75.0