5 from htsworkflow.util import queuecommands
7 LOGGER = logging.getLogger(__name__)
13 def pathname_to_run_name(base):
15 Convert a pathname to a base runfolder name
16 handle the case with a trailing /
18 >>> print pathname_to_run_name("/a/b/c/run")
20 >>> print pathname_to_run_name("/a/b/c/run/")
22 >>> print pathname_to_run_name("run")
24 >>> print pathname_to_run_name("run/")
26 >>> print pathname_to_run_name("../run")
28 >>> print pathname_to_run_name("../run/")
33 base, name = os.path.split(base)
38 def make_srf_commands(run_name, bustard_dir, lanes, site_name, destdir, cmdlevel=ILLUMINA2SRF11):
40 make a subprocess-friendly list of command line arguments to run solexa2srf
42 woldlab:080514_HWI-EAS229_0029_20768AAXX:8.srf
45 run_name - most of the file name (run folder name is a good choice)
46 lanes - list of integers corresponding to which lanes to process
47 site_name - name of your "sequencing site" or "Individual"
48 destdir - where to write all the srf files
51 LOGGER.info("run_name %s" % (run_name,))
55 name_prefix = '%s_%%l_%%t_' % (run_name,)
56 destname = '%s_%s_%d.srf' % (site_name, run_name, lane)
57 destdir = os.path.normpath(destdir)
58 dest_path = os.path.join(destdir, destname)
59 seq_pattern = 's_%d_*_seq.txt' % (lane,)
61 if cmdlevel == SOLEXA2SRF:
67 elif cmdlevel == ILLUMINA2SRF10:
68 cmd = ['illumina2srf',
72 elif cmdlevel == ILLUMINA2SRF11:
73 seq_pattern = 's_%d_*_qseq.txt' % (lane,)
74 cmd = ['illumina2srf',
78 raise ValueError("Unrecognized run level %d" % (cmdlevel,))
80 LOGGER.info("Generated command: " + " ".join(cmd))
81 cmd_list.append(" ".join(cmd))
84 def create_qseq_patterns(bustard_dir):
86 Scan a bustard directory for qseq files and determine a glob pattern
88 # grab one tile for each lane.
89 qseqs = glob(os.path.join(bustard_dir, '*_0001_qseq.txt'))
90 qseqs = [ os.path.split(x)[-1] for x in qseqs ]
91 if len(qseqs[0].split('_')) == 4:
93 return [(None, "s_%d_[0-9][0-9][0-9][0-9]_qseq.txt")]
94 elif len(qseqs[0].split('_')) == 5:
96 # build a dictionary of read numbers by lane
97 # ( just in case we didn't run all 8 lanes )
100 sample, lane, read, tile, extension = q.split('_')
101 lanes.setdefault(lane, []).append(read)
103 # grab a lane from the dictionary
104 # I don't think it matters which one.
106 # build the list of patterns
107 for read in lanes[k]:
109 qseq_patterns.append((read, 's_%d_' + '%d_[0-9][0-9][0-9][0-9]_qseq.txt' % (read,)))
112 raise RuntimeError('unrecognized qseq pattern, not a single or multiple read pattern')
114 def make_qseq_commands(run_name, bustard_dir, lanes, site_name, destdir, cmdlevel=ILLUMINA2SRF11):
116 make a subprocess-friendly list of command line arguments to run solexa2srf
117 generates files like:
118 woldlab:080514_HWI-EAS229_0029_20768AAXX:8.srf
121 run_name - most of the file name (run folder name is a good choice)
122 lanes - list of integers corresponding to which lanes to process
123 site_name - name of your "sequencing site" or "Individual"
124 destdir - where to write all the srf files
127 LOGGER.info("run_name %s" % (run_name,))
131 name_prefix = '%s_%%l_%%t_' % (run_name,)
132 destdir = os.path.normpath(destdir)
133 qseq_patterns = create_qseq_patterns(bustard_dir)
135 for read, pattern in qseq_patterns:
137 destname = '%s_%s_l%d.tar.bz2' % (site_name, run_name, lane)
138 dest_path = os.path.join(destdir, destname)
140 destname = '%s_%s_l%d_r%d.tar.bz2' % (site_name, run_name, lane, read)
141 dest_path = os.path.join(destdir, destname)
143 cmd = " ".join(['tar', 'cjf', dest_path, pattern % (lane,) ])
144 LOGGER.info("Generated command: " + cmd)
149 def run_commands(new_dir, cmd_list, num_jobs):
150 LOGGER.info("chdir to %s" % (new_dir,))
153 q = queuecommands.QueueCommands(cmd_list, num_jobs)
157 def make_md5_commands(destdir):
159 Scan the cycle dir and create md5s for the contents
162 destdir = os.path.abspath(destdir)
163 bz2s = glob(os.path.join(destdir, "*.bz2"))
164 gzs = glob(os.path.join(destdir, "*gz"))
165 srfs = glob(os.path.join(destdir, "*.srf"))
167 file_list = bz2s + gzs + srfs
170 cmd = " ".join(['md5sum', f, '>', f + '.md5'])
171 LOGGER.info('generated command: ' + cmd)