# Clustering Mass Spectra from Low Resolution LC-MS/MS Data Using CluMSID

#### Tobias Depke

#### November 01, 2022

## Introduction

As described in the GC-EI-MS tutorial, CluMSID can also be used to analyse low resolution data – although using low resolution data comes at a cost.

In this example, we will use a similar sample (1uL Pseudomonas aeruginosa PA14 cell extract) as in the General Tutorial, measured with similar chromatography but on a different mass spectrometer, a Bruker amaZon ion trap instrument operated in ESI-(+) mode with auto-MS/MS. In addition to introducing a workflow for low resolution LC-MS/MS data, this example also demonstrates that CluMSID can work with data from different types of mass spectrometers.

## Data import

We load the file from the `CluMSIDdata` package:

    library(CluMSID)
    library(CluMSIDdata)

    lowresfile <- system.file("extdata",
                            "PA14_amazon_lowres.mzXML",
                            package = "CluMSIDdata")

## Data preprocessing

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

    ms2list <- extractMS2spectra(lowresfile)
    length(ms2list)
    #> [1] 1989

Like in the GC-EI-MS example, we have to adjust `mz_tolerance` to a much higher value compared to high resolution data, while the retention time tolerance can remain unchanged.

    featlist <- mergeMS2spectra(ms2list, mz_tolerance = 0.02)

    length(featlist)
    #> [1] 525

We see that we have similar numbers of spectra as in the General Tutorial, because we tried to keep all parameters except for the mass spectrometer type comparable.

## Generation of distance matrix

As we do not have low resolution spectral libraries at hand, we skip the integration of previous knowledge on feature identities in this example 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.

When we now make an MDS plot, we learn that the similarity data is very different from the comparable high resolution data:

    MDSplot(distmat)

Figure 1: Multidimensional scaling plot as a visualisation of MS2 spectra similarities of the low resolution LC-MS/MS example data set. Black dots signify spectra from unknown metabolites.

To get a better overview of the data and the general similarity behaviour, we create a heat map of the distance matrix:

    HCplot(distmat, type = "heatmap",
                    cexRow = 0.1, cexCol = 0.1,
                    margins = c(6,6))

Figure 2: Symmetric heat map of the distance matrix displaying MS2 spectra similarities of the low resolution LC-MS/MS example data set. along with dendrograms resulting from hierarchical clustering based on the distance matrix. The colour encoding is shown in the top-left insert.

We clearly see that the heat map is generally a lot “warmer” than in the General Tutorial (an intuition that is supported by the histogram in the top-left corner), i.e. we have a higher general degree of similarity between spectra. That is not surprising as the m/z information has much fewer levels than in high resolution data and fragments of different sum formula are more likely to have indistinguishable mass-to-charge ratios.

We also see that some more or less compact clusters can be identified. This is easier to inspect in the dendrogram visualisation:

    HCplot(distmat, h = 0.8, cex = 0.3)

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

In conclusion, CluMSID is capable of processing low resolution LC-MS/MS data and if high resolution data is not available, it can be very useful to provide an overview of spectral similarities in low resolution data, thereby helping metabolite annotation if some individual metabolites can be identified by comparison to authentic standards. However, concerning feature annotation, high resolution methods should always be favoured for the many benefits they provide.

