knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This RMarkdown document demonstrates how key elements from the github notebook for the meta functionalities can be achieved using the R package. For detailed explanations of the case study please refer to the notebook on github.
Here we show the following aspects of the EpiGraphDB platform, and how to use the API to get the information:
For detailed documentation on the API endpoints please visit:
library("magrittr") library("dplyr") library("purrr") library("igraph") library("epigraphdb")
Here we query for the metadata information using the endpoint GET /meta/schema
, which will be used for downstream processing.
endpoint <- "/meta/schema" params <- list( graphviz = FALSE, plot = FALSE ) metadata <- query_epigraphdb( route = endpoint, params = params, mode = "raw" ) metadata %>% str(2)
We can extract the specific meta node information as a dataframe from the metadata.
meta_node_df <- metadata %>% pluck("nodes") %>% { names <- names(.) transpose(.) %>% as_tibble() %>% mutate(meta_node = names) %>% # Hide properties column which does not display well select(meta_node, count) %>% # We also need to flatten count mutate(count = flatten_int(count)) } meta_node_df %>% arrange(meta_node) %>% mutate(count = format(count, big.mark = ","))
We can also extract the meta relationship (edge) information, and the connections.
meta_rel_df <- metadata %>% pluck("edges") %>% { names <- names(.) transpose(.) %>% as_tibble() %>% mutate(meta_rel = names) %>% mutate(count = flatten_int(count)) %>% select(meta_rel, count) } %>% inner_join( metadata %>% pluck("connections") %>% { transpose(.) %>% as_tibble() %>% mutate(meta_rel = flatten_chr(rel)) %>% mutate_at(vars(from_node, to_node), flatten_chr) %>% select(meta_rel, from_node, to_node) } ) meta_rel_df %>% arrange(from_node, to_node) %>% mutate(count = format(count, big.mark = ","))
Users can use the explorer on the Web UI to search for a specific node by:
Here we show how these are done at the API level using Gwas
nodes as an example.
First we need to know what the "ID" and "name" fields are for the meta nodes using GET /meta/nodes/id-name-schema
:
endpoint <- "/meta/nodes/id-name-schema" meta_node_fields <- query_epigraphdb( route = endpoint, params = NULL, mode = "raw" ) meta_node_fields
Here we search for nodes can contain "body mass index" in their traits.
name <- "body mass index" endpoint <- "/meta/nodes/Gwas/search" params <- list(name = name) results <- query_epigraphdb( route = endpoint, params = params, mode = "table" ) results
Similarly, we can exact match a specific node by its ID.
id <- "ieu-a-2" endpoint <- "/meta/nodes/Gwas/search" params <- list(id = id) results <- query_epigraphdb( route = endpoint, params = params, mode = "table" ) results
Advanced users that are familiar with Neo4j Cypher can query the database using Cypher directly.
query <- " MATCH (exposure:Gwas)-[mr:MR]->(outcome:Gwas) WHERE exposure.trait = 'Body mass index' RETURN exposure, outcome, mr LIMIT 2 " endpoint <- "/cypher" params <- list(query = query) # NOTE this is a POST request results <- query_epigraphdb( route = endpoint, params = params, method = "POST", mode = "table" ) results
sessionInfo
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.