-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathepigraphdb-meta.R
124 lines (104 loc) · 3.21 KB
/
epigraphdb-meta.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
## -----------------------------------------------------------------------------
library("magrittr")
library("dplyr")
library("purrr")
library("igraph")
library("epigraphdb")
## -----------------------------------------------------------------------------
endpoint <- "/meta/schema"
params <- list(
graphviz = FALSE,
plot = FALSE
)
metadata <- query_epigraphdb(
route = endpoint, params = params, mode = "raw"
)
metadata %>% str(2)
## -----------------------------------------------------------------------------
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 = ","))
## -----------------------------------------------------------------------------
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 = ","))
## -----------------------------------------------------------------------------
graph <- meta_rel_df %>%
select(from_node, to_node) %>%
igraph::graph_from_data_frame(directed = FALSE)
graph$layout <- igraph::layout_with_kk
plot(graph)
## -----------------------------------------------------------------------------
endpoint <- "/meta/nodes/id-name-schema"
meta_node_fields <- query_epigraphdb(
route = endpoint, params = NULL, mode = "raw"
)
meta_node_fields
## -----------------------------------------------------------------------------
name <- "body mass index"
endpoint <- "/meta/nodes/Gwas/search"
params <- list(name = name)
results <- query_epigraphdb(
route = endpoint, params = params, mode = "table"
)
results
## -----------------------------------------------------------------------------
id <- "ieu-a-2"
endpoint <- "/meta/nodes/Gwas/search"
params <- list(id = id)
results <- query_epigraphdb(
route = endpoint, params = params, mode = "table"
)
results
## -----------------------------------------------------------------------------
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()