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: 52.
#> Expanding; fetched 52 of 52 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 52 edges
#> #
#> # A directed acyclic multigraph with 1 component
#> #
#> # Node Data: 49 × 15 (active)
#>    id            pcategory        name  description synonym category iri   xref 
#>    <chr>         <chr>            <chr> <chr>       <list>  <list>   <chr> <lis>
#>  1 MONDO:0007525 biolink:Disease  Ehle… An inherit… <chr>   <chr>    http… <chr>
#>  2 HP:0001058    biolink:Phenoty… Poor… A reduced … <chr>   <chr>    http… <chr>
#>  3 HP:0001476    biolink:Phenoty… Dela… A delay in… <chr>   <chr>    http… <chr>
#>  4 HP:0001252    biolink:Phenoty… Hypo… Hypotonia … <chr>   <chr>    http… <chr>
#>  5 HP:0001075    biolink:Phenoty… Atro… Scars that… <chr>   <chr>    http… <chr>
#>  6 HP:0001290    biolink:Phenoty… Gene… Generalize… <chr>   <chr>    http… <chr>
#>  7 HP:0005191    biolink:Phenoty… Cong… NA          <chr>   <chr>    http… <chr>
#>  8 HP:0009540    biolink:Phenoty… Cont… Chronic lo… <chr>   <chr>    http… <chr>
#>  9 HP:0000938    biolink:Phenoty… Oste… Osteopenia… <chr>   <chr>    http… <chr>
#> 10 HP:0001822    biolink:Phenoty… Hall… Lateral de… <chr>   <chr>    http… <chr>
#> # ℹ 39 more rows
#> # ℹ 7 more variables: related_synonyms <list>, narrow_synonyms <list>,
#> #   exact_synonyms <list>, namespace <chr>, provided_by <chr>, subsets <list>,
#> #   broad_synonyms <list>
#> #
#> # Edge Data: 52 × 22
#>    from    to subject    predicate object primary_knowledge_so…¹ knowledge_level
#>   <int> <int> <chr>      <chr>     <chr>  <chr>                  <chr>          
#> 1     1     2 MONDO:000… biolink:… HP:00… infores:omim           knowledge_asse…
#> 2     1     3 MONDO:000… biolink:… HP:00… infores:omim           knowledge_asse…
#> 3     1     4 MONDO:000… biolink:… HP:00… infores:omim           knowledge_asse…
#> # ℹ 49 more rows
#> # ℹ abbreviated name: ¹​primary_knowledge_source
#> # ℹ 15 more variables: negated <lgl>, original_subject <chr>, agent_type <chr>,
#> #   aggregator_knowledge_source <chr>, has_evidence <chr>, provided_by <chr>,
#> #   id <chr>, category <chr>, has_quotient <dbl>, has_total <dbl>,
#> #   has_count <dbl>, has_percentage <dbl>, publications <chr>,
#> #   onset_qualifier <chr>, frequency_qualifier <chr>

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