comparison util.py @ 14:a38315ecf593 draft

planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
author stevecassidy
date Wed, 01 Nov 2017 01:18:15 -0400
parents
children 5e1b7d922ea3
comparison
equal deleted inserted replaced
13:be3fd14899a1 14:a38315ecf593
1 """
2 Utility functions and settings for API tools
3 """
4 import pyalveo
5 import csv
6
7 # this should be in a config file
8 API_URL = 'https://app.alveo.edu.au'
9
10
11 def write_key(api_key, output_path, client_module=pyalveo):
12 """Tests whether an API key is valid and writes it to a file.
13
14 :type api_key: String
15 :param api_key: Alveo API key
16
17 :type output_path: String
18 :param output_path: Path to the file to store the API key in
19
20 :type client_module: pyalveo.Client
21 :param client_module: Module providing the client (used for testing purposes),
22 defaults to pyalveo
23
24 :raises: pyalveo.APIError if the API request is not successful
25
26 """
27 # validate the client key, raises an exception if it is not valid
28 client_module.Client(api_key, API_URL, use_cache=False)
29 outfile = open(output_path, 'w')
30 outfile.write(api_key)
31 outfile.close()
32
33
34 def get_item_lists(api_key):
35 client = pyalveo.Client(api_key=api_key, api_url=API_URL, use_cache=False)
36 return client.get_item_lists()
37
38
39 def read_item_list(filename, client):
40 """Read an item list from a file
41 which should be a tabular formatted file
42 with one column header ItemURL.
43 Return an instance of ItemGroup"""
44
45 with open(filename) as fd:
46 csvreader = csv.DictReader(fd, dialect='excel-tab')
47 if 'ItemURL' not in csvreader.fieldnames:
48 return None
49 itemurls = []
50 for row in csvreader:
51 itemurls.append(row['ItemURL'])
52
53 itemlist = pyalveo.ItemGroup(itemurls, client)
54
55 return itemlist