2023-12-15
Load packages:
library("ghql")
library(jsonlite)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.4
## ✔ ggplot2 3.4.4 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ purrr::flatten() masks jsonlite::flatten()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Link to the GraphQL schema and create a client object
link <- 'https://dgidb.org/api/graphql'
conn <- GraphqlClient$new(url = link)
Define a query and specify query variables
rawQuery <- '
query($id: [String!]){
genes(names: $id) {
nodes {
name
interactions {
drug {
name
}
interactionAttributes {
name
value
}
}
geneCategoriesWithSources {
name
}
}
}
}'
query <- Query$new()$query('link', rawQuery)
variable <- list(
id = list("RAMP3", "XPO1")
)
Issue the request:
result <- conn$exec(query$link, variables = variable) %>%
fromJSON()
I am utterly failing at turning this into a table that preserves the individual key/value interaction attribute pairings.
knitr::kable(
result$data$genes$nodes
)
name | interactions | geneCategoriesWithSources |
---|---|---|
XPO1 | FELEZONEXOR , SELINEXOR , LEPTOMYCIN B , OSTHOLE , GONIOTHALAMIN , Direct Interaction , Mechanism of Action , true , Exportin-1 inhibitor | CLINICALLY ACTIONABLE, KINASE |
RAMP3 | STREPTOZOCIN , PRAMLINTIDE ACETATE , PRAMLINTIDE , Direct Interaction , Mechanism of Action , true , Amylin receptor AMY3; CALCR/RAMP3 agonist, Clinical Trial Name , Novel Drug Target , Symlin , Established target | CELL SURFACE , DRUGGABLE GENOME |