-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.nf
576 lines (472 loc) · 14.8 KB
/
main.nf
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
process fasterq_dump {
publishDir "${params.publish_dir}/${meta.sample}/fasterq_dump", pattern: "{fastq_line_count.txt,*_fastqc/fastqc_data.txt,sampleinfo.txt,.command*}"
// maxForks 80
cpus 8
memory "16g"
tag "${meta.sample}"
input:
val meta
output:
val(meta), emit: meta
path "out.fastq.gz", emit: fastq
path "*_fastqc/fastqc_data.txt", emit: fastqc_data
path "fastq_line_count.txt"
path ".command*"
path "sampleinfo.txt"
path "versions.yml"
stub:
"""
touch out.fastq.gz
touch fastq_line_count.txt
touch sampleinfo.txt
touch versions.yml
touch .command.run
mkdir -p ${meta.sample}_fastqc
touch ${meta.sample}_fastqc/fastqc_data.txt
"""
script:
"""
echo "accessions: ${meta.accessions}" > sampleinfo.txt
echo "starting fasterq-dump"
for accession in ${meta.accessions.join(" ")}; do
echo "downloading \$accession"
aws s3 cp s3://sra-pub-run-odp/sra/\$accession/\$accession . \
--no-sign-request \
--no-progress
mv \$accession \$accession.sra
fasterq-dump --threads ${task.cpus} \
--skip-technical \
--force \
--split-files \$accession.sra
done
ls -ld
echo "fasterq-dump done"
wc -l *.fastq > fastq_line_count.txt
echo "combining fastq files and gzipping"
cat *.fastq | pv | pigz -p ${task.cpus} > out.fastq.gz
echo "sampling fastq file for fastqc"
seqtk sample -s100 out.fastq.gz 50000 > out_sample.fastq
echo "running fastqc"
fastqc --extract out_sample.fastq
echo "collecting version info"
cat <<-END_VERSIONS > versions.yml
versions:
awscli: \$(aws --version)
fastqc: \$( echo \$(fastqc --version 2>&1 ) | sed 's/^.*FastQC //' )
fasterq-dump: \$( echo \$(fasterq-dump --version 2>&1 ) | head -2 | tail -1 | awk '{print \$3}')
END_VERSIONS
echo "finalizing fasterqc-dump"
"""
}
process kneaddata {
publishDir "${params.publish_dir}/${meta.sample}/kneaddata", pattern: "{kneaddata_output/kneaddata_fastq_linecounts.txt,kneaddata_output/out_kneaddata.log,.command*}"
tag "${meta.sample}"
cpus 16
memory "64g"
input:
val meta
path fastq
path kd_genome
path kd_ribo_rna
output:
val(meta), emit: meta
path "kneaddata_output/out.fastq", emit: fastq
path "kneaddata_output/kneaddata_fastq_linecounts.txt"
path "kneaddata_output/out_kneaddata.log"
path ".command*"
stub:
"""
mkdir -p kneaddata_output
touch kneaddata_output/out.fastq
touch kneaddata_output/kneaddata_fastq_linecounts.txt
"""
script:
"""
kneaddata --unpaired ${fastq} \
--reference-db human_genome \
--reference-db ribosomal_RNA \
--output kneaddata_output \
--trimmomatic /installed/Trimmomatic-0.39 \
--bypass-trf \
--bowtie2-options='--very-fast' \
-t 16 -p 8
cd kneaddata_output
cat out_kneaddata.fastq | sed 's/^+.RR.*/+/g' > out.fastq
rm out_kneaddata.fastq
wc -l * | grep fastq > kneaddata_fastq_linecounts.txt
"""
}
process install_metaphlan_db {
cpus 4
memory '8g'
storeDir "${params.store_dir}"
output:
path 'metaphlan', emit: metaphlan_db, type: 'dir'
path ".command*"
path "versions.yml"
stub:
"""
mkdir -p metaphlan
touch metaphlan/db.fake
touch .command.run
touch versions.yml
"""
script:
"""
echo ${PWD}
metaphlan --install --index latest --bowtie2db metaphlan
cat <<-END_VERSIONS > versions.yml
versions:
metaphlan: \$( echo \$(metaphlan --version 2>&1 ) | awk '{print \$3}')
bowtie2: \$( echo \$(bowtie2 --version 2>&1 ) | awk '{print \$3}')
END_VERSIONS
"""
}
process metaphlan_bugs_list {
publishDir "${params.publish_dir}/${meta.sample}/metaphlan_bugs_list", pattern: "{*tsv.gz,.command*}"
tag "${meta.sample}"
cpus 16
memory '64g'
input:
val meta
path fastq
path metaphlan_db
output:
val(meta), emit: meta
path 'bowtie2.out.gz', emit: metaphlan_bt2
path 'metaphlan_bugs_list.tsv', emit: metaphlan_bugs_list
path 'metaphlan_bugs_list.tsv.gz', emit: metaphlan_bugs_list_gz
path ".command*"
path "versions.yml"
stub:
"""
touch bowtie2.out.gz
touch metaphlan_bugs_list.tsv
touch metaphlan_bugs_list.tsv.gz
touch .command.run
touch versions.yml
"""
script:
"""
find .
metaphlan --input_type fastq \
--index ${params.metaphlan_index} \
--bowtie2db metaphlan \
--samout sam.bz2 \
--bowtie2out bowtie2.out \
--nproc ${task.cpus} \
-o metaphlan_bugs_list.tsv \
${fastq}
gzip -c metaphlan_bugs_list.tsv > metaphlan_bugs_list.tsv.gz
gzip bowtie2.out
cat <<-END_VERSIONS > versions.yml
versions:
metaphlan: \$( echo \$(metaphlan --version 2>&1 ) | awk '{print \$3}')
bowtie2: \$( echo \$(bowtie2 --version 2>&1 ) | awk '{print \$3}')
END_VERSIONS
"""
}
process metaphlan_markers {
publishDir "${params.publish_dir}/${meta.sample}/metaphlan_markers/"
tag "${meta.sample}"
cpus 2
memory "8g"
input:
val meta
path metaphlan_bt2
path metaphlan_db
output:
val meta, emit: meta
path "marker_abundance.tsv.gz", emit: marker_abundance
path "marker_presence.tsv.gz", emit: marker_presence
path ".command*"
path "versions.yml"
stub:
"""
touch marker_abundance.tsv.gz
touch marker_presence.tsv.gz
touch .command.run
touch versions.yml
"""
script:
"""
metaphlan --input_type bowtie2out \
--index ${params.metaphlan_index} \
--bowtie2db metaphlan \
-t marker_pres_table \
-o marker_presence.tsv \
<( gunzip -c ${metaphlan_bt2} )
metaphlan --input_type bowtie2out \
--index ${params.metaphlan_index} \
--bowtie2db metaphlan \
-t marker_ab_table \
-o marker_abundance.tsv \
<( gunzip -c ${metaphlan_bt2} )
gzip *.tsv
cat <<-END_VERSIONS > versions.yml
versions:
metaphlan: \$( echo \$(metaphlan --version 2>&1 ) | awk '{print \$3}')
bowtie2: \$( echo \$(bowtie2 --version 2>&1 ) | awk '{print \$3}')
END_VERSIONS
"""
}
process chocophlan_db {
cpus 1
memory "1g"
storeDir "${params.store_dir}"
output:
path "chocophlan", emit: chocophlan_db, type: 'dir'
path ".command*"
path "versions.yml"
stub:
"""
mkdir -p chocophlan
touch chocophlan/db.fake
touch .command.run
touch versions.yml
"""
script:
"""
echo ${PWD}
humann_databases --update-config no --download chocophlan ${params.chocophlan} .
cat <<-END_VERSIONS > versions.yml
versions:
humann: \$( echo \$(humann --version 2>&1 ) | awk '{print \$2}')
END_VERSIONS
"""
}
process uniref_db {
cpus 1
memory "1g"
storeDir "${params.store_dir}"
output:
path "uniref", emit: uniref_db, type: 'dir'
path ".command*"
path "versions.yml"
stub:
"""
mkdir -p uniref
touch uniref/db.fake
touch .command.run
touch versions.yml
"""
script:
"""
echo ${PWD}
humann_databases --update-config no --download uniref ${params.uniref} .
cat <<-END_VERSIONS > versions.yml
versions:
humann: \$( echo \$(humann --version 2>&1 ) | awk '{print \$2}')
END_VERSIONS
"""
}
process kneaddata_human_database {
cpus 1
memory "4g"
storeDir "${params.store_dir}"
output:
path "human_genome", emit: kd_genome, type: "dir"
path ".command*"
// path "hg37dec_v0.1.1.bt2"
// path "hg37dec_v0.1.2.bt2"
// path "hg37dec_v0.1.3.bt2"
// path "hg37dec_v0.1.4.bt2"
// path "hg37dec_v0.1.rev.1.bt2"
// path "hg37dec_v0.1.rev.2.bt2"
stub:
"""
mkdir -p human_genome
touch human_genome/hg37dec_v0.1.1.bt2
touch .command.run
"""
script:
"""
echo ${PWD}
mkdir -p human_genome
kneaddata_database --download human_genome bowtie2 human_genome
"""
}
process kneaddata_ribo_rna_database {
cpus 1
memory "4g"
storeDir "${params.store_dir}"
output:
path "ribosomal_RNA", emit: kd_ribo_rna, type: "dir"
path ".command*"
// path "SILVA_128_LSUParc_SSUParc_ribosomal_RNA.1.bt2l"
// path "SILVA_128_LSUParc_SSUParc_ribosomal_RNA.2.bt2l"
// path "SILVA_128_LSUParc_SSUParc_ribosomal_RNA.3.bt2l"
// path "SILVA_128_LSUParc_SSUParc_ribosomal_RNA.4.bt2l"
// path "SILVA_128_LSUParc_SSUParc_ribosomal_RNA.rev.1.bt2l"
// path "SILVA_128_LSUParc_SSUParc_ribosomal_RNA.rev.1.bt2l"
stub:
"""
mkdir -p ribosomal_RNA
touch ribosomal_RNA/SILVA_128_LSUParc_SSUParc_ribosomal_RNA.1.bt2l
touch ribosomal_RNA/SILVA_128_LSUParc_SSUParc_ribosomal_RNA.2.bt2l
touch ribosomal_RNA/SILVA_128_LSUParc_SSUParc_ribosomal_RNA.3.bt2l
touch ribosomal_RNA/SILVA_128_LSUParc_SSUParc_ribosomal_RNA.4.bt2l
touch ribosomal_RNA/SILVA_128_LSUParc_SSUParc_ribosomal_RNA.rev.1.bt2l
touch ribosomal_RNA/SILVA_128_LSUParc_SSUParc_ribosomal_RNA.rev.2.bt2l
touch .command.run
"""
script:
"""
curl -k -LO http://huttenhower.sph.harvard.edu/kneadData_databases/SILVA_128_LSUParc_SSUParc_ribosomal_RNA_v0.2.tar.gz
echo ${PWD}
mkdir -p ribosomal_RNA
kneaddata_database --download ribosomal_RNA bowtie2 ribosomal_RNA
"""
}
process humann {
publishDir "${params.publish_dir}/${meta.sample}/humann"
cpus 16
memory '64g'
tag "${meta.sample}"
input:
val meta
path fastq
path metaphlan_bugs_list // metaphlan_bugs_list.tsv
path chocophlan_db
path uniref_db
output:
// lots of files....
path("out_genefamilies.tsv.gz")
path("out_genefamilies_cpm.tsv.gz")
path("out_genefamilies_relab.tsv.gz")
path("out_genefamilies_stratified.tsv.gz")
path("out_genefamilies_unstratified.tsv.gz")
path("out_genefamilies_cpm_stratified.tsv.gz")
path("out_genefamilies_relab_stratified.tsv.gz")
path("out_genefamilies_cpm_unstratified.tsv.gz")
path("out_genefamilies_relab_unstratified.tsv.gz")
path("out_pathabundance.tsv.gz")
path("out_pathabundance_cpm.tsv.gz")
path("out_pathabundance_relab.tsv.gz")
path("out_pathabundance_stratified.tsv.gz")
path("out_pathabundance_unstratified.tsv.gz")
path("out_pathabundance_cpm_stratified.tsv.gz")
path("out_pathabundance_relab_stratified.tsv.gz")
path("out_pathabundance_cpm_unstratified.tsv.gz")
path("out_pathabundance_relab_unstratified.tsv.gz")
path("out_pathcoverage_unstratified.tsv.gz")
path("out_pathcoverage_stratified.tsv.gz")
path("out_pathcoverage.tsv.gz")
path ".command*"
path "versions.yml"
stub:
"""
touch out_genefamilies.tsv.gz
touch out_genefamilies_cpm.tsv.gz
touch out_genefamilies_relab.tsv.gz
touch out_genefamilies_stratified.tsv.gz
touch out_genefamilies_unstratified.tsv.gz
touch out_genefamilies_cpm_stratified.tsv.gz
touch out_genefamilies_relab_stratified.tsv.gz
touch out_genefamilies_cpm_unstratified.tsv.gz
touch out_genefamilies_relab_unstratified.tsv.gz
touch out_pathabundance.tsv.gz
touch out_pathabundance_cpm.tsv.gz
touch out_pathabundance_relab.tsv.gz
touch out_pathabundance_stratified.tsv.gz
touch out_pathabundance_unstratified.tsv.gz
touch out_pathabundance_cpm_stratified.tsv.gz
touch out_pathabundance_relab_stratified.tsv.gz
touch out_pathabundance_cpm_unstratified.tsv.gz
touch out_pathabundance_relab_unstratified.tsv.gz
touch out_pathcoverage_unstratified.tsv.gz
touch out_pathcoverage_stratified.tsv.gz
touch out_pathcoverage.tsv.gz
touch .command.run
touch versions.yml
"""
script:
"""
humann -i ${fastq} \
-o '.' \
--verbose \
--metaphlan-options "-t rel_ab --index latest" \
--nucleotide-database ${chocophlan_db} \
--taxonomic-profile ${metaphlan_bugs_list} \
--protein-database ${uniref_db} \
--threads ${task.cpus}
humann_renorm_table \
--input out_pathabundance.tsv \
--output out_pathabundance_cpm.tsv \
--units cpm
humann_renorm_table \
--input out_genefamilies.tsv \
--output out_genefamilies_cpm.tsv \
--units cpm
humann_renorm_table \
--input out_genefamilies.tsv \
--output out_genefamilies_relab.tsv \
--units relab
humann_renorm_table \
--input out_pathabundance.tsv \
--output out_pathabundance_relab.tsv \
--units relab
humann_split_stratified_table -i out_pathabundance.tsv -o .
humann_split_stratified_table -i out_pathabundance_cpm.tsv -o .
humann_split_stratified_table -i out_pathabundance_relab.tsv -o .
humann_split_stratified_table -i out_pathcoverage.tsv -o .
humann_split_stratified_table -i out_genefamilies.tsv -o .
humann_split_stratified_table -i out_genefamilies_cpm.tsv -o .
humann_split_stratified_table -i out_genefamilies_relab.tsv -o .
gzip out_*tsv
cat <<-END_VERSIONS > versions.yml
versions:
humann: \$( echo \$(humann --version 2>&1 ) | awk '{print \$2}')
END_VERSIONS
"""
}
def generate_row_tuple(row) {
accessions=row.NCBI_accession.split(';');
study_id = row.study_name;
sample_id = row.sample_id;
sample_encoded = "${study_id}::${sample_id}".bytes.encodeBase64().toString()
// Create a hash of sampleID and joined accessions for
// use as a unique id.
// rowhash = "${accessions.sort().join(' ')}".md5().toString()
return [sample: sample_encoded, accessions: accessions, meta: row]
}
workflow {
// samples = Channel
// .fromPath(params.metadata_tsv)
// .splitCsv(header: true, quote: '"', sep:'\t')
// .map { row -> generate_row_tuple(row) }
// for debugging:
// samples.view()
samples = [
sample: params.sample_id,
accessions: params.run_ids.split(';')
]
fasterq_dump(samples)
install_metaphlan_db()
uniref_db()
chocophlan_db()
kneaddata_human_database()
kneaddata_ribo_rna_database()
kneaddata(
fasterq_dump.out.meta,
fasterq_dump.out.fastq,
kneaddata_human_database.out.kd_genome.collect(),
kneaddata_ribo_rna_database.out.kd_ribo_rna.collect()
)
metaphlan_bugs_list(
kneaddata.out.meta,
kneaddata.out.fastq,
install_metaphlan_db.out.metaphlan_db.collect())
metaphlan_markers(
metaphlan_bugs_list.out.meta,
metaphlan_bugs_list.out.metaphlan_bt2,
install_metaphlan_db.out.metaphlan_db.collect())
// humann(
// kneaddata.out.meta,
// kneaddata.out.fastq,
// metaphlan_bugs_list.out.metaphlan_bugs_list,
// chocophlan_db.out.chocophlan_db,
// uniref_db.out.uniref_db)
}