5 min read

Simplified simplifyEnrichment plot

The lt object contains a list of GO enrichment tables.

names(lt)
## [1] "BP_km1" "BP_km2" "BP_km3" "BP_km4"
head(lt[[1]][, 1:7])
##                    ID                              Description GeneRatio   BgRatio       pvalue
## GO:0006974 GO:0006974 cellular response to DNA damage stimulus    77/471 871/18614 3.252635e-22
## GO:0006281 GO:0006281                               DNA repair    61/471 587/18614 3.683205e-21
## GO:0000278 GO:0000278                       mitotic cell cycle    78/471 933/18614 5.191864e-21
## GO:1903047 GO:1903047               mitotic cell cycle process    70/471 777/18614 1.148628e-20
## GO:0051276 GO:0051276                  chromosome organization    58/471 626/18614 8.913192e-18
## GO:0006260 GO:0006260                          DNA replication    38/471 278/18614 1.862901e-17
##                p.adjust       qvalue
## GO:0006974 1.545002e-18 1.174030e-18
## GO:0006281 8.220452e-18 6.246633e-18
## GO:0000278 8.220452e-18 6.246633e-18
## GO:1903047 1.363995e-17 1.036485e-17
## GO:0051276 8.467532e-15 6.434386e-15
## GO:0006260 1.474797e-14 1.120682e-14

We first demonstrate the new plot on the single enrichment table. To use the simplifyEnrichment package, we extract significant GO terms, and then call simplifyGO().

library(simplifyEnrichment)
df = lt[[1]]
go_id = df$ID[df$p.adjust < 0.01]
simplifyGO(go_id)

The plot looks good, but it still contains too many graphic contents. For example, the GO similarity heatmap is useful, but it takes too much space on the final plot. Here I developed a new function summarizeGO() which simplifies the enrichment results even more. The idea is that since we already have the GO clusters, with a certain statistic of enrichment, we can simply use its average for the GO cluster.

In the following example, we use -log10(p.adjust) as an enrichment measure. The heights of bars correspond to the mean of -log10(p.adjust) of GO terms in different GO clusters. On the left side, we still use the word clouds which efficiently show the general functions in each GO cluster.

l = df$p.adjust < 0.01
summarizeGO(df$ID[l], -log10(df$p.adjust)[l], axis_label = "average -log10(p.adjust)")

GO IDs can be attached to the numeric value vector, but this time, the value argument should be explicitely specified when calling summarizeGO().

v = -log10(df$p.adjust)
names(v) = df$ID
summarizeGO(value = v[l], axis_label = "average -log10(p.adjust)")

Beside -log10(p.adjust), we also suggest to use log2 fold enrichment as the enrichment measure. It is calculated as

\[ \log_2 \left( \frac{k/m_1}{m_2/n} \right) \]

where \(k\) is the number of DE genes (if the genes of interest are DE genes) in a gene set, \(m_1\) is the size of DE genes, \(m_2\) is the size of the gene set, \(n\) is the total number of genes in the universal set. Of course, the definition of \(m_1\) and \(m_2\) can be switched.

k = as.numeric(gsub("/\\d+$", "", df$GeneRatio))
m1 = as.numeric(gsub("^\\d+/", "", df$GeneRatio))
m2 = as.numeric(gsub("/\\d+$", "", df$BgRatio))
n = as.numeric(gsub("^\\d+/", "", df$BgRatio))
log2_fold_enrichment = log2(k*n/m1/m2)

summarizeGO(df$ID[l], log2_fold_enrichment[l], axis_label = "average log2(fold_enrichment)")

Of course, you can construct a named log2_fold_enrichment vector which only contains significant GO terms.

names(log2_fold_enrichment) = df$ID
summarizeGO(value = log2_fold_enrichment[l], axis_label = "average log2(fold_enrichment)")

For multiple GO enrichment results, simplifyGOFromMultipleLists() can be used to visualize and compare GO clusters.

simplifyGOFromMultipleLists(lt, padj_cutoff = 0.001)

summarizeGO() can also be used to simplify such plot. Now the value of value is a list of numeric named vectors which contains significant GO terms in each enrichment table:

value = lapply(lt, function(df) {
    v = -log10(df$p.adjust)
    names(v) = df$ID
    v[df$p.adjust < 0.001]
})
summarizeGO(value = value, axis_label = "average -log10(p.adjust)", legend_title = "-log10(p.adjust)")

