Introduction

hRUV is a package for normalisation of multiple batches of metabolomics data in a hierarchical strategy with use of samples replicates in a large-scale studies. The tool utilises 2 types of replicates: intra-batch and inter-batch replicates to estimate the unwanted variation within and between batches with RUV-III. We have designed the replicate embedding arrangements within and between batches from http://shiny.maths.usyd.edu.au/hRUV. Our novel tool is a novel hierarchical approach to removing unwanted variation by harnessing information from sample replicates embedded in the sequence of experimental runs/batches and applying signal drift correction with robust linear or non-linear smoothers.

Below is a schematic overview of hRUV framework.

Overview of hRUV methods

The purpose of this vignette is to illustrate use of hRUV.

Installation

Install the R package from GitHub using the devtools package:

if (!("devtools" %in% rownames(installed.packages())))
    install.packages("devtools")

library(devtools)
devtools::install_github("SydneyBioX/hRUV", build_vignettes = TRUE)

Loading packages and data

First, we will load the hRUV package and other packages required for the demonstration. If you haven’t installed the packages yet, please follow the steps above. You can install dplyr package with the command install.packages("dplyr") and SummarizedExperiment object

suppressPackageStartupMessages({
    library(hRUV)
    library(dplyr)
    library(SummarizedExperiment)
})
# You can install dplyr package with the command 
# install.packages("dplyr") 

# To install SummarizedExperiment, 
# if (!requireNamespace("BiocManager", quietly = TRUE))
#     install.packages("BiocManager")
# 
# BiocManager::install("SummarizedExperiment")

For demonstration purposes, we provide a first 5 batches of BioHEART-CT metabolomics data. The data contains metabolite signals of each patients, and contains sample replicate within and between batches. The data is deposited at https://github.com/SydneyBioX/BioHEART_metabolomics.

data("metabolomics_demo")
class(b1)
## [1] "SummarizedExperiment"
## attr(,"package")
## [1] "SummarizedExperiment"
b1
## class: SummarizedExperiment 
## dim: 79 89 
## metadata(1): name
## assays(1): raw
## rownames(79): 1-methylhistamine 2-Arachidonyl glycerol ... Valine
##   Valine-d8
## rowData names(1): metabolite
## colnames(89): 1_Pool 0 2_26 ... 88_Pool 9 89_25
## colData names(7): Sample sample_name ... biological_sample batch_info
b2
## class: SummarizedExperiment 
## dim: 79 91 
## metadata(1): name
## assays(1): raw
## rownames(79): 1-methylhistamine 2-Arachidonyl glycerol ... Valine
##   Valine-d8
## rowData names(1): metabolite
## colnames(91): 1_Pool 1 2_115 ... 90_193 91_Pool 11
## colData names(7): Sample sample_name ... biological_sample batch_info

The data is already formatted in to a SummarizedExperiment object.

Data cleaning

We will now perform preprocessing of all batches.

dat_list = list(
    "Batch1" = b1,
    "Batch2" = b2,
    "Batch3" = b3,
    "Batch4" = b4,
    "Batch5" = b5
)
# checking the dimensions of the data
lapply(dat_list, dim)
## $Batch1
## [1] 79 89
## 
## $Batch2
## [1] 79 91
## 
## $Batch3
## [1] 79 87
## 
## $Batch4
## [1] 79 95
## 
## $Batch5
## [1] 79 90
# Log transform raw assay
dat_list = lapply(dat_list, function(dat) {
    assay(dat, "logRaw", withDimnames = FALSE) = log2(assay(dat, "raw") + 1)
    dat
})

# Setting the order of batches
h_order = paste("Batch", 1:5, sep = "")
h_order = h_order[order(h_order)]

# checking the dimensions of the data before cleaning
lapply(dat_list, dim)
## $Batch1
## [1] 79 89
## 
## $Batch2
## [1] 79 91
## 
## $Batch3
## [1] 79 87
## 
## $Batch4
## [1] 79 95
## 
## $Batch5
## [1] 79 90
dat_list = hRUV::clean(dat_list, threshold = 0.5, 
  method = "intersect", assay = "logRaw", newAssay = "rawImpute")

# checking the dimensions of the data after cleaning
lapply(dat_list, dim)
## $Batch1
## [1] 61 89
## 
## $Batch2
## [1] 61 91
## 
## $Batch3
## [1] 61 87
## 
## $Batch4
## [1] 61 95
## 
## $Batch5
## [1] 61 90

We have filtered metabolites with more than 50% of missing values per batch and selected metabolites that are quantified across all batches (intersect) with clean function. After filtering process, clean function performs k-nearest neighbour imputation. The new imputed assay is named as rawImpute. After cleaning we now have 61 intersecting metabolites quantified for each batch.

Perfrom hRUV

We can proceed to perform intra- and inter-batch normalisation with hRUV.

