First computes semantic similarity between all pairs of nodes in a graph. Then adds the continuous similarity score as an edge attribute.
graph_semsim(
graph,
fun = igraph::similarity,
col = "similarity",
nm = "id",
sparse = TRUE,
return_matrix = FALSE,
...
)
A graph object
The similarity function to use. Default is similarity.
Name of the new edge attribute to store the similarity score.
The node attribute to use as the matrix row/colnames.
Return a sparse matrix instead of a dense matrix.
Return the similarity matrix instead of the graph.
Additional arguments passed to the similarity function
(fun
).
Graph object with similarity added as a new edge attribute.
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")|>
expand(categories = "biolink:Gene")
g <- graph_semsim(g)
#> Computing pairwise node similarity.
#> Loading required namespace: Matrix
edges(g)$similarity
#> [1] 0.00000000 0.00000000 0.01960784 0.00000000 0.01960784 0.00000000
#> [7] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#> [13] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#> [19] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.01960784
#> [25] 0.01960784 0.00000000 0.00000000 0.00000000 0.01960784 0.01960784
#> [31] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#> [37] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#> [43] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#> [49] 0.33333333 0.33333333 0.33333333 0.00000000 0.00000000 0.00000000