# 1 Citation

If you use GOSemSim in published research, please cite G. Yu (2010). In addition, please cite G. Yu (2012) when using clusterProfiler for GO enrichment analysis and G. Yu (2015) when using DOSE for Disease Ontology analysis.

G Yu, F Li, Y Qin, X Bo, Y Wu, S Wang.
GOSemSim: an R package for measuring semantic similarity among GO terms and gene products.
Bioinformatics 2010, 26(7):976-978.
G Yu, LG Wang, Y Han, QY He.
clusterProfiler: an R package for comparing biological themes among gene clusters.
OMICS: A Journal of Integrative Biology 2012, 16(5):284-287.
G Yu, LG Wang, GR Yan, QY He.
DOSE: an R/Bioconductor package for Disease Ontology Semantic and Enrichment analysis.
Bioinformatics 2015, 31(4):608-609.

# 2 Introduction

Functional similarity of gene products can be estimated by controlled biological vocabularies, such as Gene Ontology (GO). GO comprises of three orthogonal ontologies, i.e. molecular function (MF), biological process (BP), and cellular component (CC).

Four methods have been presented to determine the semantic similarity of two GO terms based on the annotation statistics of their common ancestor terms Resnik1, Jiang2, Lin3 and Schlicker4. Wang5 proposed a method to measure the similarity based on the graph structure of GO. Each of these methods has its own advantages and weaknesses. GOSemSim package6 is developed to compute semantic similarity among GO terms, sets of GO terms, gene products, and gene clusters, providing both five methods mentioned above. We have developed another package, DOSE7, for measuring semantic similarity among Disease Ontology (DO) terms and gene products at disease perspective.

To start with GOSemSim package, type following code below:

library(GOSemSim)
help(GOSemSim)

# 3 Semantic Similarity Measurement Based on GO

## 3.1 Information content-based methods

Four methods proposed by Resnik1, Jiang2, Lin3 and Schlicker4 are information content (IC) based, which depend on the frequencies of two GO terms involved and that of their closest common ancestor term in a specific corpus of GO annotations. The information content of a GO term is computed by the negative log probability of the term occurring in GO corpus. A rarely used term contains a greater amount of information.

