I am new both to the usage of OTG and GraphQL and have recently begun using the platform for investigating variants we have discovered via GWAS meta-analysis. For this I’ve been using the V2G function and also intend to conduct a PheWAS using the Open Targets API.
I am most comfortable with R and so have been using that for most of the work I’ve conducted so far.
The issue I have run into a couple of times is that I cannot find anywhere a list or pdf or any kind of description of all the various commands that the OTG GraphQL uses. I’ve stumbled across a few tutorials and questions on here which have figured out a few things here and there, but I cannot for the life of me find a full list of the possible commands and options that I can use.
For example, I have figured out after a little trial and error how to run the V2G function of OpenTargets and cooked up the following R code:
### Get OpenTargets SNP ID
id_query_string = "query useSearchToConvertRSIDIntoIDFormat($query_rsID: String!) {
search(queryString: $query_rsID) {
variants {
id
rsId
nearestGene {
id
start
symbol
tss
description
chromosome
exons
}
nearestGeneDistance
}
}
}"
### Set variables object of arguments to be passed to endpoint
id_variables = list("query_rsID" = query_rsID)
### Construct POST request body object with query string and variables
id_search_body = list(query = id_query_string, variables = id_variables)
### Perform OpenTargets search request
id_search_out = POST(url = base_url, body = id_search_body, encode = "json")
### Variant ID output
variantID = content(id_search_out)$data$search$variants[[1]]$id
v2g_query_string = "query v2g($variantId: String!) {
genesForVariant(variantId: $variantId) {
gene {
id
symbol
}
variant
overallScore
functionalPredictions {
typeId
sourceId
aggregatedScore
}
intervals {
typeId
sourceId
aggregatedScore
}
}
}"
This was largely based off another question on here which I now can’t find.
What I want to do is now use the same output (the variantID) from the first API query and use that in a PheWAS and search for associated diseases etc. But I don’t even know what the command is to search for phenotypes and don’t know what arguments/fields are available to search for it.
In the Documentation Explorer on the right, you can click through the schema and find the different fields that you can access to help you build your query.
So, I had seen the links to the API playground, but to be honest I had totally missed that there was a browser on the right which provided some of the schema.
Looking at this now I have to admit I’m still a little uncertain about its usage and which of the various functions I need to be using for my purpose (and in fact how to use them).
I can see there is a pheWAS option, but given that I would ideally like a table output of data like that which appears on the front page of OTG when you search for a variant, I don’t see which fields I should be requesting to do this.
Let me try to give you some explanation on how I got to this query: pheWAS(variantId: "10_21589478_C_T") { ← you will do a pheWAS query on a specific variant. See screenshot below that shows this query in the Documentation Explorer.
As you can see, variantId is an accepted argument here. The “TYPE” informs you about the return type of this query. A PheWAS object in this case. Now let’s have a look at the PheWAS object in the Document Explorer. See screenshot below:
As you can see, the PheWAS object returns 2 fields: a totalGWASStudies number and an PheWASAssociation object named associations.
Now back to the proposed query: associations { ← this is the PheWASAssociation object named associations in your query.
You can have a look at this object in the Documentation Explorer again. (unfortunately I am not allowed to put more than 2 screenshots.)
As you should be able to find, this object returns several fields related to the associations (among others: pval, se, beta). One of the fields is a Study object called study.
Again, back to the proposed query: study { ← here is the study object in your query. You can do the same trick and check the study object in the Documentation Explorer to see what info you can query for a study. In this case: studyId, traitReported, etc.
I hope this information will help you put together your query as well as give some explanation on how to use the Documentation Explorer to put together your own queries.
Hi Amir, thanks for the suggestion! I have actually managed to get the API working (at least for now) so I’ll probably stick with that. I shall keep this in mind for the future though.
Thanks very much for the extremely detailed response. I actually had managed to sort out some code which ended up working to provide the PheWAS results I was looking for. At least a portion of my confusion stemmed from an unfamiliarity with the API language, so even the browser suggested by @hcornu was initially not extremely helpful as I had no idea how to use it or test it.
I did however spend a bit of time battling and playing around with it and have ended up with code very similar to what you have suggested:
This seems to be extremely similar to what you’ve provided, but I have just noticed that you also mention a traitCategory field, which is actually something I have been trying to figure out how to find, so you have inadvertently solved another problem I had! Or at least I hope you have (as I have been trying to figure out how the OpenTargets PheWAS plots are so nicely grouped into different categories).