This function calls the Monarch-hosted semantic similarity API to compare two graphs, via the same endpoints as the Monarch Phenotype Explorer: https://monarchinitiative.org/explore#phenotype-explorer.
monarch_semsim(
query_graph,
target_graph,
metric = "ancestor_information_content",
include_reverse = FALSE,
keep_unmatched = FALSE
)
A tbl_kgx graph.
A tbl_kgx graph.
The semantic similarity metric to use. Default is "ancestor_information_content"
. Also available are "jaccard_similarity"
and "phenodigm_score"
.
Whether to include the best matches from the target graph to the query graph. Default is FALSE
.
Whether to keep nodes in the target graph that do not have a match. Default is FALSE
.
A tbl_kgx graph with "computed:best_matches"
edges between the nodes of the two input graphs and columns for monarch_semsim_metric
, monarch_semsim_score
, and monarch_semsim_ancestor_id
.
The API returns the best matches between the nodes of the two graphs, based on
a specified knowledge-graph-based metric: the default is "ancestor_information_content"
,
also available are "jaccard_similarity"
and "phenodigm_score"
. The result is
returned as a graph, with "computed:best_matches"
edges between the nodes of the two input graphs.
By default, the function only returns the best matches from the first graph to the second graph, and
removes any nodes that do not have a match. If include_reverse = TRUE
, the function also returns
the best matches from the second graph to the first graph.
The engine attached to the return graph is that of the query.
g1 <- monarch_engine() |>
fetch_nodes(query_ids = "MONDO:0007947") |>
expand(categories = "biolink:PhenotypicFeature")
#> Trying to connect to https://neo4j.monarchinitiative.org
#> Connected to https://neo4j.monarchinitiative.org
#> Fetching; counting matching nodes...
#> total: 1.
#> Fetching; fetched 1 of 1
#> Expanding; counting matching edges...
#> total: 139.
#> Expanding; fetched 139 of 139 edges.
g2 <- monarch_engine() |>
fetch_nodes(query_ids = "MONDO:0007522") |>
expand(categories = "biolink:PhenotypicFeature")
#> Trying to connect to https://neo4j.monarchinitiative.org
#> Connected to https://neo4j.monarchinitiative.org
#> Fetching; counting matching nodes...
#> total: 1.
#> Fetching; fetched 1 of 1
#> Expanding; counting matching edges...
#> total: 66.
#> Expanding; fetched 66 of 66 edges.
sim <- monarch_semsim(g1, g2)
#> Trying to connect to https://neo4j.monarchinitiative.org
#> Connected to https://neo4j.monarchinitiative.org
#> Joining with `by = join_by(id, pcategory, name, description, synonym, category,
#> iri, xref, namespace, provided_by, exact_synonyms, subsets, related_synonyms,
#> broad_synonyms, narrow_synonyms)`
print(sim)
#> # A tbl_graph: 132 nodes and 107 edges
#> #
#> # A directed multigraph with 37 components
#> #
#> # Node Data: 132 × 15 (active)
#> id pcategory name description synonym category iri xref namespace
#> <chr> <chr> <chr> <chr> <list> <list> <chr> <lis> <chr>
#> 1 MONDO:000… biolink:… Marf… A disorder… <chr> <chr> http… <chr> MONDO
#> 2 HP:0000006 biolink:… Auto… A mode of … <chr> <chr> http… <chr> HP
#> 3 HP:0430043 biolink:… Thor… Thoracic l… <lgl> <chr> http… <lgl> HP
#> 4 HP:0000483 biolink:… Asti… A type of … <chr> <chr> http… <chr> HP
#> 5 HP:0001377 biolink:… Limi… Limited ab… <chr> <chr> http… <chr> HP
#> 6 HP:0000486 biolink:… Stra… A misalign… <chr> <chr> http… <chr> HP
#> 7 HP:0005136 biolink:… Mitr… Mitral ann… <chr> <chr> http… <chr> HP
#> 8 HP:0001371 biolink:… Flex… A flexion … <chr> <chr> http… <chr> HP
#> 9 HP:0003199 biolink:… Decr… NA <chr> <chr> http… <chr> HP
#> 10 HP:0025586 biolink:… Hype… A type of … <lgl> <chr> http… <lgl> HP
#> # ℹ 122 more rows
#> # ℹ 6 more variables: provided_by <chr>, exact_synonyms <chr>, subsets <chr>,
#> # related_synonyms <chr>, broad_synonyms <chr>, narrow_synonyms <chr>
#> #
#> # Edge Data: 107 × 9
#> from to subject predicate object primary_knowledge_so…¹
#> <int> <int> <chr> <chr> <chr> <chr>
#> 1 2 115 HP:0000006 computed:best_matches HP:0000286 computed:monarch_sems…
#> 2 85 85 HP:0000023 computed:best_matches HP:0000023 computed:monarch_sems…
#> 3 25 115 HP:0000098 computed:best_matches HP:0000286 computed:monarch_sems…
#> # ℹ 104 more rows
#> # ℹ abbreviated name: ¹primary_knowledge_source
#> # ℹ 3 more variables: monarch_semsim_metric <chr>, monarch_semsim_score <dbl>,
#> # monarch_semsim_ancestor_id <chr>
# also inclue the unmatched targets
sim <- monarch_semsim(g1, g2, keep_unmatched = TRUE)
#> Trying to connect to https://neo4j.monarchinitiative.org
#> Connected to https://neo4j.monarchinitiative.org
#> Joining with `by = join_by(id, pcategory, name, description, synonym, category,
#> iri, xref, namespace, provided_by, exact_synonyms, subsets, related_synonyms,
#> broad_synonyms, narrow_synonyms)`
print(sim)
#> # A tbl_graph: 162 nodes and 107 edges
#> #
#> # A directed multigraph with 67 components
#> #
#> # Node Data: 162 × 15 (active)
#> id pcategory name description synonym category iri xref namespace
#> <chr> <chr> <chr> <chr> <list> <list> <chr> <lis> <chr>
#> 1 MONDO:000… biolink:… Marf… A disorder… <chr> <chr> http… <chr> MONDO
#> 2 HP:0000006 biolink:… Auto… A mode of … <chr> <chr> http… <chr> HP
#> 3 HP:0430043 biolink:… Thor… Thoracic l… <lgl> <chr> http… <lgl> HP
#> 4 HP:0000483 biolink:… Asti… A type of … <chr> <chr> http… <chr> HP
#> 5 HP:0001377 biolink:… Limi… Limited ab… <chr> <chr> http… <chr> HP
#> 6 HP:0000486 biolink:… Stra… A misalign… <chr> <chr> http… <chr> HP
#> 7 HP:0005136 biolink:… Mitr… Mitral ann… <chr> <chr> http… <chr> HP
#> 8 HP:0001371 biolink:… Flex… A flexion … <chr> <chr> http… <chr> HP
#> 9 HP:0003199 biolink:… Decr… NA <chr> <chr> http… <chr> HP
#> 10 HP:0025586 biolink:… Hype… A type of … <lgl> <chr> http… <lgl> HP
#> # ℹ 152 more rows
#> # ℹ 6 more variables: provided_by <chr>, exact_synonyms <chr>, subsets <chr>,
#> # related_synonyms <chr>, broad_synonyms <chr>, narrow_synonyms <chr>
#> #
#> # Edge Data: 107 × 9
#> from to subject predicate object primary_knowledge_so…¹
#> <int> <int> <chr> <chr> <chr> <chr>
#> 1 2 120 HP:0000006 computed:best_matches HP:0003394 computed:monarch_sems…
#> 2 85 85 HP:0000023 computed:best_matches HP:0000023 computed:monarch_sems…
#> 3 25 126 HP:0000098 computed:best_matches HP:0000286 computed:monarch_sems…
#> # ℹ 104 more rows
#> # ℹ abbreviated name: ¹primary_knowledge_source
#> # ℹ 3 more variables: monarch_semsim_metric <chr>, monarch_semsim_score <dbl>,
#> # monarch_semsim_ancestor_id <chr>
# inclue reverse matches
sim <- monarch_semsim(g1, g2, include_reverse = TRUE)
#> Trying to connect to https://neo4j.monarchinitiative.org
#> Connected to https://neo4j.monarchinitiative.org
#> Joining with `by = join_by(id, pcategory, name, description, synonym, category,
#> iri, xref, namespace, provided_by, exact_synonyms, subsets, related_synonyms,
#> broad_synonyms, narrow_synonyms)`
print(sim)
#> # A tbl_graph: 162 nodes and 174 edges
#> #
#> # A directed multigraph with 30 components
#> #
#> # Node Data: 162 × 15 (active)
#> id pcategory name description synonym category iri xref namespace
#> <chr> <chr> <chr> <chr> <list> <list> <chr> <lis> <chr>
#> 1 MONDO:000… biolink:… Marf… A disorder… <chr> <chr> http… <chr> MONDO
#> 2 HP:0000006 biolink:… Auto… A mode of … <chr> <chr> http… <chr> HP
#> 3 HP:0430043 biolink:… Thor… Thoracic l… <lgl> <chr> http… <lgl> HP
#> 4 HP:0000483 biolink:… Asti… A type of … <chr> <chr> http… <chr> HP
#> 5 HP:0001377 biolink:… Limi… Limited ab… <chr> <chr> http… <chr> HP
#> 6 HP:0000486 biolink:… Stra… A misalign… <chr> <chr> http… <chr> HP
#> 7 HP:0005136 biolink:… Mitr… Mitral ann… <chr> <chr> http… <chr> HP
#> 8 HP:0001371 biolink:… Flex… A flexion … <chr> <chr> http… <chr> HP
#> 9 HP:0003199 biolink:… Decr… NA <chr> <chr> http… <chr> HP
#> 10 HP:0025586 biolink:… Hype… A type of … <lgl> <chr> http… <lgl> HP
#> # ℹ 152 more rows
#> # ℹ 6 more variables: provided_by <chr>, exact_synonyms <chr>, subsets <chr>,
#> # related_synonyms <chr>, broad_synonyms <chr>, narrow_synonyms <chr>
#> #
#> # Edge Data: 174 × 9
#> from to subject predicate object primary_knowledge_so…¹
#> <int> <int> <chr> <chr> <chr> <chr>
#> 1 2 118 HP:0000006 computed:best_matches HP:0002018 computed:monarch_sems…
#> 2 85 85 HP:0000023 computed:best_matches HP:0000023 computed:monarch_sems…
#> 3 25 126 HP:0000098 computed:best_matches HP:0000286 computed:monarch_sems…
#> # ℹ 171 more rows
#> # ℹ abbreviated name: ¹primary_knowledge_source
#> # ℹ 3 more variables: monarch_semsim_metric <chr>, monarch_semsim_score <dbl>,
#> # monarch_semsim_ancestor_id <chr>