2 Common functions for accessing the HTS Workflow REST API
7 # try to deal with python <2.6
11 import simplejson as json
17 def library_url(root_url, library_id):
19 Return the url for retrieving information about a specific library.
22 library_id (str): the library id of interest
23 root_url (str): the root portion of the url, e.g. http://localhost
26 str. The url to use for this REST api.
28 >>> print library_url('http://localhost', '12345')
29 http://localhost/samples/library/12345/json
32 url_fragment = '/samples/library/%s/json' % (library_id,)
33 url = urlparse.urljoin(root_url, url_fragment)
38 def flowcell_url(root_url, flowcell_id):
40 Return the url for retrieving information about a specific flowcell.
43 root_url (str): the root portion of the url, e.g. http://localhost
44 flowcell_id (str): the flowcell id of interest
47 str. The url to use for this REST api.
49 >>> print flowcell_url('http://localhost', '1234AAXX')
50 http://localhost/experiments/config/1234AAXX/json
52 url_fragment = '/experiments/config/%s/json' % (flowcell_id,)
53 url = urlparse.urljoin(root_url, url_fragment)
58 def lanes_for_user_url(root_url, username):
60 Return the url for returning all the lanes associated with a username
63 username (str): a username in your target filesystem
64 root_url (str): the root portion of the url, e.g. http://localhost
67 str. The url to use for this REST api.
69 >>> print lanes_for_user_url('http://localhost', 'diane')
70 http://localhost/lanes_for/diane/json
73 url_fragment = '/lanes_for/%s/json' % (username,)
74 url = urlparse.urljoin(root_url, url_fragment)
78 def retrieve_info(url, apidata):
80 Return a dictionary from the HTSworkflow API
83 apipayload = urllib.urlencode(apidata)
84 web = urllib2.urlopen(url, apipayload)
85 except urllib2.URLError, e:
86 if hasattr(e, 'code') and e.code == 404:
87 logging.info("%s was not found" % (url,))
90 errmsg = 'URLError: %s' % (str(e))
96 return json.loads(contents)