Computes the transitive closure of a graph, treating the specified predicate as transitive. Resulting edge predicates will the be the same, but have primary_knowledge_source set to transitive_.

transitive_closure(g, predicate = "biolink:subclass_of")

Arguments

g

The tbl_kgx graph to compute on.

predicate

The edge predicate to close over.

Value

Graph with transitive edges added.

Examples

library(dplyr)
library(tidygraph)
data(eds_marfan_kg)

eds_marfan_kg |>
    fetch_nodes(name == "Tall stature") |>
    # get 2 levels of ancestors
    expand_n(predicates = "biolink:subclass_of", direction = "out", n = 3) |>
    activate(edges) |>
    filter(primary_knowledge_source == "infores:upheno") |>
    transitive_closure(predicate = "biolink:subclass_of") |>
    plot(edge_color = primary_knowledge_source)
#> Initial graph size:1nodes ||0edges
#> Expanding graph: iteration 1/3
#> Graph size:3nodes ||2edges
#> Expanding graph: iteration 2/3
#> Graph size:7nodes ||7edges
#> Expanding graph: iteration 3/3
#> Graph size:13nodes ||15edges
#> Using "sugiyama" as default layout