Distance from all ancestors/to all offspring in the DAG

dag_longest_dist_to_offspring(dag, from, terms = NULL, background = NULL)

dag_shortest_dist_to_offspring(dag, from, terms = NULL, background = NULL)

dag_longest_dist_from_ancestors(dag, to, terms = NULL, background = NULL)

dag_shortest_dist_from_ancestors(dag, to, terms = NULL, background = NULL)

Arguments

dag

An ontology_DAG object.

from

A single term name or a vector of term names.

terms

A vector of term names. If it is set, the returned vector will be subsetted to the terms that have been set here.

background

A vector of terms. Then the lookup will only be applied in this set of terms.

to

Same format as the from argument.

Value

An integer vector having length the same as the number of terms in the DAG. If terms are not reachable to the from or to terms, the corresponding value is -1.

Details

If from or to is a vector, for a specific, the longest/shortest distance among all from/to terms is taken.

As a special case, when from is the root term, dag_longest_dist_to_offspring() is the same as dag_depth(), and when to are all leaf terms, dag_longest_dist_to_offspring() is the same as dag_height().

Examples

parents  = c("a", "a", "b", "b", "c", "d")
children = c("b", "c", "c", "d", "e", "f")
dag = create_ontology_DAG(parents, children)
dag_longest_dist_from_ancestors(dag, "e")
#>  a  b  c  d  e  f 
#>  3  2  1 -1  0 -1 
dag_shortest_dist_from_ancestors(dag, "e")
#>  a  b  c  d  e  f 
#>  2  2  1 -1  0 -1 
dag_longest_dist_to_offspring(dag, "b")
#>  a  b  c  d  e  f 
#> -1  0  1  1  2  2