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

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: 30 nodes and 26 edges
#> #
#> # A rooted forest with 4 trees
#> #
#> # Node Data: 30 × 16 (active)
#>    id       pcategory name  description synonym category iri   xref  file_source
#>    <chr>    <chr>     <chr> <chr>       <chr>   <list>   <chr> <chr> <chr>      
#>  1 MONDO:0… NA        Ehle… An inherit… "c(\"\… <chr>     NA    NA   NA         
#>  2 )        phenio_n… biol… http://pur… "c(\"\… <chr>    "c(\… "MON… phenio_nod…
#>  3 HP:0000… biolink:… Thin… Reduction … "Thin … <chr>    "htt… "c(\… phenio_nod…
#>  4 HP:0000… biolink:… Hype… A conditio… "c(\"\… <chr>    "htt… "UML… phenio_nod…
#>  5 HP:0001… biolink:… Abno… NA          "Abnor… <chr>    "htt… "UML… phenio_nod…
#>  6 HP:0001… biolink:… Hypo… Hypotonia … "c(\"\… <chr>    "htt… "c(\… phenio_nod…
#>  7 HP:0001… biolink:… Join… Displaceme… "c(\"\… <chr>    "htt… "c(\… phenio_nod…
#>  8 HP:0001… biolink:… Hip … The presen… "c(\"\… <chr>    "htt… "c(\… phenio_nod…
#>  9 HP:0001… biolink:… Join… Joint stif… "c(\"\… <chr>    "htt… "c(\… phenio_nod…
#> 10 HP:0002… biolink:… Muti… Complete l… "c(\"\… <chr>    "htt… "c(\… phenio_nod…
#> # ℹ 20 more rows
#> # ℹ 7 more variables: narrow_synonym <chr>, namespace <chr>,
#> #   provided_by <list>, exact_synonym <chr>, related_synonym <chr>,
#> #   subsets <chr>, broad_synonym <chr>
#> #
#> # Edge Data: 26 × 17
#>    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:orphanet       knowledge_asse…
#> 2     1     3 MONDO:000… biolink:… HP:00… infores:orphanet       knowledge_asse…
#> 3     1     4 MONDO:000… biolink:… HP:00… infores:orphanet       knowledge_asse…
#> # ℹ 23 more rows
#> # ℹ abbreviated name: ¹​primary_knowledge_source
#> # ℹ 10 more variables: negated <lgl>, frequency_qualifier <chr>,
#> #   file_source <chr>, original_subject <chr>, agent_type <chr>,
#> #   aggregator_knowledge_source <chr>, has_evidence <chr>, provided_by <chr>,
#> #   id <chr>, category <chr>

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