dat = hruv(
    dat_list = dat_list,
    assay = "rawImpute",
    intra = "loessShort",
    inter = "concatenate",
    intra_k = 5, inter_k = 5,
    pCtlName = "biological_sample",
    negCtl = NULL,
    intra_rep = "short_replicate",
    inter_rep = "batch_replicate"
    
)

Here, we perform hRUV on rawImpute assay. For intra batch normalisation, we perform loess smoothing on samples and RUV-III using short replicates with parameter k set to 5. For inter batch normalisation, we perform concatenating hierarchical structure using batch replicate samples. The RUV-III paramter k is also set to 5 for inter-batch normalisation.

We can now compare before and after hruv normalisation.

PCA

library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:Biobase':
## 
##     combine
## The following object is masked from 'package:BiocGenerics':
## 
##     combine
## The following object is masked from 'package:dplyr':
## 
##     combine
p1 = hRUV::plotPCA(dat, assay = "rawImpute", colour = dat$batch_info)
p2 = hRUV::plotPCA(dat, assay = "loessShort_concatenate", colour = dat$batch_info)
grid.arrange(p1, p2, nrow = 1)

From the above PCA plot, you can see that the assay before normalisation has strong batch effect. The assay after normalisation on the right panel does no longer show batch effect.

Run plot

p1 = hRUV::plotRun(dat, assay = "rawImpute", colour = dat$batch_info)
p2 = hRUV::plotRun(dat, assay = "loessShort_concatenate", colour = dat$batch_info)
grid.arrange(p1$`1-methylhistamine`, p2$`1-methylhistamine`, nrow = 2)

The run plot above shows signal drift present in the raw data for metabolite 1-methylhistamine. This is corrected after hRUV normalisation.

grid.arrange(p1$GlucosePos2, p2$GlucosePos2, nrow = 2)

Further, in metabolite GlucosePos2, the assay before normalisation shows strong batch effects, but they are corrected after hRUV normalisation.

SessionInfo

## R version 4.1.0 (2021-05-18)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Catalina 10.15.7
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] parallel  stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] gridExtra_2.3               SummarizedExperiment_1.22.0
##  [3] Biobase_2.52.0              GenomicRanges_1.44.0       
##  [5] GenomeInfoDb_1.28.1         IRanges_2.26.0             
##  [7] S4Vectors_0.30.0            BiocGenerics_0.38.0        
##  [9] MatrixGenerics_1.4.2        matrixStats_0.60.0         
## [11] dplyr_1.0.7                 hRUV_0.1.3                 
## [13] BiocStyle_2.20.2           
## 
## loaded via a namespace (and not attached):
##  [1] tidyr_1.1.3            TTR_0.24.2             highr_0.9             
##  [4] BiocManager_1.30.16    GenomeInfoDbData_1.2.6 impute_1.66.0         
##  [7] yaml_2.2.1             pillar_1.6.2           lattice_0.20-44       
## [10] glue_1.4.2             digest_0.6.27          XVector_0.32.0        
## [13] colorspace_2.0-2       htmltools_0.5.1.1      Matrix_1.3-3          
## [16] pkgconfig_2.0.3        bookdown_0.23          zlibbioc_1.38.0       
## [19] purrr_0.3.4            scales_1.1.1           tzdb_0.1.2            
## [22] tibble_3.1.3           farver_2.1.0           generics_0.1.0        
## [25] ggplot2_3.3.5          ellipsis_0.3.2         cachem_1.0.5          
## [28] quantmod_0.4.18        DMwR2_0.0.2            magrittr_2.0.1        
## [31] crayon_1.4.1           memoise_2.0.0          evaluate_0.14         
## [34] fs_1.5.0               fansi_0.5.0            MASS_7.3-54           
## [37] xts_0.12.1             class_7.3-19           textshaping_0.3.5     
## [40] tools_4.1.0            hms_1.1.0              lifecycle_1.0.0       
## [43] stringr_1.4.0          munsell_0.5.0          DelayedArray_0.18.0   
## [46] compiler_4.1.0         pkgdown_1.6.1          systemfonts_1.0.2     
## [49] rlang_0.4.11           grid_4.1.0             RCurl_1.98-1.4        
## [52] labeling_0.4.2         bitops_1.0-7           rmarkdown_2.10        
## [55] gtable_0.3.0           DBI_1.1.1              curl_4.3.2            
## [58] R6_2.5.0               zoo_1.8-9              knitr_1.33            
## [61] fastmap_1.1.0          utf8_1.2.2             rprojroot_2.0.2       
## [64] ragg_1.1.3             readr_2.0.1            desc_1.3.0            
## [67] stringi_1.7.3          vctrs_0.3.8            rpart_4.1-15          
## [70] tidyselect_1.1.1       xfun_0.25