# Import an MS/MS library

# Introduction

This vignette illustrates how to convert MS/MS spectra libraries (.msp files) to MetaboAnnotatoR metabolite library entries.

# Import .msp library

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)

# Session Info

    sessionInfo()
    #> R version 4.6.0 (2026-04-24)
    #> Platform: x86_64-pc-linux-gnu
    #> Running under: Ubuntu 24.04.4 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=en_US.UTF-8
    #>  [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: Etc/UTC
    #> tzcode source: system (glibc)
    #>
    #> attached base packages:
    #> [1] stats4    stats     graphics  grDevices utils     datasets  methods
    #> [8] base
    #>
    #> other attached packages:
    #>  [1] MetaboAnnotatoR_1.0.0 MSnbase_2.38.0        ProtGenerics_1.44.0
    #>  [4] S4Vectors_0.50.0      mzR_2.46.0            Rcpp_1.1.1-1.1
    #>  [7] Biobase_2.72.0        BiocGenerics_0.58.0   generics_0.1.4
    #> [10] xcms_4.10.0           BiocParallel_1.46.0   BiocStyle_2.40.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.78.0      otel_0.2.0
    #>  [7] matrixStats_1.5.0           compiler_4.6.0
    #>  [9] PTMods_1.0.0                vctrs_0.7.3
    #> [11] reshape2_1.4.5              stringr_1.6.0
    #> [13] crayon_1.5.3                pkgconfig_2.0.3
    #> [15] MetaboCoreUtils_1.20.0      fastmap_1.2.0
    #> [17] XVector_0.52.0              rmarkdown_2.31
    #> [19] preprocessCore_1.74.0       purrr_1.2.2
    #> [21] xfun_0.57                   MultiAssayExperiment_1.38.0
    #> [23] cachem_1.1.0                jsonlite_2.0.0
    #> [25] progress_1.2.3              DelayedArray_0.38.1
    #> [27] prettyunits_1.2.0           parallel_4.6.0
    #> [29] cluster_2.1.8.2             R6_2.6.1
    #> [31] bslib_0.10.0                stringi_1.8.7
    #> [33] RColorBrewer_1.1-3          limma_3.68.0
    #> [35] GenomicRanges_1.64.0        jquerylib_0.1.4
    #> [37] Seqinfo_1.2.0               SummarizedExperiment_1.42.0
    #> [39] iterators_1.0.14            knitr_1.51
    #> [41] IRanges_2.46.0              Matrix_1.7-5
    #> [43] igraph_2.3.0                tidyselect_1.2.1
    #> [45] abind_1.4-8                 yaml_2.3.12
    #> [47] doParallel_1.0.17           codetools_0.2-20
    #> [49] affy_1.90.0                 lattice_0.22-9
    #> [51] tibble_3.3.1                plyr_1.8.9
    #> [53] S7_0.2.2                    evaluate_1.0.5
    #> [55] Spectra_1.22.0              pillar_1.11.1
    #> [57] affyio_1.82.0               BiocManager_1.30.27
    #> [59] MatrixGenerics_1.24.0       foreach_1.5.2
    #> [61] MALDIquant_1.22.3           ncdf4_1.24
    #> [63] hms_1.1.4                   ggplot2_4.0.3
    #> [65] scales_1.4.0                MsExperiment_1.14.0
    #> [67] glue_1.8.1                  MsFeatures_1.20.0
    #> [69] lazyeval_0.2.3              maketools_1.3.2
    #> [71] tools_4.6.0                 mzID_1.50.0
    #> [73] sys_3.4.3                   data.table_1.18.2.1
    #> [75] QFeatures_1.22.0            vsn_3.80.0
    #> [77] buildtools_1.0.0            fs_2.1.0
    #> [79] XML_3.99-0.23               grid_4.6.0
    #> [81] impute_1.86.0               tidyr_1.3.2
    #> [83] MsCoreUtils_1.24.0          PSMatch_1.16.0
    #> [85] cli_3.6.6                   S4Arrays_1.12.0
    #> [87] dplyr_1.2.1                 AnnotationFilter_1.36.0
    #> [89] pcaMethods_2.4.0            gtable_0.3.6
    #> [91] sass_0.4.10                 digest_0.6.39
    #> [93] SparseArray_1.12.1          farver_2.1.2
    #> [95] htmltools_0.5.9             lifecycle_1.0.5
    #> [97] statmod_1.5.1               MASS_7.3-65