5 from htsworkflow.util import queuecommands
11 def pathname_to_run_name(base):
13 Convert a pathname to a base runfolder name
14 handle the case with a trailing /
16 >>> print pathname_to_run_name("/a/b/c/run")
18 >>> print pathname_to_run_name("/a/b/c/run/")
20 >>> print pathname_to_run_name("run")
22 >>> print pathname_to_run_name("run/")
24 >>> print pathname_to_run_name("../run")
26 >>> print pathname_to_run_name("../run/")
31 base, name = os.path.split(base)
36 def make_srf_commands(run_name, bustard_dir, lanes, site_name, destdir, cmdlevel=ILLUMINA2SRF11):
38 make a subprocess-friendly list of command line arguments to run solexa2srf
40 woldlab:080514_HWI-EAS229_0029_20768AAXX:8.srf
43 run_name - most of the file name (run folder name is a good choice)
44 lanes - list of integers corresponding to which lanes to process
45 site_name - name of your "sequencing site" or "Individual"
46 destdir - where to write all the srf files
49 logging.info("run_name %s" % ( run_name, ))
53 name_prefix = '%s_%%l_%%t_' % (run_name,)
54 destname = '%s_%s_%d.srf' % (site_name, run_name, lane)
55 destdir = os.path.normpath(destdir)
56 dest_path = os.path.join(destdir, destname)
57 seq_pattern = 's_%d_*_seq.txt' % (lane,)
59 if cmdlevel == SOLEXA2SRF:
65 elif cmdlevel == ILLUMINA2SRF10:
66 cmd = ['illumina2srf',
70 elif cmdlevel == ILLUMINA2SRF11:
71 seq_pattern = 's_%d_*_qseq.txt' % (lane,)
72 cmd = ['illumina2srf',
76 raise ValueError("Unrecognized run level %d" % (cmdlevel,))
78 logging.info("Generated command: " + " ".join(cmd))
79 cmd_list.append(" ".join(cmd))
82 def create_qseq_patterns(bustard_dir):
84 Scan a bustard directory for qseq files and determine a glob pattern
86 # grab one tile for each lane.
87 qseqs = glob(os.path.join(bustard_dir, '*_0001_qseq.txt'))
88 qseqs = [ os.path.split(x)[-1] for x in qseqs ]
89 if len(qseqs[0].split('_')) == 4:
91 return [(None,"s_%d_[0-9][0-9][0-9][0-9]_qseq.txt")]
92 elif len(qseqs[0].split('_')) == 5:
94 # build a dictionary of read numbers by lane
95 # ( just in case we didn't run all 8 lanes )
98 sample, lane, read, tile, extension = q.split('_')
99 lanes.setdefault(lane, []).append(read)
101 # grab a lane from the dictionary
102 # I don't think it matters which one.
104 # build the list of patterns
105 for read in lanes[k]:
107 qseq_patterns.append((read, 's_%d_' + '%d_[0-9][0-9][0-9][0-9]_qseq.txt' % (read,)))
110 raise RuntimeError('unrecognized qseq pattern, not a single or multiple read pattern')
112 def make_qseq_commands(run_name, bustard_dir, lanes, site_name, destdir, cmdlevel=ILLUMINA2SRF11):
114 make a subprocess-friendly list of command line arguments to run solexa2srf
115 generates files like:
116 woldlab:080514_HWI-EAS229_0029_20768AAXX:8.srf
119 run_name - most of the file name (run folder name is a good choice)
120 lanes - list of integers corresponding to which lanes to process
121 site_name - name of your "sequencing site" or "Individual"
122 destdir - where to write all the srf files
125 logging.info("run_name %s" % ( run_name, ))
129 name_prefix = '%s_%%l_%%t_' % (run_name,)
130 destdir = os.path.normpath(destdir)
131 qseq_patterns = create_qseq_patterns(bustard_dir)
133 for read, pattern in qseq_patterns:
135 destname = '%s_%s_l%d.tar.bz2' % (site_name, run_name, lane)
136 dest_path = os.path.join(destdir, destname)
138 destname = '%s_%s_l%d_r%d.tar.bz2' % (site_name, run_name, lane, read)
139 dest_path = os.path.join(destdir, destname)
141 cmd = " ".join(['tar', 'cjf', dest_path, pattern % (lane,) ])
142 logging.info("Generated command: " + cmd)
147 def run_commands(new_dir, cmd_list, num_jobs):
148 logging.info("chdir to %s" % (new_dir,))
151 q = queuecommands.QueueCommands(cmd_list, num_jobs)
155 def make_md5_commands(destdir):
157 Scan the cycle dir and create md5s for the contents
160 destdir = os.path.abspath(destdir)
161 bz2s = glob(os.path.join(destdir,"*.bz2"))
162 gzs = glob(os.path.join(destdir,"*gz"))
163 srfs = glob(os.path.join(destdir,"*.srf"))
165 file_list = bz2s + gzs + srfs
168 cmd = " ".join(['md5sum', f, '>', f+'.md5'])
169 logging.info('generated command: '+cmd)