[project @ Allow user to provide FC##### to download or a path to a config file.]
[htsworkflow.git] / scripts / configure_pipeline
1 #!/usr/bin/env python
2 import os
3 import sys
4 import re
5 from gaworkflow.pipeline.configure_run import *
6 from gaworkflow.pipeline.monitors import startCmdLineStatusMonitor
7
8 s_fc = re.compile('FC[0-9]+')
9
10
11 GENOME_DIR = '/data-store01/compbio/genomes/'
12
13
14
15 def main(args=None):
16   ci = ConfigInfo()
17
18   #FIXME: make a better command line tool
19   skip_retrieve_config = False
20   if len(args) == 1:
21     arg = args[0]
22
23     #If FC##### found
24     if s_fc.search(arg):
25       cfg_filepath = os.path.abspath('config32auto.txt')
26       flowcell = arg
27     #else, config file provide
28     else:
29       cfg_filepath = os.path.abspath(args[0])
30       skip_retrieve_config = True
31   else:
32     print "usage:\n" \
33           "       configure_pipeline FC#####\n" \
34           " or:\n" \
35           "       configure_pipeline <conf_filepath>\n"
36     return 3
37
38   genome_dir = GENOME_DIR
39
40   if not skip_retrieve_config:
41     status_retrieve_cfg = retrieve_config(ci, flowcell, cfg_filepath, genome_dir)
42     if status_retrieve_cfg:
43       print "Retrieve config file successful"
44     else:
45       print "Failed to retrieve config file"
46   else:
47     print "Config file %s provided from command-line" % (cfg_filepath)
48     ci.config_filepath = cfg_filepath
49     status_retrieve_cfg = True
50   
51   if status_retrieve_cfg:
52     status = configure(ci)
53     if status:
54       print "Configure success"
55     else:
56       print "Configure failed"
57     
58     print 'Run Dir:', ci.run_path
59     print 'Bustard Dir:', ci.bustard_path
60     
61     if status:
62       # Setup status cmdline status monitor
63       startCmdLineStatusMonitor(ci)
64       
65       print 'Running pipeline now!'
66       run_status = run_pipeline(ci)
67       if run_status is True:
68         print 'Pipeline ran successfully.'
69         return 0
70       else:
71         print 'Pipeline run failed.'
72         return 1
73
74     return 2
75
76 if __name__ == "__main__":
77   sys.exit(main(sys.argv[1:]))