Mercurial > repos > earlhaminst > ensembl_get_genetree
comparison get_feature_info/get_feature_info.py @ 0:f0018341e9f6 draft
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/Ensembl-REST commit e80af91bced56efdb4fbf62ac03232655a22f25d-dirty
author | earlhaminst |
---|---|
date | Thu, 11 Aug 2016 14:29:07 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0018341e9f6 |
---|---|
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 |