# Clustering Spectra from High Resolution DI-MS/MS Data Using CluMSID

#### Tobias Depke

#### April 15, 2025

## Introduction

Although originally developed for liquid chromatography-tandem mass spectrometry (LC-MS/MS) data, CluMSID can also be used with direct infusion-tandem mass spectrometry (DI-MS/MS) data.

Generally, the missing retention time dimension makes feature annotation in metabolomics harder but if only direct infusion data is at hand, CluMSID can help to get an overview of the chemodiversity of a sample measured by DI-MS/MS.

In this example, we will use a similar sample (1uL Pseudomonas aeruginosa PA14 cell extract) as in the General Tutorial, measured on the same machine, a Bruker maxisHD qTOF operated in ESI-(+) mode with auto-MS/MS but without chromatographic separation.

## Data import

We load the file from the `CluMSIDdata` package:

    library(CluMSID)
    library(CluMSIDdata)

    DIfile <- system.file("extdata",
                            "PA14_maxis_DI.mzXML",
                            package = "CluMSIDdata")

## Data preprocessing

The extraction of spectra works the same way as with LC-MS/MS data:

    ms2list <- extractMS2spectra(DIfile)
    length(ms2list)
    #> [1] 373

Merging of redundant spectra is less straightforward when retention time is not available. Depending on the MS/MS method it can be next to impossible to decide whether two spectra with the same precursor m/z and similar fragmentation patterns derive from the same analyte or from two different but structurally similar ones.

In this example, we would like to merge spectra with identical precursor ions only if they were recorded one right after another. We can do so by setting `rt_tolerance` to 1 second:

    featlist <- mergeMS2spectra(ms2list, rt_tolerance = 1)
    length(featlist)
    #> [1] 349

We see that we have hardly reduced the number of spectra in the list. If we would decide to merge all spectra with identical precursor m/z from the entire run, we could do so by setting `rt_tolerance` to the duration of the run, in this case approx. 250 seconds:

    testlist <- mergeMS2spectra(ms2list, rt_tolerance = 250)
    length(testlist)
    #> [1] 75

The resulting number of spectra is drastically lower but the danger of merging spectra that do not actually derive from the same analyte is also very big.

## Generation of distance matrix

In this very explorative example, we skip the integration of previous knowledge on feature identities and generate a distance matrix right away:

    distmat <- distanceMatrix(featlist)

## Data exploration

Starting from this distance matrix, we can use all the data exploration functions that `CluMSID` offers. In this example workflow, we look at a cluster dendrogram:

    HCplot(distmat, cex = 0.5)

Figure 1: Circularised dendrogram as a result of agglomerative hierarchical clustering with average linkage as agglomeration criterion based on MS2 spectra similarities of the DI-MS/MS example data set. Each leaf represents one feature and colours encode cluster affiliation of the features. Leaf labels display feature IDs, along with feature annotations, if existent. Distance from the central point is indicative of the height of the dendrogram.

It is directly obvious that we have some spectra that are nearly identical and thus most likely derive from the same analyte, e.g. the many spectra with a precursor m/z of 270.19. But we still see nice clustering of similar spectra with different precursor m/z, e.g. the huge gray cluster that contains a lot of different alkylquinolone type metabolites (see General Tutorial).

In conclusion, CluMSID is very useful to provide an overview of spectral similarities within DI-MS/MS runs but wherever annotation is in the focus, one should not do without the additional layer of information created by chromatographic separation.

