Query all snps associated with a disease

I’m not very familiar with coding (I have some history with python) so I’ve been using ChatGPT to try and construct a query to get all snps associated with pregnancy disease in the format
rsId
chromosome
position
refAllele
altAllele

The code it suggested is

import requests
import pandas as pd

# set up the Open Targets API endpoint URL
url = 'https://api.opentargets.io/v3/platform/public/evidence/filter'

# set up the query parameters
params = {
    'target': 'EFO_0009682', # set the target to pregnancy disease (EFO ID)
    'datasource': 'evarest', # set the data source to evarest (genetic associations)
    'size': 10000, # set the maximum number of results to return
    'fields': 'variant', # only return variant-level data
    'expandefo': False # don't expand the EFO hierarchy in the response
}

# send the request to the Open Targets API endpoint
response = requests.get(url, params=params)

# extract the relevant data from the response
data = response.json()
results = data['data']

# create a list of dictionaries to store the SNP data
snps = []

# loop through the results and extract the SNP data
for result in results:
    variant = result['variant']
    snp = {
        'rsId': variant['rsid'],
        'chromosome': variant['seq_region_name'],
        'position': variant['start'],
        'refAllele': variant['ref_allele'],
        'altAllele': variant['alt_allele']
    }
    snps.append(snp)

# create a pandas dataframe from the list of SNP dictionaries
df = pd.DataFrame(snps)

# export the SNP data to a CSV file
df.to_csv('pregnancy_disease_snps.csv', index=False)

I keep getting an SSL error (and ChatGPT is getting confused) - how do I get the desired output?

Hi @KayK17,

The base urls for our APIs are

The query you posted above will not give you the information you’re looking for. We have a sample query for Python in our Platform documentation and Genetics documentation, which might be good starting points to build a query.

1 Like