Introduction to ontologySimilarity

ontologySimilarity is part of the 'ontologyX' family of packages (see the 'Introduction to ontologyX' vignette supplied with the ontologyIndex package). It contains various functions for calculating semantic similarity between ontological objects. The functions operate on various kinds of object. It's useful to look out for particular parameter names, as each kind of object tends to be called the same thing by the functions. To make full use of the features in ontologySimilarity, the user is encouraged to gain familiarity of the functions in ontologyIndex.

Various kinds of similarity can be calculated, including:

Some key functions are:

Example

To use the package, first load ontologyIndex and an ontology_index object. Here we demonstrate using the Human Phenotype Ontology, hpo.

library(ontologyIndex)
library(ontologySimilarity)
data(hpo)
set.seed(1)

Next, we'll set the information content for the terms. This is typically based on some kind of 'population frequency', for example: the frequency with which the term is used, explicitly or implicity, to annotate objects in a database. Such frequency information is not always available, but it could still be useful to define the information content with respect to the frequency with which the term is an ancestor of other terms in the ontology (as this still captures the structure of the ontology).

information_content <- descendants_IC(hpo)

Now we'll generate some random sets of terms. We'll sample 5 random term sets (which could for example represent the phenotypes of patients) of 8 terms. Note that here, we call the minimal_set function from the ontologyIndex package on each sample set to remove redundant terms. Typically, ontological annotations would be stored as such minimal sets, however if you are unsure, it is best to call minimal_set on each term set to guarantee the similarity expressions are faithfully evaluated (the package chooses not to map to minimal sets by default for speed).

term_sets <- replicate(simplify=FALSE, n=5, expr=minimal_set(hpo, sample(hpo$id, size=8)))
term_sets

Then one can calculate a similarity matrix, containing pairwise term-set similarities:

sim_mat <- get_sim_grid(ontology=hpo, term_sets=term_sets)
sim_mat

Group similarity of phenotypes 1-3, based on sim_mat:

get_sim(sim_mat, group=1:3)

p-value for significance of similarity of phenotypes 1-3:

get_sim_p(sim_mat, group=1:3)


Try the ontologySimilarity package in your browser

Any scripts or data that you put into this service are public.

ontologySimilarity documentation built on May 29, 2024, 3:51 a.m.