10 from htsworkflow.util import queuecommands
11 from htsworkflow.pipelines import runfolder
17 def make_commands(run_name, lanes, site_name, destdir, cmdlevel=ILLUMINA2SRF11):
19 make a subprocess-friendly list of command line arguments to run solexa2srf
21 woldlab:080514_HWI-EAS229_0029_20768AAXX:8.srf
24 run_name - most of the file name (run folder name is a good choice)
25 lanes - list of integers corresponding to which lanes to process
26 site_name - name of your "sequencing site" or "Individual"
27 destdir - where to write all the srf files
31 name_prefix = '%s_%%l_%%t_' % (run_name,)
32 destname = '%s_%s_%d.srf' % (site_name, run_name, lane)
33 destdir = os.path.normpath(destdir)
34 dest_path = os.path.join(destdir, destname)
35 seq_pattern = 's_%d_*_seq.txt' % (lane,)
37 if cmdlevel == SOLEXA2SRF:
43 elif cmdlevel == ILLUMINA2SRF10:
44 cmd = ['illumina2srf',
48 elif cmdlevel == ILLUMINA2SRF11:
49 seq_pattern = 's_%d_*_qseq.txt' % (lane,)
50 cmd = ['illumina2srf',
54 raise ValueError("Unrecognized run level %d" % (cmdlevel,))
56 cmd_list.append(" ".join(cmd))
59 def pathname_to_run_name(base):
61 Convert a pathname to a base runfolder name
62 handle the case with a trailing /
66 base, name = os.path.split(base)
72 usage = '%prog: [options] runfolder -l 1,2,3 [runfolder -l 5,6 ...]'
74 parser = optparse.OptionParser(usage)
75 parser.add_option('--dry-run', action='store_true',
76 help='print what would be done',
79 parser.add_option('-d', '--dest-dir', dest='dest_dir',
80 help='location to write srf files to',
82 parser.add_option('-s', '--site',
85 parser.add_option('-l', '--lanes', dest='lanes', action="append",
87 help='comma seperated list of lanes to add to srf'
89 parser.add_option('-j', '--jobs', default=1, type='int',
90 help='how many jobs to run simultaneously')
91 parser.add_option('-r', '--runfolder-version', default=ILLUMINA2SRF11, type='int',
92 help='Which class of srf file should we attempt to create\n'
93 '0 = Solexa pipeline 0.2.6 - 0.3\n'
94 '1 = illumina pipeline 1.0\n'
95 '2 = illumina pipeline 1.1rc1 and later \n')
97 parser.add_option('-v', '--verbose', dest='verbose',
98 default=False, action='store_true',
99 help='report more about internals (INFO)')
100 parser.add_option('--debug', dest='debug',
101 default=False, action='store_true',
102 help='report even more about internals (DEBUG)')
106 def parse_lane_arg(lane_arg):
108 Convert comma sperated list of lane ids to a list of integers
111 for lane in lane_arg.split(','):
114 if lane < 1 or lane > 8:
115 parser.error('Lanes must be in range [1..8]')
118 parser.error('Lane selections must be integers')
121 def main(cmdline=None):
122 parser = make_parser()
123 opts, args = parser.parse_args(cmdline)
126 logging.basicConfig(level=logging.DEBUG)
128 logging.basicConfig(level=logging.INFO)
130 logging.basicConfig(level=logging.WARNING)
133 parser.error('need runfolder arguments')
135 # parse lane arguemnts
137 if len(opts.lanes) == 0:
138 lanes_list = [[1,2,3,4,5,6,7,8]] * len(args)
139 elif len(opts.lanes) == len(args):
140 for lane_arg in opts.lanes:
141 lanes_list.append(parse_lane_arg(lane_arg))
144 "Number of lane arguments must match number of runfolders"
147 # build list of commands
149 for runfolder_path, lanes in zip(args, lanes_list):
150 # normalize paths, either relative to home dirs or current dir
151 runfolder_path = os.path.abspath(runfolder_path)
152 # the last part of the path should be a runfolder name
153 name = pathname_to_run_name(runfolder_path)
154 # so any bustard directories?
155 runs = runfolder.get_runs(runfolder_path)
156 # give up if there are anything other than 1 run
158 print 'ERROR: Too many run directories in %s' %(runfolder_path,)
161 bustard_dir = runs[0].bustard.pathname
162 cmds[bustard_dir] = make_commands(name, lanes, opts.site, opts.dest_dir, opts.runfolder_version)
164 print "ERROR: Couldn't find a bustard directory in", runfolder_path
168 for cwd, cmd_list in cmds.items():
171 q = queuecommands.QueueCommands(cmd_list, opts.jobs)
175 for cwd, cmd_list in cmds.items():
178 print 'jobs: ', opts.jobs
182 if __name__ == "__main__":
183 sys.exit(main(sys.argv[1:]))