Computes the transitive reduction of a graph, treating the specified predicate as transitive.

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

Value

Graph with transitive edges added.

Examples

engine <- file_engine(system.file("extdata", "eds_marfan_kg.tar.gz", package = "monarchr"))

g <- engine |> fetch_nodes(name == "Tall stature") |>
  expand_n(predicates = "biolink:subclass_of", direction = "out", n = 3) |>
  bind_edges(data.frame(from = 2, to = 9, predicate = "biolink_subclass_of", primary_knowledge_source = "hand_annotated"))
#> Initial graph size: 1 nodes || 0 edges
#> Expanding graph: iteration 1/3
#> Graph size: 3 nodes || 2 edges
#> Expanding graph: iteration 2/3
#> Graph size: 7 nodes || 7 edges
#> Expanding graph: iteration 3/3
#> Graph size: 13 nodes || 15 edges

plot(g, edge_color = primary_knowledge_source)
#> Using "sugiyama" as default layout


g_closed <- g |>
  transitive_closure(predicate = "biolink:subclass_of")

plot(g_closed, edge_color = primary_knowledge_source)
#> Using "sugiyama" as default layout


g_reduced <- g_closed |>
  transitive_reduction()

plot(g_reduced, edge_color = primary_knowledge_source)
#> Using "sugiyama" as default layout