This document shows typical Topconfects usage with limma, edgeR, or DESeq2.

The first step is to load a dataset. Here, we’re looking at RNA-seq data that investigates the response of Arabodopsis thaliana to a bacterial pathogen. Besides the experimental and control conditions, there is also a batch effect. This dataset is also examined in section 4.2 of the edgeR user manual, and I’ve followed the initial filtering steps in the edgeR manual.

limma analysis

Standard limma analysis steps

##   (Intercept) Time2 Time3 Treathrcc
## 1           1     0     0         0
## 2           1     1     0         0
## 3           1     0     1         0
## 4           1     0     0         1
## 5           1     1     0         1
## 6           1     0     1         1
fit <-
    voom(y, design) %>%
    lmFit(design)

Apply topconfects

Find largest fold changes that we can be confident of at FDR 0.05.

confects <- limma_confects(fit, coef=4, fdr=0.05)

confects
## $table
##  rank index confect effect   AveExpr  name      SYMBOL       
##   1    9023 3.090   4.849117 6.566691 AT3G46280              
##   2   10774 2.895   4.330654 9.155218 AT4G12500              
##   3    4945 2.895   4.493384 6.052661 AT2G19190 FRK1         
##   4   10773 2.608   3.838721 9.165703 AT4G12490              
##   5    2562 2.608   3.951678 6.615271 AT1G51800 IOS1         
##   6    6264 2.608   4.299425 5.440243 AT2G39530              
##   7    6239 2.606   3.907806 7.898640 AT2G39200 ATMLO12/MLO12
##   8   16247 2.606   3.710435 8.728518 AT5G64120 AtPRX71/PRX71
##   9   14449 2.595   5.346437 1.806933 AT5G31702              
##  10    4642 2.563   4.888477 2.382601 AT2G08986              
##  GENENAME                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
##  Receptor-like protein kinase.  Involved in early defense signaling.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
##  A member of a large family of seven-transmembrane domain proteins specific to plants, homologs of the barley mildew resistance locus o (MLO) protein. The Arabidopsis genome contains 15 genes encoding MLO proteins, with localization in plasma membrane. Phylogenetic analysis revealed four clades of closely-related AtMLO genes. ATMLO6 belongs to the clade IV, with AtMLO2, AtMLO3 and AtMLO12. The gene is expressed during early seedling growth, in root tips and cotyledon vascular system, in floral organs (anthers and stigma), and in fruit abscission zone, as shown by GUS activity patterns. The expression of several phylogenetically closely-related AtMLO genes showed similar or overlapping tissue specificity and analogous responsiveness to external stimuli, suggesting functional redundancy, co-function, or antagonistic function(s).
##  encodes a cell wall bound peroxidase that is induced by hypo-osmolarity                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
## ...
## 2184 of 16526 non-zero log2 fold change at FDR 0.05
## Prior df 18.2

Looking at the result

Here the usual logFC values estimated by limma are shown as dots, with lines to the confect value.

confects_plot(confects)

confects_plot_me overlays the confects (black) on a Mean-Difference Plot (grey) (as might be produced by limma::plotMD). As we should expect, the very noisy differences with low mean expression are removed if we look at the confects.

Let’s compare this to the ranking we obtain from topTable.

fit_eb <- eBayes(fit)
top <- topTable(fit_eb, coef=4, n=Inf)

rank_rank_plot(confects$table$name, rownames(top), "limma_confects", "topTable")

You can see that the top 19 genes from topTable are all within the top 40 for topconfects ranking, but topconfects has also highly ranked some other genes. These have a large effect size, and sufficient if not overwhelming evidence of this.

An MD-plot highlighting the positions of the top 40 genes in both rankings also illustrates the differences between these two ways of ranking genes.

edgeR analysis

An analysis in edgeR produces similar results. Note that only quasi-likelihood testing from edgeR is supported.

Standard edgeR analysis

y <- estimateDisp(y, design, robust=TRUE)
efit <- glmQLFit(y, design, robust=TRUE)

Apply topconfects

econfects <- edger_confects(efit, coef=4, fdr=0.05)

