-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
46 lines (30 loc) · 975 Bytes
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import json
import requests
def do_request(url, token, **kwargs):
"""Perform a request to SITE and return response."""
headers = {"Authorization": "Bearer %s" % token}
response = requests.get(url, headers=headers, params=kwargs)
# Raise exception and abort if requests is not successful
response.raise_for_status()
try:
# Try to convert result to JSON
# abort if not possible
return response.json()
except ValueError:
raise Exception('not a JSON object: {}'.format(response.text))
def send_to_jbrowse(data):
"""Display `data` in the format required by JBrowse.
"""
return json.dumps(data)
def send_list(data):
"""Display `data` in the format required by Adama.
:type data: list
"""
for elt in data:
print json.dumps(elt)
print '---'
def send(data):
"""Display `data` in the format required by Adama.
"""
print json.dumps(data)
print '---'