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
gene1       8       1       3     127     126      47      37     121
gene2      47      73      21     860      20      10      38     169
gene3      36      25     382     150      74     457     455     372
gene4      10     222      39       1       6      11    1026      85
gene5       1     137      12     153      26     167       2       1
gene6       1      54      17      37     730       7       7      58
      sample9 sample10 sample11 sample12 sample13 sample14 sample15
gene1     155      213       62       16      374        1      752
gene2       2      636        6        4       67      105      357
gene3       2      402        1       30        2       25        1
gene4      45        1      133      250      370      143       98
gene5       1       63        2      341      128        1        4
gene6       4      608        4     1262      498       64      112
      sample16 sample17 sample18 sample19 sample20
gene1      173        2        2        1      215
gene2       62        1       15      327        1
gene3       25      163        2      160        1
gene4       14       10      194      392        1
gene5      119      198       44        1      588
gene6      356       60      105        7        5

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 67.85934 -1.8617370  0.1912061  2.37892508    0
sample2 59.77305  0.1412924  0.4844806 -0.17171879    1
sample3 20.22851 -2.2920789  1.2541955 -0.03143304    2
sample4 76.36915  0.5277706  0.7421966 -2.10155299    0
sample5 31.61560 -0.6002114  0.2913025 -0.33986158    1
sample6 59.20190 -0.5725584 -0.3810616 -0.49112913    1

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 5 columns
              baseMean              edf              stat
             <numeric>        <numeric>         <numeric>
gene1 90.0223445916752 1.00006202023321 0.417989874223938
gene2 99.8447199106719 1.00004146923865  3.08482813260575
gene3 116.603318095633 1.17313756315202  1.91840978954756
gene4 129.620065481309 1.00007983709234  0.12056885931311
gene5 72.0263609716251 1.00012745086756 0.701259411497124
gene6 170.877758873863 1.00007553113959  3.40518981678079
                  pvalue              padj
               <numeric>         <numeric>
gene1  0.517966982682795 0.742725976693875
gene2 0.0790317301987507   0.3912270673467
gene3  0.172873212566153 0.508450625194567
gene4  0.728400808229941 0.846977683988303
gene5  0.402436600805646  0.71863678715294
gene6 0.0650057990602778   0.3912270673467

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 6 columns
              baseMean               coef                SE
             <numeric>          <numeric>         <numeric>
gene1 90.0223445916752  0.708462433336299 0.390260334737052
gene2 99.8447199106719 -0.395669230817001 0.365556966182653
gene3 116.603318095633   -1.7566236902356 0.405611108070408
gene4 129.620065481309  0.337320688034654 0.428478622798008
gene5 72.0263609716251  0.991144817749539 0.417783892073528
gene6 170.877758873863   1.21515329226148 0.428474483498771
                   stat               pvalue                 padj
              <numeric>            <numeric>            <numeric>
gene1  1.81535854473564    0.069468827419237    0.248102955068704
gene2 -1.08237365833511    0.279086528190152    0.498368800339557
gene3 -4.33080765118169 1.48563417093905e-05 0.000742817085469526
gene4 0.787252082337075      0.4311343141514    0.619830976241167
gene5  2.37238638577071   0.0176735976703406   0.0940786487801255
gene6   2.8359991996232  0.00456825604953488   0.0571032006191859

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 6 columns
              baseMean                coef                SE
             <numeric>           <numeric>         <numeric>
gene1 90.0223445916752  0.0712881217744735 0.891050025315463
gene2 99.8447199106719   -1.78328194518284 0.829949582780345
gene3 116.603318095633  0.0923052717932765 0.916562305528452
gene4 129.620065481309 -0.0360569040117083 0.976593846294209
gene5 72.0263609716251   0.619014307281392 0.956735889968304
gene6 170.877758873863    0.46444006634833  0.97794067199217
                     stat             pvalue              padj
                <numeric>          <numeric>         <numeric>
