Given a graph, saves it using the tabular KGX format (see https://github.com/biolink/kgx/blob/master/specification/kgx-format.md) for later use with load_kgx() (or even backing an engine with file_engine()). Note that if any engine is associated with the graph it is not saved.

save_kgx(graph, filename = "saved_kgx_graph.tar.gz", ...)

Arguments

graph

A tbl_kgx graph to save.

filename

File to save the graph to. Must end in .tar.gz.

...

Other parameters (unused)

Value

The input graph (invisibly).

Examples

phenos <- monarch_engine() |>
          fetch_nodes(query_ids = "MONDO:0007525") |>
          expand(predicates = "biolink:has_phenotype",
                 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: 48.
#> Expanding; fetched 48 of 48 edges.

save_kgx(phenos, "phenos.tar.gz")

# when loading the graph, we can optionally attach an engine
loaded_phenos <- load_kgx("phenos.tar.gz", attach_engine = monarch_engine())
#> Trying to connect to https://neo4j.monarchinitiative.org
#> Connected to https://neo4j.monarchinitiative.org

loaded_phenos
#> # A tbl_graph: 49 nodes and 48 edges
#> #
#> # A rooted tree
#> #
#> # Node Data: 49 × 10 (active)
#>    id         pcategory name  description synonym category iri   xref  namespace
#>    <chr>      <chr>     <chr> <chr>       <list>  <list>   <chr> <lis> <chr>    
#>  1 MONDO:000… biolink:… Ehle… Arthrochal… <chr>   <chr>    http… <chr> MONDO    
#>  2 HP:0000963 biolink:… Thin… Reduction … <chr>   <chr>    http… <chr> HP       
#>  3 HP:0000974 biolink:… Hype… A conditio… <chr>   <chr>    http… <chr> HP       
#>  4 HP:0001001 biolink:… Abno… NA          <chr>   <chr>    http… <chr> HP       
#>  5 HP:0001252 biolink:… Hypo… Hypotonia … <chr>   <chr>    http… <chr> HP       
#>  6 HP:0001373 biolink:… Join… Displaceme… <chr>   <chr>    http… <chr> HP       
#>  7 HP:0001385 biolink:… Hip … The presen… <chr>   <chr>    http… <chr> HP       
#>  8 HP:0001387 biolink:… Join… Joint stif… <chr>   <chr>    http… <chr> HP       
#>  9 HP:0002300 biolink:… Muti… Complete l… <chr>   <chr>    http… <chr> HP       
#> 10 HP:0002381 biolink:… Apha… An acquire… <chr>   <chr>    http… <chr> HP       
#> # ℹ 39 more rows
#> # ℹ 1 more variable: provided_by <chr>
#> #
#> # Edge Data: 48 × 23
#>    from    to subject       predicate             object knowledge_level negated
#>   <int> <int> <chr>         <chr>                 <chr>  <chr>           <lgl>  
#> 1     1     2 MONDO:0007525 biolink:has_phenotype HP:00… knowledge_asse… TRUE   
#> 2     1     3 MONDO:0007525 biolink:has_phenotype HP:00… knowledge_asse… TRUE   
#> 3     1     4 MONDO:0007525 biolink:has_phenotype HP:00… knowledge_asse… TRUE   
#> # ℹ 45 more rows
#> # ℹ 16 more variables: primary_knowledge_source <chr>,
#> #   frequency_qualifier <chr>, original_subject <chr>, agent_type <chr>,
#> #   knowledge_source <chr>, aggregator_knowledge_source <chr>,
#> #   has_evidence <chr>, provided_by <chr>, id <chr>, category <chr>,
#> #   has_total <dbl>, has_quotient <dbl>, has_count <dbl>, has_percentage <dbl>,
#> #   publications <chr>, onset_qualifier <chr>

# cleanup saved file
file.remove("phenos.tar.gz")
#> [1] TRUE