clean up the logic for deciding the output filename when using stdin
[htsworkflow.git] / scripts / configure_pipeline
1 #!/usr/bin/env python
2 import os
3 import sys
4 import re
5 from htsworkflow.pipelines.configure_run import *
6 from htsworkflow.pipelines import retrieve_config as _rc
7 from htsworkflow.pipelines.run_status import startCmdLineStatusMonitor
8
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='pipeline_main.log',
13                     filemode='w')
14
15 s_fc = re.compile('FC[0-9]+')
16
17 #Turn on built-in command-line parsing.
18 _rc.DISABLE_CMDLINE = False
19
20 GENOME_DIR = '/data-store01/compbio/genomes/'
21
22
23
24 def main(args=None):
25   ci = ConfigInfo()
26   ci.analysis_dir = os.getcwd()
27   ci.base_analysis_dir, junk = os.path.split(ci.analysis_dir)
28
29   #FIXME: make a better command line tool
30   skip_retrieve_config = False
31   if len(args) == 1:
32     arg = args[0]
33
34     #If FC##### found
35     if s_fc.search(arg):
36       cfg_filepath = os.path.abspath('config32auto.txt')
37       flowcell = arg
38     #else, config file provide
39     else:
40       cfg_filepath = os.path.abspath(args[0])
41       skip_retrieve_config = True
42   else:
43     print "usage:\n" \
44           "       configure_pipeline FC#####\n" \
45           " or:\n" \
46           "       configure_pipeline <conf_filepath>\n"
47     return 3
48
49   genome_dir = GENOME_DIR
50
51   if not skip_retrieve_config:
52     status_retrieve_cfg = retrieve_config(ci, flowcell, cfg_filepath, genome_dir)
53     if status_retrieve_cfg:
54       print "Retrieve config file successful"
55     else:
56       print "Failed to retrieve config file"
57   else:
58     print "Config file %s provided from command-line" % (cfg_filepath)
59     ci.config_filepath = cfg_filepath
60     status_retrieve_cfg = True
61   
62   if status_retrieve_cfg:
63     status = configure(ci)
64     if status:
65       print "Configure success"
66     else:
67       print "Configure failed"
68     
69     print 'Run Dir:', ci.run_path
70     print 'Bustard Dir:', ci.bustard_path
71     
72     if status:
73       # Setup status cmdline status monitor
74       startCmdLineStatusMonitor(ci)
75       
76       print 'Running pipeline now!'
77       run_status = run_pipeline(ci)
78       if run_status is True:
79         print 'Pipeline ran successfully.'
80         return 0
81       else:
82         print 'Pipeline run failed.'
83         return 1
84
85     return 2
86
87 if __name__ == "__main__":
88   sys.exit(main(sys.argv[1:]))