This repository has been archived by the owner on Apr 19, 2018. It is now read-only.
forked from nf-core/exoseq
-
Notifications
You must be signed in to change notification settings - Fork 6
/
PairedSingleSampleWF.nf
763 lines (640 loc) · 24.5 KB
/
PairedSingleSampleWF.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
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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
#!/usr/bin/env nextflow
/*
vim: syntax=groovy
-*- mode: groovy;-*-
========================================================================================
NGI - E X O S E Q B E S T P R A C T I C E
========================================================================================
#### Homepage / Documentation
https://github.com/scilifelab/NGI-ExoSeq
#### Authors
Senthilkumar Panneerselvam @senthil10 <[email protected]>
Phil Ewels @ewels <[email protected]>
Alex Peltzer @alex_peltzer <[email protected]>
Marie Gauder <[email protected]>
Some code parts were lent from other NGI-Pipelines (e.g. CAW), specifically the error
handling, logging messages. Thanks for that @CAW guys.
----------------------------------------------------------------------------------------
Developed based on GATK's best practise, takes set of FASTQ files and performs:
- alignment (BWA)
- recalibration (GATK)
- realignment (GATK)
- variant calling (GATK)
- variant evaluation (SnpEff)
*/
// Package version
version = '0.8.1'
// Help message
helpMessage = """
===============================================================================
NGI-ExoSeq : Exome/Targeted sequence capture best practice analysis v${version}
===============================================================================
Usage: nextflow SciLifeLab/NGI-ExoSeq --reads '*_R{1,2}.fastq.gz' --genome GRCh37
This is a typical usage where the required parameters (with no defaults) were
given. The available paramaters are listed below based on category
Required parameters:
--reads Absolute path to project directory
--genome Name of iGenomes reference
Output:
--outdir Path where the results to be saved [Default: './results']
Kit files:
--kit Kit used to prep samples [Default: 'agilent_v5']
--bait Absolute path to bait file
--target Absolute path to target file
--target_bed Absolute path to target bed file (snpEff compatible format)
Genome/Variation files:
--dbsnp Absolute path to dbsnp file
--thousandg Absolute path to 1000G file
--mills Absolute path to Mills file
--omni Absolute path to Omni file
--gfasta Absolute path to genome fasta file
--bwa_index Absolute path to bwa genome index
Other options:
--exome Exome data, if this is not set, run as genome data
--project Uppnex project to user for SLURM executor
For more detailed information regarding the parameters and usage refer to package
documentation at https:// github.com/scilifelab/NGI-ExoSeq
"""
// Variables and defaults
params.name = false
params.help = false
params.reads = false
params.singleEnd = false
params.genome = false
params.run_id = false
params.exome = false //default genome, set to true to run restricting to exome positions
params.aligner = 'bwa' //Default, but stay tuned for later ;-)
params.saveReference = true
// Output configuration
params.outdir = './results'
params.saveAlignedIntermediates = false
params.saveIntermediateVariants = false
// Clipping options
params.notrim = false
params.clip_r1 = 0
params.clip_r2 = 0
params.three_prime_clip_r1 = 0
params.three_prime_clip_r2 = 0
// Kit options
params.kit = 'agilent_v5'
params.bait = params.kitFiles[ params.kit ] ? params.kitFiles[ params.kit ].bait ?: false : false
params.target = params.kitFiles[ params.kit ] ? params.kitFiles[ params.kit ].target ?: false : false
params.target_bed = params.kitFiles[ params.kit ] ? params.kitFiles[ params.kit ].target_bed ?: false : false
params.dbsnp = params.metaFiles[ params.genome ] ? params.metaFiles[ params.genome ].dbsnp ?: false : false
params.thousandg = params.metaFiles[ params.genome ] ? params.metaFiles[ params.genome ].thousandg ?: false : false
params.mills = params.metaFiles[ params.genome ] ? params.metaFiles[ params.genome ].mills ?: false : false
params.omni = params.metaFiles[ params.genome ] ? params.metaFiles[ params.genome ].omni ?: false : false
params.gfasta = params.metaFiles[ params.genome ] ? params.metaFiles[ params.genome ].gfasta ?: false : false
params.bwa_index = params.metaFiles[ params.genome ] ? params.metaFiles[ params.genome ].bwa_index ?: false : false
// Has the run name been specified by the user?
// this has the bonus effect of catching both -name and --name
custom_runName = params.name
if( !(workflow.runName ==~ /[a-z]+_[a-z]+/) ){
custom_runName = workflow.runName
}
// Show help when needed
if (params.help){
log.info helpMessage
exit 0
}
// Check blocks for certain required parameters, to see they are given and exist
if (!params.reads || !params.genome){
exit 1, "Parameters '--reads' and '--genome' are required to run the pipeline"
}
if (!params.kitFiles[ params.kit ] && ['bait', 'target'].count{ params[it] } != 2){
exit 1, "Kit '${params.kit}' is not available in pre-defined config, so " +
"provide all kit specific files with option '--bait' and '--target'"
}
if (!params.metaFiles[ params.genome ] && ['gfasta', 'bwa_index', 'dbsnp', 'thousandg', 'mills', 'omni'].count{ params[it] } != 6){
exit 1, "Genome '${params.genome}' is not available in pre-defined config, so you need to provide all genome specific " +
"files with options '--gfasta', '--bwa_index', '--dbsnp', '--thousandg', '--mills' and '--omni'"
}
// Create a channel for input files
Channel
.fromFilePairs( params.reads, size: params.singleEnd ? 1 : 2 )
.ifEmpty { exit 1, "Cannot find any reads matching: ${params.reads}\nNB: Path needs to be enclosed in quotes!\nNB: Path requires at least one * wildcard!\nIf this is single-end data, please specify --singleEnd on the command line." }
.into { read_files_fastqc; read_files_trimming }
// Validate Input indices for BWA Mem and GATK
if(params.aligner == 'bwa' ){
bwaId = Channel
.fromPath("${params.gfasta}.bwt")
.ifEmpty { exit 1, "BWA index not found: ${params.gfasta}.bwt" }
}
// Create a summary for the logfile
def summary = [:]
summary['Run Name'] = custom_runName ?: workflow.runName
summary['Reads'] = params.reads
summary['Data Type'] = params.singleEnd ? 'Single-End' : 'Paired-End'
summary['Genome'] = params.genome
summary['WES/WGS'] = params.exome ? 'WES' : 'WGS'
summary['Trim R1'] = params.clip_r1
summary['Trim R2'] = params.clip_r2
summary["Trim 3' R1"] = params.three_prime_clip_r1
summary["Trim 3' R2"] = params.three_prime_clip_r2
if(params.aligner == 'bwa'){
summary['Aligner'] = "BWA Mem"
if(params.bwa_index) summary['BWA Index'] = params.bwa_index
else if(params.gfasta) summary['Fasta Ref'] = params.gfasta
}
summary['Save Intermediate Aligned Files'] = params.saveAlignedIntermediates ? 'Yes' : 'No'
summary['Save Intermediate Variant Files'] = params.saveIntermediateVariants ? 'Yes' : 'No'
summary['Max Memory'] = params.max_memory
summary['Max CPUs'] = params.max_cpus
summary['Max Time'] = params.max_time
summary['Output dir'] = params.outdir
summary['Working dir'] = workflow.workDir
summary['Container'] = workflow.container
if(workflow.revision) summary['Pipeline Release'] = workflow.revision
summary['Current home'] = "$HOME"
summary['Current user'] = "$USER"
summary['Current path'] = "$PWD"
summary['Script dir'] = workflow.projectDir
summary['Config Profile'] = workflow.profile
log.info summary.collect { k,v -> "${k.padRight(15)}: $v" }.join("\n")
log.info "========================================="
// Nextflow version check
nf_required_version = '0.25.0'
try {
if( ! workflow.nextflow.version.matches(">= $nf_required_version") ){
throw GroovyException('Nextflow version too old')
}
} catch (all) {
log.error "====================================================\n" +
" Nextflow version $nf_required_version required! You are running v$workflow.nextflow.version.\n" +
" Pipeline execution will continue, but things may break.\n" +
" Please run `nextflow self-update` to update Nextflow.\n" +
"============================================================"
}
// Build BWA Index if this is required
if(params.aligner == 'bwa' && !params.bwa_index){
// Create Channels
fasta_for_bwa_index = Channel
.fromPath("${params.gfasta}")
fasta_for_samtools_index = Channel
.fromPath("${params.gfasta}")
// Create a BWA index for non-indexed genomes
process makeBWAIndex {
tag "$params.gfasta"
publishDir path: { params.saveReference ? "${params.outdir}/reference_genome" : params.outdir },
saveAs: { params.saveReference ? it : null }, mode: 'copy'
input:
file fasta from fasta_for_bwa_index
output:
file "*.{amb,ann,bwt,pac,sa}" into bwa_index
script:
"""
bwa index $fasta
"""
}
// Create a FastA index for non-indexed genomes
process makeFastaIndex {
tag "$params.gfasta"
publishDir path: { params.saveReference ? "${params.outdir}/reference_genome" : params.outdir },
saveAs: { params.saveReference ? it : null }, mode: 'copy'
input:
file fasta from fasta_for_samtools_index
output:
file "*.fai" into samtools_index
script:
"""
samtools faidx $fasta
"""
}
} else {
bwa_index = file("${params.bwa_index}")
}
/*
* STEP 0 - FastQC
*
*/
process fastqc {
tag "$name"
publishDir "${params.outdir}/fastqc", mode: 'copy',
saveAs: {filename -> filename.indexOf(".zip") > 0 ? "zips/$filename" : "$filename"}
input:
set val(name), file(reads) from read_files_fastqc
output:
file '*_fastqc.{zip,html}' into fastqc_results
file '.command.out' into fastqc_stdout
script:
"""
fastqc -q $reads
fastqc --version
"""
}
/*
* STEP 1 - trim with trim galore
*/
if(params.notrim){
trimmed_reads = read_files_trimming
trimgalore_results = []
trimgalore_logs = []
} else {
process trim_galore {
tag "$name"
publishDir "${params.outdir}/trim_galore", mode: 'copy'
input:
set val(name), file(reads) from read_files_trimming
output:
set val(name), file(reads) into trimmed_reads
file '*trimming_report.txt' into trimgalore_results, trimgalore_logs
script:
single = reads instanceof Path
c_r1 = params.clip_r1 > 0 ? "--clip_r1 ${params.clip_r1}" : ''
c_r2 = params.clip_r2 > 0 ? "--clip_r2 ${params.clip_r2}" : ''
tpc_r1 = params.three_prime_clip_r1 > 0 ? "--three_prime_clip_r1 ${params.three_prime_clip_r1}" : ''
tpc_r2 = params.three_prime_clip_r2 > 0 ? "--three_prime_clip_r2 ${params.three_prime_clip_r2}" : ''
if (params.singleEnd) {
"""
trim_galore --gzip $c_r1 $tpc_r1 $reads
"""
} else {
"""
trim_galore --paired --gzip $c_r1 $c_r2 $tpc_r1 $tpc_r2 $reads
"""
}
}
}
/*
* STEP 2 - Map with BWA Mem
*/
process bwamem {
tag "$name"
input:
set val(name), file(reads) from trimmed_reads
file(bwa_index) from bwa_index
output:
set val(name), file("${name}_bwa.sam") into raw_aln_sam
file '.command.log' into bwa_stdout
script:
rg="\'@RG\\tID:${params.run_id}\\tSM:${params.run_id}\\tPL:illumina\'"
"""
bwa mem \\
-R $rg \\
-t ${task.cpus} \\
-k 2 \\
$params.gfasta \\
$reads \\
> ${name}_bwa.sam
# Print version number to standard out
echo "BWA Version:"\$(bwa 2>&1)
"""
}
/*
* STEP 3 - Convert to BAM, sort BAM
*/
process sortSam {
tag "${name}"
publishDir "${params.outdir}/BWAmem", mode: 'copy',
saveAs: {filename -> params.saveAlignedIntermediates ? "$filename" : null }
input:
set val(name), file(raw_sam) from raw_aln_sam
output:
set val(name), file("${raw_sam}.sorted.bam") into samples_sorted_bam
file '.command.log' into samtools_stdout
script:
def avail_mem = task.memory ? "-m ${task.memory.toBytes().intdiv(task.cpus)}" : ''
"""
samtools sort \\
$raw_sam \\
-@ ${task.cpus}\\
$avail_mem \\
-o ${raw_sam}.sorted.bam
# Print version number to standard out
echo "Samtools V:"\$(samtools 2>&1)
"""
}
/*
* STEP 4 - Mark PCR duplicates in sorted BAM file
*/
process markDuplicates {
tag "${name}"
publishDir "${params.outdir}/Picard_Markduplicates/metrics", mode: 'copy',
saveAs: { filename -> filename.indexOf(".dup_metrics") > 0 ? filename : null }
input:
set val(name), file(sorted_bam) from samples_sorted_bam
output:
set val(name), file("${name}_markdup.bam"), file("${name}_markdup.bai") into samples_markdup_bam, samples_for_applyBQSR
file("${name}.dup_metrics") into markdup_results
file '.command.log' into markDuplicates_stdout
script:
"""
gatk MarkDuplicates \\
--INPUT $sorted_bam \\
--OUTPUT ${name}_markdup.bam \\
--METRICS_FILE ${name}.dup_metrics \\
--REMOVE_DUPLICATES false \\
--CREATE_INDEX true \\
--java-options -Xmx${task.memory.toGiga()}g
"""
}
/*
* Step 5 - Recalibrate BAM file with known variants and BaseRecalibrator
*
*/
process recal_bam_files {
tag "${name}"
publishDir "${params.outdir}/GATK_Recalibration", mode: 'copy'
input:
set val(name), file(markdup_bam), file(markdup_bam_ind) from samples_markdup_bam
output:
set val(name), file("${name}_table.recal") into samples_recal_reports
file '.command.log' into gatk_stdout
file '.command.log' into gatk_base_recalibration_results
script:
if(params.exome){
"""
gatk BaseRecalibrator \\
-R $params.gfasta \\
-I $markdup_bam \\
-O ${name}_table.recal \\
-L $params.target \\
--known-sites $params.dbsnp \\
--verbosity INFO \\
--java-options -Xmx${task.memory.toGiga()}g
# Print version number to standard out
echo "GATK version "\$(gatk BaseRecalibrator --version 2>&1)
"""
} else {
"""
gatk BaseRecalibrator \\
-R $params.gfasta \\
-I $markdup_bam \\
-O ${name}_table.recal \\
--known-sites $params.dbsnp \\
--verbosity INFO \\
--java-options -Xmx${task.memory.toGiga()}g
# Print version number to standard out
echo "GATK version "\$(gatk BaseRecalibrator --version 2>&1)
"""
}
}
process applyBQSR {
tag "${name}"
publishDir "${params.outdir}/GATK_ApplyBQSR", mode: 'copy'
input:
set val(name), file("${name}_table.recal") from samples_recal_reports
set val(name), file(markdup_bam), file(markdup_bam_ind) from samples_for_applyBQSR
output:
set val(name), file("${name}.bam"), file("${name}.bai") into bam_vcall, bam_metrics
script:
if(params.exome){
"""
gatk ApplyBQSR \\
-R $params.gfasta \\
-I $markdup_bam \\
--bqsr-recal-file ${name}_table.recal \\
-O ${name}.bam \\
-L $params.target \\
--create-output-bam-index true \\
--java-options -Xmx${task.memory.toGiga()}g
"""
} else {
"""
gatk ApplyBQSR \\
-R $params.gfasta \\
-I $markdup_bam \\
--bqsr-recal-file ${name}_table.recal \\
-O ${name}.bam \\
--create-output-bam-index true \\
--java-options -Xmx${task.memory.toGiga()}g
"""
}
}
/*
* Step 7 - Determine quality metrics of mapped BAM files using QualiMap 2
*
*/
process qualiMap {
tag "${name}"
publishDir "${params.outdir}/Qualimap", mode: 'copy'
input:
set val(name), file(realign_bam), file(realign_bam_ind) from bam_metrics
output:
file "${name}" into qualimap_results
file '.command.log' into qualimap_stdout
script:
gcref = ''
gff = ''
if(params.genome == 'GRCh37') gcref = '-gd HUMAN'
if(params.genome == 'GRCm38') gcref = '-gd MOUSE'
if(params.exome) gff ="-gff ${params.target_bed}"
"""
qualimap bamqc $gcref \\
-bam $realign_bam \\
-outdir ${name} \\
--skip-duplicated \\
--collect-overlap-pairs \\
-nt ${task.cpus} \\
$gff \\
--java-mem-size=${task.memory.toGiga()}G \\
# Print version number to standard out
echo "QualiMap version "\$(qualimap --version 2>&1)
"""
}
/*
* Step 8 - Call Variants with HaplotypeCaller in GVCF mode (differentiate between exome and whole genome data here)
*
*/
process variantCall {
tag "${name}"
publishDir "${params.outdir}/GATK_VariantCalling/", mode: 'copy',
saveAs: {filename -> filename.replaceFirst(/variants/, "raw_variants")}
input:
set val(name), file(realign_bam), file(realign_bam_ind) from bam_vcall
output:
set val(name), file("${name}_variants.vcf"), file("${name}_variants.vcf.idx") into raw_variants
script:
if(params.exome){
"""
gatk HaplotypeCaller \\
-I $realign_bam \\
-R $params.gfasta \\
-O ${name}_variants.vcf \\
-ERC GVCF \\
-L $params.target \\
--create-output-variant-index \\
--annotation MappingQualityRankSumTest \\
--annotation QualByDepth \\
--annotation ReadPosRankSumTest \\
--annotation RMSMappingQuality \\
--annotation FisherStrand \\
--annotation Coverage \\
--dbsnp $params.dbsnp \\
--verbosity INFO \\
--java-options -Xmx${task.memory.toGiga()}g
"""
} else { //We have a winner (genome)
"""
gatk HaplotypeCaller \\
-I $realign_bam \\
-R $params.gfasta \\
-O ${name}_variants.vcf \\
-ERC GVCF \\
--create-output-variant-index \\
--annotation MappingQualityRankSumTest \\
--annotation QualByDepth \\
--annotation ReadPosRankSumTest \\
--annotation RMSMappingQuality \\
--annotation FisherStrand \\
--annotation Coverage \\
--dbsnp $params.dbsnp \\
--verbosity INFO \\
--java-options -Xmx${task.memory.toGiga()}g
"""
}
}
/*
* Step 9 - Generate Software Versions Map
*
*/
software_versions = [
'FastQC': null, 'Trim Galore!': null, 'BWA': null, 'GATK': null, 'Samtools': null,
'QualiMap': null, 'Nextflow': "v$workflow.nextflow.version"
]
/*
* Step 10 - Generate a YAML file for software versions in the pipeline
* This is then parsed by MultiQC and the report feature to produce a final report with the software Versions in the pipeline.
*/
process get_software_versions {
cache false
executor 'local'
input:
val fastqc from fastqc_stdout.collect()
val trim_galore from trimgalore_logs.collect()
val bwa from bwa_stdout.collect()
val gatk from gatk_stdout.collect()
val samtools from samtools_stdout.collect()
val qualimap from qualimap_stdout.collect()
output:
file 'software_versions_mqc.yaml' into software_versions_yaml
exec:
software_versions['FastQC'] = fastqc[0].getText().find(/FastQC v(\S+)/) { match, version -> "v$version"}
software_versions['Trim Galore!'] = trim_galore[0].getText().find(/Trim Galore version: (\S+)/) {match, version -> "v$version"}
software_versions['BWA'] = bwa[0].getText().find(/Version: (\S+)/) {match, version -> "v$version"}
software_versions['GATK'] = gatk[0].getText().find(/Version:([\d\.]+)/) {match, version -> "v$version"}
software_versions['Samtools'] = samtools[0].getText().find(/Version: ([\d\.]+)/) {match, version -> "v$version"}
software_versions['QualiMap'] = qualimap[0].getText().find(/QualiMap v.(\S+)/) {match, version -> "v$version"}
def sw_yaml_file = task.workDir.resolve('software_versions_mqc.yaml')
sw_yaml_file.text = """
id: 'ngi-exoseq'
section_name: 'NGI-ExoSeq Software Versions'
section_href: 'https://github.com/SciLifeLab/NGI-ExoSeq'
plot_type: 'html'
description: 'are collected at run time from the software output.'
data: |
<dl class=\"dl-horizontal\">
${software_versions.collect{ k,v -> " <dt>$k</dt><dd>${v ?: '<span style=\"color:#999999;\">N/A</a>'}</dd>" }.join("\n")}
</dl>
""".stripIndent()
}
/**
* Step 11 - Generate MultiQC config file
*
*/
process GenerateMultiQCconfig {
publishDir "${params.outdir}/MultiQC/", mode: 'copy'
input:
output:
file("multiqc_config.yaml") into multiQCconfig
script:
"""
touch multiqc_config.yaml
echo "custom_logo_title: 'Exome Analysis Workflow'" >> multiqc_config.yaml
echo "extra_fn_clean_exts:" >> multiqc_config.yaml
echo "- _R1" >> multiqc_config.yaml
echo "- _R2" >> multiqc_config.yaml
echo "report_header_info:" >> multiqc_config.yaml
echo "- Exoseq version: ${version}" >> multiqc_config.yaml
echo "- Command Line: ${workflow.commandLine}" >> multiqc_config.yaml
echo "- Directory: ${workflow.launchDir}" >> multiqc_config.yaml
echo "- Genome: "${params.gfasta} >> multiqc_config.yaml
echo " dbSNP : ${params.dbsnp}" >> multiqc_config.yaml
echo " Omni: ${params.omni}" >> multiqc_config.yaml
echo " Mills: ${params.mills}" >> multiqc_config.yaml
echo "top_modules:" >> multiqc_config.yaml
echo "- 'fastqc'" >> multiqc_config.yaml
echo "- 'cutadapt'" >> multiqc_config.yaml
echo "- 'bwa'" >> multiqc_config.yaml
echo "- 'samtools'" >> multiqc_config.yaml
echo "- 'qualimap'" >> multiqc_config.yaml
echo "- 'gatk'" >> multiqc_config.yaml
"""
}
/*
* Step 12 - Collect metrics, stats and other resources with MultiQC in a single call
*/
process multiqc {
tag "$name"
publishDir "${params.outdir}/MultiQC", mode: 'copy'
input:
file multiQCconfig
file (fastqc:'fastqc/*') from fastqc_results.collect()
file ('trimgalore/*') from trimgalore_results.collect()
file ('gatk_base_recalibration/T*') from gatk_base_recalibration_results.collect()
file ('gatk_picard_duplicates/*') from markdup_results.collect()
file ('qualimap/*') from qualimap_results.collect()
file ('software_versions/*') from software_versions_yaml.collect()
output:
file '*multiqc_report.html' into multiqc_report
file '*_data' into multiqc_data
file '.command.err' into multiqc_stderr
val prefix into multiqc_prefix
script:
prefix = fastqc[0].toString() - '_fastqc.html' - 'fastqc/'
rtitle = custom_runName ? "--title \"$custom_runName\"" : ''
rfilename = custom_runName ? "--filename " + custom_runName.replaceAll('\\W','_').replaceAll('_+','_') + "_multiqc_report" : ''
"""
multiqc -f $rtitle $rfilename --config $multiQCconfig .
"""
}
/*
================================================================================
= F U N C T I O N S =
================================================================================
*/
def exoMessage() {
// Display NGI-ExoSeq message
log.info "NGI-ExoSeq ANALYSIS WORKFLOW ~ ${version} - " + this.grabRevision() + (workflow.commitId ? " [${workflow.commitId}]" : "")
}
def grabRevision() {
// Return the same string executed from github or not
return workflow.revision ?: workflow.commitId ?: workflow.scriptId.substring(0,10)
}
def minimalInformationMessage() {
// Minimal information message
log.info "Command Line: " + workflow.commandLine
log.info "Project Dir : " + workflow.projectDir
log.info "Launch Dir : " + workflow.launchDir
log.info "Work Dir : " + workflow.workDir
log.info "Out Dir : " + params.outdir
log.info "Genome : " + params.gfasta
}
def nextflowMessage() {
// Nextflow message (version + build)
log.info "N E X T F L O W ~ version ${workflow.nextflow.version} ${workflow.nextflow.build}"
}
def versionMessage() {
// Display version message
log.info "NGI-ExoSeq ANALYSIS WORKFLOW"
log.info " version : " + version
log.info workflow.commitId ? "Git info : ${workflow.repository} - ${workflow.revision} [${workflow.commitId}]" : " revision : " + this.grabRevision()
}
workflow.onComplete {
// Display complete message
this.nextflowMessage()
this.exoMessage()
this.minimalInformationMessage()
log.info "Completed at: " + workflow.complete
log.info "Duration : " + workflow.duration
log.info "Success : " + workflow.success
log.info "Exit status : " + workflow.exitStatus
log.info "Error report: " + (workflow.errorReport ?: '-')
}
workflow.onError {
// Display error message
this.nextflowMessage()
this.exoMessage()
log.info "Workflow execution stopped with the following message:"
log.info " " + workflow.errorMessage
}