sessionInfo()
## R version 4.3.1 (2023-06-16)
## Platform: x86_64-apple-darwin20 (64-bit)
## Running under: macOS Ventura 13.2.1
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
## 
## Random number generation:
##  RNG:     L'Ecuyer-CMRG 
##  Normal:  Inversion 
##  Sample:  Rejection 
##  
## locale:
## [1] C/UTF-8/C/C/C/C
## 
## time zone: Europe/Berlin
## tzcode source: internal
## 
## attached base packages:
## [1] grid      stats4    stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] simplifyEnrichment_1.9.5 hu6800.db_3.13.0         org.Hs.eg.db_3.17.0     
##  [4] AnnotationDbi_1.62.2     IRanges_2.34.1           S4Vectors_0.38.2        
##  [7] Biobase_2.60.0           BiocGenerics_0.46.0      cola_2.6.0              
## [10] knitr_1.44              
## 
## loaded via a namespace (and not attached):
##   [1] eulerr_7.0.0            RColorBrewer_1.1-3      jsonlite_1.8.7         
##   [4] shape_1.4.6             magrittr_2.0.3          magick_2.8.0           
##   [7] farver_2.1.1            rmarkdown_2.25          fs_1.6.3               
##  [10] GlobalOptions_0.1.2     zlibbioc_1.46.0         vctrs_0.6.3            
##  [13] memoise_2.0.1           RCurl_1.98-1.12         ggtree_3.8.2           
##  [16] blogdown_1.18           htmltools_0.5.6         gridGraphics_0.5-1     
##  [19] sass_0.4.7              bslib_0.5.1             plyr_1.8.9             
##  [22] impute_1.74.1           cachem_1.0.8            commonmark_1.9.0       
##  [25] igraph_1.5.1            lifecycle_1.0.3         iterators_1.0.14       
##  [28] pkgconfig_2.0.3         gson_0.1.0              Matrix_1.6-1.1         
##  [31] R6_2.5.1                fastmap_1.1.1           GenomeInfoDbData_1.2.10
##  [34] MatrixGenerics_1.12.3   clue_0.3-65             digest_0.6.33          
##  [37] aplot_0.2.1             enrichplot_1.20.3       colorspace_2.1-0       
##  [40] patchwork_1.1.3         irlba_2.3.5.1           RSQLite_2.3.1          
##  [43] fansi_1.0.4             httr_1.4.7              polyclip_1.10-6        
##  [46] compiler_4.3.1          microbenchmark_1.4.10   rngtools_1.5.2         
##  [49] bit64_4.0.5             withr_2.5.1             doParallel_1.0.17      
##  [52] downloader_0.4          brew_1.0-8              BiocParallel_1.34.2    
##  [55] viridis_0.6.4           DBI_1.1.3               ggforce_0.4.1          
##  [58] MASS_7.3-60             proxyC_0.3.3            rjson_0.2.21           
##  [61] HDO.db_0.99.1           tools_4.3.1             scatterpie_0.2.1       
##  [64] ape_5.7-1               skmeans_0.2-16          glue_1.6.2             
##  [67] nlme_3.1-163            GOSemSim_2.26.1         gridtext_0.1.5         
##  [70] shadowtext_0.1.2        cluster_2.1.4           reshape2_1.4.4         
##  [73] fgsea_1.26.0            generics_0.1.3          gtable_0.3.4           
##  [76] tidyr_1.3.0             data.table_1.14.8       tidygraph_1.2.3        
##  [79] xml2_1.3.5              utf8_1.2.3              XVector_0.40.0         
##  [82] ggrepel_0.9.3           foreach_1.5.2           pillar_1.9.0           
##  [85] markdown_1.9            stringr_1.5.0           yulab.utils_0.1.0      
##  [88] genefilter_1.82.1       circlize_0.4.15         splines_4.3.1          
##  [91] dplyr_1.1.3             tweenr_2.0.2            treeio_1.24.3          
##  [94] lattice_0.21-9          survival_3.5-7          bit_4.0.5              
##  [97] annotate_1.78.0         tidyselect_1.2.0        GO.db_3.17.0           
## [100] ComplexHeatmap_2.16.0   tm_0.7-11               Biostrings_2.68.1      
## [103] gridExtra_2.3           NLP_0.2-1               bookdown_0.35          
## [106] xfun_0.40               graphlayouts_1.0.1      matrixStats_1.0.0      
## [109] stringi_1.7.12          lazyeval_0.2.2          ggfun_0.1.3            
## [112] yaml_2.3.7              evaluate_0.22           codetools_0.2-19       
## [115] ggraph_2.1.0            tibble_3.2.1            qvalue_2.32.0          
## [118] ggplotify_0.1.2         cli_3.6.1               RcppParallel_5.1.7     
## [121] xtable_1.8-4            munsell_0.5.0           jquerylib_0.1.4        
## [124] Rcpp_1.0.11             GenomeInfoDb_1.36.3     png_0.1-8              
## [127] XML_3.99-0.14           parallel_4.3.1          ggplot2_3.4.3          
## [130] blob_1.2.4              clusterProfiler_4.8.3   mclust_6.0.0           
## [133] doRNG_1.8.6             DOSE_3.26.1             bitops_1.0-7           
## [136] tidytree_0.4.5          viridisLite_0.4.2       slam_0.1-50            
## [139] scales_1.2.1            purrr_1.0.2             crayon_1.5.2           
## [142] GetoptLong_1.0.5        rlang_1.1.1             cowplot_1.1.1          
## [145] fastmatch_1.1-4         KEGGREST_1.40.1