Mercurial > repos > earlhaminst > ensembl_get_genetree
view get_feature_info.py @ 3:181e12d6ac96 draft
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/Ensembl-REST commit f5c5f3d6ce676937f5c673ec7fc0631a9f490dc2
author | earlhaminst |
---|---|
date | Fri, 24 Mar 2017 11:57:35 -0400 |
parents | 950d9d11b6fb |
children | 0602dcf02768 |
line wrap: on
line source
# A simple tool to connect to the Ensembl server and retrieve feature # information using the Ensembl REST API. from __future__ import print_function import json import optparse import requests from six.moves.urllib.parse import urljoin parser = optparse.OptionParser() parser.add_option('-i', '--input', help='List of Ensembl IDs') parser.add_option('-e', '--expand', type='choice', choices=['0', '1'], default='0', help='Expands the search to include any connected features. e.g. If the object is a gene, its transcripts, translations and exons will be returned as well.') parser.add_option('-s', '--species', type='choice', choices=['ensembl', 'ensemblgenomes'], default='ensembl', help='Specify the genome databases for vertebrates and other eukaryotic species') parser.add_option('-f', '--format', type='choice', choices=['full', 'condensed'], default='full', help='Specify the formats to emit from this endpoint') options, args = parser.parse_args() if options.input is None: raise Exception('-i option must be specified') server = 'http://rest.%s.org' % options.species ext = 'lookup/id' headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} params = dict((k, getattr(options, k)) for k in ['format', 'expand']) with open(options.input) as f: ids = [line.strip() for line in f] data = {'ids': ids} r = requests.post(urljoin(server, ext), params=params, headers=headers, data=json.dumps(data)) if not r.ok: r.raise_for_status() print(r.text)