-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlongReadsqc.wdl
347 lines (294 loc) · 9.97 KB
/
longReadsqc.wdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# LongReadsQC workflow
## input can be .bam or .fq or .fq.gz
## output fq.gz
version 1.0
workflow LongReadsQC {
input {
String file
String proj
String prefix=sub(proj, ":", "_")
String log_level='INFO'
Boolean rmdup = true
Boolean overwrite = true
File? reference
String pbmarkdup_container="microbiomedata/pbmarkdup:1.1"
String bbtools_container="microbiomedata/bbtools:39.03"
String jq_container="microbiomedata/jq:1.6"
# String outdir
# String prefix = basename(file)
}
call pbmarkdup {
input:
in_file = file,
prefix = prefix,
# outdir = outdir,
log_level = log_level,
rmdup = rmdup,
container = pbmarkdup_container,
overwrite = overwrite
}
call icecreamfilter {
input:
in_file = pbmarkdup.out_fastq,
prefix = prefix,
container = bbtools_container
# outdir = outdir
}
call bbdukEnds {
input:
in_file = icecreamfilter.output_good,
prefix = prefix,
container = bbtools_container,
# outdir = outdir,
reference = reference
}
call bbdukReads {
input:
in_file = bbdukEnds.out_fastq,
prefix = prefix,
container = bbtools_container,
# outdir = outdir,
reference = reference
}
call make_info_file {
input:
prefix = prefix,
bbtools_container=bbtools_container,
pbmarkdup_log = pbmarkdup.stats
}
call finish_rqc {
input:
container = jq_container,
prefix = prefix,
filtered = bbdukReads.out_fastq,
pbmarkdup_stats = pbmarkdup.stats,
icecream_stats = icecreamfilter.stats,
bbdukEnds_stats = bbdukEnds.stats,
bbdukReads_stats = bbdukReads.stats,
input_stats = flatten(pbmarkdup.input_stats),
output_stats = flatten(bbdukReads.output_stats)
}
output {
File rqc_info = make_info_file.rqc_info
File filtered_final = finish_rqc.filtered_final
File filtered_stats1 = finish_rqc.filtered_stats1_final
File filtered_stats2 = finish_rqc.filtered_stats2_final
File stats = finish_rqc.stats
# File filter_stat_json = finish_rqc.json_out
}
}
task pbmarkdup {
input {
String in_file
String prefix
String out_file = prefix + ".pbmarkdup.fq"
String? log_level
Boolean? rmdup
Boolean? overwrite
String container
# String outdir
# String out_file = outdir + "/pbmarkdup.fq"
}
command <<<
set -oeu pipefail
# mkdir -m 755 -p ~{"outdir"}
pbmarkdup --version
pbmarkdup \
~{if (defined(log_level)) then "--log-level " + log_level else "--log-level INFO" } \
~{true="--rmdup" false="" rmdup} \
~{true="--clobber" false="" overwrite} \
~{in_file} \
~{out_file}
gzip ~{out_file}
#echo -e "inputReads\tinputBases" > input_size.txt
seqtk size ~{in_file} > input_size.txt
>>>
output {
File out_fastq = "~{out_file}.gz"
File outlog = 'stderr'
File stats = 'stdout'
Array[Array[String]] input_stats = read_tsv("input_size.txt") }
runtime {
docker: container
continueOnReturnCode: true
}
}
task icecreamfilter {
input {
File in_file
String prefix
String out_bad = prefix + ".icecreamfilter.out_bad.out.gz"
String out_good = prefix + ".icecreamfilter.out_good.out.gz"
String container
# String outdir
# String out_bad = outdir + "/" + prefix + ".icecreamfilter.out_bad.out.gz"
# String out_good = outdir + "/" + prefix + ".icecreamfilter.out_good.out.gz"
}
command <<<
set -oeu pipefail
icecreamfinder.sh \
jni=t \
json=t \
ow=t \
cq=f \
keepshortreads=f \
trim=f \
ccs=t \
stats=triangle.json \
~{"in=" + in_file} \
~{"out=" + out_good} \
~{"outb=" + out_bad}
>>>
output {
File output_good = "~{out_good}"
File output_bad = "~{out_bad}"
File stats = "triangle.json"
}
runtime {
docker: container
continueOnReturnCode: true
}
}
task bbdukEnds {
input {
File? reference
File in_file
String prefix
String out_file = prefix + ".bbdukEnds.out.fq.gz"
String container
# String outdir
# String out_file = outdir + "/" + prefix + ".bbdukEnds.out.fq.gz"
}
command <<<
set -oeu pipefail
# bbduk - trim out adapter from read ends
bbduk.sh \
k=20 \
mink=12 \
edist=1 \
mm=f \
ktrimtips=60 \
json=t \
~{if (defined(reference)) then "ref=" + reference else "ref=/bbmap/resources/PacBioAdapter.fa" } \
~{"in=" + in_file} \
~{"out=" + out_file}
grep -v _JAVA_OPTIONS stderr > bbdukEnds_stats.json
>>>
output {
File out_fastq = "~{out_file}"
File stats = "bbdukEnds_stats.json"
}
runtime {
docker: container
continueOnReturnCode: true
}
}
task bbdukReads {
input {
File? reference
File in_file
String prefix
String out_file = prefix + ".filtered.fq.gz"
String container
# String outdir
# String out_file = outdir + "/" + prefix + ".filtered.fq.gz"
}
command <<<
set -oeu pipefail
# bbduk - removes reads that still contain adapter sequence
bbduk.sh \
k=24 \
edist=1 \
mm=f \
json=t \
~{if (defined(reference)) then "ref=" + reference else "ref=/bbmap/resources/PacBioAdapter.fa" } \
~{"in=" + in_file} \
~{"out=" + out_file}
grep -v _JAVA_OPTIONS stderr > bbdukReads_stats.json
#echo -e "outputReads\toutputBases" > output_size.txt
seqtk size ~{out_file} > output_size.txt
>>>
output {
File out_fastq = "~{out_file}"
File stats = "bbdukReads_stats.json"
Array[Array[String]] output_stats = read_tsv("output_size.txt")
}
runtime {
docker: container
continueOnReturnCode: true
}
}
task make_info_file {
input {
String prefix
String bbtools_container
File pbmarkdup_log
}
command <<<
set -oeu pipefail
bbtools_version=$(grep "Version" /bbmap/README.md | sed 's/#//')
pbmarkdup_version=$(grep "pbmarkdup" ~{pbmarkdup_log})
echo -e "Long Reads QC Workflow - Info File" > ~{prefix}_readsQC.info
echo -e "This workflow performs QC on PacBio metagenome sequencing files and produces filtered fastq files and statistics using the following tools and Docker containers" >> ~{prefix}_readsQC.info
echo -e "The file first runs through ${pbmarkdup_version} (https://github.com/PacificBiosciences/pbmarkdup) to remove duplicate reads." >> ~{prefix}_readsQC.info
echo -e "The files are then filtered for inverted repeats using icecreamfinder.sh (BBTools(1)${bbtools_version}) before trimming adapters from read ends using bbduk.sh (BBTools(1)${bbtools_version})." >> ~{prefix}_readsQC.info
echo -e "Reads are run through bbduk.sh (BBTools(1)${bbtools_version}) a second time to remove any reads still containing adapter sequences." >> ~{prefix}_readsQC.info
echo -e "\n(1) B. Bushnell: BBTools software package, http://bbtools.jgi.doe.gov/" >> ~{prefix}_readsQC.info
>>>
output {
File rqc_info = "~{prefix}_readsQC.info"
}
runtime {
memory: "1 GiB"
cpu: 1
maxRetries: 1
docker: bbtools_container
}
}
task finish_rqc {
input {
File pbmarkdup_stats
File icecream_stats
File bbdukEnds_stats
File bbdukReads_stats
Array[String] input_stats
Array[String] output_stats
File filtered
String container
String prefix
}
Map [String, Int] stats_map = {
"input_read_count" : input_stats[0],
"input_read_bases" : input_stats[1],
"output_read_count" : output_stats[0],
"output_read_bases" : output_stats[1]
}
File stats_json = write_json(stats_map)
command<<<
set -oeu pipefail
#end=$(date --iso-8601=seconds)
# Generate QA objects
ln -s ~{filtered} ~{prefix}_filtered.fastq.gz
ln -s ~{pbmarkdup_stats} ~{prefix}_pbmarkdupStats.txt
ln -s ~{icecream_stats} ~{prefix}_icecreamStats.json
ln -s ~{bbdukEnds_stats} ~{prefix}_bbdukEndsStats.json
ln -s ~{bbdukReads_stats} ~{prefix}_bbdukReadsStats.json
sed -re 's/:"([0-9]+)"/:\1/g' ~{stats_json} | jq > ~{prefix}_stats.json
DUP=`grep TOTAL ~{prefix}_pbmarkdupStats.txt | awk '{print $5}'`
INVERTED=`jq .Reads_Filtered ~{prefix}_icecreamStats.json`
ADAPTER1=`jq .readsRemoved ~{prefix}_bbdukEndsStats.json`
ADAPTER2=`jq .readsRemoved ~{prefix}_bbdukReadsStats.json`
jq ".Input=.input_read_count | del(.input_read_count, .input_read_bases) | .Output=.output_read_count | del(.output_read_count, .output_read_bases) | .Duplication=$DUP | .Inverted=$INVERTED | .Adapter=$ADAPTER1+$ADAPTER2 " ~{prefix}_stats.json > ~{prefix}_filterStats2.json
>>>
output {
File filtered_final = "~{prefix}_filtered.fastq.gz"
File filtered_stats1_final = "~{prefix}_pbmarkdupStats.txt"
File filtered_stats2_final = "~{prefix}_filterStats2.json"
File stats = "~{prefix}_stats.json"
}
runtime {
docker: container
memory: "1 GiB"
cpu: 1
}
}