Mercurial > repos > earlhaminst > ensembl_get_genetree
comparison get_feature_info.py @ 1:98aba0efe77a draft
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/Ensembl-REST commit aaf8d501c3a92ed415fdf9293a65468c72aae984-dirty
| author | earlhaminst |
|---|---|
| date | Mon, 12 Dec 2016 07:47:26 -0500 |
| parents | |
| children | 950d9d11b6fb |
comparison
equal
deleted
inserted
replaced
| 0:f0018341e9f6 | 1:98aba0efe77a |
|---|---|
| 1 # A simple tool to connect to the Ensembl server and retrieve feature | |
| 2 # information using the Ensembl REST API. | |
| 3 import json | |
| 4 import optparse | |
| 5 from urlparse import urljoin | |
| 6 | |
| 7 import requests | |
| 8 | |
| 9 parser = optparse.OptionParser() | |
| 10 parser.add_option('-i', '--input', help='List of Ensembl IDs') | |
| 11 parser.add_option('-e', '--expand', type='choice', choices=['0', '1'], | |
| 12 default='0', | |
| 13 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.') | |
| 14 | |
| 15 parser.add_option('-s', '--species', type='choice', | |
| 16 choices=['ensembl', 'ensemblgenomes'], default='ensembl', | |
| 17 help='Specify the genome databases for vertebrates and other eukaryotic species') | |
| 18 | |
| 19 parser.add_option('-f', '--format', type='choice', | |
| 20 choices=['full', 'condensed'], default='full', | |
| 21 help='Specify the formats to emit from this endpoint') | |
| 22 options, args = parser.parse_args() | |
| 23 if options.input is None: | |
| 24 raise Exception('-i option must be specified') | |
| 25 | |
| 26 | |
| 27 server = 'http://rest.%s.org' % options.species | |
| 28 ext = 'lookup/id' | |
| 29 | |
| 30 headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} | |
| 31 params = dict((k, getattr(options, k)) for k in ['format', 'expand']) | |
| 32 with open(options.input) as f: | |
| 33 ids = [line.strip() for line in f] | |
| 34 data = {'ids': ids} | |
| 35 r = requests.post(urljoin(server, ext), params=params, headers=headers, | |
| 36 data=json.dumps(data)) | |
| 37 | |
| 38 if not r.ok: | |
| 39 r.raise_for_status() | |
| 40 | |
| 41 print r.text |
