BiocStyle::markdown()
knitr::opts_chunk$set(fig.wide = TRUE, fig.retina = 3, error=FALSE, eval=TRUE)
knitr::include_graphics("octopussy.png")
The octopussy `rawDiag` package logo by Lilly van de Venn.

Figure 1: The octopussy rawDiag package logo by Lilly van de Venn

1 Introduction

Over the past two decades, liquid chromatography coupled to mass spectrometry (LC–MS) has evolved into the method of choice in the field of proteomics. (Cox and Mann 2011; Mallick and Kuster 2010) During a typical LC–MS measurement, a complex mixture of analytes is separated by a liquid chromatography system coupled to a mass spectrometer (MS) through an ion source interface. This interface converts the analytes that elute from the chromatography system over time into a beam of ions. The MS records from this ion beam a series of mass spectra containing detailed information on the analyzed sample. (Savaryn, Toby, and Kelleher 2016) The resulting raw data consist of the mass spectra and their metadata, typically recorded in a vendor-specific binary format. During a measurement the mass spectrometer applies internal heuristics, which enables the instrument to adapt to sample properties, for example, sample complexity and amount of ions in near real time. Still, method parameters controlling these heuristics need to be set prior to the measurement. Optimal measurement results require a careful balancing of instrument parameters, but their complex interactions with each other make LC–MS method optimization a challenging task.

Here we present rawDiag, a platform-independent software tool implemented in the R language (Becker, Chambers, and Wilks 1988) that supports LC–MS operators during the process of empirical method optimization. Our work builds on the ideas of the discontinued software rawMeat (VAST Scientific). Our application is currently tailored toward spectral data acquired on Thermo Fisher Scientific instruments (raw format), with a particular focus on Orbitrap (Zubarev and Makarov 2013) mass analyzers (Exactive or Fusion instruments). These instruments are heavily used in the field of bottom-up proteomics (Aebersold and Mann 2003) to analyze complex peptide mixtures derived from enzymatic digests of proteomes.

rawDiag is meant to run after MS acquisition, optimally as an interactive R shiny application, and produces a series of diagnostic plots visualizing the impact of method parameter choices on the acquired data across injections. If static reports are required then pdf files can be generated using rmarkdown. In this vignette, we present the usage of our tool.

rawDiag gains advantages from being part of the Bioconductor ecosystem, such as its ability to utilize the rawrr package and potentially extend its functionality through interaction with the Spectra infrastructure, particularly with the MsBackendRawFileReader.

2 Requirements

rawDiag proides a wrapper function readRaw using the rawrr methods raw::readIndex, rawrr::readTrailer, and rawrr::readChromatogram to read proprietary mass spectrometer generated data by invoking third-party managed methods through a system2 text connection. The rawrr package provides the entire stack below, which rawDiag utilizes.

R>
text connection
system2
Mono Runtime
Managed Assembly (CIL/.NET code)
rawrr.exe
ThermoFisher.CommonCore.*.dll

3 Install

3.1 OS dependencies

3.1.1 Linux (debian/ubuntu)

In case you prefer to compile rawrr.exe from C# source code, please install the mono compiler and xbuild by installing the following Linux packages:

sudo apt-get install mono-mcs mono-xbuild

Otherwise, to execute the precompiled code, the following Linux packages are sufficient:

sudo apt-get install mono-runtime libmono-system-data4.0-cil -y

3.1.2 macOS (Catalina/BigSur)

brew install mono

or install from

https://www.mono-project.com/

3.1.3 Microsoft Windows

Running the rawrr.exe will run out of the box.

If the native C# compiler is not available install mono from:

https://www.mono-project.com/

3.2 R

To install this package, start R (version “>=4.4”) and enter:

