Mass Spectrometry Data Analysis with R

A Practical Guide to Reproducible Proteomics and Metabolomics with Bioconductor

Author

Lucas VHH TRAN

Published

July 20, 2026

Preface

A mass spectrometer can weigh a molecule to five decimal places. Turning millions of those measurements into a defensible biological conclusion — reproducibly, in both proteomics and metabolomics — is a different skill entirely, and it is the one this book teaches. Mass Spectrometry Data Analysis with R is a hands-on guide to that craft, built on the R programming language and the Bioconductor ecosystem designed for it.

About This Book

Mass spectrometry (MS) has become an indispensable tool in analytical chemistry, proteomics, metabolomics, and many other scientific disciplines. As the complexity and volume of MS data continue to grow, computational tools for data processing and analysis have become essential. R, with its extensive statistical capabilities and specialized packages for mass spectrometry, provides an excellent platform for comprehensive MS data analysis.

This book aims to bridge the gap between mass spectrometry theory and practical computational implementation, providing readers with both conceptual understanding and hands-on experience in MS data analysis using R.

Who This Book Is For

This book is designed for:

  • Graduate students in analytical chemistry, biochemistry, or related fields
  • Researchers working with mass spectrometry data
  • Data scientists entering the field of analytical chemistry
  • Bioinformaticians specializing in proteomics or metabolomics
  • Anyone interested in learning computational approaches to MS data analysis

Prerequisites

Readers should have:

  • Basic knowledge of R programming
  • Familiarity with fundamental mass spectrometry concepts
  • Understanding of basic statistics
  • Experience with data analysis workflows (helpful but not required)

What You’ll Learn

By the end of this book, you will be able to:

  • Set up reproducible R environments for MS data analysis with renv, targets, and Quarto
  • Import and work with mzML/mzXML files using the Spectra framework
  • Detect chromatographic features and align runs with xcms
  • Audit peptide–spectrum matches and assemble protein-level evidence
  • Annotate metabolites and search spectral libraries
  • Quantify proteins (label-free, TMT) and metabolites using QFeatures
  • Normalize, batch-correct, and impute missing values in feature matrices
  • Perform differential abundance analysis, machine learning, biomarker modeling, and pathway/network analysis
  • Build fully reproducible, publication-ready analysis reports

Book Structure

The book is organized into seven thematic parts that follow the natural arc of an MS data analysis project:

  • Chapter 1 — What Is Mass Spectrometry? Instrument concepts, acquisition modes, and common data artifacts every analyst must recognize.

  • **Part I — Foundations: Reproducible MS Analysis in R (Chapters 2–6): R and Bioconductor for MS data analysis; building a reproducible project with renv and targets; importing MS data files; constructing analysis-ready data objects; and performing initial quality control.

  • **Part II — Feature Detection and Identification (Chapters 7–11): Detecting chromatographic features with xcms, auditing peptide–spectrum matches, assembling protein evidence, annotating metabolites, and searching spectral libraries.

  • **Part III — Quantification Workflows (Chapters 12–16): Building quantitative proteomics objects, label-free and TMT quantification, targeted quantification, and metabolomics pipeline construction.

  • **Part IV — Normalization, Batch Correction, and Missing Data (Chapters 17–18): Normalizing across samples and batches, and handling missing values.

  • **Part V — Statistical Modeling and Machine Learning (Chapters 19–23): Experimental design and power, differential abundance analysis with design matrices, modeling covariates and repeated measures, machine learning for MS data (tidymodels, regularized regression, tree ensembles, class imbalance, calibration), and biomarker modeling without data leakage.

  • **Part VI — Biological Interpretation and Reproducible Reporting (Chapters 24–25): Pathway and network analysis for integrated MS-omics data, and building reproducible, publication-ready reports.

  • **Part VII — Capstone: End-to-End Case Studies (Chapter 26): Two complete, reproducible analyses — a real label-free proteomics study and a real untargeted metabolomics study — carried from raw data to interpreted, deposit-ready results with the same shared toolchain.

