-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmain.nf
More file actions
428 lines (343 loc) · 10.3 KB
/
main.nf
File metadata and controls
428 lines (343 loc) · 10.3 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
#!/usr/bin/env nextflow
VERSION="0.2"
log.info "===================================================================="
log.info "GATK4 Best Practice Nextflow Pipeline (v${VERSION}) "
log.info "===================================================================="
params.help = ""
if (params.help) {
log.info " "
log.info "USAGE: "
log.info " "
log.info "nextflow run oliverSI/GATK4_Best_Practice --fastq1 read_R1.fastq.gz --fastq2 read_R2.fastq.gz"
log.info " "
log.info "Mandatory arguments:"
log.info " --fastq1 FILE Fastq(.gz) file for read1"
log.info " --fastq2 FILE Fastq(.gz) file for read2"
log.info " "
log.info "Optional arguments:"
log.info " --outdir DIR Output directory(default: ./Results)"
log.info " --samplename STRING Sample name(dafault: fastq1 basename)"
log.info " --rg STRING Read group tag(dafault: fastq1 basename)"
log.info " "
log.info "===================================================================="
exit 1
}
fastq1 = file("$params.fastq1")
fastq2 = file("$params.fastq2")
params.outdir = "./Results"
params.samplename = fastq1.baseName
params.rg = fastq1.baseName
process get_reference {
publishDir "${params.outdir}/reference"
container 'oliversi/hg19'
output:
file "ucsc.hg19.fasta" into reference
file "ucsc.hg19.dict" into reference_dict
file "ucsc.hg19.fasta.fai" into reference_fai
"""
gunzip -dc /data/ucsc.hg19.fasta.gz > ucsc.hg19.fasta
gunzip -dc /data/ucsc.hg19.dict.gz > ucsc.hg19.dict
gunzip -dc /data/ucsc.hg19.fasta.fai.gz > ucsc.hg19.fasta.fai
"""
}
process get_dbSNP {
publishDir "${params.outdir}/reference"
container 'oliversi/hg19'
output:
file "dbsnp_138.hg19.vcf" into dbsnp
file "dbsnp_138.hg19.vcf.idx" into dbsnp_idx
"""
gunzip -dc /data/dbsnp_138.hg19.vcf.gz > dbsnp_138.hg19.vcf
gunzip -dc /data/dbsnp_138.hg19.vcf.idx.gz > dbsnp_138.hg19.vcf.idx
"""
}
process get_golden_indel {
publishDir "${params.outdir}/reference"
container 'oliversi/hg19'
output:
file "Mills_and_1000G_gold_standard.indels.hg19.sites.vcf" into golden_indel
file "Mills_and_1000G_gold_standard.indels.hg19.sites.vcf.idx" into golden_indel_idx
"""
gunzip -dc /data/Mills_and_1000G_gold_standard.indels.hg19.sites.vcf.gz > Mills_and_1000G_gold_standard.indels.hg19.sites.vcf
gunzip -dc /data/Mills_and_1000G_gold_standard.indels.hg19.sites.vcf.idx.gz > Mills_and_1000G_gold_standard.indels.hg19.sites.vcf.idx
"""
}
process get_hapmap {
publishDir "${params.outdir}/reference"
container 'oliversi/hg19'
output:
file "hapmap_3.3.hg19.sites.vcf" into hapmap
file "hapmap_3.3.hg19.sites.vcf.idx" into hapmap_idx
"""
gunzip -dc /data/hapmap_3.3.hg19.sites.vcf.gz > hapmap_3.3.hg19.sites.vcf
gunzip -dc /data/hapmap_3.3.hg19.sites.vcf.idx.gz > hapmap_3.3.hg19.sites.vcf.idx
"""
}
process get_omni {
publishDir "${params.outdir}/reference"
container 'oliversi/hg19'
output:
file "1000G_omni2.5.hg19.sites.vcf" into omni
file "1000G_omni2.5.hg19.sites.vcf.idx" into omni_idx
"""
gunzip -dc /data/1000G_omni2.5.hg19.sites.vcf.gz > 1000G_omni2.5.hg19.sites.vcf
gunzip -dc /data/1000G_omni2.5.hg19.sites.vcf.idx.gz > 1000G_omni2.5.hg19.sites.vcf.idx
"""
}
process get_phase1_SNPs {
publishDir "${params.outdir}/reference"
container 'oliversi/hg19'
output:
file "1000G_phase1.snps.high_confidence.hg19.sites.vcf" into phase1_snps
file "1000G_phase1.snps.high_confidence.hg19.sites.vcf.idx" into phase1_snps_idx
"""
gunzip -dc /data/1000G_phase1.snps.high_confidence.hg19.sites.vcf.gz > 1000G_phase1.snps.high_confidence.hg19.sites.vcf
gunzip -dc /data/1000G_phase1.snps.high_confidence.hg19.sites.vcf.idx.gz > 1000G_phase1.snps.high_confidence.hg19.sites.vcf.idx
"""
}
process get_BWA_index {
publishDir "${params.outdir}/reference"
container 'oliversi/hg19'
output:
set "ucsc.hg19.fasta.amb", "ucsc.hg19.fasta.ann", "ucsc.hg19.fasta.bwt", "ucsc.hg19.fasta.pac", "ucsc.hg19.fasta.sa" into bwa_index
"""
gunzip -dc /data/ucsc.hg19.fasta.amb.gz > ucsc.hg19.fasta.amb
gunzip -dc /data/ucsc.hg19.fasta.ann.gz > ucsc.hg19.fasta.ann
gunzip -dc /data/ucsc.hg19.fasta.bwt.gz > ucsc.hg19.fasta.bwt
gunzip -dc /data/ucsc.hg19.fasta.pac.gz > ucsc.hg19.fasta.pac
gunzip -dc /data/ucsc.hg19.fasta.sa.gz > ucsc.hg19.fasta.sa
"""
}
process BWA {
publishDir "${params.outdir}/MappedRead"
container 'kathrinklee/bwa:latest'
input:
file reference
file bwa_index
file fastq1
file fastq2
output:
file 'aln-pe.sam' into samfile
"""
bwa mem -M -R '@RG\\tID:${params.rg}\\tSM:${params.samplename}\\tPL:Illumina' $reference $fastq1 $fastq2 > aln-pe.sam
"""
}
process BWA_sort {
publishDir "${params.outdir}/MappedRead"
container 'comics/samtools:latest'
input:
file samfile
output:
file 'aln-pe-sorted.bam' into bam_sort
"""
samtools sort -o aln-pe-sorted.bam -O BAM $samfile
"""
}
process MarkDuplicates {
publishDir "${params.outdir}/MappedRead"
container 'broadinstitute/gatk'
input:
file bam_sort
output:
file 'aln-pe_MarkDup.bam' into bam_markdup
"""
gatk MarkDuplicates -I $bam_sort -M metrics.txt -O aln-pe_MarkDup.bam
"""
}
process BaseRecalibrator {
publishDir "${params.outdir}/BaseRecalibrator"
container 'broadinstitute/gatk:latest'
input:
file reference
file reference_fai
file reference_dict
file bam_markdup
file dbsnp
file dbsnp_idx
file golden_indel
file golden_indel_idx
output:
file 'recal_data.table' into BaseRecalibrator_table
"""
gatk BaseRecalibrator \
-I $bam_markdup \
--known-sites $dbsnp \
--known-sites $golden_indel \
-O recal_data.table \
-R $reference
"""
}
process ApplyBQSR {
publishDir "${params.outdir}/BaseRecalibrator"
container 'broadinstitute/gatk:latest'
input:
file BaseRecalibrator_table
file bam_markdup
output:
file 'aln-pe_bqsr.bam' into bam_bqsr
script:
"""
gatk ApplyBQSR -I $bam_markdup -bqsr $BaseRecalibrator_table -O aln-pe_bqsr.bam
"""
}
process HaplotypeCaller {
publishDir "${params.outdir}/HaplotypeCaller"
container 'broadinstitute/gatk:latest'
input:
file reference
file reference_fai
file reference_dict
file bam_bqsr
output:
file 'haplotypecaller.g.vcf' into haplotypecaller_gvcf
script:
"""
gatk HaplotypeCaller -I $bam_bqsr -O haplotypecaller.g.vcf --emit-ref-confidence GVCF -R $reference
"""
}
process GenotypeGVCFs {
publishDir "${params.outdir}/HaplotypeCaller"
container 'broadinstitute/gatk:latest'
input:
file reference
file reference_fai
file reference_dict
file haplotypecaller_gvcf
output:
file 'haplotypecaller.vcf' into haplotypecaller_vcf
script:
"""
gatk GenotypeGVCFs --variant haplotypecaller.g.vcf -R $reference -O haplotypecaller.vcf
"""
}
process VariantRecalibrator_SNPs {
publishDir "${params.outdir}/VariantRecalibrator"
container 'broadinstitute/gatk:latest'
input:
file reference
file reference_fai
file reference_dict
file haplotypecaller_vcf
file hapmap
file hapmap_idx
file omni
file omni_idx
file phase1_snps
file phase1_snps_idx
file dbsnp
file dbsnp_idx
output:
file 'recalibrate_SNP.recal' into variantrecalibrator_recal
file 'recalibrate_SNP.recal.idx' into variantrecalibrator_recal_idx
file 'recalibrate_SNP.tranches' into variantrecalibrator_tranches
script:
"""
gatk VariantRecalibrator \
-V $haplotypecaller_vcf \
-R $reference \
-resource hapmap,known=false,training=true,truth=true,prior=15.0:./$hapmap \
-resource omni,known=false,training=true,truth=true,prior=12.0:./$omni \
-resource 1000G,known=false,training=true,truth=false,prior=10.0:./$phase1_snps \
-resource dbsnp,known=true,training=false,truth=false,prior=2.0:./$dbsnp \
-an DP \
-an QD \
-an FS \
-an SOR \
-an MQ \
-an MQRankSum \
-an ReadPosRankSum \
-mode SNP \
-tranche 100.0 -tranche 99.9 -tranche 99.0 -tranche 90.0 \
--max-gaussians 8 \
-O recalibrate_SNP.recal \
--tranches-file recalibrate_SNP.tranches \
"""
}
process ApplyVQSR_SNPs {
publishDir "${params.outdir}/VariantRecalibrator"
container 'broadinstitute/gatk:latest'
input:
file haplotypecaller_vcf
file variantrecalibrator_recal
file variantrecalibrator_recal_idx
file variantrecalibrator_tranches
output:
file 'recalibrated_snps_raw_indels.vcf' into recalibrated_snps_raw_indels
script:
"""
gatk ApplyVQSR \
-V $haplotypecaller_vcf \
--recal-file $variantrecalibrator_recal \
--tranches-file $variantrecalibrator_tranches \
-mode SNP \
-ts-filter-level 99.0 \
-O recalibrated_snps_raw_indels.vcf
"""
}
process VariantRecalibrator_INDELs {
publishDir "${params.outdir}/VariantRecalibrator"
container 'broadinstitute/gatk:latest'
input:
file reference
file reference_fai
file reference_dict
file recalibrated_snps_raw_indels
file dbsnp
file dbsnp_idx
file golden_indel
file golden_indel_idx
output:
file 'recalibrate_INDEL.recal' into variantrecalibrator_indel_recal
file 'recalibrate_INDEL.recal.idx' into variantrecalibrator_indel_recal_idx
file 'recalibrate_INDEL.tranches' into variantrecalibrator_indel_tranches
script:
"""
gatk VariantRecalibrator \
-V $recalibrated_snps_raw_indels \
-R $reference \
--resource mills,known=false,training=true,truth=true,prior=12.0:./$golden_indel \
--resource dbsnp,known=true,training=false,truth=false,prior=2.0:./$dbsnp \
-an QD \
-an DP \
-an FS \
-an SOR \
-an MQRankSum \
-an ReadPosRankSum \
-mode INDEL \
-tranche 100.0 -tranche 99.9 -tranche 99.0 -tranche 90.0 \
--max-gaussians 4 \
-O recalibrate_INDEL.recal \
--tranches-file recalibrate_INDEL.tranches \
"""
}
process ApplyVQSR_INDELs {
publishDir "${params.outdir}/VariantRecalibrator"
container 'broadinstitute/gatk:latest'
input:
file recalibrated_snps_raw_indels
file variantrecalibrator_indel_recal
file variantrecalibrator_indel_recal_idx
file variantrecalibrator_indel_tranches
output:
file 'recalibrated_variants.vcf' into recalibrated_variants_vcf
script:
"""
gatk ApplyVQSR \
-V $recalibrated_snps_raw_indels \
--recal-file $variantrecalibrator_indel_recal \
--tranches-file $variantrecalibrator_indel_tranches \
-mode INDEL \
-ts-filter-level 99.0 \
-O recalibrated_variants.vcf
"""
}
process copy {
publishDir "${params.outdir}", mode: 'copy'
input:
file recalibrated_variants_vcf
output:
file "${params.samplename}.vcf"
"""
mv $recalibrated_variants_vcf ${params.samplename}.vcf
"""
}