Dear Open Targets Team,
First of all thank you very much for this very useful tool, I’m a big fan.
I am trying to query the following tables for multiples snps:
- PheWAS
- GWAS lead variants
- Tag variants
For PheWAS I am using this code in R:
library(httr)
library(rlist)
library(dplyr)
Build query string
query_string = "
query PheWASQuery{
pheWAS($variantId: String!) {
associations {
study {
studyId
traitReported
traitCategory
pmid
pubDate
pubAuthor
source
}
pval
beta
oddsRatio
nTotal
nCases
eaf
se
}
}
}"
Set base URL of GraphQL API endpoint
base_url ← “https://api.genetics.opentargets.org/graphql”
Set gene_id variable
variantId<-“1_154453788_C_T”
for (i in variantId) {
Set variables object of arguments to be passed to endpoint
variables ← list(“variantId” = i)
Construct POST request body object with query string and variables
post_body ← list(query = query_string, variables = variables)
Perform POST request
r ← POST(url=base_url, body=post_body, encode=‘json’)
df = content(r)
Flatten the nested result fields into a dataframe
list_result = content(r)$data$locations
x = lapply(list_result, list.flatten)
result = bind_rows(x)}
But when I do content(r) I get:
$syntaxError
[1] “Syntax error while parsing GraphQL query. Invalid input "query PheWASQuery{\n pheWAS($", expected ExecutableDefinition or TypeSystemDefinition (line 2, column 1):\nquery PheWASQuery{\n^”
$locations
$locations[[1]]
$locations[[1]]$line
[1] 2
$locations[[1]]$column
[1] 1
I’d really appreciate if you could assist me in how to correct my code.
I also would like to adapt the code to obtain this two other tables:
- GWAS lead variants
- Tag variants
Any help would be much appreciated!! Many thanks!
Paloma