2 Common functions for accessing the HTS Workflow REST API
5 # try to deal with python <2.6
9 import simplejson as json
15 def library_url(root_url, library_id):
17 Return the url for retrieving information about a specific library.
20 library_id (str): the library id of interest
21 root_url (str): the root portion of the url, e.g. http://localhost
24 str. The url to use for this REST api.
26 >>> print library_url('http://localhost', '12345')
27 http://localhost/samples/library/12345/json
30 url_fragment = '/samples/library/%s/json' % (library_id,)
31 url = urlparse.urljoin(root_url, url_fragment)
36 def flowcell_url(root_url, flowcell_id):
38 Return the url for retrieving information about a specific flowcell.
41 root_url (str): the root portion of the url, e.g. http://localhost
42 flowcell_id (str): the flowcell id of interest
45 str. The url to use for this REST api.
47 >>> print flowcell_url('http://localhost', '1234AAXX')
48 http://localhost/experiments/config/1234AAXX/json
50 url_fragment = '/experiments/config/%s/json' % (flowcell_id,)
51 url = urlparse.urljoin(root_url, url_fragment)
56 def lanes_for_user_url(root_url, username):
58 Return the url for returning all the lanes associated with a username
61 username (str): a username in your target filesystem
62 root_url (str): the root portion of the url, e.g. http://localhost
65 str. The url to use for this REST api.
67 >>> print lanes_for_user_url('http://localhost', 'diane')
68 http://localhost/lanes_for/diane/json
71 url_fragment = '/lanes_for/%s/json' % (username,)
72 url = urlparse.urljoin(root_url, url_fragment)
76 def retrieve_info(url, apidata):
78 Return a dictionary from the HTSworkflow API
81 apipayload = urllib.urlencode(apidata)
82 web = urllib2.urlopen(url, apipayload)
83 except urllib2.URLError, e:
85 logging.info("%s was not found" % (url,))
88 errmsg = 'URLError: %d %s' % (e.code, e.msg)
94 return json.loads(contents)