Skip to content

Instantly share code, notes, and snippets.

@GenDataPro
Created March 9, 2016 13:32
Show Gist options
  • Save GenDataPro/b04979e0ccb9a33d13e9 to your computer and use it in GitHub Desktop.
Save GenDataPro/b04979e0ccb9a33d13e9 to your computer and use it in GitHub Desktop.
import requests
import sys
import json
#gene_id = [line.strip() for line in open("C:/name/MyDocuments/numbers", 'r')]
gene_id = ["ENSG00000196498", "ENSG00000157764", "ENSG00000139618", "ENSMUSG00000041147"]
for gene in gene_id:
new_gene = gene
response = requests.get("http://rest.ensembl.org/lookup/id/{}?content-type=application/json".format(new_gene))
json_data = response.content.decode("utf-8")
data = json.loads(json_data)
print data['id'], data['display_name'], data['species']
@ladyrassilon
Copy link

I'd do #14
print data.get('id', 'not found'), data.get('display_name', 'not found'), data.get('species', 'not found')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment