Allow specifying a run instead of just scanning the runfolder for it.
authorDiane Trout <diane@caltech.edu>
Mon, 30 Mar 2009 18:53:49 +0000 (18:53 +0000)
committerDiane Trout <diane@caltech.edu>
Mon, 30 Mar 2009 18:53:49 +0000 (18:53 +0000)
Also rework some of the command line options to group the commands
together, and to print helpful error messages when runfolder is being used
incorrectly.

htsworkflow/pipelines/runfolder.py
scripts/runfolder

index b8cbc56b1902aaf7b9d7f790b4dba71929c6d9c9..6b953ce2f53c65760458559fae9c8e2e491d8794 100644 (file)
@@ -214,6 +214,58 @@ def get_runs(runfolder):
 
     return runs
 
+def get_specific_run(gerald_dir):
+    """
+    Given a gerald directory, construct a PipelineRun out of its parents
+
+    Basically this allows specifying a particular run instead of the previous
+    get_runs which scans a runfolder for various combinations of
+    firecrest/ipar/bustard/gerald runs.
+    """
+    from htsworkflow.pipelines import firecrest
+    from htsworkflow.pipelines import ipar
+    from htsworkflow.pipelines import bustard
+    from htsworkflow.pipelines import gerald
+
+    bustard_dir = os.path.abspath(os.path.join(gerald_dir, '..'))
+    image_dir = os.path.abspath(os.path.join(gerald_dir, '..', '..'))
+
+    runfolder_dir = os.path.abspath(os.path.join(image_dir, '..','..'))
+   
+    logging.debug('--- use-run detected options ---')
+    logging.debug('runfolder: %s' % (runfolder_dir,))
+    logging.debug('image_dir: %s' % (image_dir,))
+    logging.debug('bustard_dir: %s' % (bustard_dir,))
+    logging.debug('gerald_dir: %s' % (gerald_dir,))
+
+    # find our processed image dir
+    image_run = firecrest.firecrest(image_dir)
+    if image_run is None:
+        image_run = ipar.ipar(image_dir)
+    if image_run is None:
+        msg = '%s does not contain an image processing step' % (image_dir,)
+        logging.error(msg)
+        return None
+
+    # find our base calling
+    base_calling_run = bustard.bustard(bustard_dir)
+    if base_calling_run is None:
+        logging.error('%s does not contain a bustard run' % (bustard_dir,))
+        return None
+
+    # find alignments
+    gerald_run = gerald.gerald(gerald_dir)
+    if gerald_run is None:
+        logging.error('%s does not contain a gerald run' % (gerald_dir,))
+        return None
+
+    p = PipelineRun(runfolder_dir)
+    p.image_analysis = image_run
+    p.bustard = base_calling_run
+    p.gerald = gerald_run
+    
+    logging.info('Constructed PipelineRun from %s' % (gerald_dir,))
+    return p
 
 def extract_run_parameters(runs):
     """
index bf5c5d884d2c931a6b96040a477b6bc0577ab30f..dcdaebefa1b64bd3cb174191bdfa11240cc22a52 100644 (file)
@@ -39,21 +39,34 @@ from htsworkflow.pipelines.runfolder import ElementTree
 def make_parser():
     usage = 'usage: %prog [options] runfolder_root_dir'
     parser = optparse.OptionParser(usage)
+
     parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
                       default=False,
                       help='turn on verbose mode')
-    parser.add_option('-s', '--summary', dest='summary', action='store_true',
-                      default=False,
-                      help='produce summary report')
-    parser.add_option('-a', '--archive', dest='archive', action='store_true',
-                      default=False,
-                      help='generate run configuration archive')
-    parser.add_option('--extract-results', action='store_true',
+    commands = optparse.OptionGroup(parser, 'Commands')
+
+    commands.add_option('-s', '--summary', dest='summary', action='store_true',
+                        default=False,
+                        help='produce summary report')
+    commands.add_option('-a', '--archive', dest='archive', action='store_true',
+                        default=False,
+                        help='generate run configuration archive')
+    commands.add_option('--extract-results', action='store_true',
            default=False,
-           help='extract result files out of runfolder into a simpler archive')
+           help='create run-xml summary, compress the eland result files, and '
+                'copy them and the Summary.htm file into archival directory.')
+    parser.add_option_group(commands)
+
     parser.add_option('-o', '--output-dir', default=None,
            help="specify the default output directory for extract results")
 
+    parser.add_option('-u', '--use-run', dest='use_run', default=None,
+                      help='Specify which run to use instead of autoscanning '
+                           'the runfolder. You do this by providing the final '
+                           ' GERALD directory, and it assumes the parent '
+                           'directories are the bustard and image processing '
+                           'directories.')
+                    
     parser.add_option('--run-xml', dest='run_xml',
            default=None,
            help='specify a run_<FlowCell>.xml file for summary reports')
@@ -77,18 +90,34 @@ def main(cmdlist=None):
         opt.run_xml = os.path.expanduser(opt.run_xml)
         tree = ElementTree.parse(opt.run_xml).getroot()
         runs.append(runfolder.PipelineRun(xml=tree))
+
+    # look for manually specified run
+    if opt.use_run is not None:
+        runs.append(runfolder.get_specific_run(opt.use_run))
+
+    # scan runfolders for runs
     for run_pattern in args:
         # expand args on our own if needed
         for run_dir in glob(run_pattern):
             runs.extend(runfolder.get_runs(run_dir))
 
     if len(runs) > 0:
+        command_run = False
         if opt.summary:
             print runfolder.summary_report(runs)
+            command_run = True
         if opt.archive:
             runfolder.extract_run_parameters(runs)
+            command_run = True
         if opt.extract_results:
             runfolder.extract_results(runs, opt.output_dir)
+            command_run = True
+        if command_run == False:
+            print "You need to specify a command."+os.linesep
+            parser.print_help()
+    else:
+        print "You need to specify some run folders to process..."+os.linesep
+        parser.print_help()
 
     return 0