# Session Info

    sessionInfo()
    #> R version 4.5.0 RC (2025-04-04 r88126 ucrt)
    #> Platform: x86_64-w64-mingw32/x64
    #> Running under: Windows Server 2022 x64 (build 20348)
    #>
    #> Matrix products: default
    #>   LAPACK version 3.12.1
    #>
    #> locale:
    #> [1] LC_COLLATE=C
    #> [2] LC_CTYPE=English_United States.utf8
    #> [3] LC_MONETARY=English_United States.utf8
    #> [4] LC_NUMERIC=C
    #> [5] LC_TIME=English_United States.utf8
    #>
    #> time zone: America/New_York
    #> tzcode source: internal
    #>
    #> attached base packages:
    #> [1] stats     graphics  grDevices utils     datasets  methods   base
    #>
    #> other attached packages:
    #> [1] CluMSIDdata_1.23.0 CluMSID_1.24.0
    #>
    #> loaded via a namespace (and not attached):
    #>   [1] bitops_1.0-9                rlang_1.1.6
    #>   [3] magrittr_2.0.3              clue_0.3-66
    #>   [5] matrixStats_1.5.0           compiler_4.5.0
    #>   [7] vctrs_0.6.5                 reshape2_1.4.4
    #>   [9] stringr_1.5.1               ProtGenerics_1.40.0
    #>  [11] pkgconfig_2.0.3             MetaboCoreUtils_1.16.0
    #>  [13] crayon_1.5.3                fastmap_1.2.0
    #>  [15] XVector_0.48.0              caTools_1.18.3
    #>  [17] rmarkdown_2.29              UCSC.utils_1.4.0
    #>  [19] preprocessCore_1.70.0       network_1.19.0
    #>  [21] purrr_1.0.4                 xfun_0.52
    #>  [23] MultiAssayExperiment_1.34.0 cachem_1.1.0
    #>  [25] GenomeInfoDb_1.44.0         jsonlite_2.0.0
    #>  [27] DelayedArray_0.34.0         BiocParallel_1.42.0
    #>  [29] parallel_4.5.0              cluster_2.1.8.1
    #>  [31] R6_2.6.1                    bslib_0.9.0
    #>  [33] stringi_1.8.7               RColorBrewer_1.1-3
    #>  [35] limma_3.64.0                GGally_2.2.1
    #>  [37] GenomicRanges_1.60.0        jquerylib_0.1.4
    #>  [39] iterators_1.0.14            Rcpp_1.0.14
    #>  [41] SummarizedExperiment_1.38.0 knitr_1.50
    #>  [43] IRanges_2.42.0              BiocBaseUtils_1.10.0
    #>  [45] Matrix_1.7-3                igraph_2.1.4
    #>  [47] tidyselect_1.2.1            abind_1.4-8
    #>  [49] yaml_2.3.10                 gplots_3.2.0
    #>  [51] doParallel_1.0.17           codetools_0.2-20
    #>  [53] affy_1.86.0                 lattice_0.22-7
    #>  [55] tibble_3.2.1                plyr_1.8.9
    #>  [57] Biobase_2.68.0              coda_0.19-4.1
    #>  [59] evaluate_1.0.3              Spectra_1.18.0
    #>  [61] ggstats_0.9.0               pillar_1.10.2
    #>  [63] affyio_1.78.0               BiocManager_1.30.25
    #>  [65] MatrixGenerics_1.20.0       KernSmooth_2.23-26
    #>  [67] foreach_1.5.2               stats4_4.5.0
    #>  [69] plotly_4.10.4               MSnbase_2.34.0
    #>  [71] MALDIquant_1.22.3           ncdf4_1.24
    #>  [73] generics_0.1.3              dbscan_1.2.2
    #>  [75] S4Vectors_0.46.0            ggplot2_3.5.2
    #>  [77] munsell_0.5.1               scales_1.3.0
    #>  [79] gtools_3.9.5                glue_1.8.0
    #>  [81] lazyeval_0.2.2              tools_4.5.0
    #>  [83] data.table_1.17.0           mzID_1.46.0
    #>  [85] QFeatures_1.18.0            vsn_3.76.0
    #>  [87] mzR_2.42.0                  XML_3.99-0.18
    #>  [89] fs_1.6.6                    grid_4.5.0
    #>  [91] impute_1.82.0               ape_5.8-1
    #>  [93] tidyr_1.3.1                 MsCoreUtils_1.20.0
    #>  [95] colorspace_2.1-1            nlme_3.1-168
    #>  [97] GenomeInfoDbData_1.2.14     PSMatch_1.12.0
    #>  [99] cli_3.6.4                   viridisLite_0.4.2
    #> [101] S4Arrays_1.8.0              dplyr_1.1.4
    #> [103] AnnotationFilter_1.32.0     pcaMethods_2.0.0
    #> [105] gtable_0.3.6                sass_0.4.10
    #> [107] digest_0.6.37               BiocGenerics_0.54.0
    #> [109] SparseArray_1.8.0           htmlwidgets_1.6.4
    #> [111] sna_2.8                     htmltools_0.5.8.1
    #> [113] lifecycle_1.0.4             httr_1.4.7
    #> [115] statmod_1.5.0               statnet.common_4.11.0
    #> [117] MASS_7.3-65