library(Risa)
library(xcms)
library(CAMERA)
library(pcaMethods)

Introduction

Indole-3-acetaldoxime (IAOx) represents an early intermediate of the biosynthesis of a variety of indolic secondary metabolites including the phytoanticipin indol-3-ylmethyl glucosinolate and the phytoalexin camalexin (3-thiazol-2’-yl-indole). Arabidopsis thaliana cyp79B2 cyp79B3 double knockout plants are completely impaired in the conversion of tryptophan to indole-3-acetaldoxime and do not accumulate IAOx-derived metabolites any longer. Consequently, comparative analysis of wild-type and cyp79B2 cyp79B3 plant lines has the potential to explore the complete range of IAOx-derived indolic secondary metabolites.

Since 2006, the Bioconductor package xcms (Smith et al, 2006) provides a rich set of algorithms for mass spectrometry data processing. Typically, xcms will create an xcmsSet object from several raw data files in an assay, which are obtained from the samples in the study.
Allowed raw data formats are netCDF, mzData, mzXML and mzML.

In this vignette, we demonstrate the processing of the MTBLS2 dataset, which was described in Neumann 2012.

A few global settings

A few things might be worth to define at the beginning of an analysis

# prefilter <- c(3,200)  ## standard
prefilter=c(6,750)      ## quick-run for debugging
nSlaves=1

Raw data conversion

This can be done with the vendor tools, or the open source proteowizard converter. The preferred format should be mzML or mzData/mzXML. An overview of formats (and problems) is available at the xcms online help pages.

R and ISAtab

An ISAtab archive will contain the metadata description in several tab-separated files. (One of) the assay files contains the column Raw Spectral Data File with the paths to the mass spectral raw data files in one of the above formats.

ISAmtbls2 <- readISAtab(find.package("mtbls2"))
a.filename <- ISAmtbls2["assay.filenames"][[1]]

msfiles <- getAssayRawDataFilenames(ISAmtbls2@assay.tabs[[1]], full.path = TRUE)[,1]
adf <- getAnnotatedDataFrameAssay(ISAmtbls2, assay.filename = a.filename)

ISAtab, Risa and xcms

With the combination of Risa and xcms, we can convert the MS raw data in an ISAtab archive into an xcmsSet:

cwp <- CentWaveParam(ppm = 25, peakwidth = c(20, 50), snthresh = 10,
  prefilter = c(3, 100), mzCenterFun = "wMean", integrate = 1L,
  mzdiff = -0.001, fitgauss = FALSE, noise = 0, verboseColumns = FALSE,
  roiList = list(), firstBaselineCheck = TRUE, roiScales = numeric())

raw_data <- readMSData(msfiles, mode = "onDisk")

## Perform the peak detection using the settings defined above.
mtbls2 <- findChromPeaks(raw_data, param = cwp, BPPARAM = bpparam())

pData(mtbls2) <- pData(adf)
          

head(chromPeaks(mtbls2))
##               mz    mzmin    mzmax       rt    rtmin    rtmax     into     intb
## CP00001 112.8962 112.8942 112.8979 24.80802 20.43102 47.37300 22816.15 22654.98
## CP00002 399.0922 399.0856 399.0976 27.50400 21.10398 45.35298 31005.04 29206.56
## CP00003 240.8674 240.8649 240.8718 26.15700 22.11402 35.58600 16004.71 15993.93
## CP00004 146.1652 146.1631 146.1671 20.43102 14.70498 41.64702 54426.96 53544.79
## CP00005 223.9742 223.9701 223.9791 26.83002 21.44100 45.35298 11775.13 11749.60
## CP00006 482.0321 482.0214 482.0399 28.17702 22.11402 46.69998 21127.42 20629.23
##         maxo   sn sample
## CP00001 6051   86      1
## CP00002 3797   14      1
## CP00003 5504 5503      1
## CP00004 9077   65      1
## CP00005 1881   56      1
## CP00006 2789   22      1

The result is the same type of xcmsSet object:

show(mtbls2)
## MSn experiment data ("XCMSnExp")
## Object size in memory: 15.71 Mb
## - - - Spectra data - - -
##  MS level(s): 1 
##  Number of spectra: 57066 
##  MSn retention times: 0:00 - 20:02 minutes
## - - - Processing information - - -
## Data loaded [Thu May 20 14:29:37 2021] 
##  MSnbase version: 2.18.0 
## - - - Meta data  - - -
## phenoData
##   rowNames: Ex1-Col0-48h-Ag-1 Ex1-Col0-48h-Ag-2 ... Ex2-cyp79-48h-Ag-4
##     (16 total)
##   varLabels: Factor Value[genotype] Factor Value[replicate]
##   varMetadata: labelDescription
## Loaded from:
##   [1] MSpos-Ex1-Col0-48h-Ag-1_1-A,1_01_9818.mzData...  [16] MSpos-Ex2-cyp79-48h-Ag-4_1-B,4_01_9834.mzData
##   Use 'fileNames(.)' to see all files.
## protocolData: none
## featureData
##   featureNames: F01.S0001 F01.S0002 ... F16.S3568 (57066 total)
##   fvarLabels: fileIdx spIdx ... spectrum (35 total)
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'
## - - - xcms preprocessing - - -
## Chromatographic peak detection:
##  method: centWave 
##  24786 peaks identified in 16 samples.
##  On average 1549 chromatographic peaks per sample.

Several options exist to quantify the individual intensities. For each feature, additional attributes are available, such as the minimum/maximum and average retention time and m/z values.

Grouping and Retention time correction

In the following steps, we perform a grouping: because the UPLC system used here has very stable retention times, we just use the retention time correction step as quality control of the raw data. After that, ‘fillPeaks()’ will integrate the raw data for those features, which were not detected in some of the samples.

## Perform the peak grouping with default settings:
pdp <- PeakDensityParam(sampleGroups = as.integer(interaction(pData(mtbls2), drop=TRUE)))

mtbls2grouped <- groupChromPeaks(mtbls2, pdp)
## Processing 7195 mz slices ... OK
pgp <- PeakGroupsParam(minFraction = 1, extraPeaks = 1, smooth = "loess",
  span = 0.2, family = "gaussian")

mtbls2groupedretcor <- adjustRtime(mtbls2grouped, param = pgp)
## Performing retention time correction using 586 peak groups.
## Warning: Adjusted retention times had to be re-adjusted for some files
## to ensure them being in the same order than the raw retention times. A
## call to 'dropAdjustedRtime' might thus fail to restore retention times of
## chromatographic peaks to their original values. Eventually consider to increase
## the value of the 'span' parameter.
## Applying retention time adjustment to the identified chromatographic peaks ... OK
## Visualize the impact of the alignment. We show both versions of the plot,
## with the raw retention times on the x-axis (top) and with the adjusted
## retention times (bottom).
par(mfrow = c(2, 1))
plotAdjustedRtime(mtbls2groupedretcor, adjusted = FALSE)
grid()
plotAdjustedRtime(mtbls2groupedretcor)
grid()

QC on peaks picked

A first QC step is the visual inspection of intensities across the samples. Alternatively to a boxplot, one could also create histograms/density plots.

boxplot(featureValues(mtbls2grouped, value="into") +1, 
        #col=as.numeric(sampclass(mtbls2Set))+1, 
        log="y", las=2)

Data imputation

After grouping, peaks might be missing/not found in some samples. fillPekas() will impute them, using the consensus mz and RT from the other samples.

mtbls2groupedFilled <- fillChromPeaks(mtbls2grouped)
## Defining peak areas for filling-in .... OK
## Start integrating peak areas from original files

The final xcmsSet represents a rectangular matrix of mass spectral features, which were detected (or imputed) across the samples. The dimensionality is M * N, where M denotes the number of samples in the assay, and N the number of features grouped across the samples.

QC with some diagnostic plots

QC of mass accuracy and retention time consistency

plotQC(mtbls2grouped)