econfects
## $table
##  rank index confect effect   logCPM   name      SYMBOL           
##   1   15207 3.06    6.319297 6.729025 AT5G48430                  
##   2    9023 2.98    4.784830 8.096900 AT3G46280                  
##   3    9617 2.98    5.778590 4.902951 AT3G55150 ATEXO70H1/EXO70H1
##   4    4945 2.98    4.497055 7.373501 AT2G19190 FRK1             
##   5    6253 2.98    4.942601 5.771324 AT2G39380 ATEXO70H2/EXO70H2
##   6    2565 2.98    5.321291 5.418659 AT1G51850                  
##   7    6619 2.98    5.414120 5.199481 AT2G44370                  
##   8    6264 2.85    4.340932 6.709049 AT2G39530                  
##   9    2564 2.58    4.336766 6.373316 AT1G51820                  
##  10    5662 2.57    4.526719 5.587339 AT2G30750 CYP71A12         
##  GENENAME                                                                                                                                                                                                        
##                                                                                                                                                                                                                  
##                                                                                                                                                                                                                  
##  A member of EXO70 gene family, putative exocyst subunits, conserved in land plants. Arabidopsis thaliana contains 23 putative EXO70 genes, which can be classified into eight clusters on the phylogenetic tree.
##  Receptor-like protein kinase.  Involved in early defense signaling.                                                                                                                                             
##  A member of EXO70 gene family, putative exocyst subunits, conserved in land plants. Arabidopsis thaliana contains 23 putative EXO70 genes, which can be classified into eight clusters on the phylogenetic tree.
##                                                                                                                                                                                                                  
##                                                                                                                                                                                                                  
##                                                                                                                                                                                                                  
##                                                                                                                                                                                                                  
##  putative cytochrome P450                                                                                                                                                                                        
## ...
## 1729 of 16526 non-zero log2 fold change at FDR 0.05
## Dispersion 0.045 to 0.31
## Biological CV 21.1% to 55.8%

DESeq2 analysis

DESeq2 does its own filtering of lowly expressed genes, so we start from the original count matrix. The initial steps are as for a normal DESeq2 analysis.

Apply topconfects

The contrast or coefficient to test is specified as in the DESeq2::results function.

dconfects <- deseq2_confects(dds, name="Treat_hrcc_vs_mock")

DESeq2 offers shrunken estimates of LFC. This is another sensible way of ranking genes. Let’s compare them to the confect values.

shrunk <- lfcShrink(dds, coef="Treat_hrcc_vs_mock", type="ashr")
## using 'ashr' for LFC shrinkage. If used in published research, please cite:
##     Stephens, M. (2016) False discovery rates: a new deal. Biostatistics, 18:2.
##     https://doi.org/10.1093/biostatistics/kxw041
## Due to absence of package REBayes, switching to EM algorithm
## $table
##  rank index confect effect   baseMean   name      filtered shrunk  
##   1   14551 3.41    4.785076  586.43055 AT3G46280 FALSE    4.636533
##   2    8130 3.17    4.500949  354.89430 AT2G19190 FALSE    4.362675
##   3   17495 3.14    4.320279 2997.59547 AT4G12500 FALSE    4.210788
##   4   10088 2.92    4.976427  115.19576 AT2G39380 FALSE    4.595068
##   5    4063 2.92    5.433121   89.38966 AT1G51850 FALSE    4.829186
##   6   10106 2.91    4.350196  223.26235 AT2G39530 FALSE    4.176110
##   7   10602 2.86    5.453274   77.12549 AT2G44370 FALSE    4.784655
##   8   17494 2.86    3.838114 2532.56056 AT4G12490 FALSE    3.762840
##   9   15411 2.86    5.875086   62.87522 AT3G55150 FALSE    4.930500
##  10    4058 2.84    3.969472  448.54556 AT1G51800 FALSE    3.863951
## ...
## 1219 of 26222 non-zero effect size at FDR 0.05

DESeq2 filters some genes, these are placed last in the table. If your intention is to obtain a ranking of all genes, you should disable this with deseq2_confects(..., cooksCutoff=Inf, independentFiltering=FALSE).

## 
## FALSE  TRUE 
## 11479 14743
##        rank index confect     effect  baseMean      name filtered
## 26217 26217 26203      NA  0.8487098  6.324289 AT5G67460     TRUE
## 26218 26218 26206      NA -0.6852089  1.220362 AT5G67488     TRUE
## 26219 26219 26207      NA  1.4505333  4.657085 AT5G67490     TRUE
## 26220 26220 26210      NA -0.5940465  6.699483 AT5G67520     TRUE
## 26221 26221 26213      NA  0.6767779  1.542612 AT5G67550     TRUE
## 26222 26222 26219      NA  0.1805069 12.111601 AT5G67610     TRUE
##            shrunk
## 26217  0.08464027
## 26218 -0.01672152
## 26219  0.13703553
## 26220 -0.06727663
## 26221  0.02225857
## 26222  0.03021757

Looking at the result

Shrunk LFC estimates are shown in red.

confects_plot(dconfects) + 
    geom_point(aes(x=shrunk, size=baseMean, color="lfcShrink"), alpha=0.75)

