vignettes/v10_enrichment.Rmd
v10_enrichment.Rmd
In many applications, semantic similarity analysis is integerated with gene set enrichment analysis, especially taking GO as the source of gene sets. simona provides functions that import ontologies already integrated with gene annotations. simona also provides functions for over-representation analysis (ORA) and functions to integrate the ORA results with semantic similarity analysis.
To add gene annotations for GO, just set the name of the “org.db” package for the specific organism. For example “org.Hs.eg.db” for human and “org.Mm.eg.db” for mouse. The full list of supported “org.db” packages can be found at https://bioconductor.org/packages/release/BiocViews.html#___AnnotationData (search "org."
).
library(simona)
dag = create_ontology_DAG_from_GO_db(org_db = "org.Hs.eg.db")
dag
## An ontology_DAG object:
## Source: GO BP / GO.db package 3.19.1
## 27186 terms / 54178 relations
## Root: GO:0008150
## Terms: GO:0000001, GO:0000002, GO:0000003, GO:0000011, ...
## Max depth: 18
## Avg number of parents: 1.99
## Avg number of children: 1.87
## Aspect ratio: 356.46:1 (based on the longest distance from root)
## 756.89:1 (based on the shortest distance from root)
## Relations: is_a, part_of
## Annotations: 18888 items
## 291, 1890, 4205, 4358, ...
##
## With the following columns in the metadata data frame:
## id, name, definition
As the object dag
prints, the genes stored in dag
are in the EntreZ ID type. So when doing ORA, the input gene list should also be in the EntreZ ID type.
We generate a list of random genes for testing:
set.seed(888)
genes = random_items(dag, 500)
head(genes)
## [1] "79649" "696" "406935" "406970" "7874" "693177"
To perform ORA, use the function dag_enrich_on_genes()
.
tb = dag_enrich_on_genes(dag, genes)
tb = tb[order(tb$p_adjust), ]
head(tb)
## term name n_hits n_gs n_genes
## GO:0006835 GO:0006835 dicarboxylic acid transport 7 75 500
## GO:0007338 GO:0007338 single fertilization 11 155 500
## GO:0008210 GO:0008210 estrogen metabolic process 5 40 500
## GO:0016567 GO:0016567 protein ubiquitination 30 621 500
## GO:0031424 GO:0031424 keratinization 7 82 500
## GO:0031644 GO:0031644 regulation of nervous system process 9 119 500
## n_all log2_fold_enrichment z_score p_value p_adjust depth
## GO:0006835 18888 1.8179343 3.614040 0.003674390 0.60463 7
## GO:0007338 18888 1.4227053 3.464954 0.002833152 0.60463 4
## GO:0008210 18888 2.2393980 3.885733 0.003904392 0.60463 5
## GO:0016567 18888 0.8678392 3.446888 0.001191318 0.60463 9
## GO:0031424 18888 1.6892010 3.329240 0.006013499 0.60463 8
## GO:0031644 18888 1.5145053 3.350935 0.004394336 0.60463 5
We can take the significant GO terms and look at their semantic similarities.
top_go_ids = tb$term[1:200]
mat = term_sim(dag, top_go_ids)
library(ComplexHeatmap)
Heatmap(mat, name = "similarity",
show_row_names = FALSE, show_column_names = FALSE,
show_row_dend = FALSE, show_column_dend = FALSE)
And the significant GO terms on the global circular plot:
dag_circular_viz(dag, top_go_ids)
One of the use of the semantic similarity matrix is to cluster GO terms in groups, to simplify the read of the results. Here the semantic similarity matrix can be directly sent to simplifyEnrichment()
function from the simplifyEnrichment package. Since the terms are from GO, there will be word cloud associated with the heatmap to show their generl biological functions in each cluster.
In the previous example, when setting the organism, we use the name of the org.db
package. The value can also directly be an OrgDb
object. This expands the use of the function since there are many OrgDb
objects for less-studied organims available on AnnotationHub.
The following code demonstrates the use of the delphin organism (Delphinus truncatus). AH112417
is the ID of this dataset. Please refer to AnnotationHub for the usage of the package.
library(AnnotationHub)
ah = AnnotationHub()
org_db = ah[["AH112417"]]
dag = create_ontology_DAG_from_GO_db(org_db = org_db)
Besides GO, there are also other ontologies that have gene annotations integrated.
UniProt Keywords (https://www.uniprot.org/keywords) is a set of controlled vocabulary developed in UniProt to describe the biological functions of proteins. It is organised in a hierarchical way, thus in a form of the ontology. The function ontology_kw()
can import the UniProt Keywords ontology with gene annotations from a specific organims.
The function internally uses the UniProtKeywords package. All supported organisms can be found in the documentation of UniProtKeywords::load_keyword_genesets()
.
dag = ontology_kw("human")
dag
## An ontology_DAG object:
## Source: UniProt Keywords
## 1202 terms / 1348 relations
## Root: ~~all~~
## Terms: KW-0001, KW-0002, KW-0003, KW-0004, ...
## Max depth: 6
## Avg number of parents: 1.12
## Avg number of children: 1.07
## Aspect ratio: 112:1 (based on the longest distance from root)
## 120:1 (based on the shortest distance from root)
## Annotations: 18050 items
## 2230, 316, 55847, 493856, ...
##
## With the following columns in the metadata data frame:
## id, accession, name, description, category
As dag
shows, the gene ID type is EntreZ ID. Similar as GO, we randomly generate a list of genes and perform ORA.
genes = random_items(dag, 500)
tb = dag_enrich_on_genes(dag, genes)
tb = tb[order(tb$p_adjust), ]
top_go_ids = tb$term[1:50]
Obtain the semantic similarity matrix and make plots:
mat = term_sim(dag, top_go_ids)
Heatmap(mat, name = "similarity",
show_row_names = FALSE, show_column_names = FALSE,
show_row_dend = FALSE, show_column_dend = FALSE)
dag_circular_viz(dag, top_go_ids)
We also also use simplifyEnrichment()
to cluster terms in mat
, but there is no word cloud around the heatmap.
cl = simplifyEnrichment(mat)
head(cl)
## id cluster
## 1 KW-0242 1
## 2 KW-0341 2
## 3 KW-0769 2
## 4 KW-0013 3
## 5 KW-0043 1
## 6 KW-0130 2
The following ontologies as well as the gene annotations are from the Rat Genome Database (RGD). Although the RGD is a database for mouse, it also provides gene annotations for other oganisms. The specific files used in each function can be found at https://download.rgd.mcw.edu/ontology/.
Note that the following functions may support different sets of organims. Please go to the documentations for the list.
Pathway Ontology
dag = ontology_pw("human")
dag
## An ontology_DAG object:
## Source: pw, 7.85
## 2605 terms / 3195 relations
## Root: ~~all~~
## Terms: PW:0000001, PW:0000002, PW:0000003, PW:0000004, ...
## Max depth: 10
## Avg number of parents: 1.23
## Avg number of children: 1.26
## Aspect ratio: 79.44:1 (based on the longest distance from root)
## 95.38:1 (based on the shortest distance from root)
## Relations: is_a
## Annotations: 5954 items
## CACNA1C, MAP3K3, RASGRP3, MAP3K6, ...
##
## With the following columns in the metadata data frame:
## id, short_id, name, namespace, definition
Note that, in the pathway ontology, genes are saved in gene symbols.
To perform enrichment analysis on the pathway ontology:
# `genes` must be in symbols
tb = dag_enrich_on_genes(dag, genes)
Chemical Entities of Biological Interest
dag = ontology_chebi("human")
To perform enrichment analysis on CheBi:
# `genes` must be in symbols
tb = dag_enrich_on_genes(dag, genes)
Disease Ontology
dag = ontology_rdo("human")
To perform enrichment analysis on the disease ontology:
# `genes` must be in symbols
tb = dag_enrich_on_genes(dag, genes)
Vertebrate Trait Ontology
dag = ontology_vt("human")
To perform enrichment analysis on the vertebrate trait ontology:
# `genes` must be in symbols
tb = dag_enrich_on_genes(dag, genes)
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-apple-darwin20
## Running under: macOS Sonoma 14.5
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## locale:
## [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
##
## time zone: Europe/Berlin
## tzcode source: internal
##
## attached base packages:
## [1] grid stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] simplifyEnrichment_1.14.0 BiocGenerics_0.50.0
## [3] ComplexHeatmap_2.20.0 simona_1.3.12
## [5] knitr_1.48
##
## loaded via a namespace (and not attached):
## [1] blob_1.2.4 R.utils_2.12.3 Biostrings_2.72.1
## [4] fastmap_1.2.0 UniProtKeywords_0.99.7 promises_1.3.0
## [7] digest_0.6.37 mime_0.12 lifecycle_1.0.4
## [10] cluster_2.1.6 Cairo_1.6-2 NLP_0.3-0
## [13] KEGGREST_1.44.1 RSQLite_2.3.7 magrittr_2.0.3
## [16] compiler_4.4.1 rlang_1.1.4 sass_0.4.9
## [19] tools_4.4.1 igraph_2.0.3 yaml_2.3.10
## [22] htmlwidgets_1.6.4 bit_4.0.5 scatterplot3d_0.3-44
## [25] xml2_1.3.6 RColorBrewer_1.1-3 desc_1.4.3
## [28] R.oo_1.26.0 stats4_4.4.1 GOSemSim_2.30.2
## [31] tm_0.7-14 xtable_1.8-4 colorspace_2.1-1
## [34] GO.db_3.19.1 iterators_1.0.14 cli_3.6.3
## [37] rmarkdown_2.28 crayon_1.5.3 ragg_1.3.2
## [40] httr_1.4.7 rjson_0.2.22 DBI_1.2.3
## [43] cachem_1.1.0 zlibbioc_1.50.0 parallel_4.4.1
## [46] AnnotationDbi_1.66.0 XVector_0.44.0 proxyC_0.4.1
## [49] yulab.utils_0.1.7 matrixStats_1.3.0 vctrs_0.6.5
## [52] Matrix_1.7-0 slam_0.1-52 jsonlite_1.8.8
## [55] IRanges_2.38.1 GetoptLong_1.0.5 S4Vectors_0.42.1
## [58] bit64_4.0.5 clue_0.3-65 systemfonts_1.1.0
## [61] foreach_1.5.2 jquerylib_0.1.4 glue_1.7.0
## [64] pkgdown_2.1.0 codetools_0.2-20 Polychrome_1.5.1
## [67] shape_1.4.6.1 later_1.3.2 GenomeInfoDb_1.40.1
## [70] UCSC.utils_1.0.0 rappdirs_0.3.3 htmltools_0.5.8.1
## [73] GenomeInfoDbData_1.2.12 circlize_0.4.16 R6_2.5.1
## [76] httr2_1.0.3 textshaping_0.4.0 doParallel_1.0.17
## [79] lattice_0.22-6 evaluate_0.24.0 shiny_1.9.1
## [82] Biobase_2.64.0 highr_0.11 png_0.1-8
## [85] R.methodsS3_1.8.2 memoise_2.0.1 httpuv_1.6.15
## [88] bslib_0.8.0 Rcpp_1.0.13 org.Hs.eg.db_3.19.1
## [91] xfun_0.47 fs_1.6.4 pkgconfig_2.0.3
## [94] GlobalOptions_0.1.2