gene1   0.080004623476931   0.93623357875778 0.970547928133608
gene2   -2.14866298168236 0.0316611251622829 0.141069836941244
gene3    0.10070812560861  0.919782160868774 0.970547928133608
gene4 -0.0369210845926688  0.970547928133608 0.970547928133608
gene5   0.647006466227476  0.517627758525079  0.76694156155462
gene6   0.474916403059723  0.634846559417972 0.857900755970232

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 5 columns
               baseMean              edf             stat
              <numeric>        <numeric>        <numeric>
gene11 114.096145981131 1.00009161106674 8.90315658526706
gene15 55.3771483785019 1.00005994731693 6.72535616913074
gene45 107.219726187918  1.0001605021219 6.06083726983454
gene49 39.6521545669267 1.00009383264887 4.31214431501749
gene13  55.503451491174 1.00006114204692 4.02897665640921
gene21 59.1659906642282 1.00012335068253 3.95174603749206
                    pvalue              padj
                 <numeric>         <numeric>
gene11 0.00284763602597408 0.142381801298704
gene15 0.00950640127330121 0.230398483166231
gene45  0.0138239089899739 0.230398483166231
gene49  0.0378584827989891 0.390326288493192
gene13   0.044725009980555 0.390326288493192
gene21   0.046839154619183 0.390326288493192

Session info

R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /home/biocbuild/bbs-3.10-bioc/R/lib/libRblas.so
LAPACK: /home/biocbuild/bbs-3.10-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.2.1               NBAMSeq_1.2.0              
 [3] SummarizedExperiment_1.16.0 DelayedArray_0.12.0        
 [5] BiocParallel_1.20.0         matrixStats_0.55.0         
 [7] Biobase_2.46.0              GenomicRanges_1.38.0       
 [9] GenomeInfoDb_1.22.0         IRanges_2.20.0             
[11] S4Vectors_0.24.0            BiocGenerics_0.32.0        

loaded via a namespace (and not attached):
 [1] bit64_0.9-7            splines_3.6.1          Formula_1.2-3         
 [4] assertthat_0.2.1       latticeExtra_0.6-28    blob_1.2.0            
 [7] GenomeInfoDbData_1.2.2 yaml_2.2.0             pillar_1.4.2          
[10] RSQLite_2.1.2          backports_1.1.5        lattice_0.20-38       
[13] glue_1.3.1             digest_0.6.22          RColorBrewer_1.1-2    
[16] XVector_0.26.0         checkmate_1.9.4        colorspace_1.4-1      
[19] htmltools_0.4.0        Matrix_1.2-17          DESeq2_1.26.0         
[22] XML_3.98-1.20          pkgconfig_2.0.3        genefilter_1.68.0     
[25] zlibbioc_1.32.0        purrr_0.3.3            xtable_1.8-4          
[28] scales_1.0.0           htmlTable_1.13.2       tibble_2.1.3          
[31] annotate_1.64.0        mgcv_1.8-30            withr_2.1.2           
[34] nnet_7.3-12            lazyeval_0.2.2         survival_2.44-1.1     
[37] magrittr_1.5           crayon_1.3.4           memoise_1.1.0         
[40] evaluate_0.14          nlme_3.1-141           foreign_0.8-72        
[43] tools_3.6.1            data.table_1.12.6      stringr_1.4.0         
[46] locfit_1.5-9.1         munsell_0.5.0          cluster_2.1.0         
[49] AnnotationDbi_1.48.0   compiler_3.6.1         rlang_0.4.1           
[52] grid_3.6.1             RCurl_1.95-4.12        rstudioapi_0.10       
[55] htmlwidgets_1.5.1      labeling_0.3           bitops_1.0-6          
[58] base64enc_0.1-3        rmarkdown_1.16         gtable_0.3.0          
[61] DBI_1.0.0              R6_2.4.0               gridExtra_2.3         
[64] knitr_1.25             dplyr_0.8.3            zeallot_0.1.0         
[67] bit_1.1-14             Hmisc_4.2-0            stringi_1.4.3         
[70] Rcpp_1.0.2             geneplotter_1.64.0     vctrs_0.2.0           
[73] rpart_4.1-15           acepack_1.4.1          tidyselect_0.2.5      
[76] xfun_0.10             

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.