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      54      27       6     224     189      94      78       1       4
gene2       1       9     113     502       3     406     119       9     201
gene3       1      30       7      78      90      58       2       1       1
gene4       4       1       1      16      24     503       8       2      94
gene5      13       2       1     260      14       8       1       5       2
gene6       1      44       1     176       8      26     368      62     715
      sample10 sample11 sample12 sample13 sample14 sample15 sample16 sample17
gene1      685        1        8      497      290       22       11        8
gene2       20        1        4       11        9        1      142        1
gene3        3       27       56      193       27        3      149      183
gene4      115      302       89      124        2        1      271        1
gene5      109      136      126        5      361        4        4        5
gene6       75       19       45        1      122       27        1        4
      sample18 sample19 sample20
gene1      299      156       16
gene2        1      100        3
gene3       18       12       19
gene4      261      447        3
gene5       11        1        3
gene6       12      101       65

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 26.79020 -1.27542429 -1.32520238  1.4832340    2
sample2 51.48971 -1.16996175  0.65811996 -0.1297915    0
sample3 54.82623  0.07305023  0.01040871  1.1532551    0
sample4 20.72869  0.01964022 -1.08881102 -1.0598972    1
sample5 47.07420  2.15022855  0.23837114 -0.1112222    0
sample6 59.70244 -0.93631822  0.05047335  0.6217825    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 7 columns
              baseMean              edf               stat             pvalue
             <numeric>        <numeric>          <numeric>          <numeric>
gene1 91.5566863443651 1.00010612265569 0.0200997746823622   0.88730577880421
gene2 68.4835572010257  1.0003694790328 0.0472589413560397  0.827812601998577
gene3 39.0561196806852 1.00005891444655   4.64966503389417 0.0310616908570413
gene4  86.669186782603 1.00010733864728   1.56474931290648  0.211051943924055
gene5 43.5884018317297  1.0000474863498   2.22901305758404  0.135436240202084
gene6 96.3153340109455 1.00006709878261   4.48367177061403  0.034219648137214
                   padj              AIC              BIC
              <numeric>        <numeric>        <numeric>
gene1 0.924276852921052 231.837941451858  238.80817303649
gene2 0.923454833050553 206.517996878109 213.488490695185
gene3  0.17109824068607  198.31886566291 205.289050240803
gene4 0.651809843733155 218.858516006204 225.828748801637
gene5 0.451454134006946 185.720037757945 192.690210956514
gene6  0.17109824068607 210.558017059915 217.528209787216

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
             <numeric>           <numeric>         <numeric>          <numeric>
gene1 91.5566863443651 -0.0362071582128692  0.31866170153439 -0.113622559719376
gene2 68.4835572010257   0.653522176836443 0.382008006303065   1.71075518327742
gene3 39.0561196806852  0.0274200774914303 0.306506144198669 0.0894601234279249
gene4  86.669186782603   0.136604425839164  0.36705447002526  0.372163907525122
gene5 43.5884018317297  -0.469607593543274 0.343450322247381  -1.36732319967085
gene6 96.3153340109455   0.499054780283572 0.305717580846655   1.63240458367323
                  pvalue              padj              AIC              BIC
               <numeric>         <numeric>        <numeric>        <numeric>
gene1  0.909537003094182 0.957282557585871 231.837941451858  238.80817303649
gene2 0.0871263160073824 0.362704127946533 206.517996878109 213.488490695185
gene3  0.928716243366653 0.957282557585871  198.31886566291 205.289050240803
gene4  0.709770816709485 0.908167264014172 218.858516006204 225.828748801637
gene5  0.171524023020526 0.428810057551314 185.720037757945 192.690210956514
gene6  0.102594284175947 0.362704127946533 210.558017059915 217.528209787216

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
             <numeric>          <numeric>        <numeric>          <numeric>
gene1 91.5566863443651  -1.27133687548668 1.17516215953014  -1.08183952757209
gene2 68.4835572010257   1.66423237600501 1.40621650723009    1.1834823211421
gene3 39.0561196806852 -0.922950611613512   1.140034106372 -0.809581578704406
gene4  86.669186782603   1.48368644237118  1.3490763166412   1.09977947434814
gene5 43.5884018317297  -3.00360843376572 1.28303658747513  -2.34101541848972
gene6 96.3153340109455 -0.404504057117265 1.14149837871007 -0.354362357986321
                  pvalue              padj              AIC              BIC
               <numeric>         <numeric>        <numeric>        <numeric>
