Distance on the DAG

shortest_distances_via_NCA(dag, terms, verbose = simona_opt$verbose)

longest_distances_via_LCA(dag, terms, verbose = simona_opt$verbose)

shortest_distances_directed(dag, terms, verbose = simona_opt$verbose)

longest_distances_directed(dag, terms, verbose = simona_opt$verbose)

Arguments

dag

An ontology_DAG object.

terms

A vector of term names.

verbose

Whether to print messages.

Value

A numeric distance matrix.

Details

Denote two terms as a and b, a common ancestor as c, and the distance function d() calculates the longest distance or the shortest distance depending on the function.

  • shortest_distances_via_NCA(): It calculates the smallest d(c, a) + d(c, b) where d() calculates the shortest distance between two terms. In this case, c is the NCA (nearest common ancestor) of a and b.

  • longest_distances_via_LCA(): It calculates the largest d(c, a) + d(c, b) where d() calculates the longest distance between two terms via the LCA (lowest common ancestor) term. In this case, c is the LCA of a and b.

  • shortest_distances_directed(): It calculates d(a, b) where d() calculates the shortest distance between two terms. The distance is only calculated when a is an ancestor of b, otherwise the distance value is -1.

  • longest_distances_directed(): It calculates d(a, b) where d() calculates the longest distance between two terms. The distance is only calculated when a is an ancestor of b, otherwise the distance value is -1.

Examples

parents  = c("a", "a", "b", "b", "c", "d")
children = c("b", "c", "c", "d", "e", "f")
dag = create_ontology_DAG(parents, children)
shortest_distances_via_NCA(dag, letters[1:6])
#> collecting all ancestors of input terms ...
#> 
#> going through 0 / 6 ancestors ...
#> 
#> going through 6 / 6 ancestors ... Done.
#>   a b c d e f
#> a 0 1 1 2 2 3
#> b 1 0 1 1 2 2
#> c 1 1 0 2 1 3
#> d 2 1 2 0 3 1
#> e 2 2 1 3 0 4
#> f 3 2 3 1 4 0
longest_distances_via_LCA(dag, letters[1:6])
#> collecting all ancestors of input terms ...
#> 
#> going through 0 / 6 ancestors ...
#> 
#> going through 6 / 6 ancestors ... Done.
#>   a b c d e f
#> a 0 1 2 2 3 3
#> b 1 0 1 1 2 2
#> c 2 1 0 2 1 3
#> d 2 1 2 0 3 1
#> e 3 2 1 3 0 4
#> f 3 2 3 1 4 0
shortest_distances_directed(dag, letters[1:6])
#> collecting all ancestors of input terms ...
#> 
#> going through 0 / 6 nodes ...
#> 
#> going through 6 / 6 nodes ... Done.
#>    a  b  c  d  e  f
#> a  0  1  1  2  2  3
#> b -1  0  1  1  2  2
#> c -1 -1  0 -1  1 -1
#> d -1 -1 -1  0 -1  1
#> e -1 -1 -1 -1  0 -1
#> f -1 -1 -1 -1 -1  0
longest_distances_directed(dag, letters[1:6])
#> collecting all ancestors of input terms ...
#> 
#> going through 0 / 6 nodes ...
#> 
#> going through 6 / 6 nodes ... Done.
#>    a  b  c  d  e  f
#> a  0  1  2  2  3  3
#> b -1  0  1  1  2  2
#> c -1 -1  0 -1  1 -1
#> d -1 -1 -1  0 -1  1
#> e -1 -1 -1 -1  0 -1
#> f -1 -1 -1 -1 -1  0