1 Abstract

Wrench is a normalization technique for metagenomic count data. While principally developed for sparse 16S count data from metagenomic experiments, it can also be applied to normalizing count data from other sparse technologies like single cell RNAseq, functional microbiome etc.,.

Given (a) count data organized as features (OTUs, genes etc.,) x samples, and (b) experimental group labels associated with samples, Wrench outputs a normalization factor for each sample. The data is normalized by dividing each sample’s counts with its normalization factor.

The manuscript can be accessed here: https://www.biorxiv.org/content/early/2018/01/31/142851

2 Introduction

An unwanted side-effect of DNA sequencing is that the observed counts retain only relative abundance/expression information. Comparing such relative abundances between experimental conditions/groups (for e.g., with differential abundance analysis) can cause problems. Specifically, in the presence of features that are differentially abundant in absolute abundances, truly unperturbed features can be identified as being differentially abundant. Commonly used techniques like rarefaction/subsampling/dividing by the total count and other variants of these approaches, do not correct for this issue. Wrench was developed to address this problem of reconstructing absolute from relative abundances based on some commonly exploited assumptions in genomics.

The Introduction section in the manuscript presented here: https://www.biorxiv.org/content/early/2018/01/31/142851 provide some perspective on various commonly used normalization techniques from the above standpoint, and we recommend reading through it.

3 Installation

Download package.

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

Or install the development version of the package from Github.

BiocManager::install(“HCBravoLab/Wrench”)

Load the package.

library(Wrench)

4 Running Wrench

Below, we present a quick tutorial, where we pass count data, and group information to generate compositional and normalization factors. Details on any optional parameters are provided by typing “?wrench” in the R terminal window.

#extract count and group information for from the mouse microbiome data in the metagenomeSeq package
data(mouseData)
mouseData
## MRexperiment (storageMode: environment)
## assayData: 10172 features, 139 samples 
##   element names: counts 
## protocolData: none
## phenoData
##   sampleNames: PM1:20080107 PM1:20080108 ... PM9:20080303 (139
##     total)
##   varLabels: mouseID date ... status (5 total)
##   varMetadata: labelDescription
## featureData
##   featureNames: Prevotellaceae:1 Lachnospiraceae:1 ...
##     Parabacteroides:956 (10172 total)
##   fvarLabels: superkingdom phylum ... OTU (7 total)
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'
## Annotation:
counts <- MRcounts( mouseData, norm=FALSE )  #get the counts
counts[1:10,1:2]
##                                      PM1:20080107 PM1:20080108
## Prevotellaceae:1                                0            0
## Lachnospiraceae:1                               0            0
## Unclassified-Screened:1                         0            0
## Clostridiales:1                                 0            0
## Clostridiales:2                                 0            0
## Firmicutes:1                                    0            0
## PeptostreptococcaceaeIncertaeSedis:1            0            0
## Clostridiales:3                                 0            0
## Lachnospiraceae:7                               0            0
## Lachnospiraceae:8                               0            0
group <- pData(mouseData)$diet #get the group/condition vector
head(group)
## [1] "BK" "BK" "BK" "BK" "BK" "BK"
#Running wrench with defaults
W <- wrench( counts, condition=group  )
compositionalFactors <- W$ccf
normalizationFactors <- W$nf

head( compositionalFactors ) #one factor for each sample
## PM1:20080107 PM1:20080108 PM1:20080114 PM1:20071211 PM1:20080121 
##    0.7540966    0.8186825    1.0423187    1.2690286    0.7860119 
## PM1:20071217 
##    1.3059309
head( normalizationFactors)  #one factor for each sample
## PM1:20080107 PM1:20080108 PM1:20080114 PM1:20071211 PM1:20080121 
##    0.3364660    0.7051424    1.3295084    0.8530978    0.7545386 
## PM1:20071217 
##    2.1273695

4.1 Usage with differential abundance pipelines

Introducing the above normalization factors for the most commonly used tools is shown below.

# -- If using metagenomeSeq
normalizedObject <- mouseData  #mouseData is already a metagenomeSeq object 
normFactors(normalizedObject) <- normalizationFactors

# -- If using edgeR, we must pass in the compositional factors
edgerobj <- edgeR::DGEList( counts=counts,
                     group = as.matrix(group),
                     norm.factors=compositionalFactors )

# -- If using DESeq/DESeq2
deseq.obj <- DESeq2::DESeqDataSetFromMatrix(countData = counts,
                                   DataFrame(group),
                                   ~ group )
## converting counts to integer mode
deseq.obj
## class: DESeqDataSet 
## dim: 10172 139 
## metadata(1): version
## assays(1): counts
## rownames(10172): Prevotellaceae:1 Lachnospiraceae:1 ...
##   Bryantella:103 Parabacteroides:956
## rowData names(0):
## colnames(139): PM1:20080107 PM1:20080108 ... PM9:20080225
##   PM9:20080303
## colData names(1): group
sizeFactors(deseq.obj) <- normalizationFactors

