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