Dynamically respond to the number of lanes.
[htsworkflow.git] / htsworkflow / pipelines / retrieve_config.py
index 42ff263d97d99e6f54a659b55b5d6dba0bf13fe2..29f49bb32f8c3914976326d3b3b329db0021357e 100644 (file)
@@ -17,6 +17,7 @@ except ImportError, e:
 
 from htsworkflow.frontend.auth import apidata
 from htsworkflow.util import api
+from htsworkflow.util import alphanum
 from htsworkflow.util.url import normalize_url
 from htsworkflow.pipelines.genome_mapper import \
      getAvailableGenomes, \
@@ -110,7 +111,7 @@ def format_gerald_header(flowcell_info):
     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,
@@ -322,15 +323,15 @@ def saveConfigFile(options):
   genome_map = constructMapperDict(available_genomes)
   LOGGER.debug('available genomes: %s' % ( unicode( genome_map.keys() ),))
 
-  #config = format_gerald_config(options, flowcell_info, genome_map)
-  #
-  #if options.output_filepath is not None:
-  #    outstream = open(options.output_filepath, 'w')
-  #    LOGGER.info('Writing config file to %s' % (options.output_filepath,))
-  #else:
-  #    outstream = sys.stdout
-  #
-  #outstream.write(config)
+  config = format_gerald_config(options, flowcell_info, genome_map)
+
+  if options.output_filepath is not None:
+      outstream = open(options.output_filepath, 'w')
+      logging.info('Writing config file to %s' % (options.output_filepath,))
+  else:
+      outstream = sys.stdout
+
+  outstream.write(config)
 
   if options.sample_sheet is None:
       pass
@@ -355,8 +356,8 @@ def save_sample_sheet(outstream, options, flowcell_info):
                             '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:
@@ -410,7 +411,7 @@ def format_pooled_libraries(shared, library):
     elif (type(sequences) == types.DictType):
         pooled = []
         multiplex_ids = sequences.keys()
-        multiplex_ids.sort(key=int)
+        multiplex_ids.sort(cmp=alphanum.alphanum)
         for multiplex_id in multiplex_ids:
             sample = {}
             sample.update(shared)