import simplejson as json
from htsworkflow.frontend.auth import apidata
+from htsworkflow.util import api
from htsworkflow.util.url import normalize_url
from htsworkflow.pipelines.genome_mapper import getAvailableGenomes
from htsworkflow.pipelines.genome_mapper import constructMapperDict
"""
Return a dictionary describing a
"""
- url = base_host_url + '/experiments/config/%s/json' % (flowcell)
+ url = api.flowcell_url(base_host_url, flowcell)
try:
apipayload = urllib.urlencode(apidata)
--- /dev/null
+"""
+Common functions for accessing the HTS Workflow REST API
+
+"""
+# try to deal with python <2.6
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
+import urllib
+import urllib2
+import urlparse
+
+def library_url(root_url, library_id):
+ """
+ Return the url for retrieving information about a specific library.
+
+ Args:
+ library_id (str): the library id of interest
+ root_url (str): the root portion of the url, e.g. http://localhost
+
+ Returns:
+ str. The url to use for this REST api.
+
+ >>> print library_url('http://localhost', '12345')
+ http://localhost/samples/library/12345/json
+
+ """
+ url_fragment = '/samples/library/%s/json' % (library_id,)
+ url = urlparse.urljoin(root_url, url_fragment)
+
+ return url
+
+
+def flowcell_url(root_url, flowcell_id):
+ """
+ Return the url for retrieving information about a specific flowcell.
+
+ Args:
+ root_url (str): the root portion of the url, e.g. http://localhost
+ flowcell_id (str): the flowcell id of interest
+
+ Returns:
+ str. The url to use for this REST api.
+
+ >>> print flowcell_url('http://localhost', '1234AAXX')
+ http://localhost/experiments/config/1234AAXX/json
+ """
+ url_fragment = '/experiments/config/%s/json' % (flowcell_id,)
+ url = urlparse.urljoin(root_url, url_fragment)
+
+ return url
+
+
+def lanes_for_user_url(root_url, username):
+ """
+ Return the url for returning all the lanes associated with a username
+
+ Args:
+ username (str): a username in your target filesystem
+ root_url (str): the root portion of the url, e.g. http://localhost
+
+ Returns:
+ str. The url to use for this REST api.
+
+ >>> print lanes_for_user_url('http://localhost', 'diane')
+ http://localhost/lanes_for/diane/json
+
+ """
+ url_fragment = '/lanes_for/%s/json' % (username,)
+ url = urlparse.urljoin(root_url, url_fragment)
+
+ return url
+
+def retrieve_info(url, apidata):
+ """
+ Return a dictionary from the HTSworkflow API
+ """
+ try:
+ apipayload = urllib.urlencode(apidata)
+ web = urllib2.urlopen(url, apipayload)
+ except urllib2.URLError, e:
+ if e.code == 404:
+ logging.info("%s was not found" % (url,))
+ return None
+ else:
+ errmsg = 'URLError: %d %s' % (e.code, e.msg)
+ raise IOError(errmsg)
+
+ contents = web.read()
+ headers = web.info()
+
+ return json.loads(contents)
#!/usr/bin/env python
from ConfigParser import SafeConfigParser
-# try to deal with python <2.6
-try:
- import json
-except ImportError:
- import simplejson as json
import logging
import os
import stat
import re
import shelve
-import urllib
-import urllib2
-import urlparse
+
+from htsworkflow.util import api
eland_re = re.compile('s_(?P<lane>\d)(?P<read>_\d)?_eland_')
raw_seq_re = re.compile('woldlab_[0-9]{6}_[^_]+_[\d]+_[\dA-Z]+')
return sequences
-def retrieve_info(url, apidata):
- """
- Return a dictionary from the HTSworkflow API
- """
- try:
- apipayload = urllib.urlencode(apidata)
- web = urllib2.urlopen(url, apipayload)
- except urllib2.URLError, e:
- if e.code == 404:
- logging.info("%s was not found" % (url,))
- return None
- else:
- errmsg = 'URLError: %d %s' % (e.code, e.msg)
- raise IOError(errmsg)
-
- contents = web.read()
- headers = web.info()
-
- return json.loads(contents)
def build_flowcell_db(fcdb_filename, sequences, baseurl, apiid, apikey):
"""
# get info about flowcell from server or shelf
if not fcdb.has_key(flowcell):
- url = urlparse.urljoin(baseurl, 'experiments/config/%s/json' % (flowcell,))
- flowcell_info = retrieve_info(url, apidata)
+ url = api.flowcell_url(baseurl, flowcell)
+ flowcell_info = api.retrieve_info(url, apidata)
if flowcell_info is not None:
fcdb[flowcell] = flowcell_info
else:
if opts.sequence_archive is None and \
config_file.has_option(SECTION_NAME, ARCHIVE_OPT):
opts.sequence_archive = config_file.get(SECTION_NAME, ARCHIVE_OPT)
+ opts.sequence_archive = os.path.expanduser(opts.sequence_archive)
opts.sequence_archive = os.path.abspath(opts.sequence_archive)
opts.library_tree = os.path.join(opts.sequence_archive, 'libraries')