Improve code to extract runfolder name from the path to the runfolder.
[htsworkflow.git] / scripts / configure_pipeline
index b491a38eeee3e46768820ce761cdd259d17ac1ee..6c94b914db834f1dcb5eb2d034591ed4ed19cb74 100644 (file)
@@ -1,21 +1,64 @@
 #!/usr/bin/env python
+import os
 import sys
+import re
 from gaworkflow.pipeline.configure_run import *
+from gaworkflow.pipeline import retrieve_config as _rc
+from gaworkflow.pipeline.run_status import startCmdLineStatusMonitor
+
+logging.basicConfig(level=logging.DEBUG,
+                    format='%(asctime)s %(levelname)-8s %(message)s',
+                    datefmt='%a, %d %b %Y %H:%M:%S',
+                    #filename='pipeline_main.log',
+                    filemode='w')
+
+s_fc = re.compile('FC[0-9]+')
+
+#Turn on built-in command-line parsing.
+_rc.DISABLE_CMDLINE = False
+
+GENOME_DIR = '/data-store01/compbio/genomes/'
+
+
 
 def main(args=None):
   ci = ConfigInfo()
+  ci.analysis_dir = os.getcwd()
+  ci.base_analysis_dir, junk = os.path.split(ci.analysis_dir)
 
-  flowcell = 'FC12150'
-  cfg_filepath = 'config32auto.txt'
-  genome_dir = '/home/king/trog_drive/'
+  #FIXME: make a better command line tool
+  skip_retrieve_config = False
+  if len(args) == 1:
+    arg = args[0]
 
-  status_retrieve_cfg = retrieve_config(ci, flowcell, cfg_filepath, genome_dir)
-  if status_retrieve_cfg:
-    print "Retrieve config file successful"
+    #If FC##### found
+    if s_fc.search(arg):
+      cfg_filepath = os.path.abspath('config32auto.txt')
+      flowcell = arg
+    #else, config file provide
+    else:
+      cfg_filepath = os.path.abspath(args[0])
+      skip_retrieve_config = True
   else:
-    print "Failed to retrieve config file"
-  #ci.config_filepath = 'config32bk.txt'
+    print "usage:\n" \
+          "       configure_pipeline FC#####\n" \
+          " or:\n" \
+          "       configure_pipeline <conf_filepath>\n"
+    return 3
+
+  genome_dir = GENOME_DIR
 
+  if not skip_retrieve_config:
+    status_retrieve_cfg = retrieve_config(ci, flowcell, cfg_filepath, genome_dir)
+    if status_retrieve_cfg:
+      print "Retrieve config file successful"
+    else:
+      print "Failed to retrieve config file"
+  else:
+    print "Config file %s provided from command-line" % (cfg_filepath)
+    ci.config_filepath = cfg_filepath
+    status_retrieve_cfg = True
+  
   if status_retrieve_cfg:
     status = configure(ci)
     if status:
@@ -27,6 +70,9 @@ def main(args=None):
     print 'Bustard Dir:', ci.bustard_path
     
     if status:
+      # Setup status cmdline status monitor
+      startCmdLineStatusMonitor(ci)
+      
       print 'Running pipeline now!'
       run_status = run_pipeline(ci)
       if run_status is True: