Reduce the DAG to a tree
dag_treelize(dag, verbose = simona_opt$verbose)
dag_as_dendrogram(dag)
# S3 method for ontology_tree
print(x, ...)
An ontology_DAG
object.
Whether to print messages.
An ontology_DAG
object.
Ignored.
A tree is also an ontology_DAG
object.
A tree is a reduced DAG where a child only has one parent. The reducing is applied by a breadth-first searching
Starting from the root and on a certain depth (the depth is the maximal distance to root), for every term t
on this depth,
its child term c
and parent-child relation are kept only when depth(c) == depth(t) + 1
. If c
is selected, it is
marked as visited and will not be checked again.
In this way, depths of all terms in the orignal DAG are still identical to the depths in the tree (see the Examples section).
dag_as_dendrogram()
coverts the tree to a dendrogram
object.
parents = c("a", "a", "b", "b", "c", "d")
children = c("b", "c", "c", "d", "e", "f")
dag = create_ontology_DAG(parents, children)
tree = dag_treelize(dag)
#>
#> going through 6 / 6 nodes ... Done.
d1 = dag_depth(dag)
d2 = dag_depth(tree)
identical(d1, d2)
#> [1] TRUE
dend = dag_as_dendrogram(tree)
dend
#> This is a normal `dendrogram` object, but with several more attributes attached to each node:
#> - label: term name
#> - term_id: the integer index of the term
#> - n_nodes: number of offspring terms, including itself
#> - members: this is the standard attribute, which is the number of leaves the term can reach to
#> - max_dist_to_leaf: max distance to the term's leaves
#>
#> 'dendrogram' with 1 branches and 2 members total, at height 3