Variant to Gene Query

Dear Open Target team,

First of all, thank you very much for your valuable work.

I need to perform a Variant to Gene search for multiple variants (>200).

I am trying to find a way to do it through a script that generates a table with the results containing the same parameters as when I search the rsid individually through the browser but I’ve been not able to find what I am looking for in the documentation.

Your guidance would be very appreciated.

Thank you very much!


Thanks for your question Paloma. For a moderate number of variants, you could use the GraphQL API, which can be access via a browser, or programmatically.

For example, a query in the browser might look something like this:
GraphQL variant to gene query.

You can use a language of your choice to do the query programmatically, e.g. python or R. Here is an example in R:

# Install relevant library for HTTP requests

# Set gene_id variable
variantId <- "17_44352876_C_T"

# Build query string
query_string = "
query v2g($variantId: String!) {
  genesForVariant(variantId: $variantId) {
    gene {
    distances {
      tissues {

# Set base URL of GraphQL API endpoint
base_url <- ""

# Set variables object of arguments to be passed to endpoint
variables <- list("variantId" = variantId)

# 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)
# Print first entry of V2G data console
head(content(r)$data$genesForVariant, 1)

# Flatten the nested result fields into a dataframe
list_result = content(r)$data$genesForVariant
x = lapply(list_result, list.flatten)

df = bind_rows(x)

Note that if you want to get the information for individual QTL associations, you would need to do a bit more to flatten the resulting nested lists.

Thank you very much for your detailed and very helpful response Jeremy! It worked!

1 Like