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       5     236       4      11       3       5       4      55     332
gene2      55     177       1      49      72     144       7       1      30
gene3     404      75      26     757       3      87      25     159       6
gene4      47      16     234       1      71      12       3       5      13
gene5       1      39       9       1       1      20       8       1       3
gene6      36      57       6      23       7      70     494      54      79
      sample10 sample11 sample12 sample13 sample14 sample15 sample16 sample17
gene1       43       80       35      325        2      126      229       77
gene2      131       17        1      156      173      676        5      352
gene3       10       28      236       49      112      201        5        1
gene4       10        1       43      119        1      287       11       33
gene5       54      314        4       23       47        1      168        4
gene6       17        1       15       25       26      100      181       75
      sample18 sample19 sample20
gene1      134       43      229
gene2       39      279       40
gene3       59      156       16
gene4      383      322      176
gene5      307        2        9
gene6       10        4        2

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 29.26069 0.459426595  2.44412228  1.689561114    2
sample2 62.71179 0.726911389 -3.30635101  1.971382379    2
sample3 56.04423 0.436778751 -0.05945345 -0.290502229    1
sample4 78.74817 0.005909693  3.54486355 -0.005807506    1
sample5 29.87971 1.164830545 -1.17048059  0.202401609    0
sample6 47.94344 0.772809514  0.32631741  1.055372233    0

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
      <numeric> <numeric>   <numeric>   <numeric>  <numeric> <numeric>
gene1   88.8412   1.00006  0.00663657 9.35133e-01 0.99482219   232.143
gene2   86.8711   1.00016  1.66180091 1.97361e-01 0.59035732   231.009
gene3   99.7145   1.00010  2.36585714 1.24052e-01 0.48909341   234.944
gene4   68.3691   1.00015  7.93070335 4.86209e-03 0.08103487   218.681
gene5   36.6069   1.00005  5.53562302 1.86354e-02 0.18635423   186.787
gene6   64.7683   1.00005 18.09030372 2.10755e-05 0.00105377   208.345
            BIC
      <numeric>
gene1   239.113
gene2   237.979
gene3   241.914
gene4   225.652
gene5   193.757
gene6   215.315

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   88.8412 -0.642901  0.437645  -1.46900 0.14183207 0.3939780   232.143
gene2   86.8711  0.751001  0.419988   1.78815 0.07375201 0.2384105   231.009
gene3   99.7145  0.955607  0.424934   2.24883 0.02452306 0.1532691   234.944
gene4   68.3691 -0.873040  0.456298  -1.91331 0.05570815 0.2321173   218.681
gene5   36.6069 -1.265770  0.489371  -2.58652 0.00969495 0.0692497   186.787
gene6   64.7683  1.103606  0.403977   2.73186 0.00629787 0.0647809   208.345
            BIC
      <numeric>
gene1   239.113
gene2   237.979
gene3   241.914
gene4   225.652
gene5   193.757
gene6   215.315

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   88.8412 -0.761575  0.818393 -0.930574  0.352074  0.871706   232.143
gene2   86.8711  0.128746  0.779939  0.165072  0.868887  0.943712   231.009
gene3   99.7145  0.624624  0.789138  0.791528  0.428636  0.871706   234.944
gene4   68.3691 -0.120950  0.851832 -0.141988  0.887089  0.943712   218.681
gene5   36.6069  0.522830  0.911795  0.573407  0.566369  0.871706   186.787
gene6   64.7683 -0.148466  0.735365 -0.201894  0.839999  0.933333   208.345
            BIC
      <numeric>
gene1   239.113
gene2   237.979
gene3   241.914
gene4   225.652
gene5   193.757
gene6   215.315

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>
gene6    64.7683   1.00005  18.09030 2.10755e-05 0.00105377   208.345   215.315
gene47  130.9994   1.00007   8.84511 2.94038e-03 0.07350950   233.623   240.593
gene4    68.3691   1.00015   7.93070 4.86209e-03 0.08103487   218.681   225.652
gene15  129.5991   1.00016   5.67572 1.72123e-02 0.18635423   227.397   234.368
gene5    36.6069   1.00005   5.53562 1.86354e-02 0.18635423   186.787   193.757
gene22  143.9462   1.00007   3.70848 5.41397e-02 0.40160891   254.260   261.231

Session info

R Under development (unstable) (2020-01-28 r77731)
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] parallel  stats4    stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] ggplot2_3.2.1               NBAMSeq_1.3.1              
 [3] SummarizedExperiment_1.17.2 DelayedArray_0.13.4        
 [5] BiocParallel_1.21.2         matrixStats_0.55.0         
 [7] Biobase_2.47.2              GenomicRanges_1.39.2       
 [9] GenomeInfoDb_1.23.13        IRanges_2.21.3             
[11] S4Vectors_0.25.12           BiocGenerics_0.33.0        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3             locfit_1.5-9.1         lattice_0.20-38       
 [4] assertthat_0.2.1       digest_0.6.24          R6_2.4.1              
 [7] RSQLite_2.2.0          evaluate_0.14          pillar_1.4.3          
[10] zlibbioc_1.33.1        rlang_0.4.4            lazyeval_0.2.2        
[13] annotate_1.65.1        blob_1.2.1             Matrix_1.2-18         
[16] rmarkdown_2.1          labeling_0.3           splines_4.0.0         
[19] geneplotter_1.65.0     stringr_1.4.0          RCurl_1.98-1.1        
[22] bit_1.1-15.2           munsell_0.5.0          compiler_4.0.0        
[25] xfun_0.12              pkgconfig_2.0.3        mgcv_1.8-31           
[28] htmltools_0.4.0        tidyselect_1.0.0       tibble_2.1.3          
[31] GenomeInfoDbData_1.2.2 XML_3.99-0.3           withr_2.1.2           
[34] crayon_1.3.4           dplyr_0.8.4            bitops_1.0-6          
[37] grid_4.0.0             nlme_3.1-144           xtable_1.8-4          
[40] gtable_0.3.0           lifecycle_0.1.0        DBI_1.1.0             
[43] magrittr_1.5           scales_1.1.0           stringi_1.4.6         
[46] farver_2.0.3           XVector_0.27.0         genefilter_1.69.0     
[49] vctrs_0.2.2            RColorBrewer_1.1-2     tools_4.0.0           
[52] bit64_0.9-7            glue_1.3.1             DESeq2_1.27.24        
[55] purrr_0.3.3            survival_3.1-8         yaml_2.2.1            
[58] AnnotationDbi_1.49.1   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.