Package: PSMatch
Authors: Laurent Gatto [aut, cre] (ORCID: https://orcid.org/0000-0002-1520-2268), Johannes Rainer [aut] (ORCID: https://orcid.org/0000-0002-6977-7147), Sebastian Gibb [aut] (ORCID: https://orcid.org/0000-0001-7406-4443), Samuel Wieczorek [ctb], Thomas Burger [ctb], Guillaume Deflandre [ctb] (ORCID: https://orcid.org/0009-0008-1257-2416)
Last modified: 2026-04-07 13:49:20.578182
Compiled: Tue Apr 7 19:31:58 2026

1 Introduction

This vignette is one among several illustrating how to use the PSMatch package, focusing on the calculation and visualisation of MS2 fragment ions. For a general overview of the package, see the PSMatch package manual page (?PSMatch) and references therein.

To illustrate this vignette, we will import and merge raw and identification data from the MsDataHub. For details about this section, please visit the Spectra package webpage.

Load the raw MS data:

spf <- MsDataHub::TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.20141210.mzML.gz()
library(Spectra)
sp <- Spectra(spf)

Load the identification data:

idf <- MsDataHub::TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.20141210.mzid()
## see ?MsDataHub and browseVignettes('MsDataHub') for documentation
## loading from cache
id <- PSM(idf) |> filterPSMs()
## Starting with 5802 PSMs:
## Removed 2896 decoy hits.
## Removed 155 PSMs with rank > 1.
## Removed 85 shared peptides.
## 2666 PSMs left.
id
## PSM with 2666 rows and 35 columns.
## names(35): sequence spectrumID ... subReplacementResidue subLocation

Merge both:

sp <- joinSpectraData(sp, id, by.x = "spectrumId", by.y = "spectrumID")
## Warning in joinSpectraData(sp, id, by.x = "spectrumId", by.y = "spectrumID"):
## Duplicates found in the 'y' key. Only last instance will be kept!
sp
## MSn data (Spectra) with 7534 spectra in a MsBackendMzR backend:
##        msLevel     rtime scanIndex
##      <integer> <numeric> <integer>
## 1            1    0.4584         1
## 2            1    0.9725         2
## 3            1    1.8524         3
## 4            1    2.7424         4
## 5            1    3.6124         5
## ...        ...       ...       ...
## 7530         2   3600.47      7530
## 7531         2   3600.83      7531
## 7532         2   3601.18      7532
## 7533         2   3601.57      7533
## 7534         2   3601.98      7534
##  ... 68 more variables/columns.
## 
## file(s):
## 11c59b8e63ab2_7858

In this example, we are going to focus the MS2 scan with index 1158 and its parent MS1 scan (index 1148, selected automatically with the filterPrecursorScan() function).

sp1158 <- filterPrecursorScan(sp, 1158)
plotSpectra(sp1158[1], xlim = c(400, 600))
abline(v = precursorMz(sp1158)[2], col = "red", lty = "dotted")

2 Calculating fragment ions

The MS2 scan was matched to the sequence SCALITDGR.

sp1158$sequence
## [1] NA          "SCALITDGR"

The calculateFragments() simply takes a peptide sequence as input and returns a data.frame with the fragment sequences, M/Z, ion type, charge, position and the peptide sequence of the parent ion. By default, carbamidomethylation of cysteines is applied, but it can be turned off with the parameter addCarbamidomethyl = FALSE.

calculateFragments(sp1158$sequence[2], addCarbamidomethyl = FALSE)
##           mz ion type pos z      seq   peptide
## 1   88.03931  b1    b   1 1        S SCALITDGR
## 2  191.04850  b2    b   2 1       SC SCALITDGR
## 3  262.08561  b3    b   3 1      SCA SCALITDGR
## 4  375.16967  b4    b   4 1     SCAL SCALITDGR
## 5  488.25373  b5    b   5 1    SCALI SCALITDGR
## 6  589.30141  b6    b   6 1   SCALIT SCALITDGR
## 7  704.32835  b7    b   7 1  SCALITD SCALITDGR
## 8  761.34981  b8    b   8 1 SCALITDG SCALITDGR
## 9  175.11895  y1    y   1 1        R SCALITDGR
## 10 232.14041  y2    y   2 1       GR SCALITDGR
## 11 347.16735  y3    y   3 1      DGR SCALITDGR
## 12 448.21503  y4    y   4 1     TDGR SCALITDGR
## 13 561.29909  y5    y   5 1    ITDGR SCALITDGR
## 14 674.38315  y6    y   6 1   LITDGR SCALITDGR
## 15 745.42026  y7    y   7 1  ALITDGR SCALITDGR
## 16 848.42945  y8    y   8 1 CALITDGR SCALITDGR
## 17 686.31778 b7_   b_   7 1  SCALITD SCALITDGR
## 18 743.33924 b8_   b_   8 1 SCALITDG SCALITDGR
## 19 329.15679 y3_   y_   3 1      DGR SCALITDGR
## 20 543.28853 y5_   y_   5 1    ITDGR SCALITDGR
## 21 656.37259 y6_   y_   6 1   LITDGR SCALITDGR
## 22 727.40970 y7_   y_   7 1  ALITDGR SCALITDGR
## 23 830.41889 y8_   y_   8 1 CALITDGR SCALITDGR
## 24 157.10839 y1_   y_   1 1        R SCALITDGR
## 25 214.12985 y2_   y_   2 1       GR SCALITDGR
## 26 430.20447 y4_   y_   4 1     TDGR SCALITDGR

The function also allows to generate fragment sequences with fixed and/or variable modifications using the PTMods::addFixedModifications() and PTMods::addVariableModifications() functions from the r BiocStyle::Biocpkg("PTMods") package.

With variable modifications, multiple sets of fragments are generated based on the peptide-modifications combinations available. The fragments can be traced to their parent ion by checking the peptide column. A fragment can have multiple modifications.

var_seq <- PTMods::addVariableModifications(sp1158$sequence[2],
    variableModifications = c(C = 57.02146, T = 79.966)
)

calculateFragments(var_seq)
##            mz ion type pos z      seq                       peptide
## 1    88.03931  b1    b   1 1        S                     SCALITDGR
## 2   191.04850  b2    b   2 1       SC                     SCALITDGR
## 3   262.08561  b3    b   3 1      SCA                     SCALITDGR
## 4   375.16967  b4    b   4 1     SCAL                     SCALITDGR
## 5   488.25373  b5    b   5 1    SCALI                     SCALITDGR
## 6   589.30141  b6    b   6 1   SCALIT                     SCALITDGR
## 7   704.32835  b7    b   7 1  SCALITD                     SCALITDGR
## 8   761.34981  b8    b   8 1 SCALITDG                     SCALITDGR
## 9   175.11895  y1    y   1 1        R                     SCALITDGR
## 10  232.14041  y2    y   2 1       GR                     SCALITDGR
## 11  347.16735  y3    y   3 1      DGR                     SCALITDGR
## 12  448.21503  y4    y   4 1     TDGR                     SCALITDGR
## 13  561.29909  y5    y   5 1    ITDGR                     SCALITDGR
## 14  674.38315  y6    y   6 1   LITDGR                     SCALITDGR
## 15  745.42026  y7    y   7 1  ALITDGR                     SCALITDGR
## 16  848.42945  y8    y   8 1 CALITDGR                     SCALITDGR
## 17  686.31778 b7_   b_   7 1  SCALITD                     SCALITDGR
## 18  743.33924 b8_   b_   8 1 SCALITDG                     SCALITDGR
## 19  329.15679 y3_   y_   3 1      DGR                     SCALITDGR
## 20  543.28853 y5_   y_   5 1    ITDGR                     SCALITDGR
## 21  656.37259 y6_   y_   6 1   LITDGR                     SCALITDGR
## 22  727.40970 y7_   y_   7 1  ALITDGR                     SCALITDGR
## 23  830.41889 y8_   y_   8 1 CALITDGR                     SCALITDGR
## 24  157.10839 y1_   y_   1 1        R                     SCALITDGR
## 25  214.12985 y2_   y_   2 1       GR                     SCALITDGR
## 26  430.20447 y4_   y_   4 1     TDGR                     SCALITDGR
## 27   88.03931  b1    b   1 1        S          SC[+57.02146]ALITDGR
## 28  248.06996  b2    b   2 1       SC          SC[+57.02146]ALITDGR
## 29  319.10707  b3    b   3 1      SCA          SC[+57.02146]ALITDGR
## 30  432.19113  b4    b   4 1     SCAL          SC[+57.02146]ALITDGR
## 31  545.27519  b5    b   5 1    SCALI          SC[+57.02146]ALITDGR
## 32  646.32287  b6    b   6 1   SCALIT          SC[+57.02146]ALITDGR
## 33  761.34981  b7    b   7 1  SCALITD          SC[+57.02146]ALITDGR
## 34  818.37127  b8    b   8 1 SCALITDG          SC[+57.02146]ALITDGR
## 35  175.11895  y1    y   1 1        R          SC[+57.02146]ALITDGR
## 36  232.14041  y2    y   2 1       GR          SC[+57.02146]ALITDGR
## 37  347.16735  y3    y   3 1      DGR          SC[+57.02146]ALITDGR
## 38  448.21503  y4    y   4 1     TDGR          SC[+57.02146]ALITDGR
## 39  561.29909  y5    y   5 1    ITDGR          SC[+57.02146]ALITDGR
## 40  674.38315  y6    y   6 1   LITDGR          SC[+57.02146]ALITDGR
## 41  745.42026  y7    y   7 1  ALITDGR          SC[+57.02146]ALITDGR
## 42  905.45091  y8    y   8 1 CALITDGR          SC[+57.02146]ALITDGR
## 43  743.33924 b7_   b_   7 1  SCALITD          SC[+57.02146]ALITDGR
## 44  800.36070 b8_   b_   8 1 SCALITDG          SC[+57.02146]ALITDGR
## 45  329.15679 y3_   y_   3 1      DGR          SC[+57.02146]ALITDGR
## 46  543.28853 y5_   y_   5 1    ITDGR          SC[+57.02146]ALITDGR
## 47  656.37259 y6_   y_   6 1   LITDGR          SC[+57.02146]ALITDGR
## 48  727.40970 y7_   y_   7 1  ALITDGR          SC[+57.02146]ALITDGR
## 49  887.44035 y8_   y_   8 1 CALITDGR          SC[+57.02146]ALITDGR
## 50  157.10839 y1_   y_   1 1        R          SC[+57.02146]ALITDGR
## 51  214.12985 y2_   y_   2 1       GR          SC[+57.02146]ALITDGR
## 52  430.20447 y4_   y_   4 1     TDGR          SC[+57.02146]ALITDGR
## 53   88.03931  b1    b   1 1        S            SCALIT[+79.966]DGR
## 54  191.04850  b2    b   2 1       SC            SCALIT[+79.966]DGR
## 55  262.08561  b3    b   3 1      SCA            SCALIT[+79.966]DGR
## 56  375.16967  b4    b   4 1     SCAL            SCALIT[+79.966]DGR
## 57  488.25373  b5    b   5 1    SCALI            SCALIT[+79.966]DGR
## 58  669.26741  b6    b   6 1   SCALIT            SCALIT[+79.966]DGR
## 59  784.29435  b7    b   7 1  SCALITD            SCALIT[+79.966]DGR
## 60  841.31581  b8    b   8 1 SCALITDG            SCALIT[+79.966]DGR
## 61  175.11895  y1    y   1 1        R            SCALIT[+79.966]DGR
## 62  232.14041  y2    y   2 1       GR            SCALIT[+79.966]DGR
## 63  347.16735  y3    y   3 1      DGR            SCALIT[+79.966]DGR
## 64  528.18103  y4    y   4 1     TDGR            SCALIT[+79.966]DGR
## 65  641.26509  y5    y   5 1    ITDGR            SCALIT[+79.966]DGR
## 66  754.34915  y6    y   6 1   LITDGR            SCALIT[+79.966]DGR
## 67  825.38626  y7    y   7 1  ALITDGR            SCALIT[+79.966]DGR
## 68  928.39545  y8    y   8 1 CALITDGR            SCALIT[+79.966]DGR
## 69  766.28378 b7_   b_   7 1  SCALITD            SCALIT[+79.966]DGR
## 70  823.30524 b8_   b_   8 1 SCALITDG            SCALIT[+79.966]DGR
## 71  329.15679 y3_   y_   3 1      DGR            SCALIT[+79.966]DGR
## 72  623.25453 y5_   y_   5 1    ITDGR            SCALIT[+79.966]DGR
## 73  736.33859 y6_   y_   6 1   LITDGR            SCALIT[+79.966]DGR
## 74  807.37570 y7_   y_   7 1  ALITDGR            SCALIT[+79.966]DGR
## 75  910.38489 y8_   y_   8 1 CALITDGR            SCALIT[+79.966]DGR
## 76  157.10839 y1_   y_   1 1        R            SCALIT[+79.966]DGR
## 77  214.12985 y2_   y_   2 1       GR            SCALIT[+79.966]DGR
## 78  510.17047 y4_   y_   4 1     TDGR            SCALIT[+79.966]DGR
## 79   88.03931  b1    b   1 1        S SC[+57.02146]ALIT[+79.966]DGR
## 80  248.06996  b2    b   2 1       SC SC[+57.02146]ALIT[+79.966]DGR
## 81  319.10707  b3    b   3 1      SCA SC[+57.02146]ALIT[+79.966]DGR
## 82  432.19113  b4    b   4 1     SCAL SC[+57.02146]ALIT[+79.966]DGR
## 83  545.27519  b5    b   5 1    SCALI SC[+57.02146]ALIT[+79.966]DGR
## 84  726.28887  b6    b   6 1   SCALIT SC[+57.02146]ALIT[+79.966]DGR
## 85  841.31581  b7    b   7 1  SCALITD SC[+57.02146]ALIT[+79.966]DGR
## 86  898.33727  b8    b   8 1 SCALITDG SC[+57.02146]ALIT[+79.966]DGR
## 87  175.11895  y1    y   1 1        R SC[+57.02146]ALIT[+79.966]DGR
## 88  232.14041  y2    y   2 1       GR SC[+57.02146]ALIT[+79.966]DGR
## 89  347.16735  y3    y   3 1      DGR SC[+57.02146]ALIT[+79.966]DGR
## 90  528.18103  y4    y   4 1     TDGR SC[+57.02146]ALIT[+79.966]DGR
## 91  641.26509  y5    y   5 1    ITDGR SC[+57.02146]ALIT[+79.966]DGR
## 92  754.34915  y6    y   6 1   LITDGR SC[+57.02146]ALIT[+79.966]DGR
## 93  825.38626  y7    y   7 1  ALITDGR SC[+57.02146]ALIT[+79.966]DGR
## 94  985.41691  y8    y   8 1 CALITDGR SC[+57.02146]ALIT[+79.966]DGR
## 95  823.30524 b7_   b_   7 1  SCALITD SC[+57.02146]ALIT[+79.966]DGR
## 96  880.32670 b8_   b_   8 1 SCALITDG SC[+57.02146]ALIT[+79.966]DGR
## 97  329.15679 y3_   y_   3 1      DGR SC[+57.02146]ALIT[+79.966]DGR
## 98  623.25453 y5_   y_   5 1    ITDGR SC[+57.02146]ALIT[+79.966]DGR
## 99  736.33859 y6_   y_   6 1   LITDGR SC[+57.02146]ALIT[+79.966]DGR
## 100 807.37570 y7_   y_   7 1  ALITDGR SC[+57.02146]ALIT[+79.966]DGR
## 101 967.40635 y8_   y_   8 1 CALITDGR SC[+57.02146]ALIT[+79.966]DGR
## 102 157.10839 y1_   y_   1 1        R SC[+57.02146]ALIT[+79.966]DGR
## 103 214.12985 y2_   y_   2 1       GR SC[+57.02146]ALIT[+79.966]DGR
## 104 510.17047 y4_   y_   4 1     TDGR SC[+57.02146]ALIT[+79.966]DGR

Additional parameters can alter the type of ions produced or the charge applied in calculateFragments. See ?calculateFragments for more details on those. See the PTMods functions (?PTMods::convertAnnotation, ?PTMods::getCanonicalSequence, ?PTMods::combineModifications) for how to handle/apply/change the annotation style of modifications on your sequences or check out the corresponding vignette with vignette("PTMods", package = "PTMods").

3 Visualising fragment ions

We can now visualise these fragments directly on the MS spectrum. Let’s first visualise the spectrum as is:

plotSpectra(sp1158[2])

plotSpectraPTM() allows a more in depth visualisation of a PSM by providing a delta mass plot of matched fragments and a direct visualisation of matched b- and y-ion fragment sequences.

Labels are automatically applied based on the sequence defined in the spectraVariables. Additionally, variable or fixed modifications such as carbamidomethylation of cysteines can be added using the variableModifications and fixedModifications parameters. Remember, by default, carbamidomethylation is applied on all sequences.

dataOrigin(sp1158)[2] <- "TMT_Erwinia" ## Reduces the mzspec text
plotSpectraPTM(sp1158[2],
    fixedModifications = c(C = "Carbamidomethyl")
)

For instance, there is a better match when carbamidomethylation of cysteines is applied (as above) compared to no modifications at all.

plotSpectraPTM(sp1158[2],
    variableModifications = c(C = "Carbamidomethyl"),
    addCarbamidomethyl = FALSE, ## Remove carbamidomethyl by default
    asp = 1/2,
    deltaMz = FALSE,
    main = c("Scan 1158 without carbamidomethyl", "Scan 1158 with carbamidomethyl")
)

As glycine has the same mass as carbamidomethylation, the b7 and b8 ions are overlapping in both spectra.

The spectra displayed in this vignette might be overlapping due to the restricted windows. For a better visualisation, we suggest running the code locally.

For more details on what plotSpectraPTM() can do, run ?plotSpectraPTM.

4 Session information

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] Spectra_1.21.6              BiocParallel_1.45.0        
##  [3] factoextra_2.0.0            ggplot2_4.0.2              
##  [5] QFeatures_1.21.2            MultiAssayExperiment_1.37.4
##  [7] SummarizedExperiment_1.41.1 Biobase_2.71.0             
##  [9] GenomicRanges_1.63.2        Seqinfo_1.1.0              
## [11] IRanges_2.45.0              MatrixGenerics_1.23.0      
## [13] matrixStats_1.5.0           MsDataHub_1.11.3           
## [15] PSMatch_1.15.3              PTMods_0.99.4              
## [17] S4Vectors_0.49.1            BiocGenerics_0.57.0        
## [19] generics_0.1.4              BiocStyle_2.39.0           
## 
## loaded via a namespace (and not attached):
##   [1] DBI_1.3.0               httr2_1.2.2             rlang_1.2.0            
##   [4] magrittr_2.0.5          clue_0.3-68             otel_0.2.0             
##   [7] compiler_4.6.0          RSQLite_2.4.6           png_0.1-9              
##  [10] vctrs_0.7.2             reshape2_1.4.5          stringr_1.6.0          
##  [13] ProtGenerics_1.43.0     pkgconfig_2.0.3         MetaboCoreUtils_1.19.2 
##  [16] crayon_1.5.3            fastmap_1.2.0           backports_1.5.1        
##  [19] dbplyr_2.5.2            magick_2.9.1            XVector_0.51.0         
##  [22] labeling_0.4.3          rmarkdown_2.31          tinytex_0.59           
##  [25] purrr_1.2.1             bit_4.6.0               xfun_0.57              
##  [28] cachem_1.1.0            jsonlite_2.0.0          blob_1.3.0             
##  [31] DelayedArray_0.37.1     broom_1.0.12            parallel_4.6.0         
##  [34] cluster_2.1.8.2         R6_2.6.1                RColorBrewer_1.1-3     
##  [37] bslib_0.10.0            stringi_1.8.7           car_3.1-5              
##  [40] jquerylib_0.1.4         Rcpp_1.1.1              bookdown_0.46          
##  [43] knitr_1.51              Matrix_1.7-5            igraph_2.2.3           
##  [46] tidyselect_1.2.1        dichromat_2.0-0.1       abind_1.4-8            
##  [49] yaml_2.3.12             codetools_0.2-20        curl_7.0.0             
##  [52] lattice_0.22-9          tibble_3.3.1            plyr_1.8.9             
##  [55] S7_0.2.1                withr_3.0.2             KEGGREST_1.51.1        
##  [58] evaluate_1.0.5          BiocFileCache_3.1.0     ExperimentHub_3.1.0    
##  [61] Biostrings_2.79.5       ggpubr_0.6.3            pillar_1.11.1          
##  [64] BiocManager_1.30.27     filelock_1.0.3          carData_3.0-6          
##  [67] ncdf4_1.24              BiocVersion_3.23.1      scales_1.4.0           
##  [70] glue_1.8.0              lazyeval_0.2.3          tools_4.6.0            
##  [73] AnnotationHub_4.1.0     data.table_1.18.2.1     mzR_2.45.1             
##  [76] ggsignif_0.6.4          fs_2.0.1                grid_4.6.0             
##  [79] tidyr_1.3.2             MsCoreUtils_1.23.6      AnnotationDbi_1.73.0   
##  [82] Formula_1.2-5           cli_3.6.5               rappdirs_0.3.4         
##  [85] S4Arrays_1.11.1         dplyr_1.2.1             AnnotationFilter_1.35.0
##  [88] gtable_0.3.6            rstatix_0.7.3           sass_0.4.10            
##  [91] digest_0.6.39           ggrepel_0.9.8           SparseArray_1.11.13    
##  [94] farver_2.1.2            memoise_2.0.1           htmltools_0.5.9        
##  [97] lifecycle_1.0.5         httr_1.4.8              bit64_4.6.0-1          
## [100] MASS_7.3-65