Repository navigation
Expand file tree
/
Copy pathmain.nf
More file actions
609 lines (424 loc) · 12.6 KB
/
Copy pathmain.nf
File metadata and controls
609 lines (424 loc) · 12.6 KB
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
#!/usr/bin/env nextflow
params.help = null
println """\
G E R M L I N E V A R I A N T D I S C O V E R Y (S N V s + I N D E L S)
============================================================================
Start : $workflow.start
BWA : BWA-0.7.15
Annovar : Annovar-4.18
Samtools : Samtools-1.9
Strelka : Strelka-2.9.7
Varscan : Varscan-2.4.2
Picard : Picard-2.18.15
GATK : GenomeAnalysisTK-3.8-0
Results : ${params.results}
"""
.stripIndent()
/*
* parse the input parameters.
*/
genome_fasta = file(params.genome_fasta)
genome_fasta_sa = file(params.genome_fasta_sa)
genome_fasta_fai = file(params.genome_fasta_fai)
genome_fasta_bwt = file(params.genome_fasta_bwt)
genome_fasta_ann = file(params.genome_fasta_ann)
genome_fasta_amb = file(params.genome_fasta_amb)
genome_fasta_pac = file(params.genome_fasta_pac)
genome_fasta_dict = file(params.genome_fasta_dict)
mills_indel_file = file(params.mills_indel_file)
known_indel_file = file(params.known_indel_file)
known_dbsnps_file = file(params.known_dbsnps_file)
known_dbsnps_1000_file = file(params.known_dbsnps_1000_file)
/*
* read in the FASTQ files from s3 in pairs.
*/
raw_reads_ch = Channel.fromFilePairs("s3://noelnamai/data/${params.population}/*_{1,2}.fastq.gz")
/*
* perform a variety of useful trimming tasks for Illumina data.
*/
process trimmomatic {
tag "$sample"
container "noelnamai/trimmomatic:0.38"
cpus = 2
memory = "7.5 GB"
when:
sample == "ERR034520"
input:
set sample, file(reads) from raw_reads_ch
output:
set sample, file("${sample}.trimmed.paired.1.fq.gz"), file("${sample}.trimmed.paired.2.fq.gz") into trimmed_raw_reads_ch_1, trimmed_raw_reads_ch_2
script:
"""
java -Xmx4g -jar /opt/trimmomatic-0.38.jar PE \
-phred33 \
${reads[0]} ${reads[1]} \
${sample}.trimmed.paired.1.fq.gz ${sample}.trimmed.unpaired.1.fq.gz \
${sample}.trimmed.paired.2.fq.gz ${sample}.trimmed.unpaired.2.fq.gz \
ILLUMINACLIP:TruSeq3-PE.fa:2:30:10 \
LEADING:3 \
TRAILING:3 \
SLIDINGWINDOW:4:15 \
MINLEN:36
"""
}
/*
* perform a simple quality control check on raw sequence data coming from high throughput sequencing pipelines.
*/
process fastqc {
tag "$sample"
container "noelnamai/fastqc:0.11.3"
cpus = 2
memory = "7.5 GB"
publishDir "${params.results}/${params.population}/$sample", mode: "copy", overwrite: true
input:
set sample, file(forward), file(reverse) from trimmed_raw_reads_ch_1
output:
file("*.html") into fastqc_ch
script:
"""
gunzip ${forward} ${reverse}
cat "${forward.baseName}" "${reverse.baseName}" > ${sample}.fastq
/usr/bin/fastqc ${sample}.fastq \
--noextract \
--threads ${task.cpus}
mv ${sample}_fastqc.html ${sample}.fastqc.html
"""
}
/*
* read alignment via Burrows-Wheeler Aligner - MEM algorithm.
*/
process bwa_mem {
tag "$sample"
container "noelnamai/bwa:0.7.12"
cpus = 8
memory = "30 GB"
input:
file genome_fasta
file genome_fasta_sa
file genome_fasta_fai
file genome_fasta_bwt
file genome_fasta_ann
file genome_fasta_amb
file genome_fasta_pac
set sample, file(forward), file(reverse) from trimmed_raw_reads_ch_2
output:
set sample, file("${sample}.sam") into bwa_aligned_sam_ch
script:
"""
bwa mem -t ${task.cpus} -M ${genome_fasta} ${forward} ${reverse} > "${sample}.sam"
"""
}
/*
* use Samtools to convert the SAM output from BWA to BAM format.
*/
process samtools_view {
tag "$sample"
container "noelnamai/samtools:1.9"
cpus = 2
memory = "7.5 GB"
input:
set sample, file(sam_file) from bwa_aligned_sam_ch
output:
set sample, file("${sam_file.baseName}.aligned.bam") into bwa_aligned_bam_ch
script:
"""
samtools view -bS ${sam_file} > "${sam_file.baseName}.aligned.bam"
"""
}
/*
* use Picard tools to add group to raw bam file.
*/
process picard_add_or_replace_read_groups {
tag "$sample"
container "noelnamai/picard:2.18.25"
cpus = 2
memory = "7.5 GB"
input:
set sample, file(bam_file) from bwa_aligned_bam_ch
output:
set sample, file("${bam_file.baseName}.grouped.sorted.bam") into picard_added_group_bam_ch1, picard_added_group_bam_ch2
script:
"""
java -Xmx4g -jar /opt/picard.jar AddOrReplaceReadGroups \
I=${bam_file} \
O="${bam_file.baseName}.grouped.sorted.bam" \
SO=coordinate \
RGLB=${sample} \
RGPL=illumina \
RGPU=${sample} \
RGSM=${sample}
"""
}
/*
* generate summary mapping statistics using Samtools.
*/
process samtools_flagstat {
tag "$sample"
container "noelnamai/samtools:1.9"
cpus = 2
memory = "7.5 GB"
publishDir "${params.results}/${params.population}/$sample", mode: "copy", overwrite: true
input:
set sample, file(bam_file_added_group) from picard_added_group_bam_ch1
output:
set sample, file("${sample}.mapping.statistic.txt") into samtools_flagstat_ch
script:
"""
samtools flagstat ${bam_file_added_group} > "${sample}.mapping.statistic.txt"
"""
}
/*
* use Picard tools to mark duplicates and create BAI from the BAM file.
*/
process picard_mark_duplicates {
tag "$sample"
container "noelnamai/picard:2.18.25"
cpus = 2
memory = "7.5 GB"
input:
set sample, file(bam_file_added_group) from picard_added_group_bam_ch2
output:
set sample, file("${bam_file_added_group.baseName}.deduplicated.bam"), file("${bam_file_added_group.baseName}.deduplicated.bai") into picard_mark_duplicates_ch1, picard_mark_duplicates_ch2
script:
"""
java -Xmx4g -jar /opt/picard.jar MarkDuplicates \
I=${bam_file_added_group} \
O="${bam_file_added_group.baseName}.deduplicated.bam" \
METRICS_FILE="${bam_file_added_group.baseName}.output.metrics" \
VALIDATION_STRINGENCY=SILENT \
CREATE_INDEX=true
"""
}
/*
* GATK realigner target creator.
*/
process gatk_realigner_target_creator {
tag "$sample"
container "broadinstitute/gatk3:3.8-0"
cpus = 8
memory = "30 GB"
input:
file genome_fasta
file genome_fasta_fai
file genome_fasta_dict
file mills_indel_file
file known_indel_file
set sample, file(bam_file_marked_duplicate), file(bai_file_marked_duplicate) from picard_mark_duplicates_ch1
output:
set sample, file("${bam_file_marked_duplicate.baseName}.intervals.list") into gatk_target_creator_ch
script:
"""
java -Xmx4g -jar /usr/GenomeAnalysisTK.jar \
-T RealignerTargetCreator \
-nt ${task.cpus} \
-R ${genome_fasta} \
-I ${bam_file_marked_duplicate} \
-known ${mills_indel_file} \
-known ${known_indel_file} \
-o "${bam_file_marked_duplicate.baseName}.intervals.list"
"""
}
/*
* GATK perform local realignment of reads around indels.
*/
process gatk_indel_realignment {
tag "$sample"
container "broadinstitute/gatk3:3.8-0"
cpus = 8
memory = "30 GB"
input:
file genome_fasta
file genome_fasta_fai
file genome_fasta_dict
file mills_indel_file
file known_indel_file
set sample, file(interval_list) from gatk_target_creator_ch
set sample, file(bam_file_marked_duplicate), file(bai_file_marked_duplicate) from picard_mark_duplicates_ch2
output:
set sample, file("${bam_file_marked_duplicate.baseName}.realigned.bam"), file("${bam_file_marked_duplicate.baseName}.realigned.bai") into gatk_indel_realignment_ch
script:
"""
java -Xmx4g -jar /usr/GenomeAnalysisTK.jar \
-T IndelRealigner \
-R ${genome_fasta} \
-I ${bam_file_marked_duplicate} \
-known ${mills_indel_file} \
-known ${known_indel_file} \
-targetIntervals ${interval_list} \
-o "${bam_file_marked_duplicate.baseName}.realigned.bam"
"""
}
/*
* use GATK to detect systematic errors in base quality scores.
*/
process gatk_base_recalibrator {
tag "$sample"
container "broadinstitute/gatk3:3.8-0"
cpus = 8
memory = "30 GB"
input:
file genome_fasta
file genome_fasta_fai
file genome_fasta_dict
file known_indel_file
file mills_indel_file
file known_dbsnps_file
file known_dbsnps_1000_file
set sample, file(indel_realigned_bam), file(indel_realigned_bai) from gatk_indel_realignment_ch
output:
set sample, file(indel_realigned_bam), file(indel_realigned_bai), file("${indel_realigned_bam.baseName}.data.table") into gatk_base_recalibrator_ch
script:
"""
java -Xmx4g -jar /usr/GenomeAnalysisTK.jar \
-T BaseRecalibrator \
-nct ${task.cpus} \
-R ${genome_fasta} \
-I ${indel_realigned_bam} \
--knownSites ${known_dbsnps_1000_file} \
--knownSites ${known_dbsnps_file} \
--knownSites ${mills_indel_file} \
--knownSites ${known_indel_file} \
-o "${indel_realigned_bam.baseName}.data.table"
"""
}
/*
* use GATK to write out sequence read data (for filtering, merging, subsetting etc).
*/
process gatk_print_reads {
tag "$sample"
container "broadinstitute/gatk3:3.8-0"
cpus = 8
memory = "30 GB"
input:
file genome_fasta
file genome_fasta_fai
file genome_fasta_dict
set sample, file(indel_realigned_bam), file(indel_realigned_bai), file(recalibration_table) from gatk_base_recalibrator_ch
output:
set sample, file("*.processed.bam"), file("*.processed.bai") into processed_bam_ch_1, processed_bam_ch_2
script:
"""
java -Xmx4g -jar /usr/GenomeAnalysisTK.jar \
-T PrintReads \
-nct ${task.cpus} \
-R ${genome_fasta} \
-I ${indel_realigned_bam} \
-BQSR ${recalibration_table} \
-o "${indel_realigned_bam.baseName}.processed.bam"
"""
}
/*
* call Germline SNPs and indels via local re-assembly of Haplotypes.
*/
process haplotype_caller {
tag "$sample"
container "broadinstitute/gatk3:3.8-0"
cpus = 2
memory = "7.5 GB"
input:
file genome_fasta
file genome_fasta_fai
file genome_fasta_dict
file known_dbsnps_file
set sample, file(processed_bam), file(processed_bai) from processed_bam_ch_1
output:
set sample, file("${sample}.vcf") into haplotype_caller_ch
script:
"""
java -Xmx4g -jar /usr/GenomeAnalysisTK.jar \
-T HaplotypeCaller \
-R ${genome_fasta} \
-I ${processed_bam} \
--dbsnp ${known_dbsnps_file} \
--out "${sample}.vcf"
"""
}
/*
* sort VCF files according to the order of the contigs in the header/sequence dictionary and then by coordinate.
*/
process picard_sort_vcf {
tag "$sample"
container "noelnamai/picard:2.18.25"
cpus = 2
memory = "7.5 GB"
publishDir "${params.results}/${params.population}/$sample", mode: "copy", overwrite: true
input:
file genome_fasta
file genome_fasta_fai
file genome_fasta_dict
set sample, file(original_vcf) from haplotype_caller_ch
output:
set sample, file("${original_vcf.baseName}.sorted.vcf") into picard_sort_vcf_ch
script:
"""
java -Xmx4g -jar /opt/picard.jar SortVcf \
I=${original_vcf} \
O="${original_vcf.baseName}.sorted.vcf" \
SEQUENCE_DICTIONARY=${genome_fasta_dict}
"""
}
/*
* filter variant calls based on INFO and FORMAT annotations.
*/
process gatk_variant_filtration {
tag "$sample"
container "broadinstitute/gatk3:3.8-0"
cpus = 2
memory = "7.5 GB"
publishDir "${params.results}/${params.population}/$sample", mode: "copy", overwrite: true
input:
file genome_fasta
file genome_fasta_fai
file genome_fasta_dict
set sample, file(sorted_vcf) from picard_sort_vcf_ch
output:
set sample, file("${sorted_vcf.baseName}.filtered.vcf") into gatk_variant_filtration_ch
script:
"""
java -Xmx4g -jar /usr/GenomeAnalysisTK.jar \
-T VariantFiltration \
-R ${genome_fasta} \
-V ${sorted_vcf} \
-window 35 \
-cluster 3 \
-filterName FS \
-filter "FS > 30.0" \
-filterName QD \
-filter "QD < 2.0" \
-o "${sorted_vcf.baseName}.filtered.vcf"
"""
}
/*
* functionally annotate genetic variants detected from diverse genomes using ANNOVAR.
*/
process annovar {
tag "$sample"
container "noelnamai/annovar:4.18"
cpus = 4
memory = "15 GB"
publishDir "${params.results}/${params.population}/$sample", mode: "copy", overwrite: true
input:
set sample, file(haplotype_caller_vcf) from gatk_variant_filtration_ch
output:
set sample, file("${sample}.annovar.hg19.multianno.txt") into annovar_ch
script:
"""
perl /opt/annovar/annotate_variation.pl -buildver hg19 -downdb -webfrom annovar refGene /opt/annovar/humandb/
perl /opt/annovar/annotate_variation.pl -buildver hg19 -downdb cytoBand /opt/annovar/humandb/
perl /opt/annovar/annotate_variation.pl -buildver hg19 -downdb -webfrom annovar exac03 /opt/annovar/humandb/
perl /opt/annovar/annotate_variation.pl -buildver hg19 -downdb -webfrom annovar avsnp147 /opt/annovar/humandb/
perl /opt/annovar/annotate_variation.pl -buildver hg19 -downdb -webfrom annovar dbnsfp30a /opt/annovar/humandb/
perl /opt/annovar/table_annovar.pl ${haplotype_caller_vcf} /opt/annovar/humandb \
-buildver hg19 \
-out "${sample}.annovar" \
-protocol refGene \
-operation g \
-nastring . \
-vcfinput \
--thread ${task.cpus} \
--maxgenethread ${task.cpus} \
-polish \
-otherinfo
mv ${sample}.annovar.hg19_multianno.txt ${sample}.annovar.hg19.multianno.txt
"""
}