[project @ Bypass pipe lock mystery bug for configure step]
[htsworkflow.git] / gaworkflow / pipeline / configure_run.py
index 34fd3c598469191b2b7e825adb833ff722fadf80..448576d1ec5b846d3374a89461b06b330605b0f5 100644 (file)
@@ -126,6 +126,9 @@ s_stderr_taskcomplete = re.compile('^Task complete, exiting')
 s_invalid_cmdline = re.compile('Usage:[\S\s]*goat_pipeline.py')
 s_species_dir_err = re.compile('Error: Lane [1-8]:')
 s_goat_traceb = re.compile("^Traceback \(most recent call last\):")
+s_missing_cycles = re.compile('^Error: Tile s_[1-8]_[0-9]+: Different number of cycles: [0-9]+ instead of [0-9]+')
+
+SUPPRESS_MISSING_CYCLES = False
 
 
 ##Ignore - Example of out above each ignore regex.
@@ -260,6 +263,7 @@ def config_stderr_handler(line, conf_info):
           False if neutral message
             (i.e. doesn't signify failure or success)
   """
+  global SUPPRESS_MISSING_CYCLES
 
   # Detect invalid species directory error
   if s_species_dir_err.search(line):
@@ -273,6 +277,16 @@ def config_stderr_handler(line, conf_info):
   elif s_stderr_taskcomplete.search(line):
     logging.info('Configure step successful (from: stderr)')
     return True
+  # Detect missing cycles
+  elif s_missing_cycles.search(line):
+
+    # Only display error once
+    if not SUPPRESS_MISSING_CYCLES:
+      logging.error("Missing cycles detected; Not all cycles copied?")
+      logging.debug("CONF:STDERR:MISSING_CYCLES: %s" % (line))
+      SUPPRESS_MISSING_CYCLES = True
+    return RUN_ABORT
+  
   # Log all other output as debug output
   else:
     logging.debug('CONF:STDERR:?: %s' % (line))
@@ -422,33 +436,54 @@ def configure(conf_info):
 
   # CONTINUE HERE
   #FIXME: this only does a run on 5 tiles on lane 4
+
+  stdout_filepath = "pipeline_configure_stdout.txt"
+  stderr_filepath = "pipeline_configure_stderr.txt"
+
+  fout = open(stdout_filepath, 'w')
+  ferr = open(stderr_filepath, 'w')
+  
   pipe = subprocess.Popen(['goat_pipeline.py',
                     '--GERALD=%s' % (conf_info.config_filepath),
-                           '--tiles=s_4_0100,s_4_0101,s_4_0102,s_4_0103,s_4_0104',
+                           #'--tiles=s_4_0100,s_4_0101,s_4_0102,s_4_0103,s_4_0104',
                            '--make',
                            '.'],
-                          stdout=subprocess.PIPE,
-                          stderr=subprocess.PIPE)
+                          stdout=fout,
+                          stderr=ferr)
+
+  print "Configuring pipeline: %s" % (time.ctime())
+  error_code = pipe.wait()
+
+  # Clean up
+  fout.close()
+  ferr.close()
+  
+  
   ##################
   # Process stdout
-  stdout_line = pipe.stdout.readline()
+  fout = open(stdout_filepath, 'r')
+  
+  stdout_line = fout.readline()
 
   complete = False
   while stdout_line != '':
     # Handle stdout
     if config_stdout_handler(stdout_line, conf_info):
       complete = True
-    stdout_line = pipe.stdout.readline()
+    stdout_line = fout.readline()
 
+  fout.close()
 
-  error_code = pipe.wait()
+
+  #error_code = pipe.wait()
   if error_code:
     logging.error('Recieved error_code: %s' % (error_code))
   else:
     logging.info('We are go for launch!')
 
   #Process stderr
-  stderr_line = pipe.stderr.readline()
+  ferr = open(stderr_filepath, 'r')
+  stderr_line = ferr.readline()
 
   abort = 'NO!'
   stderr_success = False
@@ -458,7 +493,9 @@ def configure(conf_info):
       abort = RUN_ABORT
     elif stderr_status is True:
       stderr_success = True
-    stderr_line = pipe.stderr.readline()
+    stderr_line = ferr.readline()
+
+  ferr.close()
 
 
   #Success requirements: