Skip to content

Instantly share code, notes, and snippets.

@GenDataPro
Created March 3, 2016 13:33
Show Gist options
  • Save GenDataPro/8bbb9fe1963ec9918ae9 to your computer and use it in GitHub Desktop.
Save GenDataPro/8bbb9fe1963ec9918ae9 to your computer and use it in GitHub Desktop.
import sys
import json
gene_id = "NCOR2"
response = requests.get("http://rest.ensembl.org/lookup/symbol/homo_sapiens/{}?content-type=application/json;expand=1".format(gene_id))
json_data = response.content.decode("utf-8")
data = json.loads(json_data)
numbers = []
#Enumerate provides item, and its position (idx) in the list
for idx, transcript in enumerate(data.get("Transcript", [])):
#get a default empty dictionary, and then if no id, print "No ID"
print transcript.get("Translation", {}).get("Parent") or "No ID",
print transcript.get("Translation", {}).get("id") or "No ID"
numbers.append(idx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment