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
)

Arguments

query_graph

A tbl_kgx graph.

target_graph

A tbl_kgx graph.

metric

The semantic similarity metric to use. Default is "ancestor_information_content". Also available are "jaccard_similarity" and "phenodigm_score".

include_reverse

Whether to include the best matches from the target graph to the query graph. Default is FALSE.

keep_unmatched

Whether to keep nodes from either graph that do not have a match (as nodes with no edges). Default is FALSE.

Value

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.

Details

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. A node whose best match shares no common ancestor with it (e.g. a disease node compared against phenotypes) is considered unmatched and gets no edge.

The engine attached to the return graph is that of the query.

Examples


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; fetched1of1
#> Expanding; counting matching edges... 
#>  total: 139.
#> Expanding; fetched139of139edges.

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; fetched1of1
#> Expanding; counting matching edges... 
#>  total: 66.
#> Expanding; fetched66of66edges.

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, file_source, exact_synonym, subsets,
#> broad_synonym, related_synonym, narrow_synonym)`
print(sim)
#> # A tbl_graph: 129 nodes and 107 edges
#> #
#> # A directed multigraph with 34 components
#> #
#> # Node Data: 129 × 16 (active)
#>    id        pcategory name  description synonym category iri   xref   namespace
#>    <chr>     <chr>     <chr> <chr>       <list>  <list>   <chr> <list> <chr>    
#>  1 MONDO:00… biolink:… Marf… A disorder… <list>  <chr>    http… <list> MONDO    
#>  2 HP:04300… biolink:… Thor… Thoracic l… <lgl>   <chr>    http… <lgl>  HP       
#>  3 HP:00004… biolink:… Asti… A type of … <list>  <chr>    http… <list> HP       
#>  4 HP:00013… biolink:… Limi… Limited ab… <list>  <chr>    http… <list> HP       
#>  5 HP:00004… biolink:… Stra… A misalign… <list>  <chr>    http… <list> HP       
#>  6 HP:00051… biolink:… Mitr… Mitral ann… <list>  <chr>    http… <list> HP       
#>  7 HP:00013… biolink:… Flex… A flexion … <list>  <chr>    http… <list> HP       
#>  8 HP:00031… biolink:… Decr… NA          <list>  <chr>    http… <list> HP       
#>  9 HP:00255… biolink:… Hype… A type of … <lgl>   <chr>    http… <lgl>  HP       
#> 10 HP:00005… biolink:… Cata… A cataract… <list>  <chr>    http… <list> HP       
#> # ℹ 119 more rows
#> # ℹ 7 more variables: provided_by <chr>, file_source <chr>,
#> #   exact_synonym <list>, subsets <list>, broad_synonym <list>,
#> #   related_synonym <list>, narrow_synonym <list>
#> #
#> # Edge Data: 107 × 9
#>    from    to subject       predicate             object  primary_knowledge_so…¹
#>   <int> <int> <chr>         <chr>                 <chr>   <chr>                 
#> 1     1   108 MONDO:0007947 computed:best_matches MONDO:… computed:monarch_sems…
#> 2     2    54 HP:0430043    computed:best_matches HP:000… computed:monarch_sems…
#> 3     3   116 HP:0000483    computed:best_matches HP:000… 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 include 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, file_source, exact_synonym, subsets,
#> broad_synonym, related_synonym, narrow_synonym)`
print(sim)
#> # A tbl_graph: 162 nodes and 107 edges
#> #
#> # A directed multigraph with 67 components
#> #
#> # Node Data: 162 × 16 (active)
#>    id        pcategory name  description synonym category iri   xref   namespace
#>    <chr>     <chr>     <chr> <chr>       <list>  <list>   <chr> <list> <chr>    
#>  1 MONDO:00… biolink:… Marf… A disorder… <list>  <chr>    http… <list> MONDO    
#>  2 HP:04300… biolink:… Thor… Thoracic l… <lgl>   <chr>    http… <lgl>  HP       
#>  3 HP:00004… biolink:… Asti… A type of … <list>  <chr>    http… <list> HP       
#>  4 HP:00013… biolink:… Limi… Limited ab… <list>  <chr>    http… <list> HP       
#>  5 HP:00004… biolink:… Stra… A misalign… <list>  <chr>    http… <list> HP       
#>  6 HP:00051… biolink:… Mitr… Mitral ann… <list>  <chr>    http… <list> HP       
#>  7 HP:00013… biolink:… Flex… A flexion … <list>  <chr>    http… <list> HP       
#>  8 HP:00031… biolink:… Decr… NA          <list>  <chr>    http… <list> HP       
#>  9 HP:00255… biolink:… Hype… A type of … <lgl>   <chr>    http… <lgl>  HP       
#> 10 HP:00005… biolink:… Cata… A cataract… <list>  <chr>    http… <list> HP       
#> # ℹ 152 more rows
#> # ℹ 7 more variables: provided_by <chr>, file_source <chr>,
#> #   exact_synonym <list>, subsets <list>, broad_synonym <list>,
#> #   related_synonym <list>, narrow_synonym <list>
#> #
#> # Edge Data: 107 × 9
#>    from    to subject       predicate             object  primary_knowledge_so…¹
#>   <int> <int> <chr>         <chr>                 <chr>   <chr>                 
#> 1     1   108 MONDO:0007947 computed:best_matches MONDO:… computed:monarch_sems…
#> 2     2    54 HP:0430043    computed:best_matches HP:000… computed:monarch_sems…
#> 3     3   127 HP:0000483    computed:best_matches HP:000… 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>

