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