Mercurial > repos > earlhaminst > ensembl_get_genetree
comparison get_feature_info.py @ 4:0602dcf02768 draft
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/Ensembl-REST commit 95bab1105cf8a7b07c668f08f712399e8775a4ae
| author | earlhaminst |
|---|---|
| date | Fri, 13 Apr 2018 09:43:28 -0400 |
| parents | 950d9d11b6fb |
| children | 675fd774314e |
comparison
equal
deleted
inserted
replaced
| 3:181e12d6ac96 | 4:0602dcf02768 |
|---|---|
| 2 # information using the Ensembl REST API. | 2 # information using the Ensembl REST API. |
| 3 from __future__ import print_function | 3 from __future__ import print_function |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import optparse | 6 import optparse |
| 7 from itertools import islice | |
| 7 | 8 |
| 8 import requests | 9 import requests |
| 9 from six.moves.urllib.parse import urljoin | 10 from six.moves.urllib.parse import urljoin |
| 10 | 11 |
| 11 parser = optparse.OptionParser() | 12 parser = optparse.OptionParser() |
| 29 server = 'http://rest.%s.org' % options.species | 30 server = 'http://rest.%s.org' % options.species |
| 30 ext = 'lookup/id' | 31 ext = 'lookup/id' |
| 31 | 32 |
| 32 headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} | 33 headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} |
| 33 params = dict((k, getattr(options, k)) for k in ['format', 'expand']) | 34 params = dict((k, getattr(options, k)) for k in ['format', 'expand']) |
| 35 | |
| 36 first = True | |
| 37 | |
| 38 print('{') | |
| 39 | |
| 34 with open(options.input) as f: | 40 with open(options.input) as f: |
| 35 ids = [line.strip() for line in f] | 41 while True: |
| 36 data = {'ids': ids} | 42 ids = [line.strip() for line in islice(f, 50)] |
| 37 r = requests.post(urljoin(server, ext), params=params, headers=headers, | 43 if not ids: |
| 38 data=json.dumps(data)) | 44 break |
| 45 if not first: | |
| 46 print(",") | |
| 47 data = {'ids': ids} | |
| 48 r = requests.post(urljoin(server, ext), params=params, headers=headers, | |
| 49 data=json.dumps(data)) | |
| 39 | 50 |
| 40 if not r.ok: | 51 if not r.ok: |
| 41 r.raise_for_status() | 52 r.raise_for_status() |
| 42 | 53 |
| 43 print(r.text) | 54 print(r.text[1:-1]) |
| 55 | |
| 56 first = False | |
| 57 | |
| 58 print('}') |
