# AdductomicsR workflow

#### Josie Hayes

#### April 28, 2020

# Getting Started

    #ensure you have mzR installed
    if (!requireNamespace("BiocManager", quietly = TRUE))
        install.packages("BiocManager")
    BiocManager::install("mzR", version = "3.8")

    # install the package directly from Github
    library(devtools)
    devtools::install_github("JosieLHayes/adductomicsR")

    #install the data package containing the data
    if (!requireNamespace("BiocManager", quietly = TRUE))
        install.packages("BiocManager")
    BiocManager::install("ExperimentHub", version = "3.9")

    #or download the packages and install from source
    library(devtools)
    devtools::install("path_to_dir/adductomicsR")
    devtools::install("path_to_dir/adductData")

After installation of the adductomics package and all dependencies attach the adductomics package by typing (copying and pasting) this line of code into the R console and hitting enter:

    # load the package
    library(adductomicsR)
    library(adductData)
    library(ExperimentHub)

We have provided 2 mzXML files for use in this vignette in adductData.

# Preparation of the data

Mass drift correction: Usually mass drift is corrected using lock masses on the mass spectrometer. If this has not been done a python script is provided in the directory in which the package is saved on your computer at /inst/extdata/thermo_MassDriftCalc.py and can be launched from within python using (replace the path to the python script in your system): `exec(open(“thermo_MassDriftCalc.py“).read())`

# Retention time correction

Each sample is corrected for retention time drift using the rtDevModeling function. To run this with the default parameters enter the path of the directory containing your mzXML files and the run order file (order in which samples were run). For further information on parameters see ??rtDevModelling. An example run order file is available in inst/extdata (within the directory where the package is saved on your computer) and 2 mzXML files are available in adductData/ExperimentHub.These files will be used in this vignette automatically.

Download the mzXML files from ExperimentHub for use in this vignette. They must have .mzXML to be recognized by the package so they are renamed as well.

    eh  = suppressMessages(suppressWarnings(ExperimentHub::ExperimentHub()))
    temp = suppressMessages(suppressWarnings(
    AnnotationHub::query(eh, 'adductData')))

    suppressMessages(suppressWarnings(temp[['EH1957']])) #first mzXML file

    ##                                                                                        EH1957
    ## "C:\\Users\\biocbuild\\AppData\\Local\\ExperimentHub\\ExperimentHub\\Cache/2a383c834a99_1957"

    file.rename(cache(temp["EH1957"]), file.path(hubCache(temp),
                                                 'ORB35017.mzXML'))

    ## [1] TRUE

    temp[['EH1958']] #second mzXML file

    ## see ?adductData and browseVignettes('adductData') for documentation

    ## downloading 1 resources

    ## retrieving 1 resource

    ## loading from cache

    ##                                                                                        EH1958
    ## "C:\\Users\\biocbuild\\AppData\\Local\\ExperimentHub\\ExperimentHub\\Cache/2a3842132798_1958"

    file.rename(cache(temp["EH1958"]), file.path(hubCache(temp), 'ORB35022.mzXML'))

    ## [1] TRUE

    rtDevModelling(
      MS2Dir = hubCache(temp),
      nCores=4,
      runOrder =paste0(system.file("extdata",
                                   package ="adductomicsR"),'/runOrder.csv')
      )

# Identify adducts

The specSimPepId function detects adducts present on the peptide. To run this with the default parameters (the largest triply charged peptide of human serum albumin) enter the path of your mzxml files and rtDevModels object. For further information on running this with different peptides see ??specSimPepId. This produces MS2 spectra plots, each in a separate directory for each sample. A plot of the model spectrum is also saved in the mzXML files directory for comparison. The spectra are grouped based on the mz and RT windows, and plots of these groups are also provided based on the raw RT and adjusted RT. These plots can be used to determine whether multiple groups pertain to the same peak.

    specSimPepId(
      MS2Dir = hubCache(temp),
      nCores=4,
      rtDevModels =paste0(hubCache(temp),'/rtDevModels.RData')
      )

# Generate a target table for quantification

A list of the adducts for quantification and their monoisotopic mass (MIM), retention time (RT), peptide and charge is generated using the following command. Substitute the file path of the allResults file to the location of your allResults file from the previous step.

    generateTargTable(
      allresultsFile=paste0(system.file("extdata",package =
      "adductomicsR"),'/allResults_ALVLIAFAQYLQQCPFEDHVK_example.csv'),
      csvDir=tempdir(check = FALSE)
      )

It is recommended that the allGroups plot ( m/z vs RT) is used to ensure that the adducts in the target table do not pertain to the same peak, as the quantification step can be computationally intensive.

# Quantify adducts

See ??adductQuant for an explanation on the parameters for this function. To use your target table produced in the previous step, alter the value in the ‘targTable’ option to the path of your target table. Similarly replaced the path to the directory of your own mzXML files in filePaths (set as “Users/Documents/mzXMLfiles” here.

    adductQuant(
      nCores=2,
      targTable=paste0(system.file("extdata",
                                   package="adductomicsR"),
                                   '/exampletargTable2.csv'),
      intStdRtDrift=30,
      rtDevModels= paste0(hubCache(temp),'/rtDevModels.RData'),
      filePaths=list.files(hubCache(temp),pattern=".mzXML",
                           all.files=FALSE,full.names=TRUE),
      quantObject=NULL,
      indivAdduct=NULL,
      maxPpm=5,
      minSimScore=0.8,
      spikeScans=1,
      minPeakHeight=100,
      maxRtDrift=20,
      maxRtWindow=240,
      isoWindow=80,
      hkPeptide='LVNEVTEFAK',
      gaussAlpha=16
      )

# Extract the results from the AdductQuantif Object

It is recommended that spectra for each of the adducts found are checked manually using LC-MS software, either at this step or before quantification.

To load your adductquantif object set the path to the file on your system. In the example it assumes the file is present in your working directory.

    #load the adductquantif object
    load(paste0(hubCache(temp),"/adductQuantResults.Rda"))

    #produce a peakTable from the Adductquantif object and save to a temporary
    #directory
    suppressMessages(suppressWarnings(outputPeakTable(object=
        object, outputDir=tempdir(check = FALSE))))

# Filter the results from the peak area table

Mass spectrometry data is inherently noisy, and the filterAdductTable() function will filter out samples and adducts based on set thresholds. It is recommended to use this filter function to remove adducts that have many missing values and samples where the housekeeping peptide is weak, suggestive of misintegration. Substitute the name of the peaklist file with the path and the name of your peaklist file produced in the previous step.

    filterAdductTable(
      paste0(tempdir(check = FALSE),"/adductQuantif_peakList_", Sys.Date(), ".csv")
      )

    #session info
    sessionInfo()

    ## R version 4.0.0 (2020-04-24)
    ## Platform: x86_64-w64-mingw32/x64 (64-bit)
    ## Running under: Windows Server 2012 R2 x64 (build 9600)
    ##
    ## Matrix products: default
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.1252
    ## [3] LC_MONETARY=English_United States.1252
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.1252
    ##
    ## attached base packages:
    ## [1] parallel  stats     graphics  grDevices utils     datasets  methods
    ## [8] base
    ##
    ## other attached packages:
    ## [1] adductomicsR_1.4.0   ExperimentHub_1.14.0 AnnotationHub_2.20.0
    ## [4] BiocFileCache_1.12.0 dbplyr_1.4.3         BiocGenerics_0.34.0
    ## [7] adductData_1.3.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] Biobase_2.48.0                httr_1.4.1
    ##  [3] bit64_0.9-7                   foreach_1.5.0
    ##  [5] shiny_1.4.0.2                 assertthat_0.2.1
    ##  [7] interactiveDisplayBase_1.26.0 BiocManager_1.30.10
    ##  [9] stats4_4.0.0                  blob_1.2.1
    ## [11] yaml_2.2.1                    robustbase_0.93-6
    ## [13] BiocVersion_3.11.1            pillar_1.4.3
    ## [15] RSQLite_2.2.0                 lattice_0.20-41
    ## [17] glue_1.4.0                    digest_0.6.25
    ## [19] promises_1.1.0                rvest_0.3.5
    ## [21] plyr_1.8.6                    htmltools_0.4.0
    ## [23] httpuv_1.5.2                  pkgconfig_2.0.3
    ## [25] purrr_0.3.4                   xtable_1.8-4
    ## [27] later_1.0.0                   tibble_3.0.1
    ## [29] IRanges_2.22.0                ellipsis_0.3.0
    ## [31] DT_0.13                       nnet_7.3-14
    ## [33] magrittr_1.5                  crayon_1.3.4
    ## [35] mime_0.9                      mclust_5.4.6
    ## [37] memoise_1.1.0                 evaluate_0.14
    ## [39] MASS_7.3-51.6                 xml2_1.3.2
    ## [41] class_7.3-17                  tools_4.0.0
    ## [43] lifecycle_0.2.0               stringr_1.4.0
    ## [45] S4Vectors_0.26.0              kernlab_0.9-29
    ## [47] cluster_2.1.0                 pastecs_1.3.21
    ## [49] AnnotationDbi_1.50.0          fpc_2.2-5
    ## [51] ade4_1.7-15                   compiler_4.0.0
    ## [53] rlang_0.4.5                   grid_4.0.0
    ## [55] iterators_1.0.12              rappdirs_0.3.1
    ## [57] htmlwidgets_1.5.1             rmarkdown_2.1
    ## [59] boot_1.3-25                   codetools_0.2-16
    ## [61] flexmix_2.3-15                DBI_1.1.0
    ## [63] curl_4.3                      reshape2_1.4.4
    ## [65] R6_2.4.1                      knitr_1.28
    ## [67] prabclus_2.3-2                dplyr_0.8.5
    ## [69] fastmap_1.0.1                 bit_1.1-15.2
    ## [71] modeltools_0.2-23             stringi_1.4.6
    ## [73] Rcpp_1.0.4.6                  vctrs_0.2.4
    ## [75] DEoptimR_1.0-8                tidyselect_1.0.0
    ## [77] xfun_0.13                     diptest_0.75-7