gene1  0.279323839303227 0.634826907507333 231.837941451858  238.80817303649
gene2  0.236618048917585 0.616963459657534 206.517996878109 213.488490695185
gene3  0.418180699025496  0.71881025845431  198.31886566291 205.289050240803
gene4  0.271428217533569 0.634826907507333 218.858516006204 225.828748801637
gene5 0.0192313728822898 0.160261440685748 185.720037757945 192.690210956514
gene6  0.723067340610996  0.80340815623444 210.558017059915 217.528209787216

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
              <numeric>        <numeric>        <numeric>           <numeric>
gene40 129.393221190859 1.00047318006385 9.92661781419204 0.00163466004339095
gene9  21.9664495514087 1.00012465183134 9.56162582737083 0.00198682394199224
gene28 88.2940814508719 1.00003327382457 9.54173904609394 0.00200894862816198
gene18 122.406076659233 1.00011213225772 8.16754175772495 0.00426730401495609
gene50 97.7057164654965 1.00026051320955 7.01098494100516 0.00810662629015978
gene23 130.118993411758 1.00017555055086 6.48943518629599  0.0108627855318179
                     padj              AIC              BIC
                <numeric>        <numeric>        <numeric>
gene40  0.033482477136033  218.83475776545 225.805354840989
gene9   0.033482477136033 162.406523952355 169.376773987084
gene28  0.033482477136033 206.056566917923 213.026725964622
gene18 0.0533413001869511 233.222088611091 240.192326179677
gene50 0.0810662629015978 207.809681502408 214.780066818697
gene23 0.0905232127651491 217.259859036922 224.230159753149

Session info

R version 3.6.2 (2019-12-12)
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.1              
 [3] SummarizedExperiment_1.16.1 DelayedArray_0.12.2        
 [5] BiocParallel_1.20.1         matrixStats_0.55.0         
 [7] Biobase_2.46.0              GenomicRanges_1.38.0       
 [9] GenomeInfoDb_1.22.0         IRanges_2.20.2             
[11] S4Vectors_0.24.3            BiocGenerics_0.32.0        

loaded via a namespace (and not attached):
 [1] bit64_0.9-7            splines_3.6.2          Formula_1.2-3         
 [4] assertthat_0.2.1       latticeExtra_0.6-29    blob_1.2.1            
 [7] GenomeInfoDbData_1.2.2 yaml_2.2.1             RSQLite_2.2.0         
[10] pillar_1.4.3           backports_1.1.5        lattice_0.20-38       
[13] glue_1.3.1             digest_0.6.24          RColorBrewer_1.1-2    
[16] XVector_0.26.0         checkmate_2.0.0        colorspace_1.4-1      
[19] htmltools_0.4.0        Matrix_1.2-18          DESeq2_1.26.0         
[22] XML_3.99-0.3           pkgconfig_2.0.3        genefilter_1.68.0     
[25] zlibbioc_1.32.0        purrr_0.3.3            xtable_1.8-4          
[28] scales_1.1.0           jpeg_0.1-8.1           htmlTable_1.13.3      
[31] tibble_2.1.3           annotate_1.64.0        mgcv_1.8-31           
[34] farver_2.0.3           withr_2.1.2            nnet_7.3-12           
[37] lazyeval_0.2.2         survival_3.1-8         magrittr_1.5          
[40] crayon_1.3.4           memoise_1.1.0          evaluate_0.14         
[43] nlme_3.1-144           foreign_0.8-75         tools_3.6.2           
[46] data.table_1.12.8      lifecycle_0.1.0        stringr_1.4.0         
[49] locfit_1.5-9.1         munsell_0.5.0          cluster_2.1.0         
[52] AnnotationDbi_1.48.0   compiler_3.6.2         rlang_0.4.4           
[55] grid_3.6.2             RCurl_1.98-1.1         rstudioapi_0.11       
[58] htmlwidgets_1.5.1      labeling_0.3           bitops_1.0-6          
[61] base64enc_0.1-3        rmarkdown_2.1          gtable_0.3.0          
[64] DBI_1.1.0              R6_2.4.1               gridExtra_2.3         
[67] knitr_1.28             dplyr_0.8.4            bit_1.1-15.2          
[70] Hmisc_4.3-1            stringi_1.4.6          Rcpp_1.0.3            
[73] geneplotter_1.64.0     vctrs_0.2.2            rpart_4.1-15          
[76] acepack_1.4.1          png_0.1-7              tidyselect_1.0.0      
[79] xfun_0.12             

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.