7 logging.basicConfig(level=logging.DEBUG,
8 format='%(asctime)s %(levelname)-8s %(message)s',
9 datefmt='%a, %d %b %Y %H:%M:%S',
10 filename='config_pipeline.log',
17 self.bustard_path = None
18 self.config_filepath = None
21 s_start = re.compile('Starting Genome Analyzer Pipeline')
22 s_gerald = re.compile("[\S\s]+--GERALD[\S\s]+--make[\S\s]+")
23 s_generating = re.compile('Generating journals, Makefiles and parameter files')
24 s_seq_folder = re.compile('^Sequence folder: ')
27 s_invalid_cmdline = re.compile('Usage:[\S\s]*goat_pipeline.py')
30 s_skip = re.compile('s_[0-8]_[0-9]+')
32 def handler(line, conf_info):
34 Processes each line of output from GOAT
35 and stores useful information using the logging module
37 Loads useful information into conf_info as well, for future
38 use outside the function.
40 returns True if found condition that signifies success.
44 if s_skip.search(line):
46 elif s_invalid_cmdline.search(line):
47 logging.error("Invalid commandline options!")
48 elif s_start.search(line):
49 logging.info('START: Configuring pipeline')
50 elif s_gerald.search(line):
51 logging.info('Running make now')
52 elif s_generating.search(line):
53 logging.info('Make files generted')
55 elif s_seq_folder.search(line):
56 mo = s_seq_folder.search(line)
57 conf_info.bustard_path = line[mo.end():]
58 conf_info.run_path, temp = os.path.split(conf_info.bustard_path)
60 logging.warning('How to handle: %s' % (line))
65 def configure(conf_info):
67 Attempts to configure the GA pipeline using goat.
69 Uses logging module to store information about status.
71 returns True if configuration successful, otherwise False.
74 #pipe = subprocess.Popen(['goat_pipeline.py',
75 # '--GERALD=config32bk.txt',
78 # stdout=subprocess.PIPE,
79 # stderr=subprocess.PIPE)
81 #Not a test; actual run attempt.
82 pipe = subprocess.Popen(['goat_pipeline.py',
83 '--GERALD=%s' % (conf_info.config_filepath),
86 stdout=subprocess.PIPE,
87 stderr=subprocess.PIPE)
89 line = pipe.stdout.readline()
93 if handler(line, conf_info):
95 line = pipe.stdout.readline()
97 error_code = pipe.wait()
99 logging.error('Recieved error_code: %s' % (error_code))
101 logging.info ('We are go for launch!')
103 #If log says complete and we don't have an
104 # error code (i.e. error_code == False)
105 status = complete is True and bool(error_code) is False
107 # If everything was successful, but for some reason
108 # we didn't retrieve the path info, log it.
110 if conf_info.bustard_path is None or conf_info.run_path is None:
111 logging.error("Failed to retrieve run_path")
117 if __name__ == '__main__':
119 ci.config_filepath = 'config32bk.txt'
121 status = configure(ci)
123 print "Configure success"
125 print "Configure failed"
127 print 'Run Dir:', ci.run_path
128 print 'Bustard Dir:', ci.bustard_path