Installation

To install and load NBAMSeq

Introduction

High-throughput sequencing experiments followed by differential expression analysis is a widely used approach to detect genomic biomarkers. A fundamental step in differential expression analysis is to model the association between gene counts and covariates of interest. NBAMSeq is a flexible statistical model based on the generalized additive model and allows for information sharing across genes in variance estimation. Specifically, we model the logarithm of mean gene counts as sums of smooth functions with the smoothing parameters and coefficients estimated simultaneously by a nested iteration. The variance is estimated by the Bayesian shrinkage approach to fully exploit the information across all genes.

The workflow of NBAMSeq contains three main steps:

Here we illustrate each of these steps respectively.

Data input

Users are expected to provide three parts of input, i.e. countData, colData, and design.

countData is a matrix of gene counts generated by RNASeq experiments.

      sample1 sample2 sample3 sample4 sample5 sample6 sample7 sample8 sample9
gene1     149      54      36      21     181      12       1       2      65
gene2      16      59     191       1      69     238     315      58      90
gene3     223     186       6       1     202       9     248     231       4
gene4      84     503       2     115       1       2       1      33      47
gene5      14     122     108      43      13       1      10     121     118
gene6      29       1     203       2      58      19     485     119     379
      sample10 sample11 sample12 sample13 sample14 sample15 sample16 sample17
gene1        1      615        1       46       37       14      161      127
gene2      387        5      205        1        6        1      184      137
gene3        5       79        3        8       85        1        2        2
gene4      132       64        8       42      479        1       19      117
gene5      613       96        5      122       36        2       20        5
gene6       42      162      148       83      281      437      263       54
      sample18 sample19 sample20
gene1        5       70       12
gene2       92      274        9
gene3       63       67       54
gene4       48       60       16
gene5      685        3      272
gene6      867      120      330

colData is a data frame which contains the covariates of samples. The sample order in colData should match the sample order in countData.

           pheno       var1       var2       var3 var4
sample1 52.03148  0.2618515 -0.6656633  0.6129048    2
sample2 22.22902  1.3525567  0.4106865  0.3780545    0
sample3 73.23137 -1.3180993 -0.1906767 -0.7677955    0
sample4 37.00439  0.3475406  0.6929285 -0.4117238    1
sample5 32.27789  0.3885155 -0.1585314  0.8688875    1
sample6 45.55982  0.9917814  0.7774949  0.1518606    2

design is a formula which specifies how to model the samples. Compared with other packages performing DE analysis including DESeq2 (Love, Huber, and Anders 2014), edgeR (Robinson, McCarthy, and Smyth 2010), NBPSeq (Di et al. 2015) and BBSeq (Zhou, Xia, and Wright 2011), NBAMSeq supports the nonlinear model of covariates via mgcv (Wood and Wood 2015). To indicate the nonlinear covariate in the model, users are expected to use s(variable_name) in the design formula. In our example, if we would like to model pheno as a nonlinear covariate, the design formula should be:

Several notes should be made regarding the design formula:

We then construct the NBAMSeqDataSet using countData, colData, and design:

class: NBAMSeqDataSet 
dim: 50 20 
metadata(1): fitted
assays(1): counts
rownames(50): gene1 gene2 ... gene49 gene50
rowData names(0):
colnames(20): sample1 sample2 ... sample19 sample20
colData names(5): pheno var1 var2 var3 var4

Differential expression analysis

Differential expression analysis can be performed by NBAMSeq function:

Several other arguments in NBAMSeq function are available for users to customize the analysis.

Pulling out DE results

Results of DE analysis can be pulled out by results function. For continuous covariates, the name argument should be specified indicating the covariate of interest. For nonlinear continuous covariates, base mean, effective degrees of freedom (edf), test statistics, p-value, and adjusted p-value will be returned.

DataFrame with 6 rows and 7 columns
       baseMean       edf      stat    pvalue      padj       AIC       BIC
      <numeric> <numeric> <numeric> <numeric> <numeric> <numeric> <numeric>
gene1   64.7271   1.00017 0.0483596  0.826015  0.957270   217.404   224.374
gene2  113.6147   1.00004 0.3259410  0.568110  0.957270   238.986   245.956
gene3   75.6826   1.00002 1.6503122  0.198935  0.555999   215.511   222.481
gene4   71.5740   1.00005 1.5626494  0.211280  0.555999   219.600   226.570
gene5   78.5283   1.00006 1.8614700  0.172485  0.555999   217.646   224.616
gene6  178.1046   1.00006 2.1525779  0.142357  0.508416   266.366   273.336

For linear continuous covariates, base mean, estimated coefficient, standard error, test statistics, p-value, and adjusted p-value will be returned.

DataFrame with 6 rows and 8 columns
       baseMean      coef        SE      stat     pvalue      padj       AIC
      <numeric> <numeric> <numeric> <numeric>  <numeric> <numeric> <numeric>
gene1   64.7271  0.397008  0.457498  0.867780 0.38551452  0.721486   217.404
gene2  113.6147 -0.241391  0.465337 -0.518744 0.60393908  0.895525   238.986
gene3   75.6826  1.352876  0.488272  2.770740 0.00559291  0.120965   215.511
gene4   71.5740  0.245625  0.460222  0.533711 0.59354182  0.895525   219.600
gene5   78.5283 -0.713184  0.380567 -1.874003 0.06092998  0.328366   217.646
gene6  178.1046  0.178886  0.433886  0.412289 0.68012745  0.959669   266.366
            BIC
      <numeric>
gene1   224.374
gene2   245.956
gene3   222.481
gene4   226.570
gene5   224.616
gene6   273.336

For discrete covariates, the contrast argument should be specified. e.g. contrast = c("var4", "2", "0") means comparing level 2 vs. level 0 in var4.

