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       1      72       1       7       1     151     143       1     240
gene2     172      32      96      69      49       6      34      41       2
gene3      37      11     437      62      92      83       2     412      18
gene4      14     139      44      34       3       1      11     246      12
gene5       8     118       1       1      45      13       8       6     150
gene6      40      10       1     227     131     324     139      33       2
      sample10 sample11 sample12 sample13 sample14 sample15 sample16 sample17
gene1      102        2       99      428        1       11      108        5
gene2      109       61       13      238       82       30        3        1
gene3        7      267        1       34       26        1        2      104
gene4        8      105        2      200      468        4       73       34
gene5       12        1        4        1        5        1       16        8
gene6      202      114       12       11      166        1       29       16
      sample18 sample19 sample20
gene1       26      512       10
gene2       40       44      324
gene3        2        1        3
gene4        1       23        1
gene5       42        1        7
gene6      324        1       18

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 21.53320  0.8593507 -1.58040647 -0.8362181    1
sample2 74.15480  0.2633423  0.03276398 -0.3846802    0
sample3 47.87655  1.1158054 -0.20812746  0.2271564    0
sample4 74.42441 -0.6560438  1.18843300  0.7566315    1
sample5 73.50917 -1.5356562  1.14785424  1.1707991    1
sample6 56.64656  0.5715289 -0.29170733 -0.9921368    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   96.0694   1.00012 0.58801840  0.443210  0.698965   213.914   220.884
gene2   60.3336   1.00006 1.83255778  0.175835  0.586118   222.477   229.447
gene3   70.8030   1.00045 0.82224587  0.364458  0.698965   209.644   216.614
gene4   66.2147   1.00012 0.00612727  0.938207  0.957354   209.710   216.680
gene5   17.9287   1.00004 0.22985627  0.631699  0.819146   167.284   174.254
gene6   65.1081   1.00009 0.34999839  0.554193  0.769713   222.291   229.262

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   96.0694 -0.563469  0.479275 -1.175671 0.2397263  0.521144   213.914
gene2   60.3336  0.120597  0.392591  0.307181 0.7587056  0.843006   222.477
gene3   70.8030  0.854813  0.481897  1.773849 0.0760882  0.231846   209.644
gene4   66.2147  0.353616  0.459995  0.768739 0.4420483  0.650071   209.710
gene5   17.9287 -0.542410  0.437720 -1.239171 0.2152823  0.489278   167.284
gene6   65.1081 -0.771614  0.435399 -1.772201 0.0763612  0.231846   222.291
            BIC
      <numeric>
gene1   220.884
gene2   229.447
gene3   216.614
gene4   216.680
gene5   174.254
gene6   229.262

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   96.0694 -0.157223   1.23931 -0.126863 0.8990486  0.950030   213.914
gene2   60.3336 -1.039591   1.03114 -1.008193 0.3133620  0.489628   222.477
gene3   70.8030  0.603422   1.24590  0.484326 0.6281548  0.785194   209.644
gene4   66.2147 -1.444814   1.20267 -1.201340 0.2296192  0.441575   209.710
gene5   17.9287 -1.514675   1.15000 -1.317107 0.1878027  0.395802   167.284
gene6   65.1081  2.271623   1.13631  1.999119 0.0455955  0.227978   222.291
            BIC
      <numeric>
gene1   220.884
gene2   229.447
gene3   216.614
gene4   216.680
gene5   174.254
gene6   229.262

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>
gene33  155.3096   1.00005  12.05408 0.000516938 0.0258469   218.101   225.071
gene24   42.4292   1.00003  10.76616 0.001034065 0.0258516   178.710   185.680
gene45  127.6744   1.00313   9.82029 0.001739697 0.0289950   211.572   218.546
gene49   60.5273   1.00004   6.41996 0.011288256 0.1411032   207.831   214.801
gene32   74.8824   1.00042   5.92735 0.014918849 0.1491885   222.055   229.025
gene25  109.3950   1.00003   5.04778 0.024664014 0.1905565   233.993   240.964

Session info

R version 4.2.0 RC (2022-04-21 r82226)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB              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] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] ggplot2_3.3.5               BiocParallel_1.31.0        
 [3] NBAMSeq_1.13.0              SummarizedExperiment_1.27.0
 [5] Biobase_2.57.0              GenomicRanges_1.49.0       
 [7] GenomeInfoDb_1.33.0         IRanges_2.31.0             
 [9] S4Vectors_0.35.0            BiocGenerics_0.43.0        
[11] MatrixGenerics_1.9.0        matrixStats_0.62.0         

loaded via a namespace (and not attached):
 [1] httr_1.4.2             sass_0.4.1             bit64_4.0.5           
 [4] jsonlite_1.8.0         splines_4.2.0          bslib_0.3.1           
 [7] assertthat_0.2.1       highr_0.9              blob_1.2.3            
[10] GenomeInfoDbData_1.2.8 yaml_2.3.5             pillar_1.7.0          
[13] RSQLite_2.2.12         lattice_0.20-45        glue_1.6.2            
[16] digest_0.6.29          RColorBrewer_1.1-3     XVector_0.37.0        
[19] colorspace_2.0-3       htmltools_0.5.2        Matrix_1.4-1          
[22] DESeq2_1.37.0          XML_3.99-0.9           pkgconfig_2.0.3       
[25] genefilter_1.79.0      zlibbioc_1.43.0        purrr_0.3.4           
[28] xtable_1.8-4           scales_1.2.0           tibble_3.1.6          
[31] annotate_1.75.0        mgcv_1.8-40            KEGGREST_1.37.0       
[34] farver_2.1.0           generics_0.1.2         ellipsis_0.3.2        
[37] withr_2.5.0            cachem_1.0.6           cli_3.3.0             
[40] survival_3.3-1         magrittr_2.0.3         crayon_1.5.1          
[43] memoise_2.0.1          evaluate_0.15          fansi_1.0.3           
[46] nlme_3.1-157           tools_4.2.0            lifecycle_1.0.1       
[49] stringr_1.4.0          locfit_1.5-9.5         munsell_0.5.0         
[52] DelayedArray_0.23.0    AnnotationDbi_1.59.0   Biostrings_2.65.0     
[55] compiler_4.2.0         jquerylib_0.1.4        rlang_1.0.2           
[58] grid_4.2.0             RCurl_1.98-1.6         labeling_0.4.2        
[61] bitops_1.0-7           rmarkdown_2.14         gtable_0.3.0          
[64] DBI_1.1.2              R6_2.5.1               knitr_1.38            
[67] dplyr_1.0.8            fastmap_1.1.0          bit_4.0.4             
[70] utf8_1.2.2             stringi_1.7.6          parallel_4.2.0        
[73] Rcpp_1.0.8.3           vctrs_0.4.1            geneplotter_1.75.0    
[76] png_0.1-7              tidyselect_1.1.2       xfun_0.30             

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.