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       1       2       9     291     421     453      39      89
gene2      26     420       7     106      60       2     189     208       1
gene3       1     174     340       1       8       5       2     119       2
gene4      11     132      54       7      79      46      80       3       6
gene5     126     929      19     124      11     359       8      85       3
gene6       1     328       3    1119      12      24      10       4      42
      sample10 sample11 sample12 sample13 sample14 sample15 sample16 sample17
gene1        3        1       17       11        1       40      230        1
gene2        1       63        2      595       52      142        3       19
gene3        1        9       80       12        1       40      201        1
gene4        1        1       89       32        1       18       14     1161
gene5        1       12        1      146       47      159       93      444
gene6       19        1        1      358      144        1       46       10
      sample18 sample19 sample20
gene1       11       18        2
gene2      126       76      148
gene3       71       31       26
gene4       24        1      184
gene5      114      162       27
gene6       46      403       23

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 41.73174  0.9468455 -0.1231153 -0.50320534    1
sample2 61.79489 -1.2978668  0.5838662 -0.08850541    1
sample3 78.25007  1.6509330  1.5847842 -0.00786075    0
sample4 64.72470  0.5327862 -0.8553626  0.39325437    2
sample5 65.15181  0.8759616  0.7456919  0.84867099    0
sample6 67.79239 -0.7312094  0.0374443 -1.29698795    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   65.0314   1.00013 0.0349426  0.851836  0.913758   196.873   203.843
gene2   83.1839   1.00017 0.0242483  0.876462  0.913758   230.356   237.326
gene3   54.4536   1.00011 0.3665395  0.545028  0.801651   187.975   194.945
gene4   70.8177   1.00008 0.3034318  0.581806  0.801651   207.397   214.367
gene5  103.1989   1.00012 0.6178096  0.431978  0.799959   237.420   244.391
gene6   93.4488   1.00011 0.0615414  0.804217  0.913758   215.271   222.241

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   65.0314  0.1583023  0.439083  0.3605290  0.718452  0.846646   196.873
gene2   83.1839  0.0207493  0.410970  0.0504887  0.959733  0.988504   230.356
gene3   54.4536 -0.1106871  0.397565 -0.2784126  0.780696  0.867440   187.975
gene4   70.8177 -0.6378196  0.415525 -1.5349721  0.124791  0.311977   207.397
gene5  103.1989 -0.2115241  0.384776 -0.5497328  0.582503  0.824217   237.420
gene6   93.4488  0.1388827  0.434182  0.3198723  0.749065  0.851210   215.271
            BIC
      <numeric>
gene1   203.843
gene2   237.326
gene3   194.945
gene4   214.367
gene5   244.391
gene6   222.241

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   65.0314 -0.454763   1.40160 -0.324460 0.745590016 0.93478332   196.873
gene2   83.1839  0.322964   1.32707  0.243367 0.807721368 0.94650109   230.356
gene3   54.4536 -4.902645   1.29185 -3.795045 0.000147616 0.00738082   187.975
gene4   70.8177 -0.431718   1.34280 -0.321506 0.747826655 0.93478332   207.397
gene5  103.1989  0.241940   1.24408  0.194472 0.845806080 0.94650109   237.420
gene6   93.4488  4.054993   1.41788  2.859907 0.004237657 0.04556218   215.271
            BIC
      <numeric>
gene1   203.843
gene2   237.326
gene3   194.945
gene4   214.367
gene5   244.391
gene6   222.241

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>
gene27   55.3069   1.00007   15.3250 9.05769e-05 0.00448350   208.320   215.290
gene21  152.5731   1.00009   14.0376 1.79340e-04 0.00448350   227.492   234.462
gene43   86.3873   1.00008   12.3738 4.35538e-04 0.00725896   190.809   197.779
gene38  116.6806   1.00012   11.3185 7.68016e-04 0.00954241   223.442   230.412
gene31  103.8317   1.00005   10.9150 9.54241e-04 0.00954241   231.098   238.068
gene33   41.7787   1.00010   10.0025 1.56356e-03 0.01302969   188.655   195.625

Session info

R version 4.0.0 RC (2020-04-19 r78255)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS

Matrix products: default
BLAS:   /home/biocbuild/bbs-3.12-bioc/R/lib/libRblas.so
LAPACK: /home/biocbuild/bbs-3.12-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.3.0               BiocParallel_1.23.0        
 [3] NBAMSeq_1.5.1               SummarizedExperiment_1.19.2
 [5] DelayedArray_0.15.1         matrixStats_0.56.0         
 [7] Biobase_2.49.0              GenomicRanges_1.41.1       
 [9] GenomeInfoDb_1.25.0         IRanges_2.23.4             
[11] S4Vectors_0.27.5            BiocGenerics_0.35.2        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6           locfit_1.5-9.4         lattice_0.20-41       
 [4] assertthat_0.2.1       digest_0.6.25          R6_2.4.1              
 [7] RSQLite_2.2.0          evaluate_0.14          pillar_1.4.4          
[10] zlibbioc_1.35.0        rlang_0.4.6            annotate_1.67.0       
[13] blob_1.2.1             Matrix_1.2-18          rmarkdown_2.1         
[16] labeling_0.3           splines_4.0.0          geneplotter_1.67.0    
[19] stringr_1.4.0          RCurl_1.98-1.2         bit_1.1-15.2          
[22] munsell_0.5.0          compiler_4.0.0         xfun_0.13             
[25] pkgconfig_2.0.3        mgcv_1.8-31            htmltools_0.4.0       
[28] tidyselect_1.0.0       tibble_3.0.1           GenomeInfoDbData_1.2.3
[31] XML_3.99-0.3           withr_2.2.0            crayon_1.3.4          
[34] dplyr_0.8.5            bitops_1.0-6           grid_4.0.0            
[37] nlme_3.1-147           xtable_1.8-4           gtable_0.3.0          
[40] lifecycle_0.2.0        DBI_1.1.0              magrittr_1.5          
[43] scales_1.1.0           stringi_1.4.6          farver_2.0.3          
[46] XVector_0.29.0         genefilter_1.71.0      ellipsis_0.3.0        
[49] vctrs_0.2.4            RColorBrewer_1.1-2     tools_4.0.0           
[52] bit64_0.9-7            glue_1.4.0             DESeq2_1.29.0         
[55] purrr_0.3.4            survival_3.1-12        yaml_2.2.1            
[58] AnnotationDbi_1.51.0   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.