Created
March 3, 2016 13:33
-
-
Save GenDataPro/8bbb9fe1963ec9918ae9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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