9 logging.basicConfig(level=logging.DEBUG,
10 format='%(asctime)s %(levelname)-8s %(message)s',
11 datefmt='%a, %d %b %Y %H:%M:%S',
12 filename='config_pipeline.log',
19 self.bustard_path = None
20 self.config_filepath = None
27 #####################################
28 # Configure Step (goat_pipeline.py)
30 s_start = re.compile('Starting Genome Analyzer Pipeline')
31 s_gerald = re.compile("[\S\s]+--GERALD[\S\s]+--make[\S\s]+")
32 s_generating = re.compile('Generating journals, Makefiles and parameter files')
33 s_seq_folder = re.compile('^Sequence folder: ')
34 s_seq_folder_sub = re.compile('want to make ')
35 s_stderr_taskcomplete = re.compile('^Task complete, exiting')
38 s_invalid_cmdline = re.compile('Usage:[\S\s]*goat_pipeline.py')
39 s_species_dir_err = re.compile('Error: Lane [1-8]:')
40 s_goat_traceb = re.compile("^Traceback \(most recent call last\):")
44 s_skip = re.compile('s_[0-8]_[0-9]+')
46 ##########################################
47 # Pipeline Run Step (make -j8 recursive)
53 s_make_error = re.compile('^make[\S\s]+Error')
54 s_no_gnuplot = re.compile('gnuplot: command not found')
55 s_no_convert = re.compile('^Can\'t exec "convert"')
58 PL_STDERR_IGNORE_LIST = []
60 PL_STDERR_IGNORE_LIST.append( re.compile('^Info: PF') )
61 # About to analyse intensity file s_4_0101_sig2.txt
62 PL_STDERR_IGNORE_LIST.append( re.compile('^About to analyse intensity file') )
63 # Will send output to standard output
64 PL_STDERR_IGNORE_LIST.append( re.compile('^Will send output to standard output') )
65 # Found 31877 clusters
66 PL_STDERR_IGNORE_LIST.append( re.compile('^Found [0-9]+ clusters') )
67 # Will use quality criterion ((CHASTITY>=0.6)
68 PL_STDERR_IGNORE_LIST.append( re.compile('^Will use quality criterion') )
69 # Quality criterion translated to (($F[5]>=0.6))
70 PL_STDERR_IGNORE_LIST.append( re.compile('^Quality criterion translated to') )
71 # opened /woldlab/trog/data1/king/070924_USI-EAS44_0022_FC12150/Data/C1-36_Firecrest1.9.1_14-11-2007_king.4/Bustard1.9.1_14-11-2007_king/s_4_0101_qhg.txt
73 # opened s_4_0103_qhg.txt
74 PL_STDERR_IGNORE_LIST.append( re.compile('^opened[\S\s]+qhg.txt') )
77 def pl_stderr_ignore(line):
79 Searches lines for lines to ignore (i.e. not to log)
81 returns True if line should be ignored
82 returns False if line should NOT be ignored
84 for s in PL_STDERR_IGNORE_LIST:
90 def config_stdout_handler(line, conf_info):
92 Processes each line of output from GOAT
93 and stores useful information using the logging module
95 Loads useful information into conf_info as well, for future
96 use outside the function.
98 returns True if found condition that signifies success.
101 # Skip irrelevant line (without logging)
102 if s_skip.search(line):
105 # Detect invalid command-line arguments
106 elif s_invalid_cmdline.search(line):
107 logging.error("Invalid commandline options!")
109 # Detect starting of configuration
110 elif s_start.search(line):
111 logging.info('START: Configuring pipeline')
113 # Detect it made it past invalid arguments
114 elif s_gerald.search(line):
115 logging.info('Running make now')
117 # Detect that make files have been generated (based on output)
118 elif s_generating.search(line):
119 logging.info('Make files generted')
122 # Capture run directory
123 elif s_seq_folder.search(line):
124 mo = s_seq_folder_sub.search(line)
125 #Output changed when using --tiles=<tiles>
126 # at least in pipeline v0.3.0b2
128 firecrest_bustard_gerald_makefile = line[mo.end():]
129 firecrest_bustard_gerald, junk = \
130 os.path.split(firecrest_bustard_gerald_makefile)
131 firecrest_bustard, junk = os.path.split(firecrest_bustard_gerald)
132 firecrest, junk = os.path.split(firecrest_bustard)
134 conf_info.bustard_path = firecrest_bustard
135 conf_info.run_path = firecrest
137 #Standard output handling
139 print 'Sequence line:', line
140 mo = s_seq_folder.search(line)
141 conf_info.bustard_path = line[mo.end():]
142 conf_info.run_path, temp = os.path.split(conf_info.bustard_path)
144 # Log all other output for debugging purposes
146 logging.warning('CONF:?: %s' % (line))
152 def config_stderr_handler(line, conf_info):
154 Processes each line of output from GOAT
155 and stores useful information using the logging module
157 Loads useful information into conf_info as well, for future
158 use outside the function.
160 returns RUN_ABORT upon detecting failure;
161 True on success message;
162 False if neutral message
163 (i.e. doesn't signify failure or success)
166 # Detect invalid species directory error
167 if s_species_dir_err.search(line):
170 # Detect goat_pipeline.py traceback
171 elif s_goat_traceb.search(line):
172 logging.error("Goat config script died, traceback in debug output")
174 # Detect indication of successful configuration (from stderr; odd, but ok)
175 elif s_stderr_taskcomplete.search(line):
176 logging.info('Configure step successful (from: stderr)')
178 # Log all other output as debug output
180 logging.debug('CONF:STDERR:?: %s' % (line))
182 # Neutral (not failure; nor success)
186 #FIXME: Temperary hack
187 f = open('pipeline_run.log.1', 'w')
188 #ferr = open('pipeline_err.log.1', 'w')
192 def pipeline_stdout_handler(line, conf_info):
194 Processes each line of output from running the pipeline
195 and stores useful information using the logging module
197 Loads useful information into conf_info as well, for future
198 use outside the function.
200 returns True if found condition that signifies success.
209 def pipeline_stderr_handler(line, conf_info):
213 if pl_stderr_ignore(line):
215 elif s_make_error.search(line):
216 logging.error("make error detected; run failed")
218 elif s_no_gnuplot.search(line):
219 logging.error("gnuplot not found")
221 elif s_no_convert.search(line):
222 logging.error("imagemagick's convert command not found")
225 logging.debug('PIPE:STDERR:?: %s' % (line))
230 def configure(conf_info):
232 Attempts to configure the GA pipeline using goat.
234 Uses logging module to store information about status.
236 returns True if configuration successful, otherwise False.
239 #pipe = subprocess.Popen(['goat_pipeline.py',
240 # '--GERALD=config32bk.txt',
243 # stdout=subprocess.PIPE,
244 # stderr=subprocess.PIPE)
246 #ERROR Test (2), causes goat_pipeline.py traceback
247 #pipe = subprocess.Popen(['goat_pipeline.py',
248 # '--GERALD=%s' % (conf_info.config_filepath),
249 # '--tiles=s_4_100,s_4_101,s_4_102,s_4_103,s_4_104',
252 # stdout=subprocess.PIPE,
253 # stderr=subprocess.PIPE)
255 ##########################
256 # Run configuration step
257 # Not a test; actual configure attempt.
258 #pipe = subprocess.Popen(['goat_pipeline.py',
259 # '--GERALD=%s' % (conf_info.config_filepath),
262 # stdout=subprocess.PIPE,
263 # stderr=subprocess.PIPE)
266 #FIXME: this only does a run on 5 tiles on lane 4
267 pipe = subprocess.Popen(['goat_pipeline.py',
268 '--GERALD=%s' % (conf_info.config_filepath),
269 '--tiles=s_4_0100,s_4_0101,s_4_0102,s_4_0103,s_4_0104',
272 stdout=subprocess.PIPE,
273 stderr=subprocess.PIPE)
276 stdout_line = pipe.stdout.readline()
279 while stdout_line != '':
281 if config_stdout_handler(stdout_line, conf_info):
283 stdout_line = pipe.stdout.readline()
286 error_code = pipe.wait()
288 logging.error('Recieved error_code: %s' % (error_code))
290 logging.info('We are go for launch!')
293 stderr_line = pipe.stderr.readline()
296 stderr_success = False
297 while stderr_line != '':
298 stderr_status = config_stderr_handler(stderr_line, conf_info)
299 if stderr_status == RUN_ABORT:
301 elif stderr_status is True:
302 stderr_success = True
303 stderr_line = pipe.stderr.readline()
306 #Success requirements:
307 # 1) The stdout completed without error
308 # 2) The program exited with status 0
309 # 3) No errors found in stdout
310 print '#Expect: True, False, True, True'
311 print complete, bool(error_code), abort != RUN_ABORT, stderr_success is True
312 status = complete is True and \
313 bool(error_code) is False and \
314 abort != RUN_ABORT and \
315 stderr_success is True
317 # If everything was successful, but for some reason
318 # we didn't retrieve the path info, log it.
320 if conf_info.bustard_path is None or conf_info.run_path is None:
321 logging.error("Failed to retrieve run_path")
327 def run_pipeline(conf_info):
329 Run the pipeline and monitor status.
331 # Fail if the run_path doesn't actually exist
332 if not os.path.exists(conf_info.run_path):
333 logging.error('Run path does not exist: %s' \
334 % (conf_info.run_path))
337 # Change cwd to run_path
338 os.chdir(conf_info.run_path)
340 # Log pipeline starting
341 logging.info('STARTING PIPELINE @ %s' % (time.ctime()))
343 # Start the pipeline (and hide!)
344 pipe = subprocess.Popen(['make',
347 stdout=subprocess.PIPE,
348 stderr=subprocess.PIPE)
350 line = pipe.stdout.readline()
354 if pipeline_stdout_handler(line, conf_info):
356 line = pipe.stdout.readline()
358 error_code = pipe.wait()
360 #ferr.write(pipe.stderr.read())
363 stderr_line = pipe.stderr.readline()
367 while stderr_line != '':
368 stderr_status = pipeline_stderr_handler(stderr_line, conf_info)
369 if stderr_status is True:
371 if stderr_status == RUN_FAILED:
373 stderr_line = pipe.stderr.readline()
376 print 'RUN STATUS: expect: True, True, True, True'
378 print complete is True, error_code == 0,
379 print run_succeded is True, run_failed is False
382 status = complete is True and \
383 error_code == 0 and \
384 run_succeded is True and \
391 if __name__ == '__main__':
393 ci.config_filepath = 'config32bk.txt'
395 status = configure(ci)
397 print "Configure success"
399 print "Configure failed"
401 print 'Run Dir:', ci.run_path
402 print 'Bustard Dir:', ci.bustard_path
405 print 'Running pipeline now!'
408 #FIXME: Temperary hack