Skip to contents


Tutorials and workshops for the use of the Spectra Bioconductor package to analyze mass spectrometry (MS) data.


Seamless Integration of Mass Spectrometry Data from Different Sources

Short description

In this workshop we will use Spectra to:

  • import MS data from mzML files,
  • select MS2 spectra for a certain compound,
  • compare and match the MS2 spectra against reference MS2 spectra from a public database,
  • annotate the spectra and export them to a file in MGF format.


This (instructor-led live demo) workshop explains the Spectra package and shows how this new infrastructure can be used to represent and analyze Mass Spectrometry (MS) data. The use of different data type and format specific backends guarantees an easy expandability of the infrastructure. This is illustrated in this tutorial on a simple use case, in which MS/MS (a.k.a. MS2) spectra, measured by an MS instrument, are compared and matched against a public spectral database containing public domain reference MS2 spectra.

The video recording of this workshop at the BioC2021 conference is available here.

The video recording of this workshop at the EuroBioc2020 conference is available here.

Workshop goals and objectives

Learning goals

  • Understand how to import MS data into R.
  • Understand the basic concept how different backends can be used in Spectra to work with MS data from various sources.

Learning objectives

  • Import and export MS data with Spectra.
  • Integrate MS data from different resources into an MS data analysis workflow.
  • Apply different data manipulations on MS data represented as a Spectra object.
  • Use Spectra to perform spectra comparisons in R.


  • Basic familiarity with R and Bioconductor.
  • Basic understanding of Mass Spectrometry (MS) data.

Installation and participation

Docker-based setup

This workshop is available as a self-contained docker image simplifying installation and usage.

  • Get the docker image of this tutorial with docker pull jorainer/spectra_tutorials:latest.

  • Start docker using

    docker run \
        -e PASSWORD=bioc \
        -p 8787:8787 \
  • Enter http://localhost:8787 in a web browser and log in with username rstudio and password bioc.

  • Open this R-markdown file (vignettes/analyzing-MS-data-from-different-sources-with-Spectra.Rmd) in the RStudio server version in the web browser and evaluate the R code blocks.

  • To get the source code: clone this github repository, e.g. with git clone

Manual installation

As an alternative, it is possible to install all required R packages locally on R and to download an SQLite database with MassBank annotations that will be required during the workshop.

  • To get the source code: clone this github repository, e.g. with git clone
  • Install the required R packages:
install.packages(c("devtools", "rmarkdown", "BiocManager"))
  • Download the SQLite database with the content from MassBank from here.

Manual installation with available MySQL database

For more advanced users it is also possible to manually install all the resources required for this tutorial. In addition to R version >= 4, specifically for the examples involving the MassBank database, a running MySQL/MariaDB server is also required.

First install all R packages as detailed in the previous section. A MySQL database dump of the MassBank database can be downloaded from the official github page. A database named MassBank should then be created in the local MySQL/MariaDB server. The downloaded .sql.gz needs to be unzipped and can then be installed with mysql MassBank < *.sql.

The source code for all tutorials in this package can be downloaded with:

git clone

Then open the R-markdown (Rmd) files of one of the tutorials (which are located within the vignettes folder with the editor of choice (e.g. RStudio, emacs, vim, …) and evaluate the R-code in the tutorial interactively.

Time outline

Activity Time
Introduction (LC-MS/MS, Spectra package) 10min
MS data import and handling 5min
Data processing and manipulation 5min
Spectrum data comparison 5min
Comparing spectra against MassBank 10min
Data export 5min
(Comparing spectra against HMDB) (5min)

MS/MS Spectra Matching with the MetaboAnnotation Package

The Spectra package provides all the functionality required for annotation and identification workflows for untargeted LC-MS/MS data, but, while being very flexible and customizable, it might be too cumbersome for beginners or analysts not accustomed with R. To fill this gap we developed the MetaboAnnotation package that builds upon Spectra and provides functions for annotation of LC-MS and LC-MS/MS data sets tailored towards the less experienced R user.

This tutorial shows how MetaboAnnotatio can be used in R-based LC-MS/MS annotation workflows.

Note that there is also an additional tutorial for the MetaboAnnotation, CompoundDb and MetaboCoreUtils packages available: MetaboAnnotationTutorials.