DataFrame with 6 rows and 8 columns
       baseMean      coef        SE      stat     pvalue      padj       AIC
      <numeric> <numeric> <numeric> <numeric>  <numeric> <numeric> <numeric>
gene1   64.7271  1.531094  0.956190  1.601245 0.10932272 0.3036742   217.404
gene2  113.6147  0.947606  0.973088  0.973813 0.33014962 0.5859518   238.986
gene3   75.6826 -0.320984  1.022575 -0.313898 0.75359844 0.8373316   215.511
gene4   71.5740  0.128533  0.964606  0.133250 0.89399595 0.9312458   219.600
gene5   78.5283 -2.233128  0.809602 -2.758304 0.00581022 0.0515908   217.646
gene6  178.1046  1.103802  0.908037  1.215591 0.22414090 0.5094111   266.366
            BIC
      <numeric>
gene1   224.374
gene2   245.956
gene3   222.481
gene4   226.570
gene5   224.616
gene6   273.336

Visualization

We suggest two approaches to visualize the nonlinear associations. The first approach is to plot the smooth components of a fitted negative binomial additive model by plot.gam function in mgcv (Wood and Wood 2015). This can be done by calling makeplot function and passing in NBAMSeqDataSet object. Users are expected to provide the phenotype of interest in phenoname argument and gene of interest in genename argument.

In addition, to explore the nonlinear association of covariates, it is also instructive to look at log normalized counts vs. variable scatter plot. Below we show how to produce such plot.

DataFrame with 6 rows and 7 columns
        baseMean       edf      stat     pvalue      padj       AIC       BIC
       <numeric> <numeric> <numeric>  <numeric> <numeric> <numeric> <numeric>
gene50  115.9531   1.00004   9.69323 0.00185028 0.0925138   203.056   210.027
gene40  127.2841   1.00004   8.38922 0.00377612 0.0944029   213.087   220.057
gene10  251.0238   1.46594   8.57862 0.00670475 0.0951255   238.576   246.010
gene11   81.0455   1.00008   7.12356 0.00761004 0.0951255   224.182   231.152
gene27   81.2482   1.00006   6.53544 0.01057645 0.1057645   221.921   228.891
gene36   45.3985   1.00005   5.72845 0.01669752 0.1391460   186.652   193.622

Session info

R version 4.0.0 (2020-04-24)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 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] parallel  stats4    stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] ggplot2_3.3.0               BiocParallel_1.22.0        
 [3] NBAMSeq_1.4.1               SummarizedExperiment_1.18.1
 [5] DelayedArray_0.14.0         matrixStats_0.56.0         
 [7] Biobase_2.48.0              GenomicRanges_1.40.0       
 [9] GenomeInfoDb_1.24.0         IRanges_2.22.1             
[11] S4Vectors_0.26.0            BiocGenerics_0.34.0        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6           locfit_1.5-9.4         lattice_0.20-41       
 [4] assertthat_0.2.1       digest_0.6.25          R6_2.4.1              
 [7] RSQLite_2.2.0          evaluate_0.14          pillar_1.4.4          
[10] zlibbioc_1.34.0        rlang_0.4.6            annotate_1.66.0       
[13] blob_1.2.1             Matrix_1.2-18          rmarkdown_2.1         
[16] labeling_0.3           splines_4.0.0          geneplotter_1.66.0    
[19] stringr_1.4.0          RCurl_1.98-1.2         bit_1.1-15.2          
[22] munsell_0.5.0          compiler_4.0.0         xfun_0.13             
[25] pkgconfig_2.0.3        mgcv_1.8-31            htmltools_0.4.0       
[28] tidyselect_1.0.0       tibble_3.0.1           GenomeInfoDbData_1.2.3
[31] XML_3.99-0.3           withr_2.2.0            crayon_1.3.4          
[34] dplyr_0.8.5            bitops_1.0-6           grid_4.0.0            
[37] nlme_3.1-147           xtable_1.8-4           gtable_0.3.0          
[40] lifecycle_0.2.0        DBI_1.1.0              magrittr_1.5          
[43] scales_1.1.0           stringi_1.4.6          farver_2.0.3          
[46] XVector_0.28.0         genefilter_1.70.0      ellipsis_0.3.0        
[49] vctrs_0.2.4            RColorBrewer_1.1-2     tools_4.0.0           
[52] bit64_0.9-7            glue_1.4.0             DESeq2_1.28.0         
[55] purrr_0.3.4            survival_3.1-12        yaml_2.2.1            
[58] AnnotationDbi_1.50.0   colorspace_1.4-1       memoise_1.1.0         
[61] knitr_1.28            

References

Di, Y, DW Schafer, JS Cumbie, and JH Chang. 2015. “NBPSeq: Negative Binomial Models for Rna-Sequencing Data.” R Package Version 0.3. 0, URL Http://CRAN. R-Project. Org/Package= NBPSeq.

Love, Michael I, Wolfgang Huber, and Simon Anders. 2014. “Moderated Estimation of Fold Change and Dispersion for Rna-Seq Data with Deseq2.” Genome Biology 15 (12). BioMed Central:550.

Robinson, Mark D, Davis J McCarthy, and Gordon K Smyth. 2010. “EdgeR: A Bioconductor Package for Differential Expression Analysis of Digital Gene Expression Data.” Bioinformatics 26 (1). Oxford University Press:139–40.

Wood, Simon, and Maintainer Simon Wood. 2015. “Package ’Mgcv’.” R Package Version 1:29.

Zhou, Yi-Hui, Kai Xia, and Fred A Wright. 2011. “A Powerful and Flexible Approach to the Analysis of Rna Sequence Count Data.” Bioinformatics 27 (19). Oxford University Press:2672–8.