Introduction

AutoTuner is a parameter tuning algorithm for XCMS, MZmine2, and other metabolomics data processing softwares. Using statistical inference, AutoTuner quickly finds estimates for nine distinct parameters. This guide provides an interactive example of how to use AutoTuner.

Installation

Dev Version

Currently, AutoTuner is being distributed through my github acount [here]: github.com/crmclean/Autotuner

The easiest way to download that package is by using the install_github command from the devtools package as illustrated below.

devtools::install_github("crmclean/Autotuner")

Bioconductor Release

Hopefully the package will be available through bioconductor in the near future. Once this occurs, the package may be downloaded by running the following code.

if(!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("Autotuner")

Autotuner

This tutorial uses additional data from the package, mtbls2 This second package contains raw untargeted metabolomics data, and may be downloaded from bioconductor in a manner as the BioC installation for Autotuner.

library(Autotuner)
#>      ____________________________________________________________
#>     / __  / / / /__  __/ _   /__  __/ / / /\     / / ____/ __   / 
#>    / / / / / / /  / / / / / /  / / / / / /  \   / / /___/ /_/  /  
#>   / /_/ / / / /  / / / / / /  / / / / / / /\ \ / / ____/  _   \ 
#>  / __  / /_/ /  / / / /_/ /  / / / /_/ / /  \   /  /__/  / /  /
#> /_/ /_/_____/  /_/ /_____/  /_/ /_____/_/    \ /_____/__/ /__/   v.1.0.0
#> https://github.com/crmclean/autotuner
library(mtbls2)  

Set Up

Input - Raw Data

AutoTuner is designed to work directly with raw mass spectral data that has been processed by using MSconvert. So far file types .mzML, .mzXML, .msData, and .netCDF have been tested and confirmed to work.

rawPaths <- c(
    system.file("mzData/MSpos-Ex2-cyp79-48h-Ag-1_1-B,3_01_9828.mzData", 
                             package = "mtbls2"),
system.file("mzData/MSpos-Ex2-cyp79-48h-Ag-2_1-B,4_01_9830.mzData", 
            package = "mtbls2"),
system.file("mzData/MSpos-Ex2-cyp79-48h-Ag-4_1-B,4_01_9834.mzData", 
            package = "mtbls2"))

if(!all(file.exists(rawPaths))) {
    stop("Not all files matched here exist.")
}

Here are the filetypes that will be used within this tutorial:

print(basename(rawPaths))
#> [1] "MSpos-Ex2-cyp79-48h-Ag-1_1-B,3_01_9828.mzData"
#> [2] "MSpos-Ex2-cyp79-48h-Ag-2_1-B,4_01_9830.mzData"
#> [3] "MSpos-Ex2-cyp79-48h-Ag-4_1-B,4_01_9834.mzData"

Here are what the paths look like that I am entering into AutoTuner directly:

print(rawPaths)
#> [1] "/home/biocbuild/bbs-3.10-bioc/R/library/mtbls2/mzData/MSpos-Ex2-cyp79-48h-Ag-1_1-B,3_01_9828.mzData"
#> [2] "/home/biocbuild/bbs-3.10-bioc/R/library/mtbls2/mzData/MSpos-Ex2-cyp79-48h-Ag-2_1-B,4_01_9830.mzData"
#> [3] "/home/biocbuild/bbs-3.10-bioc/R/library/mtbls2/mzData/MSpos-Ex2-cyp79-48h-Ag-4_1-B,4_01_9834.mzData"

Input - Metadata

AutoTuner also requires a metadata file that has at least two columns in order to derive estimates. One column should contain string matches to all the raw data files that will be processed (see above for an example). The second should contain information on the experimental factor each sample belongs to.

metadata <- read.table(system.file(
    "a_mtbl2_metabolite_profiling_mass_spectrometry.txt", 
    package = "mtbls2"), header = TRUE, stringsAsFactors = FALSE)

metadata <- metadata[sub("mzData/", "", metadata$Raw.Spectral.Data.File) %in% 
                         basename(rawPaths),]

This is what the metadata file should look like. In our case, the column matching the raw data files is called “File.Name”, while the one with experimental factor information is called “Sample.Type”.

print(metadata)
#>           Sample.Name Protocol.REF   Parameter.Value.Post.Extraction.
#> 13 Ex2-cyp79-48h-Ag-1   Extraction 200 µL methanol/water, 30/70 (v/v)
#> 14 Ex2-cyp79-48h-Ag-2   Extraction 200 µL methanol/water, 30/70 (v/v)
#> 16 Ex2-cyp79-48h-Ag-4   Extraction 200 µL methanol/water, 30/70 (v/v)
#>    Parameter.Value.Derivatization.       Extract.Name Protocol.REF.1
#> 13                            none Ex2-cyp79-48h-Ag-1 Chromatography
#> 14                            none Ex2-cyp79-48h-Ag-2 Chromatography
#> 16                            none Ex2-cyp79-48h-Ag-4 Chromatography
#>    Parameter.Value.Chromatography.Instrument. Term.Source.REF
#> 13    ACQUITY UPLC Systems with 2D Technology              MS
#> 14    ACQUITY UPLC Systems with 2D Technology              MS
#> 16    ACQUITY UPLC Systems with 2D Technology              MS
#>    Term.Accession.Number Parameter.Value.Column.type.
#> 13               1001765                       HSS T3
#> 14               1001765                       HSS T3
#> 16               1001765                       HSS T3
#>    Parameter.Value.Chromatogram.Name. Term.Source.REF.1
#> 13                                N/A                NA
#> 14                                N/A                NA
#> 16                                N/A                NA
#>    Term.Accession.Number.1    Protocol.REF.2 Parameter.Value.instrument.
#> 13                      NA Mass spectrometry                  micrOTOF-Q
#> 14                      NA Mass spectrometry                  micrOTOF-Q
#> 16                      NA Mass spectrometry                  micrOTOF-Q
#>    Term.Source.REF.2 Term.Accession.Number.2 Parameter.Value.ion.source.
#> 13                MS                      NA                         ESI
#> 14                MS                      NA                         ESI
#> 16                MS                      NA                         ESI
#>    Term.Source.REF.3 Term.Accession.Number.3 Parameter.Value.analyzer.
#> 13                MS                 1000073            time-of-flight
#> 14                MS                 1000073            time-of-flight
#> 16                MS                 1000073            time-of-flight
#>    Term.Source.REF.4 Term.Accession.Number.4
#> 13                MS                 1000084
#> 14                MS                 1000084
#> 16                MS                 1000084
#>                       MS.Assay.Name
#> 13 Ex2-cyp79-48h-Ag-1_1-B,3_01_9828
#> 14 Ex2-cyp79-48h-Ag-2_1-B,4_01_9830
#> 16 Ex2-cyp79-48h-Ag-4_1-B,4_01_9834
#>                                  Raw.Spectral.Data.File     Protocol.REF.3
#> 13 mzData/MSpos-Ex2-cyp79-48h-Ag-1_1-B,3_01_9828.mzData Data normalization
#> 14 mzData/MSpos-Ex2-cyp79-48h-Ag-2_1-B,4_01_9830.mzData Data normalization
#> 16 mzData/MSpos-Ex2-cyp79-48h-Ag-4_1-B,4_01_9834.mzData Data normalization
#>    Normalization.Name      Protocol.REF.4 Data.Transformation.Name
#> 13                N/A Data transformation                      N/A
#> 14                N/A Data transformation                      N/A
#> 16                N/A Data transformation                      N/A
#>    Derived.Spectral.Data.File
#> 13                         NA
#> 14                         NA
#> 16                         NA
#>                                Metabolite.Assignment.File
#> 13 a_mtbl2_metabolite_profiling_mass_spectrometry_maf.csv
#> 14 a_mtbl2_metabolite_profiling_mass_spectrometry_maf.csv
#> 16 a_mtbl2_metabolite_profiling_mass_spectrometry_maf.csv
#>    Factor.Value.genotype. Term.Source.REF.5 Term.Accession.Number.5
#> 13                  cyp79                NA                      NA
#> 14                  cyp79                NA                      NA
#> 16                  cyp79                NA                      NA
#>    Factor.Value.replicate. Term.Source.REF.6 Term.Accession.Number.6
#> 13                    Exp2                NA                      NA
#> 14                    Exp2                NA                      NA
#> 16                    Exp2                NA                      NA

Creating AutoTuner Object

AutoTuner first requires that user create an AutoTuner object. All future computations will be contained within this object.

The file_col argument corresponds to the string column of the metadata that matches raw data samples by name. The factorCol argument corresponds to the specific factor column.

Autotuner <- createAutotuner(rawPaths,
                             metadata,
                             file_col = "Raw.Spectral.Data.File",
                             factorCol = "Factor.Value.genotype.")
#> ~~~ Autotuner: Initializator ~~~
#> ~~~ Parsing Raw Data into R ~~~
#> ~~~ Extracting the Raw Data from Individual Samples ~~~
#> No TIC data was found.
#> Using integrated intensity data instead.
#> ~~~ Storing Everything in Autotuner Object ~~~
#> ~~~ The Autotuner Object has been Created ~~~

Part 1:

Total Ion Current Peak Identification

The first part of AutoTuner involves the identification of peaks within the total ion current (TIC) of the samples loaded up into AutoTuner. These regions will be important later to estimate parameters from the raw data since AutoTuner assumes that they contain a greater number of real chemical measurements.

Sliding Window Analysis

To do this, the user peforms a sliding window analysis. A sliding window analysis is a simple time series analysis algorithm used to identify peaks within a time trace. The window is essentially using a moving average. From this, the algorithm asks whether the next observation to the right of the average is a peak. More on sliding window analyses can be found here.

The aim here is to identify TIC peaks. The user should prioritize finding where peaks start rather than caturing the entire peak bound. Downstream steps actually do a better job of estimating what the proper peak bounds should be.

The user should play with the lag, threshold, and influence parameters to perform the sliding window analysis. Here is what they represent relative to chromatography:

Lag - The number of chromatographic scan points used to test if next point is significance (ie the size number of points making up the moving average).

Threshold - A numerical constant representing how many times greater the intensity of an adjacent scan has to be from the scans in the sliding window to be considered significant.

Influence - A numerical factor used to scale the magnitude of a significant scan once it has been added to the sliding window.

lag <- 25
threshold<- 3.1
influence <- 0.1
signals <- lapply(getAutoIntensity(Autotuner), 
                 ThresholdingAlgo, lag, threshold, influence)

The output of the sliding window can be displayed with the plot_signals function:

plot_signals(Autotuner, 
             threshold, 
             ## index for which data files should be displayed
             sample_index = 1:3, 
             signals = signals)

rm(lag, influence, threshold)

Interpreting Sliding Window Results

The figure above has two components:

  1. Top Plot: The chromatotgraphic trace for each sample (solid line) along with the noise associated with each sample (dashed line).
  2. Bottom Plot: A signal plot used to indicate which chromatographic regions have peaks.

The user should look for combinations of the three sliding window parameters that returns many narrow peaks within the signal plot. See the example above.

Autotuner will expand each of these regions to obtain improved estimates on the bounds within the isolatePeaks function below. The return_peaks arguement there represents the number of peaks to return from all detected TIC peaks for parameter estimation. This number is bounded by the total number of detected peaks by the sliding windown analysis above, so seeing more narrow peaks within the signal plot is recommended.

Autotuner <- isolatePeaks(Autotuner = Autotuner, 
                          returned_peaks = 10, 
                          signals = signals)

Checking Peak Estimates

The peaks with expanded bounds returned from the isolatePeaks function can be rapidly checked visually using the plot_peaks function as shown below. The bounds should capture the correct ascention and descention points of each peak. If peak bounds are not satisfactory, the user should return to the sliding window analysis, and try a different conbination of the three parameters.

Remember, this whole process is only designed to isolate regions enriched in real features rather than find true peaks. The bounds don’t need to be completely perfect. Its much more important that the bounds contain some kind of chromatographic peaks rather than less dynamic regions of the chromatographic trace.

for(i in 1:5) {
    plot_peaks(Autotuner = Autotuner, 
           boundary = 100, 
           peak = i)    
}