Improve code to extract runfolder name from the path to the runfolder.
[htsworkflow.git] / scripts / runfolder
1 #!/usr/bin/env python
2 """
3 Runfolder.py can generate a xml file capturing all the 'interesting' parameters from a finished pipeline run. (using the -a option). The information currently being captured includes:
4
5   * Flowcell ID
6   * run dates
7   * start/stop cycle numbers
8   * Firecrest, bustard, gerald version numbers
9   * Eland analysis types, and everything in the eland configuration file.
10   * cluster numbers and other values from the Summary.htm 
11     LaneSpecificParameters table. 
12   * How many reads mapped to a genome from an eland file
13
14 The ELAND "mapped reads" counter will also check for eland squashed file
15 that were symlinked from another directory. This is so I can track how 
16 many reads landed on the genome of interest and on the spike ins. 
17
18 Basically my subdirectories something like:
19
20 genomes/hg18
21 genomes/hg18/chr*.2bpb <- files for hg18 genome
22 genomes/hg18/chr*.vld  
23 genomes/hg18/VATG.fa.2bp <- symlink to genomes/spikeins
24 genomes/spikein 
25
26 runfolder.py can also spit out a simple summary report (-s option) 
27 that contains the per lane post filter cluster numbers and the mapped 
28 read counts. (The report isn't currently very pretty)
29 """
30 import logging
31 import optparse
32 import sys
33
34 from gaworkflow.pipeline import runfolder
35 from gaworkflow.pipeline.runfolder import ElementTree
36         
37 def make_parser():
38     usage = 'usage: %prog [options] runfolder_root_dir'
39     parser = optparse.OptionParser(usage)
40     parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
41                       default=False,
42                       help='turn on verbose mode')
43     parser.add_option('-s', '--summary', dest='summary', action='store_true',
44                       default=False,
45                       help='produce summary report')
46     parser.add_option('-a', '--archive', dest='archive', action='store_true',
47                       default=False,
48                       help='generate run configuration archive')
49     parser.add_option('--extract-results', action='store_true',
50            default=False,
51            help='extract result files out of runfolder into a simpler archive')
52     parser.add_option('--run-xml', dest='run_xml',
53            default=None,
54            help='specify a run_<FlowCell>.xml file for summary reports')
55
56     return parser
57
58 def main(cmdlist=None):
59     parser = make_parser()
60     opt, args = parser.parse_args(cmdlist)
61
62     logging.basicConfig()
63     if opt.verbose:
64         root_log = logging.getLogger()
65         root_log.setLevel(logging.INFO)
66
67     runs = []
68     if opt.run_xml:
69         tree = ElementTree.parse(opt.run_xml).getroot()
70         runs.append(runfolder.PipelineRun(xml=tree))
71     for run_dir in args:
72         runs.extend(runfolder.get_runs(run_dir))
73
74     if len(runs) > 0:
75         if opt.summary:
76             print runfolder.summary_report(runs)
77         if opt.archive:
78             runfolder.extract_run_parameters(runs)
79         if opt.extract_results:
80             runfolder.extract_results(runs)
81
82     return 0
83
84 if __name__ == "__main__":
85   sys.exit(main(sys.argv[1:]))