3809bc6441316a8055a61e53b45c1a4007a1ba5e
[htsworkflow.git] / htsworkflow / pipelines / srf.py
1 import logging
2 import os
3
4 from htsworkflow.util import queuecommands
5
6 SOLEXA2SRF = 0
7 ILLUMINA2SRF10 = 1
8 ILLUMINA2SRF11 = 2
9
10 def pathname_to_run_name(base):
11   """
12   Convert a pathname to a base runfolder name
13   handle the case with a trailing /
14   """
15   name = ""
16   while len(name) == 0:
17     base, name = os.path.split(base)
18     if len(base) == 0:
19       return None
20   return name
21
22 def make_commands(run_name, lanes, site_name, destdir, cmdlevel=ILLUMINA2SRF11):
23   """
24   make a subprocess-friendly list of command line arguments to run solexa2srf
25   generates files like: 
26   woldlab:080514_HWI-EAS229_0029_20768AAXX:8.srf
27    site        run name                    lane
28              
29   run_name - most of the file name (run folder name is a good choice)
30   lanes - list of integers corresponding to which lanes to process
31   site_name - name of your "sequencing site" or "Individual"
32   destdir - where to write all the srf files
33   """
34   # clean up pathname
35   logging.info("run_name %s" % ( run_name, ))
36   
37   cmd_list = []
38   for lane in lanes:
39     name_prefix = '%s_%%l_%%t_' % (run_name,)
40     destname = '%s_%s_%d.srf' % (site_name, run_name, lane)
41     destdir = os.path.normpath(destdir)
42     dest_path = os.path.join(destdir, destname)
43     seq_pattern = 's_%d_*_seq.txt' % (lane,)
44
45     if cmdlevel == SOLEXA2SRF:
46         cmd = ['solexa2srf', 
47                '-N', name_prefix,
48                '-n', '%3x:%3y', 
49                '-o', dest_path, 
50                seq_pattern]
51     elif cmdlevel == ILLUMINA2SRF10:
52         cmd = ['illumina2srf', 
53                '-v1.0',
54                '-o', dest_path,
55                seq_pattern]
56     elif cmdlevel == ILLUMINA2SRF11:
57         seq_pattern = 's_%d_*_qseq.txt' % (lane,)
58         cmd = ['illumina2srf', 
59                '-o', dest_path,
60                seq_pattern]
61     else:
62         raise ValueError("Unrecognized run level %d" % (cmdlevel,))
63
64     logging.info("Generated command: " + " ".join(cmd))
65     cmd_list.append(" ".join(cmd))
66   return cmd_list
67
68 def run_srf_commands(bustard_dir, cmd_list, num_jobs):
69     logging.info("chdir to %s" % (bustard_dir,))
70     curdir = os.getcwd()
71     os.chdir(bustard_dir)
72     q = queuecommands.QueueCommands(cmd_list, num_jobs)
73     q.run()
74     os.chdir(curdir)
75