This vignette illustrates how to convert MS/MS spectra libraries (.msp files) to MetaboAnnotatoR metabolite library entries.
Load MetaboAnnotatoR library and dependencies
library(MetaboAnnotatoR)
Get the path to the example .msp MS/MS spectra library file:
Get the path to the example file containing the .msp library. For illustrative purposes, an .msp file containing some MS/MS spectra obtained from MassBank from both positive and negative ionisation modes was used:
msp_path <- system.file("extdata", "MassBank_example.msp",
package="MetaboAnnotatoR")
**Set a directory to store
Generate library entries imported from the .msp file
For this example a temporary directory will be used, but the user is encouraged to use any other preferred directory.
LibDir <- tempdir()
Use function mspToLib to read and convert the spectra records from the .msp files into library entries (.csv files), which will be stored in the user-defined library directory (LibDir). A “positive” or “negative” mode suffix will be added to each file name to facilitate the organisation of the custom libraries. Similarly to the function genFragEntry this function will attribute occurrence scores to the peaks above mpeaksThres threshold (“marker peaks”) and above the noise level. The peak-picking parameters noise and mpeaksThres and the occurrence scores used here are the default parameters.
mspToLib(msp_path, LibDir, noise=0.005, mpeaksScore=0.9, mpeaksThres=0.1)
sessionInfo()
#> R version 4.6.0 alpha (2026-04-05 r89794)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.4 LTS
#>
#> Matrix products: default
#> BLAS: /home/biocbuild/bbs-3.23-bioc/R/lib/libRblas.so
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0 LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_GB 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=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: America/New_York
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats4 stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] MetaboAnnotatoR_0.99.21 MSnbase_2.37.3 ProtGenerics_1.43.0
#> [4] S4Vectors_0.49.1 mzR_2.45.1 Rcpp_1.1.1
#> [7] Biobase_2.71.0 BiocGenerics_0.57.0 generics_0.1.4
#> [10] xcms_4.9.2 BiocParallel_1.45.0 BiocStyle_2.39.0
#>
#> loaded via a namespace (and not attached):
#> [1] DBI_1.3.0 rlang_1.2.0
#> [3] magrittr_2.0.5 clue_0.3-68
#> [5] MassSpecWavelet_1.77.0 otel_0.2.0
#> [7] matrixStats_1.5.0 compiler_4.6.0
#> [9] PTMods_0.99.6 systemfonts_1.3.2
#> [11] vctrs_0.7.3 reshape2_1.4.5
#> [13] stringr_1.6.0 crayon_1.5.3
#> [15] pkgconfig_2.0.3 MetaboCoreUtils_1.19.2
#> [17] fastmap_1.2.0 magick_2.9.1
#> [19] XVector_0.51.0 labeling_0.4.3
#> [21] rmarkdown_2.31 preprocessCore_1.73.0
#> [23] ragg_1.5.2 tinytex_0.59
#> [25] purrr_1.2.2 xfun_0.57
#> [27] MultiAssayExperiment_1.37.4 cachem_1.1.0
#> [29] jsonlite_2.0.0 progress_1.2.3
#> [31] DelayedArray_0.37.1 prettyunits_1.2.0
#> [33] parallel_4.6.0 cluster_2.1.8.2
#> [35] R6_2.6.1 bslib_0.10.0
#> [37] stringi_1.8.7 RColorBrewer_1.1-3
#> [39] limma_3.67.1 GenomicRanges_1.63.2
#> [41] jquerylib_0.1.4 Seqinfo_1.1.0
#> [43] bookdown_0.46 SummarizedExperiment_1.41.1
#> [45] iterators_1.0.14 knitr_1.51
#> [47] IRanges_2.45.0 Matrix_1.7-5
#> [49] igraph_2.2.3 tidyselect_1.2.1
#> [51] dichromat_2.0-0.1 abind_1.4-8
#> [53] yaml_2.3.12 doParallel_1.0.17
#> [55] codetools_0.2-20 affy_1.89.0
#> [57] lattice_0.22-9 tibble_3.3.1
#> [59] plyr_1.8.9 withr_3.0.2
#> [61] S7_0.2.1 evaluate_1.0.5
#> [63] Spectra_1.21.7 pillar_1.11.1
#> [65] affyio_1.81.0 BiocManager_1.30.27
#> [67] MatrixGenerics_1.23.0 foreach_1.5.2
#> [69] MALDIquant_1.22.3 ncdf4_1.24
#> [71] hms_1.1.4 ggplot2_4.0.2
#> [73] scales_1.4.0 MsExperiment_1.13.1
#> [75] glue_1.8.0 MsFeatures_1.19.0
#> [77] lazyeval_0.2.3 tools_4.6.0
#> [79] mzID_1.49.1 data.table_1.18.2.1
#> [81] QFeatures_1.21.2 vsn_3.79.6
#> [83] fs_2.0.1 XML_3.99-0.23
#> [85] grid_4.6.0 impute_1.85.0
#> [87] tidyr_1.3.2 MsCoreUtils_1.23.7
#> [89] PSMatch_1.15.3 cli_3.6.6
#> [91] textshaping_1.0.5 S4Arrays_1.11.1
#> [93] dplyr_1.2.1 AnnotationFilter_1.35.0
#> [95] pcaMethods_2.3.0 gtable_0.3.6
#> [97] sass_0.4.10 digest_0.6.39
#> [99] SparseArray_1.11.13 farver_2.1.2
#> [101] htmltools_0.5.9 lifecycle_1.0.5
#> [103] statmod_1.5.1 MASS_7.3-65