Question: Hi,
I would like to **get SNPs associated with a gene** from EBI over API request in Python. I found this tutorial:

[https://colab.research.google.com/github/EBISPOT/GWAS_Catalog-workshop/blob/master/notebooks/workshop_01.ipynb#scrollTo=1rraZwYctEud][1]

Which is helpful to get a trait or SNPs, which is already good! However, I have to say that I am not really good with APIs and how to change this query to a gene query.

This is from the tutorial:

# API Address:
apiUrl = 'https://www.ebi.ac.uk/gwas/summary-statistics/api'

trait = "EFO_0001360"
p_upper = "0.000000001"

requestUrl = '%s/traits/%s/associations?p_upper=%s&size=10' %(apiUrl, trait, p_upper)
response = requests.get(requestUrl, headers={ "Content-Type" : "application/json"})

# The returned response is a "response" object, from which we have to extract and parse the information:
decoded = response.json()
extractedData = []

def getGene(studyLink):
# Accessing data for a single study:
response = requests.get(studyLink, headers={ "Content-Type" : "application/json"})
decoded = response.json()

gwasData = requests.get(decoded['_links']['gwas_catalog']['href'], headers={ "Content-Type" : "application/json"})
decodedGwasData = gwasData.json()

traitName = decodedGwasData['diseaseTrait']['trait']
pubmedId = decodedGwasData['publicationInfo']['pubmedId']

return(traitName, pubmedId)

extractedData = []

for association in decoded['_embedded']['associations'].values():
pvalue = association['p_value']
variant = association['variant_id']
studyID = association['study_accession']
studyLink = association['_links']['study']['href']
traitName, pubmedId = getStudy(studyLink)

extractedData.append({'variant' : variant,
'studyID': studyID,
'pvalue' : pvalue,
'traitName': traitName,
'pubmedID': pubmedId})

ssWithGWASTable = pd.DataFrame.from_dict(extractedData)
ssWithGWASTable

In the `decoded` you get this:

'trait': [{'href': 'https://www.ebi.ac.uk/gwas/summary-statistics/api/traits/EFO_0001360'}],

which is I guess where to change it (maybe with /summary-staistics/gene/... ??). But I am not really good with APIs and hope to get some pointers or solutions here.

Thanks,
Simon

[1]: https://colab.research.google.com/github/EBISPOT/GWAS_Catalog-workshop/blob/master/notebooks/workshop_01.ipynb#scrollTo=1rraZwYctEud

Answer: I could be wrong, but I think you might be able to achieve this using the [eQTL][1] RESTful API as described [here][2].

For example, for gene TP53BP1 ([ENSG00000067369][3]), here are the first two results:

curl -s https://www.ebi.ac.uk/eqtl/api/genes/ENSG00000067369/associations?size=2 | jsonpp
{
"_embedded": {
"associations": {
"0": {
"qtl_group": "macrophage_IFNg",
"se": 0.0312781,
"beta": 0.0306393,
"median_tpm": 3.798,
"study_id": "Alasoo_2018",
"neg_log10_pvalue": 0.4806052046189824,
"rsid": "rs4573906",
"chromosome": "15",
"type": "SNP",
"alt": "A",
"position": 42512802,
"ac": 124.0,
"maf": 0.255952,
"variant": "chr15_42512802_G_A",
"ref": "G",
"pvalue": 0.33067,
"r2": 0.81584,
"an": 168.0,
"molecular_trait_id": "ENSG00000067369",
"gene_id": "ENSG00000067369",
"tissue": "CL_0000235"
},
"1": {
"qtl_group": "macrophage_IFNg",
"se": 0.0312826,
"beta": 0.0307136,
"median_tpm": 3.798,
"study_id": "Alasoo_2018",
"neg_log10_pvalue": 0.4820470569928696,
"rsid": "rs5812225",
"chromosome": "15",
"type": "INDEL",
"alt": "C",
"position": 42514003,
"ac": 125.0,
"maf": 0.255952,
"variant": "chr15_42514003_CG_C",
"ref": "CG",
"pvalue": 0.329574,
"r2": 0.81564,
"an": 168.0,
"molecular_trait_id": "ENSG00000067369",
"gene_id": "ENSG00000067369",
"tissue": "CL_0000235"
}
}
},
"_links": {
"self": {
"href": "http://www.ebi.ac.uk/eqtl/api/genes/ENSG00000067369/associations?links=False"
},
"first": {
"href": "http://www.ebi.ac.uk/eqtl/api/genes/ENSG00000067369/associations?size=2&links=False&start=0"
},
"next": {
"href": "http://www.ebi.ac.uk/eqtl/api/genes/ENSG00000067369/associations?size=2&links=False&start=2"
}
}
}

Note that the API is paginated, so you'll need to specify the number of results to return on each page (the default is 20) and the link to the next page is returned in `_links.next.href`. There are more query parameters that you can tweak, such as `p_lower` and `p_upper`.

[1]: https://www.ebi.ac.uk/eqtl/
[2]: https://www.ebi.ac.uk/eqtl/api-docs/#get--eqtl-api-genes-(string-gene_id)-associations
[3]: http://www.ensembl.org/Homo_sapiens/Gene/Summary?db=core;g=ENSG00000067369;r=15:43403061-43510728