8 from htsworkflow.pipelines import runfolder
9 from htsworkflow.pipelines.srf import make_commands, run_srf_commands
10 from htsworkflow.pipelines.srf import ILLUMINA2SRF10, ILLUMINA2SRF11, SOLEXA2SRF
13 usage = '%prog: [options] runfolder -l 1,2,3 [runfolder -l 5,6 ...]'
15 parser = optparse.OptionParser(usage)
16 parser.add_option('--dry-run', action='store_true',
17 help='print what would be done',
20 parser.add_option('-d', '--dest-dir', dest='dest_dir',
21 help='location to write srf files to',
23 parser.add_option('-s', '--site',
26 parser.add_option('-l', '--lanes', dest='lanes', action="append",
28 help='comma seperated list of lanes to add to srf'
30 parser.add_option('-j', '--jobs', default=1, type='int',
31 help='how many jobs to run simultaneously')
32 parser.add_option('-r', '--runfolder-version', default=ILLUMINA2SRF11, type='int',
33 help='Which class of srf file should we attempt to create\n'
34 '0 = Solexa pipeline 0.2.6 - 0.3\n'
35 '1 = illumina pipeline 1.0\n'
36 '2 = illumina pipeline 1.1rc1 and later \n')
38 parser.add_option('-v', '--verbose', dest='verbose',
39 default=False, action='store_true',
40 help='report more about internals (INFO)')
41 parser.add_option('--debug', dest='debug',
42 default=False, action='store_true',
43 help='report even more about internals (DEBUG)')
47 def parse_lane_arg(lane_arg):
49 Convert comma sperated list of lane ids to a list of integers
52 for lane in lane_arg.split(','):
55 if lane < 1 or lane > 8:
56 parser.error('Lanes must be in range [1..8]')
59 parser.error('Lane selections must be integers')
62 def main(cmdline=None):
63 parser = make_parser()
64 opts, args = parser.parse_args(cmdline)
67 logging.basicConfig(level=logging.DEBUG)
69 logging.basicConfig(level=logging.INFO)
71 logging.basicConfig(level=logging.WARNING)
74 parser.error('need runfolder arguments')
76 # parse lane arguemnts
78 if len(opts.lanes) == 0:
79 lanes_list = [[1,2,3,4,5,6,7,8]] * len(args)
80 elif len(opts.lanes) == len(args):
81 for lane_arg in opts.lanes:
82 lanes_list.append(parse_lane_arg(lane_arg))
85 "Number of lane arguments must match number of runfolders"
88 # build list of commands
90 for runfolder_path, lanes in zip(args, lanes_list):
91 # normalize paths, either relative to home dirs or current dir
92 runfolder_path = os.path.abspath(runfolder_path)
93 run_name = pathname_to_run_name(runfolder_path)
94 # so any bustard directories?
95 runs = runfolder.get_runs(runfolder_path)
96 # give up if there are anything other than 1 run
98 print 'ERROR: Too many run directories in %s' %(runfolder_path,)
101 bustard_dir = runs[0].bustard.pathname
102 cmds[bustard_dir] = make_commands(run_name, lanes, opts.site, opts.dest_dir, opts.runfolder_version)
104 print "ERROR: Couldn't find a bustard directory in", runfolder_path
108 for cwd, cmd_list in cmds.items():
109 run_srf_command(cwd, cmd_list, opts.jobs)
111 for cwd, cmd_list in cmds.items():
114 print 'jobs: ', opts.jobs
118 if __name__ == "__main__":
119 sys.exit(main(sys.argv[1:]))