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      11       2      13       1       1       1     182      37
gene2       4     215       1       1      22       2     102     251
gene3       1       1     755      22     771      80     100      11
gene4     206      33       1      14      27      47     100      27
gene5      74       3       1      46       1       2     367     948
gene6     359     218      86      12       2      74      80       1
      sample9 sample10 sample11 sample12 sample13 sample14 sample15
gene1       1       39        1       33      260        1       60
gene2       1      730      103        1       22       10      248
gene3      33       13       60       29       18      155        1
gene4       1        1        1        4       80      198        1
gene5      74        1       11      450       62       38        1
gene6       2       12      155       16       34        1        2
      sample16 sample17 sample18 sample19 sample20
gene1       41        1      366       58      125
gene2       20       31        6       80      382
gene3      234       64       39      330        1
gene4       99        1       26        1       35
gene5       44        1      301       48        1
gene6      310       35       31       10       25

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 56.71001 -0.9252505  2.5510666 -0.04407704    1
sample2 42.82190 -0.4743782  0.1186176  0.69148752    0
sample3 56.39007 -1.0110220  1.8915161 -0.65682697    1
sample4 61.96079  0.4861810 -0.6827808 -1.06145104    1
sample5 78.65690 -1.5942347  0.1678182 -0.09032828    1
sample6 50.10764  0.3402041 -0.4617337  0.40869536    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 40.3810146240061 1.00017302129931  1.12044733145051
gene2 96.7401711174761 1.00039281978881 0.171517325979447
gene3 149.573397066495 1.00006351214147  13.8061182285047
gene4  47.235216463515  1.0000945107179  1.43635576975853
gene5 95.9107080475714  1.0001624639408  4.90521198796358
gene6 84.1219859462146 1.00021586944167  4.57684858147298
                    pvalue                padj
                 <numeric>           <numeric>
gene1    0.289915767979256                  NA
gene2    0.678943874202626   0.754382082447362
gene3 0.000202849778211936 0.00811399112847742
gene4    0.230820684901683                  NA
gene5   0.0267854835391625  0.0989579098302048
gene6   0.0324248504278656  0.0989579098302048

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 40.3810146240061    0.353433740196638 0.414016182003223
gene2 96.7401711174761   0.0871144252319114 0.441707871041739
gene3 149.573397066495 -0.00154839879570697 0.390158033656235
gene4  47.235216463515     1.05830851716423 0.392288278246941
gene5 95.9107080475714     1.29107549206216 0.406902766883482
gene6 84.1219859462146    0.370196602672857 0.394083646878235
                      stat              pvalue               padj
                 <numeric>           <numeric>          <numeric>
gene1    0.853671319044932   0.393287129912476    0.6832066370896
gene2    0.197221808672908   0.843653964919896  0.938686985438606
gene3 -0.00396864516974487   0.996833487603929  0.996833487603929
gene4     2.69778266608834 0.00698029956400901 0.0707383696245858
gene5     3.17293367639316 0.00150906993629059 0.0289491930302151
gene6    0.939385852738114    0.34753267389232  0.643579025726519

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 40.3810146240061 -0.855860329793421  1.03260925066148
gene2 96.7401711174761  -1.25067920649459  1.10070173899278
gene3 149.573397066495   3.54281601766681  1.00302321903271
gene4  47.235216463515 -0.556913273859132 0.990916453627581
gene5 95.9107080475714   2.81210596534219  1.04488357762558
gene6 84.1219859462146  0.894420466004872 0.987885983814718
                    stat               pvalue               padj
               <numeric>            <numeric>          <numeric>
gene1 -0.828832716000915    0.407199072804799                 NA
gene2  -1.13625622835761     0.25584934415566  0.513377986070939
gene3   3.53213759207231 0.000412214814169106 0.0161082737828756
gene4 -0.562018394003213    0.574103486848939  0.748074240439526
gene5   2.69131032926415  0.00711719558427978 0.0612078820248061
gene6  0.905388355193653    0.365259682672914  0.604083321343666

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>
gene3  149.573397066495 1.00006351214147 13.8061182285047
gene49 66.0854645089602 1.00005373188331 10.2593467301833
gene17 77.4485801604086 1.00010374540359  8.9558005471839
gene13 97.5065784092174 1.00020404133988 8.77140103140255
gene15 76.8324894578036 1.00009577334564  8.2674782977527
gene28 139.360992342529 1.00016414887239 7.59776763363783
                     pvalue                padj
                  <numeric>           <numeric>
gene3  0.000202849778211936 0.00811399112847742
gene49  0.00136015516538303  0.0272031033076607
gene17   0.0027688630648992  0.0306634012293218
gene13  0.00306634012293218  0.0306634012293218
gene15  0.00403866918625302  0.0323093534900242
gene28  0.00584860568825095  0.0389907045883397

Session info

R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] C/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] ggplot2_3.2.1               NBAMSeq_1.0.1              
 [3] SummarizedExperiment_1.14.1 DelayedArray_0.10.0        
 [5] BiocParallel_1.18.1         matrixStats_0.54.0         
 [7] Biobase_2.44.0              GenomicRanges_1.36.0       
 [9] GenomeInfoDb_1.20.0         IRanges_2.18.1             
[11] S4Vectors_0.22.0            BiocGenerics_0.30.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.1 yaml_2.2.0             pillar_1.4.2          
[10] RSQLite_2.1.2          backports_1.1.4        lattice_0.20-38       
[13] glue_1.3.1             digest_0.6.20          RColorBrewer_1.1-2    
[16] XVector_0.24.0         checkmate_1.9.4        colorspace_1.4-1      
[19] htmltools_0.3.6        Matrix_1.2-17          DESeq2_1.24.0         
[22] XML_3.98-1.20          pkgconfig_2.0.2        genefilter_1.66.0     
[25] zlibbioc_1.30.0        purrr_0.3.2            xtable_1.8-4          
[28] scales_1.0.0           htmlTable_1.13.1       tibble_2.1.3          
[31] annotate_1.62.0        mgcv_1.8-28            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.2      stringr_1.4.0         
[46] locfit_1.5-9.1         munsell_0.5.0          cluster_2.1.0         
[49] AnnotationDbi_1.46.0   compiler_3.6.1         rlang_0.4.0           
[52] grid_3.6.1             RCurl_1.95-4.12        rstudioapi_0.10       
[55] htmlwidgets_1.3        labeling_0.3           bitops_1.0-6          
[58] base64enc_0.1-3        rmarkdown_1.14         gtable_0.3.0          
[61] DBI_1.0.0              R6_2.4.0               gridExtra_2.3         
[64] knitr_1.24             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.62.0     vctrs_0.2.0           
[73] rpart_4.1-15           acepack_1.4.1          tidyselect_0.2.5      
[76] xfun_0.8              

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): 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): 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): 2672–8.