The book closes with a summary, references, and six appendices:

  • Appendix A — Package Reference (every package used, with source, role, and chapter locations)
  • Appendix B — MS File Formats (vendor and open formats, conversion tools)
  • Appendix C — Adduct Tables (common adducts, neutral losses, and modifications)
  • Appendix D — Statistics Reference (formulas, distributions, and test decision guides)
  • Appendix E — Single-Cell Proteomics with scp (SCP data model, QC, filtering, normalization, and differential analysis)
  • Appendix F — Mass Spectrometry Imaging with Cardinal (import, visualization, preprocessing, and spatial analysis of imaging MS data)

Reading Paths

The book rewards a straight read, but it is built so you can follow the track that matches your work. Every path shares the same foundations, preprocessing, statistics, and reporting — only the identification and quantification chapters differ.

  • Full path (recommended): Chapters 1–26 in order. You learn one toolchain and see it applied to both proteomics and metabolomics.
  • Proteomics-focused path: Ch 1 → Foundations (2–6) → Audit PSMs & Protein Evidence (10–11) → Quantification (12–15) → Normalization & Missing Data (17–18) → Statistical Modeling & ML (19–23) → Interpretation & Reporting (24–25) → Case Study 1 (Ch 26). You can skip the metabolomics-specific chapters (7–9, 16).
  • Metabolomics-focused path: Ch 1 → Foundations (2–6) → Detect Features, Annotate, Library Search (7–9) → Metabolomics Pipelines (16) → Normalization & Missing Data (17–18) → Statistical Modeling & ML (19–23) → Interpretation & Reporting (24–25) → Case Study 2 (Ch 26). You can skip the proteomics-specific chapters (10–15).

Whichever path you take, the capstone (Chapter 26) shows both studies side by side — the clearest demonstration that the two fields share one computational grammar in R.

Conventions Used in This Book

  • Package names are set in fixed-width type: Spectra, xcms, QFeatures. Functions are shown with parentheses: findChromPeaks(). When a function’s package is not obvious from context, it is qualified as package::function().
  • Code chunks show R input; where output is shown, it follows directly. Setup and installation chunks are marked #| eval: false because they require data or network access; demonstration chunks run against bundled example data.
  • Cross-references to other chapters use the rendered chapter number (for example, “Chapter 7 covers feature detection”).
  • Callout boxes flag notes (background), tips (recommended practice), and warnings (common mistakes).
  • Data: runnable examples use bundled or versioned example data from Bioconductor packages (msdata, faahKO, MsDataHub) so they reproduce without external downloads. Chapters that demonstrate importing from public repositories include stable accession numbers and retrieval instructions.

Getting Started

To follow along with the examples in this book, you’ll need to install R (≥ 4.4), Bioconductor (≥ 3.20), and several specialized packages. Installation is covered in Chapters 2 and 3; Appendix A lists every package used, with its source and role.

Code
# Example of loading key packages
library(Spectra)
library(xcms)
library(tidyverse)
library(ggplot2)

Code and Data Availability

This book is written as a set of literate, reproducible programs. All source (Quarto .qmd files), the rendered book, and the package lockfile are available in the companion repository:

The examples depend only on openly available example-data packages from Bioconductor (msdata, faahKO, MsDataHub), so no proprietary data is required to reproduce them. Readers are encouraged to clone the repository and re-render the book to confirm reproducibility on their own systems. Each chapter ends with its session information; the Bioconductor and CRAN packages used are catalogued in Appendix A.

Acknowledgments

This book builds upon the excellent work of the R for Mass Spectrometry community and the developers of key packages including Spectra, xcms, MSnbase, and many others.

Disclaimer

The materials, examples, and code samples in this book are provided for educational purposes only and are offered “as is,” without warranty of any kind, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, or noninfringement. While the author has made reasonable efforts to ensure the accuracy of the content, no guarantee is made as to its completeness or suitability. Readers who adopt, run, or modify any code or follow any procedure do so entirely at their own risk. Under no circumstances shall the author be liable for any loss, damage, or other liability, whether in an action of contract, tort, negligence, or otherwise, arising from or in connection with the use of this book.

Feedback and Updates

This book is a living document. Please report errors, suggest improvements, or request additional topics through the book’s repository.

Let’s begin our journey into the world of mass spectrometry data analysis with R!