Compute edge weights for the given tbl_kgx graph using several pieces of categorical, ordinal, and continuous metadata.

kg_edge_weights(
  graph,
  normalise = TRUE,
  encodings = monarch_edge_weight_encodings(),
  fun = function(x) {
     rowSums(x, na.rm = TRUE)
 }
)

Arguments

graph

A graph object

normalise

Normalise each encoding from 0-1 by dividing by the maximum value. Default is TRUE.

encodings

A list of named lists of encoding values for different edge attributes.

fun

Function to compute edge weights with across the numerically encoded attributes. Default is rowSums.

Value

The input graph with a new weight column on edges.

Examples

data(eds_marfan_kg)
g <- eds_marfan_kg |>
    fetch_nodes(query_ids = "MONDO:0007525") |>
    expand(
        predicates = "biolink:has_phenotype",
        categories = "biolink:PhenotypicFeature"
    ) |>
    expand(categories = "biolink:Gene")
g2 <- kg_edge_weights(g)
edges(g2)$weight
#>  [1] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
#> [39] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2