Downloading variant information

Hi!
I used to be able run the following in R to download details on variants. It doesn’t work with the new API link.

I also cannot find the following in the schema.

qry <- Query$new()
   # using this
   id <- "rs12345" # variant ID
   
   
   #====================
   # build query, e.g.:
   qry$query('my_query', paste0('{search(queryString:', "\"",id, "\"", ') {
     
    variants {
      id
      rsId
      chromosome
      position
      refAllele
      altAllele
      nearestGeneDistance
      nearestCodingGeneDistance
 
}
  
    
  }}'))
   
   ##===================
   # run query and format results:
   res1 <- fromJSON(cli$exec(qry$queries$my_query), flatten = TRUE)$data$search$variants

Hi @Gpathak and wellcome to the Community!

There have not been any changes to the endpoints you are describing. I am not familiar with the process of inserting a subquery inside a query, and I wonder if the problem is coming from the R library that is handling this type of query.

You can obtain the same result if you make 2 consecutive queries. This is a snippet of how I would do the process in Python:

import requests

url = 'https://api.genetics.opentargets.org/graphql'

search_query  = """
	query searchRsId($rsId: String!) {
		search(queryString: $rsId) {
	    variants {
	      id
	    }
	  }
	}
"""

variant_query = """
	query variantInfo($variantId: String!) {
	  variantInfo(variantId: $variantId) {
		id
	    rsId
	    chromosome
	    position
	    refAllele
	    altAllele
	    nearestGeneDistance
	    nearestCodingGeneDistance
	  }
	}
"""

variables = {'rsId': 'rs10469840'} # Your rsID of interest

search_result = requests.post(url, json={'query': search_query, 'variables':variables}).json()
# This returns: {'data': {'search': {'variants': [{'id': '2_102476784_T_C'}]}}}

variables.update({'variantId': search_result['data']['search']['variants'][0]['id']})

variant_result = requests.post(url, json={'query': variant_query, 'variables':variables}).json()
'''
This returns: {'data': {'variantInfo': {'id': '2_102476784_T_C',
   'rsId': 'rs10469840',
   'chromosome': '2',
   'position': 102476784,
   'refAllele': 'T',
   'altAllele': 'C',
   'nearestGeneDistance': 3558,
   'nearestCodingGeneDistance': 3558}}}
''' 

Can you try a similar approach in R and let me know if it works?

At the same time, I also want to let you know that if you need to process multiple rsIDs it is worth checking out our variant dataset, downloadable from EBI’s FTP at: Index of /pub/databases/opentargets/genetics/latest/variant-index/

This dataset is the one feeding our API, so you can expect having the same information.

Thank you for your question!
Irene

2 Likes

Thank you so much Irene, this works. I didn’t understand the use of variantInfo
I used the following for another query and it doesn’t work again. How do I find the top level schema for such queries.

query variantInfo {
	  indexVariantsAndStudiesForTagVariant(variantId: "1_46810098_T_C") {
	associations {
    
     study {
      studyId
      traitReported
      traitCategory
      pmid
      pubAuthor
      pubDate
    }
    indexVariant {
      id
      rsId
      refAllele
        altAllele
        nearestGeneDistance
        nearestGene {
          symbol
        }
    }
 pval
      nTotal
      nCases
      overallR2
      afr1000GProp
      amr1000GProp
      eas1000GProp
      eur1000GProp
      sas1000GProp
      log10Abf
      posteriorProbability
      pvalMantissa
      pvalExponent
      oddsRatio
      oddsRatioCILower
      oddsRatioCIUpper
      beta
      direction
      betaCILower
      betaCIUpper
  }
  
}
	  }

Hi @Gpathak ,

You can explore the queries and the schema on the graphql palyground. See this example query on variantInfo.

On the graphql playground page you can click the docs on the upper-left corner and explore the available objects.