#!/usr/bin/env python
import csv
-from ConfigParser import RawConfigParser
+from six.moves.configparser import RawConfigParser
import logging
from optparse import OptionParser, IndentedHelpFormatter
import os
import sys
import types
-import urllib
-import urllib2
+import six
+from six.moves import urllib
-try:
- import json
-except ImportError, e:
- import simplejson as json
+import json
-from htsworkflow.frontend.auth import apidata
+from htsworkflow.auth import apidata
from htsworkflow.util import api
-from htsworkflow.util import alphanum
+from htsworkflow.util.alphanum import natural_sort_key
from htsworkflow.util.url import normalize_url
from htsworkflow.pipelines.genome_mapper import \
getAvailableGenomes, \
constructMapperDict
-from htsworkflow.pipelines.runfolder import LANE_LIST
+from htsworkflow.pipelines import LANE_LIST
# JSON dictionaries use strings
LANE_LIST_JSON = [ str(l) for l in LANE_LIST ]
url = api.flowcell_url(base_host_url, flowcell)
try:
- apipayload = urllib.urlencode(apidata)
- web = urllib2.urlopen(url, apipayload)
- except urllib2.URLError, e:
+ apipayload = urllib.parse.urlencode(apidata)
+ web = urllib.request.urlopen(url, apipayload)
+ except urllib.error.HTTPError as e:
errmsg = 'URLError: %d %s' % (e.code, e.msg)
LOGGER.error(errmsg)
LOGGER.error('opened %s' % (url,))
config += ['Flowcell Notes:']
config.extend(flowcell_info['notes'].split('\r\n'))
config += ['']
- for lane_number in LANE_LIST_JSON:
+ for lane_number in sorted(flowcell_info['lane_set']):
lane_contents = flowcell_info['lane_set'][lane_number]
for lane_info in lane_contents:
config += ['Lane%s: %s | %s' % (lane_number,
'Operator': format_operator_name}
out = csv.DictWriter(outstream, sample_sheet_fields)
out.writerow(dict(((x,x) for x in sample_sheet_fields)))
- for lane_number in LANE_LIST:
- lane_contents = flowcell_info['lane_set'][str(lane_number)]
+ for lane_number in sorted(flowcell_info['lane_set']):
+ lane_contents = flowcell_info['lane_set'][lane_number]
pooled_lane_contents = []
for library in lane_contents:
sequences = library.get('index_sequence', None)
if sequences is None:
return []
- elif (type(sequences) in types.StringTypes and
- sequences.lower().startswith('err')):
+ elif isinstance(sequences, six.string_types):
shared['Index'] = ''
shared['SampleProject'] = library['library_id']
return [shared]
- elif (type(sequences) == types.DictType):
+ elif isinstance(sequences, dict):
pooled = []
- multiplex_ids = sequences.keys()
- multiplex_ids.sort(cmp=alphanum.alphanum)
+ multiplex_ids = sorted(sequences.keys(), key=natural_sort_key)
for multiplex_id in multiplex_ids:
sample = {}
sample.update(shared)