lfcShrink aims for a best estimate of the LFC, whereas confect is a conservative estimate. lfcShrink can produce non-zero values for genes which can’t be said to significantly differ from zero – it doesn’t do double duty as an indication of significance – whereas the confect value will be NA in this case. The plot below compares these two quantities. Only un-filtered genes are shown (see above).

filter(dconfects$table, !filtered) %>%
ggplot(aes(x=ifelse(is.na(confect),0,confect), y=shrunk, color=!is.na(confect))) +
    geom_point() + geom_abline() + coord_fixed() + theme_bw() +
    labs(color="Significantly\nnon-zero at\nFDR 0.05", x="confect", y="lfcShrink using ashr")

Comparing results

rank_rank_plot(confects$table$name, econfects$table$name, "limma confects", "edgeR confects")

rank_rank_plot(confects$table$name, dconfects$table$name, "limma confects", "DESeq2 confects")

rank_rank_plot(econfects$table$name, dconfects$table$name, "edgeR confects", "DESeq2 confects")


## R version 3.5.0 (2018-04-23)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS High Sierra 10.13.6
## 
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
## 
## attached base packages:
## [1] parallel  stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] DESeq2_1.20.0               SummarizedExperiment_1.10.1
##  [3] DelayedArray_0.6.6          BiocParallel_1.14.2        
##  [5] matrixStats_0.54.0          Biobase_2.40.0             
##  [7] GenomicRanges_1.32.7        GenomeInfoDb_1.16.0        
##  [9] IRanges_2.14.12             S4Vectors_0.18.3           
## [11] BiocGenerics_0.26.0         bindrcpp_0.2.2             
## [13] ggplot2_3.1.0               dplyr_0.7.7                
## [15] edgeR_3.22.5                limma_3.36.5               
## [17] NBPSeq_0.3.0                topconfects_1.1.3          
## 
## loaded via a namespace (and not attached):
##  [1] bitops_1.0-6           fs_1.2.6               bit64_0.9-7           
##  [4] doParallel_1.0.14      RColorBrewer_1.1-2     rprojroot_1.3-2       
##  [7] tools_3.5.0            backports_1.1.2        R6_2.3.0              
## [10] rpart_4.1-13           Hmisc_4.1-1            DBI_1.0.0             
## [13] lazyeval_0.2.1         colorspace_1.3-2       nnet_7.3-12           
## [16] withr_2.1.2            tidyselect_0.2.5       gridExtra_2.3         
## [19] bit_1.1-14             compiler_3.5.0         htmlTable_1.12        
## [22] xml2_1.2.0             desc_1.2.0             labeling_0.3          
## [25] checkmate_1.8.5        scales_1.0.0           SQUAREM_2017.10-1     
## [28] genefilter_1.62.0      pkgdown_1.1.0.9000     commonmark_1.6        
## [31] stringr_1.3.1          digest_0.6.18          foreign_0.8-71        
## [34] rmarkdown_1.10         XVector_0.20.0         pscl_1.5.2            
## [37] base64enc_0.1-3        pkgconfig_2.0.2        htmltools_0.3.6       
## [40] htmlwidgets_1.3        org.At.tair.db_3.6.0   rlang_0.3.0.1         
## [43] rstudioapi_0.8         RSQLite_2.1.1          bindr_0.1.1           
## [46] acepack_1.4.1          RCurl_1.95-4.11        magrittr_1.5          
## [49] GenomeInfoDbData_1.1.0 Formula_1.2-3          Matrix_1.2-15         
## [52] Rcpp_1.0.0             munsell_0.5.0          stringi_1.2.4         
## [55] yaml_2.2.0             MASS_7.3-51.1          zlibbioc_1.26.0       
## [58] plyr_1.8.4             qvalue_2.12.0          grid_3.5.0            
## [61] blob_1.1.1             crayon_1.3.4           lattice_0.20-35       
## [64] splines_3.5.0          annotate_1.58.0        locfit_1.5-9.1        
## [67] knitr_1.20             pillar_1.3.0           codetools_0.2-15      
## [70] geneplotter_1.58.0     reshape2_1.4.3         XML_3.98-1.16         
## [73] glue_1.3.0             evaluate_0.12          latticeExtra_0.6-28   
## [76] data.table_1.11.8      foreach_1.4.4          gtable_0.2.0          
## [79] purrr_0.2.5            assertthat_0.2.0       ashr_2.2-7            
## [82] xtable_1.8-3           roxygen2_6.1.0         survival_2.43-1       
## [85] truncnorm_1.0-8        tibble_1.4.2           iterators_1.0.10      
## [88] AnnotationDbi_1.42.1   memoise_1.1.0          cluster_2.0.7-1       
## [91] statmod_1.4.30