Snippets

Adam Labadorf Fetch ensembl gene info

Created by Adam Labadorf
import json
import os
import requests
import shelve
def ensembl(g) :
  with shelve.open("ensembl_shelf") as db :
      if g in db :
        return db[g]

      r = requests.get("http://rest.ensembl.org/lookup/id/{}?content-type=application/json;expand=1".format(g))
      t = r.text
      j = json.loads(t)
      j["description"] = re.sub(r' \[.*\]','',j.get("description","no description"))
      j.pop("Transcript",None)
      db[g] = je
      return j

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.