--- title: "Quick start example analysis" subtitle: "`r paste0('pretreateR v',packageVersion('pretreateR'))`" author: "Jasen Finch" date: "`r format(Sys.time(), '%d %B, %Y')`" output: prettydoc::html_pretty: toc: true highlight: github theme: tactile vignette: > %\VignetteIndexEntry{Quick start example analysis} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.align = 'center', message = FALSE ) ``` This example analysis will use the `abr1` data set from the [metaboData](https://aberhrml.github.io/metaboData/) package. It is nominal mass flow-injection mass spectrometry (FI-MS) fingerprinting data from a plant-pathogen infection time course experiment. The analysis will also include use of the pipe `%>%` from the [magrittr](https://magrittr.tidyverse.org/) package. First load the necessary packages. ```{r setup} library(pretreateR) library(metaboData) ``` For this example we will use only the negative acquisition mode data (`abr1$neg`) and sample meta-information (`abr1$fact`). Create an `AnalysisData` class object using the following: ```{r analysis_data} d <- analysisData(abr1$neg,abr1$fact) ``` The data includes `r nSamples(d)` samples and `r nFeatures(d)` mass spectral features as shown below. ```{r print_analysis_data} d ``` The `clsAvailable()` function can be used to identify the columns available in our meta-information table. ```{r} clsAvailable(d) ``` For this analysis, we will be using the infection time course class information contained in the `day` column. This can be extracted and the class frequencies tabulated using the following: ```{r} d %>% clsExtract(cls = 'day') %>% table() ``` As can be seen above, the experiment is made up of six infection time point classes that includes a healthy control class (`H`) and five day infection time points (`1-5`), each with 20 replicates. For data pre-treatment prior to statistical analysis, a two-thirds maximum class occupancy filter can be applied. Features where the maximum proportion of non-missing data per class is above two-thirds are retained. A total ion count normalisation will also be applied. ```{r pre_treat} d <- d %>% occupancyMaximum(cls = 'day', occupancy = 2/3) %>% transformTICnorm() %>% transformLog10() ``` ```{r pre_treat_result} d ``` This has reduced the data set to `r nFeatures(d)` relevant features. PCA can help inspect the structure of the pre-treated data and identify unusual samples. ```{r pca} plotPCA(d,cls = 'day',xAxis = 'PC1',yAxis = 'PC2') ``` Individual features can also be inspected after pre-treatment. ```{r feature_plot} plotFeature(d,feature = 'N341',cls = 'day') ``` For a reusable routine, define the steps and pass them to `metabolyse()`. ```{r routine} p <- analysisParameters() parameters(p,'pre-treatment') <- preTreatmentParameters( list(occupancyFilter = 'maximum', transform = 'TICnorm') ) changeParameter(p,'cls') <- 'day' analysis <- metabolyse(abr1$neg,abr1$fact,p,verbose = FALSE) preTreated(analysis) ```