if (!require("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("rawrr")

assemblies aka Common Intermediate Language bytecode - the download and install can be done on all platforms using the command:

rawDiag::checkRawrr
## function () 
## {
##     if (isFALSE(requireNamespace("BiocManager", quietly = TRUE))) 
##         stop("exec", "install.packages('BiocManager')")
##     if (isFALSE(requireNamespace("rawrr", quietly = TRUE))) 
##         stop("exec", "BiocManager::install('rawrr')")
##     if (isFALSE(rawrr:::.checkRawFileReaderDLLs())) 
##         rawrr::installRawFileReaderDLLs()
##     if (isFALSE(file.exists(rawrr:::.rawrrAssembly()))) 
##         rawrr::installRawrrExe()
##     if (isFALSE(rawrr:::.isAssemblyWorking())) 
##         stop("rawrr assembly is not working. check if mono if available.")
##     TRUE
## }
## <bytecode: 0x55a3831e7ca8>
## <environment: namespace:rawDiag>
rawDiag::checkRawrr()
## [1] TRUE
if (isFALSE(rawrr::.checkDllInMonoPath())){
  rawrr::installRawFileReaderDLLs()
}
## removing files in directory '/home/biocbuild/.cache/R/rawrr/rawrrassembly'
##  ThermoFisher.CommonCore.BackgroundSubtraction.dll 
##                                                  0 
##                   ThermoFisher.CommonCore.Data.dll 
##                                                  0 
## ThermoFisher.CommonCore.MassPrecisionEstimator.dll 
##                                                  0 
##          ThermoFisher.CommonCore.RawFileReader.dll 
##                                                  0
rawrr::installRawrrExe()
## MD5 96e3a4cc1b7caaf92890d85ed4c72f77 /home/biocbuild/.cache/R/rawrr/rawrrassembly/rawrr.exe
## [1] 0

for more information please read the INSTALL file in the rawrr package.

4 Usage

4.1 R command line

4.1.1 Input

fetch example Orbitrap raw files from ExperimentHub’s tartare package.

library(ExperimentHub)
## Loading required package: BiocGenerics
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
## 
##     Filter, Find, Map, Position, Reduce, anyDuplicated, aperm, append,
##     as.data.frame, basename, cbind, colnames, dirname, do.call,
##     duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
##     lapply, mapply, match, mget, order, paste, pmax, pmax.int, pmin,
##     pmin.int, rank, rbind, rownames, sapply, setdiff, table, tapply,
##     union, unique, unsplit, which.max, which.min
## Loading required package: AnnotationHub
## Loading required package: BiocFileCache
## Loading required package: dbplyr
ExperimentHub::ExperimentHub() -> eh
normalizePath(eh[["EH3222"]]) -> EH3222
## see ?tartare and browseVignettes('tartare') for documentation
## loading from cache
normalizePath(eh[["EH4547"]]) -> EH4547
## see ?tartare and browseVignettes('tartare') for documentation
## loading from cache
(rawfileEH3222 <- paste0(EH3222, ".raw"))
## [1] "/home/biocbuild/.cache/R/ExperimentHub/21fa175b5a0962_3238.raw"
if (!file.exists(rawfileEH3222)){
  file.copy(EH3222, rawfileEH3222)
}

(rawfileEH4547 <- paste0(EH4547, ".raw"))
## [1] "/home/biocbuild/.cache/R/ExperimentHub/21fa1715d0f23a_4590.raw"
if (!file.exists(rawfileEH4547)){
  file.copy(EH4547, rawfileEH4547)
}

c(rawfileEH3222, rawfileEH4547) -> rawfile

Of note, the proprietary .Net assemblies (Shofstahl 2018) require a file extentention of .raw. Therfore we have to rename the EH files and add the .raw suffix.

list meta data of the raw files.

(rawfile |>
  lapply(FUN = rawrr::readFileHeader) -> rawFileHeader)
## [[1]]
## [[1]]$`RAW file`
## [1] "21fa175b5a0962_3238.raw"
## 
## [[1]]$`RAW file version`
## [1] "66"
## 
## [[1]]$`Creation date`
## [1] "7/16/2019 5:56:24 PM"
## 
## [[1]]$Operator
## [1] "lumos"
## 
## [[1]]$`Number of instruments`
## [1] 2
## 
## [[1]]$Description
## [1] ""
## 
## [[1]]$`Instrument model`
## [1] "Orbitrap Fusion Lumos"
## 
## [[1]]$`Instrument name`
## [1] "Orbitrap Fusion Lumos"
## 
## [[1]]$`Instrument method`
## [1] "C:/Xcalibur/methods/p3181/methMelt_GT20_RT35.meth"
## 
## [[1]]$`Serial number`
## [1] "FSN20583"
## 
## [[1]]$`Software version`
## [1] "3.1.2412.25"
## 
## [[1]]$`Firmware version`
## [1] ""
## 
## [[1]]$Units
## [1] "None"
## 
## [[1]]$`Mass resolution`
## [1] "0.500"
## 
## [[1]]$`Number of scans`
## [1] 8742
## 
## [[1]]$`Number of ms2 scans`
## [1] 2346
## 
## [[1]]$`Scan range`
## [1]    1 8742
## 
## [[1]]$`Time range`
## [1]  0.00 35.01
## 
## [[1]]$`Mass range`
## [1]   91 2000
## 
## [[1]]$`Scan filter (first scan)`
## [1] "FTMS + c ESI Full ms [350.0000-2000.0000]"
## 
## [[1]]$`Scan filter (last scan)`
## [1] "FTMS + c ESI Full ms [350.0000-2000.0000]"
## 
## [[1]]$`Total number of filters`
## [1] "2205"
## 
## [[1]]$`Sample name`
## [1] ""
## 
## [[1]]$`Sample id`
## [1] "1:A,5"
## 
## [[1]]$`Sample type`
## [1] "Unknown"
## 
## [[1]]$`Sample comment`
## [1] ""
## 
## [[1]]$`Sample vial`
## [1] "1:B,1"
## 
## [[1]]$`Sample volume`
## [1] "0"
## 
## [[1]]$`Sample injection volume`
## [1] "2"
## 
## [[1]]$`Sample row number`
## [1] "0"
## 
## [[1]]$`Sample dilution factor`
## [1] "1"
## 
## [[1]]$`Sample barcode`
## [1] ""
## 
## [[1]]$`User text 0`
## [1] ""
## 
## [[1]]$`User text 1`
## [1] ""
## 
## [[1]]$`User text 2`
## [1] ""
## 
## [[1]]$`User text 3`
## [1] ""
## 
## [[1]]$`User text 4`
## [1] ""
## 
## 
## [[2]]
## [[2]]$`RAW file`
## [1] "21fa1715d0f23a_4590.raw"
## 
## [[2]]$`RAW file version`
## [1] "66"
## 
## [[2]]$`Creation date`
## [1] "11/16/2018 9:58:53 AM"
## 
## [[2]]$Operator
## [1] "QexactiveHF"
## 
## [[2]]$`Number of instruments`
## [1] 2
## 
## [[2]]$Description
## [1] ""
## 
## [[2]]$`Instrument model`
## [1] "Q Exactive HF Orbitrap"
## 
## [[2]]$`Instrument name`
## [1] "Q Exactive HF Orbitrap"
## 
## [[2]]$`Instrument method`
## [1] "C:/Xcalibur/methods/__QCloud/current_method/forward trap elute/autoQC01_TRAP_GT20min_RT35min.meth"
## 
## [[2]]$`Serial number`
## [1] "Exactive Series slot #2496"
## 
## [[2]]$`Software version`
## [1] "2.9-290204/2.9.2.2947"
## 
## [[2]]$`Firmware version`
## [1] "rev. 1"
## 
## [[2]]$Units
## [1] "None"
## 
## [[2]]$`Mass resolution`
## [1] "0.500"
## 
## [[2]]$`Number of scans`
## [1] 21881
## 
## [[2]]$`Number of ms2 scans`
## [1] 20885
## 
## [[2]]$`Scan range`
## [1]     1 21881
## 
## [[2]]$`Time range`
## [1]  0 35
## 
## [[2]]$`Mass range`
## [1]  100 1805
## 
## [[2]]$`Scan filter (first scan)`
## [1] "FTMS + c NSI Full ms [350.0000-1800.0000]"
## 
## [[2]]$`Scan filter (last scan)`
## [1] "FTMS + c NSI Full ms2 582.3190@hcd27.00 [100.0000-1205.0000]"
## 
## [[2]]$`Total number of filters`
## [1] "22"
## 
## [[2]]$`Sample name`
## [1] "autoQC01"
## 
## [[2]]$`Sample id`
## [1] "NA"
## 
## [[2]]$`Sample type`
## [1] "Unknown"
## 
## [[2]]$`Sample comment`
## [1] ""
## 
## [[2]]$`Sample vial`
## [1] "1:F,8"
## 
## [[2]]$`Sample volume`
## [1] "0"
## 
## [[2]]$`Sample injection volume`
## [1] "2"
## 
## [[2]]$`Sample row number`
## [1] "0"
## 
## [[2]]$`Sample dilution factor`
## [1] "0"
## 
## [[2]]$`Sample barcode`
## [1] ""
## 
## [[2]]$`User text 0`
## [1] "1000"
## 
## [[2]]$`User text 1`
## [1] ""
## 
## [[2]]$`User text 2`
## [1] "FGCZ"
## 
## [[2]]$`User text 3`
## [1] ""
## 
## [[2]]$`User text 4`
## [1] ""

4.1.2 readRaw - read Orbitrap raw file

read the two instrument raw files by using the rawDiag package.

rawfile |>
  BiocParallel::bplapply(FUN = rawDiag::readRaw) |>
  Reduce(f = rbind) -> x

4.1.3 Output - Visualization

This package provides several plot functions tailored toward MS data. The following list shows all available plot methods.

library(rawDiag)
ls("package:rawDiag") |>
  grep(pattern = '^plot', value = TRUE) -> pm

pm |>
  knitr::kable(col.names = "package:rawDiag plot functions")
package:rawDiag plot functions
plotChargeState
plotCycleLoad
plotCycleTime
plotInjectionTime
plotLockMassCorrection
plotMassDistribution
plotMzDistribution
plotPrecursorHeatmap
plotScanTime
plotTicBasepeak

An inherent problem of visualizing data is the fact that depending on the data at hand, specific visualizations lose their usefulness, e.g., overplotting in a scatter plot if too many data points are present. To address this problem, we implemented most of the plot functions in different versions inspired by the work of Cleveland (1993), Sarkar (2008), and Wickham (2009). The data can be displayed in trellis plot manner using the faceting functionality of ggplot2. Alternatively, overplotting using color coding or violin plots based on descriptive statistics values can be chosen, which allows the user to interactively change the appearance of the plots based on the situation at hand. For instance, a large number of files are best visualized by violin plots, giving the user an idea about the distribution of the data points. On the basis of this, a smaller subset of files can be selected and visualized with another technique.

The code snippet below applies all plot methods on the example data.

pm |> 
  lapply(FUN = function(plotFUN) {
    lapply(c('trellis'), function(method) {
      message("plotting", plotFUN, "using method", method, "...")
      do.call(plotFUN, list(x, method)) 
    })
  }) 
## plottingplotChargeStateusing methodtrellis...
## plottingplotCycleLoadusing methodtrellis...
## plottingplotCycleTimeusing methodtrellis...
## plottingplotInjectionTimeusing methodtrellis...
## plottingplotLockMassCorrectionusing methodtrellis...
## plottingplotMassDistributionusing methodtrellis...
## plottingplotMzDistributionusing methodtrellis...
## plottingplotPrecursorHeatmapusing methodtrellis...
## plottingplotScanTimeusing methodtrellis...
## plottingplotTicBasepeakusing methodtrellis...
## [[1]]
## [[1]][[1]]