#!/usr/bin/python
-from glob import glob
import logging
import optparse
import os
-import subprocess
import sys
-from htsworkflow.util import queuecommands
from htsworkflow.pipelines import runfolder
-
-SOLEXA2SRF = 0
-ILLUMINA2SRF10 = 1
-ILLUMINA2SRF11 = 2
-
-def make_commands(run_name, lanes, site_name, destdir, cmdlevel=ILLUMINA2SRF11):
- """
- make a subprocess-friendly list of command line arguments to run solexa2srf
- generates files like:
- woldlab:080514_HWI-EAS229_0029_20768AAXX:8.srf
- site run name lane
-
- run_name - most of the file name (run folder name is a good choice)
- lanes - list of integers corresponding to which lanes to process
- site_name - name of your "sequencing site" or "Individual"
- destdir - where to write all the srf files
- """
- cmd_list = []
- for lane in lanes:
- name_prefix = '%s_%%l_%%t_' % (run_name,)
- destname = '%s_%s_%d.srf' % (site_name, run_name, lane)
- destdir = os.path.normpath(destdir)
- dest_path = os.path.join(destdir, destname)
- seq_pattern = 's_%d_*_seq.txt' % (lane,)
-
- if cmdlevel == SOLEXA2SRF:
- cmd = ['solexa2srf',
- '-N', name_prefix,
- '-n', '%3x:%3y',
- '-o', dest_path,
- seq_pattern]
- elif cmdlevel == ILLUMINA2SRF10:
- cmd = ['illumina2srf',
- '-v1.0',
- '-o', dest_path,
- seq_pattern]
- elif cmdlevel == ILLUMINA2SRF11:
- seq_pattern = 's_%d_*_qseq.txt' % (lane,)
- cmd = ['illumina2srf',
- '-o', dest_path,
- seq_pattern]
- else:
- raise ValueError("Unrecognized run level %d" % (cmdlevel,))
-
- cmd_list.append(" ".join(cmd))
- return cmd_list
-
-def pathname_to_run_name(base):
- """
- Convert a pathname to a base runfolder name
- handle the case with a trailing /
- """
- name = ""
- while len(name) == 0:
- base, name = os.path.split(base)
- if len(base) == 0:
- return None
- return name
+from htsworkflow.pipelines.srf import make_commands, run_srf_commands
+from htsworkflow.pipelines.srf import ILLUMINA2SRF10, ILLUMINA2SRF11, SOLEXA2SRF
def make_parser():
usage = '%prog: [options] runfolder -l 1,2,3 [runfolder -l 5,6 ...]'
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)
- # the last part of the path should be a runfolder name
- name = pathname_to_run_name(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
return 1
elif len(runs) == 1:
bustard_dir = runs[0].bustard.pathname
- cmds[bustard_dir] = make_commands(name, lanes, opts.site, opts.dest_dir, opts.runfolder_version)
+ cmds[bustard_dir] = make_commands(run_name, 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():
- curdir = os.getcwd()
- os.chdir(cwd)
- q = queuecommands.QueueCommands(cmd_list, opts.jobs)
- q.run()
- os.chdir(curdir)
+ run_srf_command(cwd, cmd_list, opts.jobs)
else:
for cwd, cmd_list in cmds.items():
print cwd