# Session Info

    sessionInfo()
    #> R version 4.2.1 (2022-06-23 ucrt)
    #> Platform: x86_64-w64-mingw32/x64 (64-bit)
    #> Running under: Windows Server x64 (build 20348)
    #>
    #> Matrix products: default
    #>
    #> 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
    #>
    #> attached base packages:
    #> [1] stats4    stats     graphics  grDevices utils     datasets  methods
    #> [8] base
    #>
    #> other attached packages:
    #>  [1] magrittr_2.0.3      metaMSdata_1.33.0   metaMS_1.34.0
    #>  [4] CAMERA_1.54.0       xcms_3.20.0         MSnbase_2.24.0
    #>  [7] ProtGenerics_1.30.0 S4Vectors_0.36.0    mzR_2.32.0
    #> [10] Rcpp_1.0.9          BiocParallel_1.32.0 Biobase_2.58.0
    #> [13] BiocGenerics_0.44.0 CluMSIDdata_1.13.0  CluMSID_1.14.0
    #>
    #> loaded via a namespace (and not attached):
    #>   [1] snow_0.4-4                  backports_1.4.1
    #>   [3] Hmisc_4.7-1                 plyr_1.8.7
    #>   [5] igraph_1.3.5                lazyeval_0.2.2
    #>   [7] splines_4.2.1               GenomeInfoDb_1.34.0
    #>   [9] ggplot2_3.3.6               digest_0.6.30
    #>  [11] foreach_1.5.2               htmltools_0.5.3
    #>  [13] fansi_1.0.3                 checkmate_2.1.0
    #>  [15] cluster_2.1.4               doParallel_1.0.17
    #>  [17] tzdb_0.3.0                  limma_3.54.0
    #>  [19] readr_2.1.3                 sna_2.7
    #>  [21] matrixStats_0.62.0          vroom_1.6.0
    #>  [23] MsFeatures_1.6.0            jpeg_0.1-9
    #>  [25] colorspace_2.0-3            xfun_0.34
    #>  [27] dplyr_1.0.10                crayon_1.5.2
    #>  [29] RCurl_1.98-1.9              jsonlite_1.8.3
    #>  [31] graph_1.76.0                impute_1.72.0
    #>  [33] survival_3.4-0              iterators_1.0.14
    #>  [35] ape_5.6-2                   glue_1.6.2
    #>  [37] gtable_0.3.1                zlibbioc_1.44.0
    #>  [39] XVector_0.38.0              DelayedArray_0.24.0
    #>  [41] DEoptimR_1.0-11             scales_1.2.1
    #>  [43] vsn_3.66.0                  DBI_1.1.3
    #>  [45] GGally_2.1.2                viridisLite_0.4.1
    #>  [47] htmlTable_2.4.1             clue_0.3-62
    #>  [49] archive_1.1.5               bit_4.0.4
    #>  [51] foreign_0.8-83              preprocessCore_1.60.0
    #>  [53] Formula_1.2-4               MsCoreUtils_1.10.0
    #>  [55] htmlwidgets_1.5.4           httr_1.4.4
    #>  [57] gplots_3.1.3                RColorBrewer_1.1-3
    #>  [59] ellipsis_0.3.2              farver_2.1.1
    #>  [61] pkgconfig_2.0.3             reshape_0.8.9
    #>  [63] XML_3.99-0.12               nnet_7.3-18
    #>  [65] sass_0.4.2                  deldir_1.0-6
    #>  [67] utf8_1.2.2                  labeling_0.4.2
    #>  [69] tidyselect_1.2.0            rlang_1.0.6
    #>  [71] munsell_0.5.0               tools_4.2.1
    #>  [73] cachem_1.0.6                cli_3.4.1
    #>  [75] dbscan_1.1-11               generics_0.1.3
    #>  [77] statnet.common_4.7.0        evaluate_0.17
    #>  [79] stringr_1.4.1               fastmap_1.1.0
    #>  [81] mzID_1.36.0                 yaml_2.3.6
    #>  [83] bit64_4.0.5                 knitr_1.40
    #>  [85] robustbase_0.95-0           caTools_1.18.2
    #>  [87] purrr_0.3.5                 RANN_2.6.1
    #>  [89] ncdf4_1.19                  RBGL_1.74.0
    #>  [91] nlme_3.1-160                compiler_4.2.1
    #>  [93] rstudioapi_0.14             plotly_4.10.0
    #>  [95] png_0.1-7                   affyio_1.68.0
    #>  [97] MassSpecWavelet_1.64.0      tibble_3.1.8
    #>  [99] bslib_0.4.0                 stringi_1.7.8
    #> [101] highr_0.9                   lattice_0.20-45
    #> [103] Matrix_1.5-1                vctrs_0.5.0
    #> [105] pillar_1.8.1                lifecycle_1.0.3
    #> [107] BiocManager_1.30.19         jquerylib_0.1.4
    #> [109] MALDIquant_1.21             data.table_1.14.4
    #> [111] bitops_1.0-7                GenomicRanges_1.50.0
    #> [113] R6_2.5.1                    latticeExtra_0.6-30
    #> [115] pcaMethods_1.90.0           affy_1.76.0
    #> [117] network_1.18.0              KernSmooth_2.23-20
    #> [119] gridExtra_2.3               IRanges_2.32.0
    #> [121] codetools_0.2-18            MASS_7.3-58.1
    #> [123] gtools_3.9.3                assertthat_0.2.1
    #> [125] SummarizedExperiment_1.28.0 withr_2.5.0
    #> [127] GenomeInfoDbData_1.2.9      hms_1.1.2
    #> [129] parallel_4.2.1              grid_4.2.1
    #> [131] rpart_4.1.19                tidyr_1.2.1
    #> [133] coda_0.19-4                 rmarkdown_2.17
    #> [135] MatrixGenerics_1.10.0       base64enc_0.1-3
    #> [137] interp_1.1-3