The frequency of a term t is defined as: $$p(t) = \frac{n_{t'}}{N} | t' \in \left\{t, \; children\: of\: t \right\}$$

where $$n_{t'}$$ is the number of term t’, and N is the total number of terms in GO corpus.

Thus the information content is defined as: $$IC(t) = -\log(p(t))$$

As GO allow multiple parents for each concept, two terms can share parents by multiple paths. IC-based methods calculate similarity of two GO terms based on the information content of their closest common ancestor term, which was also called most informative information ancestor (MICA).

### 3.1.1 Resnik method

The Resnik method is defined as: $$sim_{Resnik}(t_1,t_2) = IC(MICA)$$

### 3.1.2 Lin method

The Lin method is defined as: $$sim_{Lin}(t_1,t_2) = \frac{2IC(MICA)}{IC(t_1)+IC(t_2)}$$

### 3.1.3 Rel method

The Relevance method, which was proposed by Schlicker, combine Resnik’s and Lin’s method and is defined as: $$sim_{Rel}(t_1,t_2) = \frac{2IC(MICA)(1-p(MICA))}{IC(t_1)+IC(t_2)}$$

### 3.1.4 Jiang method

The Jiang and Conrath’s method is defined as: $$sim_{Jiang}(t_1,t_2) = 1-\min(1, IC(t_1) + IC(t_2) - 2IC(MICA))$$

At present, GOSemSim supports about 20 species internally. We used the following Bioconductor packages to calculate the information content.

The information content will update regularly.

## 3.2 Graph-based method

Graph-based methods using the topology of GO graph structure to compute semantic similarity. Formally, a GO term A can be represented as $$DAG_{A}=(A,T_{A},E_{A})$$ where $$T_{A}$$ is the set of GO terms in $$DAG_{A}$$, including term A and all of its ancestor terms in the GO graph, and $$E_{A}$$ is the set of edges connecting the GO terms in $$DAG_{A}$$.

### 3.2.1 Wang method

To encode the semantic of a GO term in a measurable format to enable a quantitative comparison, Wang5 firstly defined the semantic value of term A as the aggregate contribution of all terms in $$DAG_{A}$$ to the semantics of term A, terms closer to term A in $$DAG_{A}$$ contribute more to its semantics. Thus, defined the contribution of a GO term t to the semantic of GO term A as the S-value of GO term t related to term A. For any of term t in $$DAG_{A}$$, its S-value related to term A, $$S_{A}(\textit{t})$$ is defined as: $$\left\{\begin{array}{l} S_{A}(A)=1 \\ S_{A}(\textit{t})=\max\{w_{e} \times S_{A}(\textit{t}') | \textit{t}' \in children \: of(\textit{t}) \} \; if \: \textit{t} \ne A \end{array} \right.$$

where $$w_{e}$$ is the semantic contribution factor for edge $$e \in E_{A}$$ linking term t with its child term t’. Term A contributes to its own is defined as one. After obtaining the S-values for all terms in $$DAG_{A}$$, the semantic value of DO term A, SV(A), is calculated as:

$$SV(A)=\displaystyle\sum_{t \in T_{A}} S_{A}(t)$$

Thus given two GO terms A and B, the semantic similarity between these two terms is defined as:

$$sim_{Wang}(A, B) = \frac{\displaystyle\sum_{t \in T_{A} \cap T_{B}}{S_{A}(t) + S_{B}(t)}}{SV(A) + SV(B)}$$

where $$S_{A}(\textit{t})$$ is the S-value of GO term t related to term A and $$S_{B}(\textit{t})$$ is the S-value of GO term t related to term B.

This method proposed by Wang5 determines the semantic similarity of two GO terms based on both the locations of these terms in the GO graph and their relations with their ancestor terms.

## 3.3 goSim and mgoSim function

In GOSemSim, we implemented all these IC-based and graph-based methods. goSim function calculates semantic similarity between two GO terms, while mgoSim function calculates semantic similarity between two sets of GO terms.

goSim("GO:0004022", "GO:0005515", ont="MF", measure="Wang")
## [1] 0.158
go1 = c("GO:0004022","GO:0004024","GO:0004174")
go2 = c("GO:0009055","GO:0005515")
mgoSim(go1, go2, ont="MF", measure="Wang", combine=NULL)
##            GO:0009055 GO:0005515
## GO:0004022      0.205      0.158
## GO:0004024      0.185      0.141
## GO:0004174      0.205      0.158
mgoSim(go1, go2, ont="MF", measure="Wang", combine="BMA")
## [1] 0.192

# 4 Gene Semantic Similarity Measurement

On the basis of semantic similarity between GO terms, GOSemSim can also compute semantic similarity among sets of GO terms, gene products, and gene clusters.

Suppose we have gene $$g_1$$ annotated by GO terms sets $$GO_{1}=\{go_{11},go_{12} \cdots go_{1m}\}$$ and $$g_2$$ annotated by $$GO_{2}=\{go_{21},go_{22} \cdots go_{2n}\}$$, GOSemSim implemented four methods which called max, avg, rcmax, and BMA to combine semantic similarity scores of multiple GO terms. The similarities among gene products and gene clusters which annotated by multiple GO terms were also calculated by the same combine methods mentioned above.

## 4.1 Combine methods

### 4.1.1 max

The max method calculates the maximum semantic similarity score over all pairs of GO terms between these two GO term sets. $$sim_{max}(g\_1, g\_2) = \displaystyle\max_{1 \le i \le m, 1 \le j \le n} sim(go_{1i}, go_{2j})$$

### 4.1.2 avg

The avg calculates the average semantic similarity score over all pairs of GO terms. $$sim_{avg}(g_1, g_2) = \frac{\displaystyle\sum_{i=1}^m\sum_{j=1}^nsim(go_{1i}, go_{2j})}{m \times n}$$

### 4.1.3 rcmax

Similarities among two sets of GO terms form a matrix, the rcmax method uses the maximum of RowScore and ColumnScore as the similarity, where RowScore (or ColumnScore) is the average of maximum similarity on each row (or column). $$sim_{rcmax}(g_1, g_2) = \max(\frac{\displaystyle\sum_{i=1}^m \max_{1 \le j \le n} sim(go_{1i}, go_{2j})}{m},\frac{\displaystyle\sum_{j=1}^n \max_{1 \le i \le m} sim(go_{1i},go_{2j})}{n})$$

### 4.1.4 BMA

The BMA method, used the best-match average strategy, calculates the average of all maximum similarities on each row and column, and is defined as: $$sim_{BMA}(g_1, g_2) = \frac{\displaystyle\sum_{1=i}^m \max_{1 \le j \le n}sim(go_{1i}, go_{2j}) + \displaystyle\sum_{1=j}^n \max_{1 \le i \le m}sim(go_{1i}, go_{2j})} {m+n}$$

## 4.2 geneSim and mgeneSim

In GOSemSim, we implemented geneSim to calculate semantic similarity between two gene products, and mgeneSim to calculate semantic similarity among multiple gene products.

geneSim("241", "251", ont="MF", organism="human", measure="Wang", combine="BMA")
## $geneSim ## [1] 0.141 ## ##$GO1
## [1] "GO:0005515" "GO:0047485" "GO:0050544"
##
## \$GO2
## [1] "GO:0004035"
mgeneSim(genes=c("835", "5261","241", "994"),
ont="MF", organism="human", measure="Wang",verbose=FALSE)
##        835  5261   241   994
## 835  1.000 0.116 0.612 0.615
## 5261 0.116 1.000 0.108 0.115
## 241  0.612 0.108 1.000 0.626
## 994  0.615 0.115 0.626 1.000

## 4.3 clusterSim and mclusterSim

We also implemented clusterSim for calculating semantic similarity between two gene clusters and mclusterSim for calculating semantic similarities among multiple gene clusters.

gs1 <- c("835", "5261","241", "994", "514", "533")
gs2 <- c("578","582", "400", "409", "411")
clusterSim(gs1, gs2, ont="MF", organism="human", measure="Wang", combine="BMA")
## [1] 0.588
x <- org.Hs.egGO
hsEG <- mappedkeys(x)
set.seed <- 123
clusters <- list(a=sample(hsEG, 20), b=sample(hsEG, 20), c=sample(hsEG, 20))
mclusterSim(clusters, ont="MF", organism="human", measure="Wang", combine="BMA")
##       a     b     c
## a 1.000 0.638 0.625
## b 0.638 1.000 0.611
## c 0.625 0.611 1.000

# 5 Case Study

We proposed a method for measuring functional similarity of microRNAs8. This method was based on semantic similarity of microRNAs’ target genes, and was calculated by GOSemSim. We further analyzed viral microRNAs using this method and compared significant KEGG pathways regulated by different viruses’ microRNAs9 using clusterProfiler10.

# 6 GO enrichment analysis

GO enrichment analysis can be supported by our package clusterProfiler10, which supports hypergeometric test and Gene Set Enrichment Analysis (GSEA). Enrichment results across different gene clusters can be compared using compareCluster function.

# 7 Disease Ontology Semantic and Enrichment analysis

Disease Ontology (DO) annotates human genes in the context of disease. DO is important annotation in translating molecular findings from high-throughput data to clinical relevance. DOSE7 supports semantic similarity computation among DO terms and genes. Enrichment analysis including hypergeometric model and GSEA are also implemented to support discovering disease associations of high-throughput biological data.

# 9 Bugs/Feature Requests

If you have any, let me know.

# 10 Session Information

Here is the output of sessionInfo() on the system on which this document was compiled:

## R version 3.2.3 (2015-12-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 14.04.3 LTS
##
## 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] GOSemSim_1.28.2      GO.db_3.2.2          org.Hs.eg.db_3.2.3
##  [4] RSQLite_1.0.0        DBI_0.3.1            AnnotationDbi_1.32.2
##  [7] IRanges_2.4.6        S4Vectors_0.8.5      Biobase_2.30.0
## [10] BiocGenerics_0.16.1  BiocStyle_1.8.0
##
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.2     digest_0.6.8    formatR_1.2.1   magrittr_1.5
##  [5] evaluate_0.8    stringi_1.0-1   rmarkdown_0.8.1 tools_3.2.3
##  [9] stringr_1.0.0   yaml_2.1.13     htmltools_0.2.6 knitr_1.11

# References

1.Philip, R. Semantic similarity in a taxonomy: An Information-Based measure and its application to problems of ambiguity in natural language. Journal of Artificial Intelligence Research 11, 95–130 (1999).

2.Jiang, J. J. & Conrath, D. W. Semantic similarity based on corpus statistics and lexical taxonomy. Proceedings of 10th International Conference on Research In Computational Linguistics (1997). at <http://www.citebase.org/abstract?id=oai:arXiv.org:cmp-lg/9709008>

3.Lin, D. An Information-Theoretic definition of similarity. In Proceedings of the 15th International Conference on Machine Learning 296—304 (1998). doi:10.1.1.55.1832

4.Schlicker, A., Domingues, F. S., Rahnenführer, J. & Lengauer, T. A new measure for functional similarity of gene products based on gene ontology. BMC Bioinformatics 7, 302 (2006).

5.Wang, J. Z., Du, Z., Payattakool, R., Yu, P. S. & Chen, C.-F. A new method to measure the semantic similarity of gO terms. Bioinformatics (Oxford, England) 23, 1274–81 (2007).

6.Yu, G. et al. GOSemSim: An r package for measuring semantic similarity among gO terms and gene products. Bioinformatics 26, 976–978 (2010).

7.Yu, G., Wang, L.-G., Yan, G.-R. & He, Q.-Y. DOSE: An r/Bioconductor package for disease ontology semantic and enrichment analysis. Bioinformatics 31, 608–609 (2015).

8.Yu, G. et al. A new method for measuring functional similarity of microRNAs. Journal of Integrated OMICS 1, 49–54 (2011).

9.Yu, G. & He, Q. Functional similarity analysis of human virus-encoded miRNAs. Journal of Clinical Bioinformatics 1, 15 (2011).

10.Yu, G., Wang, L.-G., Han, Y. & He, Q.-Y. clusterProfiler: an r package for comparing biological themes among gene clusters. OMICS: A Journal of Integrative Biology 16, 284–287 (2012).