I'd like to query a JSON output for VEP using the REST API. I have the following code in python 3, can anyone tell me where I'm going wrong? I'm getting a HTTP 400 error.
import json
import requests
import sys
enter code here`with open('sample.tsv','r') as file:
for line in file:
if line.startswith("rs"):
snps = line.split()[0]
for i in snps :
server = "https://rest.ensembl.org"
ext = "/vep/human/id"
headers = { "Content-Type" : "application/json", "Accept" : "application/json"}
r = requests.post(server+ext, headers=headers, data='{ "ids" : [i] }')
if not r.ok:
r.raise_for_status()
sys.exit()
decoded = r.json()
print(repr(decoded))
This is pretty basic, I just want to get multiple outputs at the same time, instead of one by one. Any suggestions?
I wouldn't mind doing it using R either, if that's a good alternative. Thanks!
can you please print i here? what are you querying?
rs2329763 rs6716521 rs4686605 rs9290916 rs7622109 rs16877127 rs160885 rs16908004 rs622120 rs970275 . . 1000 rows more
output:
input:
One question, do you have a good way of parsing or formatting the JSON output ? Right now I'm outputting everything into a text file.
Sure. What kind of output are you expecting?
All fields into a tsv or a csv format preferably. Something that's easy to read. Right now it's a mess when outputting into a text file directly.
I dump json file and then I use jq (standalone) offline for parsing output from Ensembl. I generally catch g,c, p syntax and calculated effect. But I do know there are enough json libraries in all languages, that can parse the way you want.
Please can you indent your script properly so that other people can run it.