Given an initialized tbl_kgx graph, iteratively expand the graph n iterations using certain predicates/categories. Arguments can either be a single value or a list of values. If an argument is provided as a list, its length must be equal to the number of iterations (n).

expand_n(
  graph,
  return_each = FALSE,
  direction = "both",
  predicates = NULL,
  categories = NULL,
  transitive = NULL,
  drop_unused_query_nodes = FALSE,
  n = 1,
  ...
)

Arguments

graph

A query tbl_kgx() graph ot query with.

return_each

If TRUE, return a list of graphs for each iteration. If FALSE, return the final graph with all expanded edges.

direction

The direction of associations to fetch. Can be "in", "out", or "both". Default is "both".

predicates

A vector of relationship predicates (nodes in g are subjects in the KG), indicating which edges to consider in the neighborhood. If NULL (default), all edges are considered.

categories

A vector of node categories, indicating which nodes in the larger KG may be fetched. If NULL (default), all nodes in the larger KG are will be fetched.

transitive

NULL (not used in this function).

drop_unused_query_nodes

If TRUE, remove query nodes from the result, unless they are at the neighborhood boundary, i.e., required for connecting to the result nodes. Default is FALSE.

n

Number of expansion iterations to run.

...

Other parameters passed to methods.

Value

A tbl_kgx() graph

Examples

## Using example KGX file packaged with monarchr
filename <- system.file("extdata", "eds_marfan_kg.tar.gz", package = "monarchr")
g <- file_engine(filename) |>
          fetch_nodes(query_ids = "MONDO:0007525") |>
          expand(predicates = "biolink:has_phenotype",
                 categories = "biolink:PhenotypicFeature")
g_expanded <- g |>
              expand_n(predicates = "biolink:subclass_of", n=3)
#> Initial graph size: 49 nodes || 48 edges
#> Expanding graph: iteration 1/3
#> Graph size: 153 nodes || 120 edges
#> Expanding graph: iteration 2/3
#> Graph size: 415 nodes || 441 edges
#> Expanding graph: iteration 3/3
#> Graph size: 936 nodes || 1201 edges