5 Some caveats / work in development

Wrench currently implements strategies for categorical group labels only. While extension to continuous covariates is still in development, you can create factors/levels out of your continuous covariates (however you think is reasonable) by discretizing/cutting them in pieces.

time <- as.numeric(as.character(pData(mouseData)$relativeTime))
time.levs <- cut( time, breaks = c(0, 6, 28, 42, 56, 70) )
overall_group <- paste( group, time.levs ) #merge the time information and the group information together
W <- wrench( counts, condition = overall_group )

6 The “detrend” option

In cases of very low sample depths and high sparsity, one might find a roughly linear trend between the reconstructed compositional factors (“ccf” entry in the returned list object from Wrench) and the sample depths (total count of a sample) within each experimental group. This can potentially be caused by a large number of zeros affecting the average estimate of the sample-wise ratios of proportions in a downward direction. Existing approaches that exploit zeroes during estimation also suffer from this issue (for instance, varying Scran’s abundance filtering by changing the “min.mean” parameter will reveal the same issue, although in general we have found their pooling approach to be slightly less sensitive with their default abundance filtering).

If you find this happening with the Wrench reconstructed compositional factors, and if you can assume it is reasonable to do so, you can use the detrend=T option (a work in progress) in Wrench to remove such linear trends within groups. It is also worth mentioning that even though low sample-depth samples’ compositional factors can show this behavior, in our experience, we have often found that group-wise averages of compositional factors can still be robust.

7 Session Info

sessionInfo()
## R Under development (unstable) (2019-10-24 r77329)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.3 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.11-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.11-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    parallel  stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] DESeq2_1.27.2               SummarizedExperiment_1.17.0
##  [3] DelayedArray_0.13.0         BiocParallel_1.21.0        
##  [5] matrixStats_0.55.0          GenomicRanges_1.39.1       
##  [7] GenomeInfoDb_1.23.0         IRanges_2.21.1             
##  [9] S4Vectors_0.25.0            Wrench_1.5.0               
## [11] edgeR_3.29.0                metagenomeSeq_1.29.0       
## [13] RColorBrewer_1.1-2          glmnet_2.0-18              
## [15] foreach_1.4.7               Matrix_1.2-17              
## [17] limma_3.43.0                Biobase_2.47.0             
## [19] BiocGenerics_0.33.0        
## 
## loaded via a namespace (and not attached):
##  [1] bitops_1.0-6           bit64_0.9-7            tools_4.0.0           
##  [4] backports_1.1.5        R6_2.4.0               rpart_4.1-15          
##  [7] KernSmooth_2.23-16     DBI_1.0.0              Hmisc_4.2-0           
## [10] lazyeval_0.2.2         colorspace_1.4-1       nnet_7.3-12           
## [13] tidyselect_0.2.5       gridExtra_2.3          bit_1.1-14            
## [16] compiler_4.0.0         fdrtool_1.2.15         htmlTable_1.13.2      
## [19] slam_0.1-46            caTools_1.17.1.2       scales_1.0.0          
## [22] checkmate_1.9.4        genefilter_1.69.0      stringr_1.4.0         
## [25] digest_0.6.22          foreign_0.8-72         rmarkdown_1.16        
## [28] XVector_0.27.0         base64enc_0.1-3        pkgconfig_2.0.3       
## [31] htmltools_0.4.0        lpsymphony_1.15.0      htmlwidgets_1.5.1     
## [34] rlang_0.4.1            RSQLite_2.1.2          rstudioapi_0.10       
## [37] IHW_1.15.0             gtools_3.8.1           acepack_1.4.1         
## [40] dplyr_0.8.3            RCurl_1.95-4.12        magrittr_1.5          
## [43] GenomeInfoDbData_1.2.2 Formula_1.2-3          Rcpp_1.0.2            
## [46] munsell_0.5.0          stringi_1.4.3          yaml_2.2.0            
## [49] zlibbioc_1.33.0        gplots_3.0.1.1         blob_1.2.0            
## [52] grid_4.0.0             gdata_2.18.0           crayon_1.3.4          
## [55] lattice_0.20-38        splines_4.0.0          annotate_1.65.0       
## [58] locfit_1.5-9.1         zeallot_0.1.0          knitr_1.25            
## [61] pillar_1.4.2           geneplotter_1.65.0     codetools_0.2-16      
## [64] XML_3.98-1.20          glue_1.3.1             evaluate_0.14         
## [67] latticeExtra_0.6-28    data.table_1.12.6      vctrs_0.2.0           
## [70] gtable_0.3.0           purrr_0.3.3            assertthat_0.2.1      
## [73] ggplot2_3.2.1          xfun_0.10              xtable_1.8-4          
## [76] survival_2.44-1.1      tibble_2.1.3           iterators_1.0.12      
## [79] memoise_1.1.0          AnnotationDbi_1.49.0   cluster_2.1.0