#!/usr/bin/python import logging import optparse import os import sys from htsworkflow.pipelines import runfolder from htsworkflow.pipelines.srf import make_srf_commands, make_qseq_commands, \ run_commands, pathname_to_run_name from htsworkflow.pipelines.srf import ILLUMINA2SRF10, ILLUMINA2SRF11, SOLEXA2SRF def make_parser(): usage = '%prog: [options] runfolder -l 1,2,3 [runfolder -l 5,6 ...]' parser = optparse.OptionParser(usage) parser.add_option('--dry-run', action='store_true', help='print what would be done', default=False) parser.add_option('-d', '--dest-dir', dest='dest_dir', help='location to write srf files to', default='.') parser.add_option('-s', '--site', help='site name', default='Individual') parser.add_option('-l', '--lanes', dest='lanes', action="append", default=[], help='comma seperated list of lanes to add to srf' ) parser.add_option('-j', '--jobs', default=1, type='int', help='how many jobs to run simultaneously') parser.add_option('-r', '--runfolder-version', default=ILLUMINA2SRF11, type='int', help='Which class of srf file should we attempt to create\n' '0 = Solexa pipeline 0.2.6 - 0.3\n' '1 = illumina pipeline 1.0\n' '2 = illumina pipeline 1.1rc1 and later \n') parser.add_option('-v', '--verbose', dest='verbose', default=False, action='store_true', help='report more about internals (INFO)') parser.add_option('--debug', dest='debug', default=False, action='store_true', help='report even more about internals (DEBUG)') return parser def parse_lane_arg(lane_arg): """ Convert comma sperated list of lane ids to a list of integers """ lanes = [] for lane in lane_arg.split(','): try: lane = int(lane) if lane < 1 or lane > 8: parser.error('Lanes must be in range [1..8]') lanes.append(lane) except ValueError: parser.error('Lane selections must be integers') return lanes def main(cmdline=None): parser = make_parser() opts, args = parser.parse_args(cmdline) if opts.debug: logging.basicConfig(level=logging.DEBUG) elif opts.verbose: logging.basicConfig(level=logging.INFO) else: logging.basicConfig(level=logging.WARNING) if len(args) == 0: parser.error('need runfolder arguments') # parse lane arguemnts lanes_list = [] if len(opts.lanes) == 0: lanes_list = [[1,2,3,4,5,6,7,8]] * len(args) elif len(opts.lanes) == len(args): for lane_arg in opts.lanes: lanes_list.append(parse_lane_arg(lane_arg)) else: parser.error( "Number of lane arguments must match number of runfolders" ) make_commands = make_qseq_commands # build list of commands cmds = {} for runfolder_path, lanes in zip(args, lanes_list): # normalize paths, either relative to home dirs or current dir runfolder_path = os.path.abspath(runfolder_path) run_name = pathname_to_run_name(runfolder_path) # so any bustard directories? runs = runfolder.get_runs(runfolder_path) # give up if there are anything other than 1 run if len(runs) > 1: print 'ERROR: Too many run directories in %s' %(runfolder_path,) return 1 elif len(runs) == 1: bustard_dir = runs[0].bustard.pathname cmds[bustard_dir] = make_commands(run_name, bustard_dir, lanes, opts.site, opts.dest_dir, opts.runfolder_version) else: print "ERROR: Couldn't find a bustard directory in", runfolder_path return 1 if not opts.dry_run: for cwd, cmd_list in cmds.items(): run_commands(cwd, cmd_list, opts.jobs) else: for cwd, cmd_list in cmds.items(): print cwd print cmd_list print 'jobs: ', opts.jobs return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))