# include 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, file_source, exact_synonym, subsets,
#> broad_synonym, related_synonym, narrow_synonym)`
print(sim)
#> # A tbl_graph: 162 nodes and 174 edges
#> #
#> # A directed multigraph with 30 components
#> #
#> # Node Data: 162 × 16 (active)
#>    id        pcategory name  description synonym category iri   xref   namespace
#>    <chr>     <chr>     <chr> <chr>       <list>  <list>   <chr> <list> <chr>    
#>  1 MONDO:00… biolink:… Marf… A disorder… <list>  <chr>    http… <list> MONDO    
#>  2 HP:04300… biolink:… Thor… Thoracic l… <lgl>   <chr>    http… <lgl>  HP       
#>  3 HP:00004… biolink:… Asti… A type of … <list>  <chr>    http… <list> HP       
#>  4 HP:00013… biolink:… Limi… Limited ab… <list>  <chr>    http… <list> HP       
#>  5 HP:00004… biolink:… Stra… A misalign… <list>  <chr>    http… <list> HP       
#>  6 HP:00051… biolink:… Mitr… Mitral ann… <list>  <chr>    http… <list> HP       
#>  7 HP:00013… biolink:… Flex… A flexion … <list>  <chr>    http… <list> HP       
#>  8 HP:00031… biolink:… Decr… NA          <list>  <chr>    http… <list> HP       
#>  9 HP:00255… biolink:… Hype… A type of … <lgl>   <chr>    http… <lgl>  HP       
#> 10 HP:00005… biolink:… Cata… A cataract… <list>  <chr>    http… <list> HP       
#> # ℹ 152 more rows
#> # ℹ 7 more variables: provided_by <chr>, file_source <chr>,
#> #   exact_synonym <list>, subsets <list>, broad_synonym <list>,
#> #   related_synonym <list>, narrow_synonym <list>
#> #
#> # Edge Data: 174 × 9
#>    from    to subject       predicate             object  primary_knowledge_so…¹
#>   <int> <int> <chr>         <chr>                 <chr>   <chr>                 
#> 1     1   108 MONDO:0007947 computed:best_matches MONDO:… computed:monarch_sems…
#> 2     2    54 HP:0430043    computed:best_matches HP:000… computed:monarch_sems…
#> 3     3   127 HP:0000483    computed:best_matches HP:000… 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>