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     995     269     112      11      18       3      18      88
gene2     126     457     106       1       3       2     207     311
gene3       2     162      95     286      59      18     471      26
gene4       1     105       1      61      87      48       1       1
gene5       1       3       7     414     281       1     259     204
gene6       2     219     266       9     510       1       1       1
      sample9 sample10 sample11 sample12 sample13 sample14 sample15
gene1     194      118       46       81       37       36        1
gene2      26       17        1      229        6       98        6
gene3     207       94       64        1       14       14       78
gene4       1      342       12      461      248       45        1
gene5     462      141      116        5      285       60       89
gene6     661      184      402       76        1        7      281
      sample16 sample17 sample18 sample19 sample20
gene1        1       68      137      530       67
gene2       38       26      110       14        5
gene3      415       10       32        4      502
gene4        2      121        6        9      185
gene5      170      192        1       15        1
gene6       41      481      352       56       15

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 36.86757  1.1311246  1.0493673 -0.5471740    1
sample2 50.75459  1.3719671  1.5492184 -0.2166502    1
sample3 50.45867  1.4369906 -1.5450964 -0.5121450    1
sample4 77.00218  1.2863959 -1.3439815 -0.2148201    2
sample5 62.71826 -0.9012493  0.4691974 -0.2900253    1
sample6 75.28463 -0.5606395 -0.3894758 -0.9466211    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 5 columns
              baseMean              edf              stat
             <numeric>        <numeric>         <numeric>
gene1   91.60292210857 1.00008921585673  1.07855413878035
gene2 67.2852607677891 1.00037446195523  1.81537081352052
gene3 125.936796785014 1.00005361704823  4.10610436042032
gene4 73.0058338023216  1.0001020254979 0.477991532067814
gene5 102.629659365242 1.00009004853503     1.34484701446
gene6  108.04471122824 1.00012745999835  2.91596875280838
                  pvalue              padj
               <numeric>         <numeric>
gene1  0.299076094381302 0.553844619224634
gene2  0.177879876434193 0.444699691085482
gene3 0.0427390053641161 0.213695026820581
gene4  0.489436945682868 0.775575657492247
gene5  0.246226972208515 0.522999555844424
gene6 0.0877096201299905 0.311220141137408

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   91.60292210857  0.310220938455762 0.340224544469899
gene2 67.2852607677891  0.547831072029087 0.378158311026578
gene3 125.936796785014 -0.429772581141254 0.360977752264964
gene4 73.0058338023216  -0.54025530914963 0.387831728712902
gene5 102.629659365242 -0.282282973564461 0.385672503218715
gene6  108.04471122824  0.218092360909677 0.380752669735136
                    stat            pvalue              padj
               <numeric>         <numeric>         <numeric>
gene1   0.91181234128512 0.361867512578129 0.753890651204436
gene2   1.44868182466201 0.147426458500031 0.611793533362911
gene3  -1.19057913803451 0.233818845486659 0.655505139225826
gene4  -1.39301472559395  0.16361533775686 0.611793533362911
gene5 -0.731924031940587 0.464214937065764 0.785751709955485
gene6  0.572792729362579 0.566785042516756 0.811144124182436

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   91.60292210857 -0.0076446386972103 0.878667047086749
gene2 67.2852607677891   0.398195223302995 0.975874185874245
gene3 125.936796785014   0.638471353241488 0.933166140781474
gene4 73.0058338023216  -0.711105834751735   1.0006651094212
gene5 102.629659365242    1.03021670774034 0.996633510139689
gene6  108.04471122824   -1.08467334661438 0.983490190739813
                      stat            pvalue              padj
                 <numeric>         <numeric>         <numeric>
gene1 -0.00870026789163923 0.993058278149737 0.993058278149737
gene2    0.408039508644517 0.683244669326188 0.854055836657735
gene3    0.684199013807771 0.493849504923499  0.79653145955403
gene4   -0.710633185924762 0.477311572837233  0.79653145955403
gene5     1.03369663698739 0.301278005781281 0.753195014453202
gene6    -1.10288171333814 0.270078536490824 0.753195014453202

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>
gene21 101.634996183142 1.00005810012748 13.4306178647762
gene39 104.126727292461 1.00040518617408 11.2427462237282
gene17 52.5189944095466 1.00005325871012 7.84736332735752
gene36 91.7386627425789 1.00019165833277 6.87580220018975
gene9  86.2372831115399 1.00014326658416 6.41330098985743
gene33 62.4688636837751 1.00013121197986 5.20264904970037
                     pvalue               padj
                  <numeric>          <numeric>
gene21 0.000247650465535714 0.0123825232767857
gene39 0.000801974092689597 0.0200493523172399
gene17    0.005091533336132 0.0848588889355333
gene36   0.0087505374392623  0.109381717990779
gene9    0.0113357791916588  0.113357791916588
gene33    0.022570966593355  0.163625939370434

Session info

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2012 R2 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=C                          
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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] snow_0.4-3             scales_1.0.0           htmlTable_1.13.1      
[31] tibble_2.1.3           annotate_1.62.0        mgcv_1.8-28           
[34] withr_2.1.2            nnet_7.3-12            lazyeval_0.2.2        
[37] survival_2.44-1.1      magrittr_1.5           crayon_1.3.4          
[40] memoise_1.1.0          evaluate_0.14          nlme_3.1-141          
[43] foreign_0.8-72         tools_3.6.1            data.table_1.12.2     
[46] stringr_1.4.0          locfit_1.5-9.1         munsell_0.5.0         
[49] cluster_2.1.0          AnnotationDbi_1.46.0   compiler_3.6.1        
[52] rlang_0.4.0            grid_3.6.1             RCurl_1.95-4.12       
[55] rstudioapi_0.10        htmlwidgets_1.3        labeling_0.3          
[58] bitops_1.0-6           base64enc_0.1-3        rmarkdown_1.14        
[61] gtable_0.3.0           DBI_1.0.0              R6_2.4.0              
[64] gridExtra_2.3          knitr_1.24             dplyr_0.8.3           
[67] zeallot_0.1.0          bit_1.1-14             Hmisc_4.2-0           
[70] stringi_1.4.3          Rcpp_1.0.2             geneplotter_1.62.0    
[73] vctrs_0.2.0            rpart_4.1-15           acepack_1.4.1         
[76] tidyselect_0.2.5       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). 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.