-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.nf
4134 lines (3500 loc) · 110 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
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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env nextflow
// GENERAL PATHS //
OUTDIR = params.outdir+'/'+params.subdir
CRONDIR = params.crondir
// SENTIEON CONFIGS //
K_size = 100000000
sentieon_model = params.sentieon_model
bwa_num_shards = params.bwa_shards
bwa_shards = Channel.from( 0..bwa_num_shards-1 )
genomic_num_shards = params.genomic_shards_num
// FASTA //
genome_file = params.genome_file
PON = [F: params.GATK_PON_FEMALE, M: params.GATK_PON_MALE]
// Count lines of input csv, if more than 2(header + 1 ind) then mode is set to family //
csv = file(params.csv)
mode = csv.countLines() > 2 ? "family" : "single"
trio = csv.countLines() > 3 ? true : false
println(csv)
println("mode: "+mode)
println("trio: "+trio)
// Print commit-version of active deployment
file(params.git)
.readLines()
.each { println "git commit-hash: "+it }
// Print active container
container = file(params.container).toRealPath()
println("container: "+container)
workflow.onComplete {
def msg = """\
Pipeline execution summary
---------------------------
Completed at: ${workflow.complete}
Duration : ${workflow.duration}
Success : ${workflow.success}
scriptFile : ${workflow.scriptFile}
workDir : ${workflow.workDir}
csv : ${params.csv}
exit status : ${workflow.exitStatus}
errorMessage: ${workflow.errorMessage}
errorReport :
"""
.stripIndent()
def error = """\
${workflow.errorReport}
"""
.stripIndent()
base = csv.getBaseName()
File logFile = new File("${params.crondir}/logs/${base}.complete")
if (!logFile.getParentFile().exists()) {
logFile.getParentFile().mkdirs()
}
logFile.text = msg
logFile.append(error)
}
// Input channels for alignment, variant calling and annotation //
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row-> tuple(row.group,
row.id,
(row.containsKey("bam") ? file(row.bam) : (row.containsKey("vcf") ? file(row.vcf) : file(row.read1) ) ),
(row.containsKey("bai") ? file(row.bai) : (row.containsKey("idx") ? file(row.idx) : file(row.read2) ) ) ) }
.set { input_files }
fastq = Channel.create()
bam_choice = Channel.create()
//vcf_choice = Channel.create()
fastq_sharded = Channel.create()
fastq_umi = Channel.create()
annotate_only = Channel.create()
// If input-files has bam files bypass alignment, otherwise go for fastq-channels => three options for fastq, sharded bwa, normal bwa or umi trimming
input_files.view().choice(bam_choice, fastq, fastq_sharded, fastq_umi, annotate_only ) { it[2] =~ /\.bam/ ? 0 : ( it[2] =~ /\.vcf.gz/ ? 4 : (params.shardbwa ? 2 : (params.umi ? 3 : 1) )) }
annotate_only.into{
annotate_only_vep;
annotate_only_cadd
}
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row-> tuple(row.group, row.assay) }
.set{ meta_loqusdb_no_sv_calling }
// Input channels for various meta information //
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row-> tuple(row.id, row.diagnosis, row.read1, row.read2) }
.set{ qc_extra }
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row-> tuple(row.group, row.id, row.sex, row.mother, row.father, row.phenotype, row.diagnosis, row.type, row.assay, row.clarity_sample_id, (row.containsKey("ffpe") ? row.ffpe : false), (row.containsKey("analysis") ? row.analysis : false) ) }
.into { ped; yml_diag; meta_upd; meta_str }
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row-> tuple(row.group, row.id, row.sex, row.type) }
.into { meta_gatkcov; meta_exp; meta_svbed; meta_pod; meta_mutect2; meta_eklipse}
Channel
.fromPath(params.gatkreffolders)
.splitCsv(header:true)
.map{ row-> tuple(row.i, row.refpart) }
.into{ gatk_ref; gatk_postprocess }
// Check whether genome assembly is indexed //
if(genome_file) {
bwaId = Channel
.fromPath("${genome_file}.bwt")
.ifEmpty { exit 1, "BWA index not found: ${genome_file}.bwt" }
}
process fastp {
cpus 10
tag "$id"
time '1h'
memory '20 GB'
scratch true
stageInMode 'copy'
stageOutMode 'copy'
container = "${params.container_fastp}"
when:
params.umi
input:
set group, val(id), r1, r2 from fastq_umi
output:
set group, val(id), file("${id}_R1_a_q_u_trimmed.fq.gz"), file("${id}_R2_a_q_u_trimmed.fq.gz") into fastq_trimmed
set group, file("*versions.yml") into ch_fastp_versions
script:
"""
fastp -i $r1 -I $r2 --stdout \\
-U --umi_loc=per_read --umi_len=3 \\
-w ${task.cpus} \\
| fastp --stdin --interleaved_in -f 2 -F 2 \\
-o ${id}_R1_a_q_u_trimmed.fq.gz \\
-O ${id}_R2_a_q_u_trimmed.fq.gz \\
-l 30 \\
-w ${task.cpus}
${fastp_version(task)}
"""
stub:
"""
touch "${id}_R1_a_q_u_trimmed.fq.gz"
touch "${id}_R2_a_q_u_trimmed.fq.gz"
${fastp_version(task)}
"""
}
def fastp_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
fastp: \$(echo \$(fastp -v 2>&1) | cut -f 2 -d " ")
END_VERSIONS
"""
}
// Align fractions of fastq files with BWA
process bwa_align_sharded {
cpus 50
memory '120 GB'
tag "$id $shard"
time '5h'
container = "${params.container_sentieon}"
input:
set val(shard), val(group), val(id), r1, r2 from bwa_shards.combine(fastq_sharded)
output:
set val(id), group, file("${id}_${shard}.bwa.sort.bam"), file("${id}_${shard}.bwa.sort.bam.bai") into bwa_shards_ch
set group, file("*versions.yml") into ch_bwa_align_shareded_versions
when:
params.align && params.shardbwa
script:
"""
sentieon bwa mem -M \\
-R '@RG\\tID:${id}\\tSM:${id}\\tPL:illumina' \\
-K $K_size \\
-t ${task.cpus} \\
-p $genome_file '<sentieon fqidx extract -F $shard/$bwa_num_shards -K $K_size $r1 $r2' | sentieon util sort \\
-r $genome_file \\
-o ${id}_${shard}.bwa.sort.bam \\
-t ${task.cpus} --sam2bam -i -
${bwa_align_sharded_version(task)}
"""
stub:
"""
touch "${id}_${shard}.bwa.sort.bam"
touch "${id}_${shard}.bwa.sort.bam.bai"
${bwa_align_sharded_version(task)}
"""
}
def bwa_align_sharded_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
sentieon: \$(echo \$(sentieon util --version 2>&1) | sed -e "s/sentieon-genomics-//g")
bwa: \$(echo \$(sentieon bwa 2>&1) | sed 's/^.*Version: //; s/Contact:.*\$//')
END_VERSIONS
"""
}
// Merge the fractioned bam files
process bwa_merge_shards {
cpus 50
tag "$id"
time '1h'
memory '120 GB'
container = "${params.container_sentieon}"
input:
set val(id), group, file(shard), file(shard_bai) from bwa_shards_ch.groupTuple(by: [0,1])
output:
set id, group, file("${id}_merged.bam"), file("${id}_merged.bam.bai") into merged_bam_locusc
set id, file("${id}_merged.bam"), file("${id}_merged.bam.bai") into merged_bam_dedup
set group, file("*versions.yml") into ch_bwa_merge_shards_versions
when:
params.shardbwa
script:
bams = shard.sort(false) { a, b -> a.getBaseName() <=> b.getBaseName() } .join(' ')
"""
sentieon util merge -o ${id}_merged.bam ${bams}
${bwa_merge_shards_version(task)}
"""
stub:
"""
touch "${id}_merged.bam"
touch "${id}_merged.bam.bai"
${bwa_merge_shards_version(task)}
"""
}
def bwa_merge_shards_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
sentieon: \$(echo \$(sentieon util --version 2>&1) | sed -e "s/sentieon-genomics-//g")
END_VERSIONS
"""
}
// ALTERNATIVE PATH: Unsharded BWA, utilize local scratch space.
process bwa_align {
cpus 50
memory '100 GB'
// 64 GB peak giab //
scratch true
stageInMode 'copy'
stageOutMode 'copy'
tag "$id"
container = "${params.container_sentieon}"
input:
set val(group), val(id), file(r1), file(r2) from fastq.mix(fastq_trimmed)
output:
set id, group, file("${id}_merged.bam"), file("${id}_merged.bam.bai") into bam_locusc, bam_markdup
// set id, file("${id}_merged.bam"), file("${id}_merged.bam.bai") into bam_dedup remnant of distri
set group, file("*versions.yml") into ch_bwa_align_versions
when:
params.align && !params.shardbwa
script:
"""
sentieon bwa mem \\
-M \\
-K $K_size \\
-R '@RG\\tID:${id}\\tSM:${id}\\tPL:illumina' \\
-t ${task.cpus} \\
$genome_file $r1 $r2 \\
| sentieon util sort \\
-r $genome_file \\
-o ${id}_merged.bam \\
-t ${task.cpus} --sam2bam -i -
${bwa_align_versions(task)}
"""
stub:
"""
touch "${id}_merged.bam"
touch "${id}_merged.bam.bai"
${bwa_align_versions(task)}
"""
}
def bwa_align_versions(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
sentieon: \$(echo \$(sentieon util --version 2>&1) | sed -e "s/sentieon-genomics-//g")
bwa: \$(echo \$(sentieon bwa 2>&1) | sed 's/^.*Version: //; s/Contact:.*\$//')
END_VERSIONS
"""
}
process markdup {
cpus 40
errorStrategy 'retry'
maxErrors 5
tag "$id"
memory '50 GB'
// 12gb peak giab //
time '3h'
// scratch true
// stageInMode 'copy'
// stageOutMode 'copy'
container = "${params.container_sentieon}"
publishDir "${OUTDIR}/bam", mode: 'copy' , overwrite: 'true', pattern: '*_dedup.bam*'
input:
set id, group, file(bam), file(bai) from bam_markdup.mix(merged_bam_dedup)
output:
set group, id, file("${id}_dedup.bam"), file("${id}_dedup.bam.bai") into complete_bam, chanjo_bam, d4_bam, verifybamid2_bam, expansionhunter_bam, yaml_bam, cov_bam, bam_manta, bam_nator, bam_tiddit, bam_manta_panel, bam_delly_panel, bam_cnvkit_panel, bam_freebayes, bam_mito, smncnc_bam, bam_gatk, depth_onco
set id, group, file("${id}_dedup.bam"), file("${id}_dedup.bam.bai") into qc_bam, bam_melt, bam_bqsr
set val(id), file("dedup_metrics.txt") into dedupmet_sentieonqc
set group, file("${group}_bam.INFO") into bam_INFO
set group, file("*versions.yml") into ch_markdup_versions
script:
"""
sentieon driver \\
--temp_dir /local/scratch/ \\
-t ${task.cpus} \\
-i $bam --shard 1:1-248956422 --shard 2:1-242193529 --shard 3:1-198295559 --shard 4:1-190214555 --shard 5:1-120339935 --shard 5:120339936-181538259 --shard 6:1-170805979 --shard 7:1-159345973 --shard 8:1-145138636 --shard 9:1-138394717 --shard 10:1-133797422 --shard 11:1-135086622 --shard 12:1-56232327 --shard 12:56232328-133275309 --shard 13:1-114364328 --shard 14:1-107043718 --shard 15:1-101991189 --shard 16:1-90338345 --shard 17:1-83257441 --shard 18:1-80373285 --shard 19:1-58617616 --shard 20:1-64444167 --shard 21:1-46709983 --shard 22:1-50818468 --shard X:1-124998478 --shard X:124998479-156040895 --shard Y:1-57227415 --shard M:1-16569 \\
--algo LocusCollector \\
--fun score_info ${id}.score
sentieon driver \\
--temp_dir /local/scratch/ \\
-t ${task.cpus} \\
-i $bam \\
--algo Dedup --score_info ${id}.score \\
--metrics dedup_metrics.txt \\
--rmdup ${id}_dedup.bam
echo "BAM $id /access/${params.subdir}/bam/${id}_dedup.bam" > ${group}_bam.INFO
${markdup_versions(task)}
"""
stub:
"""
touch "${id}_dedup.bam"
touch "${id}_dedup.bam.bai"
touch "dedup_metrics.txt"
touch "${group}_bam.INFO"
${markdup_versions(task)}
"""
}
def markdup_versions(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
sentieon: \$(echo \$(sentieon driver --version 2>&1) | sed -e "s/sentieon-genomics-//g")
END_VERSIONS
"""
}
process copy_bam {
tag "$id"
cpus 1
memory '2GB'
time '1h'
input:
set group, id, file(bam), file(bai) from bam_choice
output:
set group, id, file("${id}_dedup.bam"), file("${id}_dedup.bam.bai") into expansionhunter_bam_choice, dnascope_bam_choice, bampath_start, cov_bam_choice, bam_manta_choice, bam_tiddit_choice, bam_mito_choice, bam_SMN_choice, bam_freebayes_choice, bam_mantapanel_choice, bam_cnvkitpanel_choice, bam_dellypanel_choice, bam_melt_choice, bam_qc_choice, dedup_dummy_choice, bam_bqsr_choice, bam_gatk_choice, verifybamid2_bam_choice
script:
"""
ionice -c 2 -n 7 cp ${bam} "${id}_dedup.copy.bam"
ionice -c 2 -n 7 cp ${bai} "${id}_dedup.copy.bam.bai"
"""
stub:
"""
touch "${id}_dedup.copy.bam"
touch "${id}_dedup.copy.bam.bai"
"""
}
// These processes expects ID, group instead of group, ID
// FIXME: We should really fix this to be part of the channels
def remap_bam_choice_tuple = { channel ->
channel.map { tup -> return tuple(tup.get(1), tup.get(0), tup.get(2), tup.get(3))
}
}
remap_bam_choice_tuple(cov_bam_choice).set { cov_bam_choice }
remap_bam_choice_tuple(bam_melt_choice).set { bam_melt_choice }
remap_bam_choice_tuple(bam_bqsr_choice).set { bam_bqsr_choice }
remap_bam_choice_tuple(bam_qc_choice).set { bam_qc_choice }
// For melt to work if started from bam-file.
process dedupdummy {
when:
params.run_melt
input:
set group, id, file(bam), file(bai) from dedup_dummy_choice
output:
set id, file("dummy") into dedup_dummy
"""
echo test > dummy
"""
}
process bqsr {
cpus 40
errorStrategy 'retry'
maxErrors 5
tag "$id"
memory '30 GB'
// 12gb peak giab //
time '5h'
// scratch true
// stageInMode 'copy'
// stageOutMode 'copy'
container = "${params.container_sentieon}"
publishDir "${OUTDIR}/bqsr", mode: 'copy' , overwrite: 'true', pattern: '*.table'
input:
set id, group, file(bam), file(bai) from bam_bqsr.mix(bam_bqsr_choice)
output:
set group, id, file("${id}.bqsr.table") into dnascope_bqsr
set group, file("*versions.yml") into ch_bqsr_versions
script:
"""
sentieon driver -t ${task.cpus} \\
-r $genome_file -i $bam \\
--algo QualCal ${id}.bqsr.table \\
-k $params.KNOWN
${bqsr_version(task)}
"""
stub:
"""
touch "${id}.bqsr.table"
${bqsr_version(task)}
"""
}
def bqsr_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
sentieon: \$(echo \$(sentieon driver --version 2>&1) | sed -e "s/sentieon-genomics-//g")
END_VERSIONS
"""
}
//Collect various QC data:
process sentieon_qc {
cpus 52
memory '30 GB'
tag "$id"
time '2h'
// scratch true
// stageInMode 'copy'
// stageOutMode 'copy'
container = "${params.container_sentieon}"
input:
set id, group, file(bam), file(bai) from qc_bam.mix(bam_qc_choice)
output:
set id, group, file("mq_metrics.txt"), file("qd_metrics.txt"), file("gc_summary.txt"),
file("gc_metrics.txt"), file("aln_metrics.txt"), file("is_metrics.txt"), file("assay_metrics.txt"),
file("cov_metrics.txt"), file("cov_metrics.txt.sample_summary") into ch_sentieon_qc_metrics
set group, file("*versions.yml") into ch_sentieon_qc_versions
script:
target = ""
// A bit of cheating here - these are really optional arguments
panel_command = "touch cov_metrics.txt cov_metrics.txt.sample_summary"
cov = "WgsMetricsAlgo assay_metrics.txt"
if (params.onco || params.exome) {
target = "--interval $params.intervals"
cov = "CoverageMetrics --cov_thresh 1 --cov_thresh 10 --cov_thresh 30 --cov_thresh 100 --cov_thresh 250 --cov_thresh 500 cov_metrics.txt"
panel_command = "sentieon driver -r ${params.genome_file} -t ${task.cpus} -i ${bam} --algo HsMetricAlgo --targets_list ${params.intervals} --baits_list ${params.intervals} assay_metrics.txt"
}
"""
sentieon driver \\
-r $genome_file $target \\
-t ${task.cpus} \\
-i $bam \\
--algo MeanQualityByCycle mq_metrics.txt \\
--algo QualDistribution qd_metrics.txt \\
--algo GCBias --summary gc_summary.txt gc_metrics.txt \\
--algo AlignmentStat aln_metrics.txt \\
--algo InsertSizeMetricAlgo is_metrics.txt \\
--algo $cov
$panel_command
${sentieon_qc_version(task)}
"""
stub:
"""
touch "assay_metrics.txt"
touch "mq_metrics.txt"
touch "qd_metrics.txt"
touch "gc_summary.txt"
touch "gc_metrics.txt"
touch "aln_metrics.txt"
touch "is_metrics.txt"
touch "cov_metrics.txt"
touch "cov_metrics.txt.sample_summary"
${sentieon_qc_version(task)}
"""
}
def sentieon_qc_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
sentieon: \$(echo \$(sentieon driver --version 2>&1) | sed -e "s/sentieon-genomics-//g")
END_VERSIONS
"""
}
process sentieon_qc_postprocess {
cpus 2
memory '1 GB'
tag "$id"
time '2h'
// scratch true
// stageInMode 'copy'
// stageOutMode 'copy'
input:
set id, file(dedup) from dedupmet_sentieonqc.mix(dedup_dummy)
set id, group, file(mq_metrics), file(qd_metrics), file(gc_summary), file(gc_metrics), file(aln_metrics),
file(is_metrics), file(assay_metrics), file(cov_metrics), file(cov_metrics_sample_summary) from ch_sentieon_qc_metrics
output:
set group, id, file("${id}_qc.json") into qc_cdm
set group, id, file("${id}_qc.json") into qc_melt
script:
assay = (params.onco || params.exome) ? "panel" : "wgs"
"""
qc_sentieon.pl \\
--SID ${id} \\
--type ${assay} \\
--align_metrics_file ${aln_metrics} \\
--insert_file ${is_metrics} \\
--dedup_metrics_file ${dedup} \\
--metrics_file ${assay_metrics} \\
--gcsummary_file ${gc_summary} \\
--coverage_file ${cov_metrics} \\
--coverage_file_summary ${cov_metrics_sample_summary} \\
> ${id}_qc.json
"""
}
process d4_coverage {
cpus 16
memory '10 GB'
publishDir "${OUTDIR}/cov", mode: 'copy', overwrite: 'true', pattern: '*.d4'
tag "$id"
container = "${params.container_d4tools}"
when:
params.run_chanjo2
input:
set group, id, file(bam), file(bai) from d4_bam
output:
file("${id}_coverage.d4")
set group, id, file("${id}_coverage.d4") into ch_final_d4
set group, file("*versions.yml") into ch_d4_coverage_versions
set group, file("${group}_d4.INFO") into d4_INFO
script:
"""
d4tools create \\
--threads ${task.cpus} \\
"${bam}" \\
"${id}_coverage.d4"
echo "D4 $id /access/${params.subdir}/cov/${id}_coverage.d4" > ${group}_d4.INFO
${d4_coverage_version(task)}
"""
stub:
"""
touch "${id}_coverage.d4"
touch "${group}_d4.INFO"
${d4_coverage_version(task)}
"""
}
def d4_coverage_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
d4tools: \$(echo \$( d4tools 2>&1 | head -1 ) | sed "s/.*version: //" | sed "s/)//" )
END_VERSIONS
"""
}
process verifybamid2 {
cpus 16
memory '10 GB'
// publishDir "${OUTDIR}/contamination", mode: 'copy', overwrite: 'true', pattern: '*.selfSM'
tag "$id"
container = "${params.container_verifybamid2}"
input:
set group, id, file(bam), file(bai) from verifybamid2_bam.mix(verifybamid2_bam_choice)
output:
file("${id}.result.selfSM")
file("${id}.result.Ancestry")
set group, file("*versions.yml") into ch_verifybamid2_versions
script:
if ( params.antype == "wgs") {
"""
verifybamid2 \
--SVDPrefix ${params.verifybamid2_svdprefix} \
--Reference ${genome_file} \
--BamFile ${bam}
mv result.selfSM ${id}.result.selfSM
mv result.Ancestry ${id}.result.Ancestry
${verifybamid2_version(task)}
"""
}
else {
"""
verifybamid2 \
--DisableSanityCheck \
--SVDPrefix ${params.verifybamid2_svdprefix} \
--Reference ${genome_file} \
--BamFile ${bam}
mv result.selfSM ${id}.result.selfSM
mv result.Ancestry ${id}.result.Ancestry
${verifybamid2_version(task)}
"""
}
stub:
"""
touch "${id}.result.selfSM"
touch "${id}.result.Ancestry"
${verifybamid2_version(task)}
"""
}
def verifybamid2_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
VerifyBamID2: \$( echo \$( verifybamid2 --help 2>&1 | grep Version ) | sed "s/^.*Version://" )
END_VERSIONS
"""
}
// Calculate coverage for paneldepth
process depth_onco {
cpus 2
time '1h'
memory '10 GB'
publishDir "${OUTDIR}/cov", mode: 'copy', overwrite: 'true'
tag "$id"
// scratch true
// stageInMode 'copy'
// stageOutMode 'copy'
when:
params.assay == "swea"
input:
set group, id, file(bam), file(bai) from depth_onco
output:
file("${id}.lowcov.overlapping.bed") into cov_onco
script:
"""
panel_depth.pl $bam $params.scoutbed > ${id}.lowcov.bed
overlapping_genes.pl ${id}.lowcov.bed $params.gene_regions > ${id}.lowcov.overlapping.bed
"""
stub:
"""
touch "${id}.lowcov.overlapping.bed"
"""
}
process SMNCopyNumberCaller {
cpus 10
memory '25GB'
time '2h'
publishDir "${OUTDIR}/plots/SMNcnc", mode: 'copy' , overwrite: 'true', pattern: '*.pdf*'
tag "$id"
when:
params.antype == "wgs"
input:
set group, id, file(bam), file(bai) from smncnc_bam.mix(bam_SMN_choice)
output:
file("*.tsv") into smn_tsv
set file("*.pdf"), file("*.json")
set group, file("${group}_smn.INFO") into smn_INFO
set group, file("*versions.yml") into ch_smn_copy_number_caller_versions
script:
"""
samtools view -H $bam | \\
sed -e 's/SN:1/SN:chr1/' | sed -e 's/SN:2/SN:chr2/' | \\
sed -e 's/SN:3/SN:chr3/' | sed -e 's/SN:4/SN:chr4/' | \\
sed -e 's/SN:5/SN:chr5/' | sed -e 's/SN:6/SN:chr6/' | \\
sed -e 's/SN:7/SN:chr7/' | sed -e 's/SN:8/SN:chr8/' | \\
sed -e 's/SN:9/SN:chr9/' | sed -e 's/SN:10/SN:chr10/' | \\
sed -e 's/SN:11/SN:chr11/' | sed -e 's/SN:12/SN:chr12/' | \\
sed -e 's/SN:13/SN:chr13/' | sed -e 's/SN:14/SN:chr14/' | \\
sed -e 's/SN:15/SN:chr15/' | sed -e 's/SN:16/SN:chr16/' | \\
sed -e 's/SN:17/SN:chr17/' | sed -e 's/SN:18/SN:chr18/' | \\
sed -e 's/SN:19/SN:chr19/' | sed -e 's/SN:20/SN:chr20/' | \\
sed -e 's/SN:21/SN:chr21/' | sed -e 's/SN:22/SN:chr22/' | \\
sed -e 's/SN:X/SN:chrX/' | sed -e 's/SN:Y/SN:chrY/' | \\
sed -e 's/SN:MT/SN:chrM/' | \\
samtools reheader - $bam > ${id}.bam
samtools index -b ${id}.bam -@ ${task.cpus}
echo ${id}.bam > manifest.txt
smn_caller.py --manifest manifest.txt --genome 38 --prefix ${id} --outDir . --threads ${task.cpus}
rm ${id}.bam
source activate py3-env
python /SMNCopyNumberCaller/smn_charts.py -s ${id}.json -o .
mv ${id}.tsv ${group}_SMN.tsv
echo "SMN ${params.accessdir}/smn/${group}_SMN.tsv" > ${group}_smn.INFO
${smn_copy_number_caller_version(task)}
"""
stub:
"""
touch "${id}.bam"
touch "${id}.tsv"
touch "${id}.pdf"
touch "${id}.json"
touch "${group}_SMN.tsv"
touch "${group}_smn.INFO"
${smn_copy_number_caller_version(task)}
"""
}
// collects each individual's SMNCNC-tsv and creates one tsv-file
smn_tsv
.collectFile(keepHeader: true, storeDir: "${OUTDIR}/smn/")
def smn_copy_number_caller_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
smn-copy-number-caller: 1.1.2
END_VERSIONS
"""
}
////////////////////////////////////////////////////////////////////////
////////////////////////// EXPANSION HUNTER ////////////////////////////
////////////////////////////////////////////////////////////////////////
// call STRs using ExpansionHunter, and plot alignments with GraphAlignmentViewer
process expansionhunter {
tag "$group"
cpus 2
time '10h'
memory '40 GB'
// scratch true
// stageInMode 'copy'
// stageOutMode 'copy'
when:
params.str
input:
set group, id, file(bam), file(bai), sex, type \
from expansionhunter_bam.mix(expansionhunter_bam_choice).join(meta_exp, by: [0,1]).filter { item -> item[5] == 'proband' }
output:
set group, id, file("${group}.eh.vcf") into expansionhunter_vcf
set group, id, file("${group}.eh_realigned.sort.bam"), file("${group}.eh_realigned.sort.bam.bai"), file("${group}.eh.vcf") into reviewer
set group, file("*versions.yml") into ch_expansionhunter_versions
script:
"""
source activate htslib10
ExpansionHunter \
--reads $bam \
--reference $genome_file \
--variant-catalog $params.expansionhunter_catalog \
--output-prefix ${group}.eh
samtools sort ${group}.eh_realigned.bam -o ${group}.eh_realigned.sort.bam
samtools index ${group}.eh_realigned.sort.bam
${expansionhunter_version(task)}
"""
stub:
"""
source activate htslib10
touch "${group}.eh.vcf"
touch "${group}.eh_realigned.sort.bam"
touch "${group}.eh_realigned.sort.bam.bai"
${expansionhunter_version(task)}
"""
}
def expansionhunter_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
expansionhunter: \$(echo \$(ExpansionHunter --version 2>&1) | sed 's/.*ExpansionHunter v// ; s/]//')
samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
END_VERSIONS
"""
}
// annotate expansionhunter vcf
process stranger {
tag "$group"
memory '1 GB'
time '10m'
cpus 2
// scratch true
// stageInMode 'copy'
// stageOutMode 'copy'
container = "/fs1/resources/containers/stranger_0.8.sif"
input:
set group, id, file(eh_vcf) from expansionhunter_vcf
output:
set group, id, file("${group}.fixinfo.eh.stranger.vcf") into expansionhunter_vcf_anno
set group, file("*versions.yml") into ch_stranger_versions
script:
"""
stranger ${eh_vcf} -f $params.expansionhunter_catalog > ${group}.eh.stranger.vcf
grep ^# ${group}.eh.stranger.vcf > ${group}.fixinfo.eh.stranger.vcf
grep -v ^# ${group}.eh.stranger.vcf | sed 's/ /_/g' >> ${group}.fixinfo.eh.stranger.vcf
${stranger_version(task)}
"""
stub:
"""
touch "${group}.fixinfo.eh.stranger.vcf"
${stranger_version(task)}
"""
}
def stranger_version(task) {
"""
cat <<-END_VERSIONS > ${task.process}_versions.yml
${task.process}:
stranger: \$( stranger --version )
END_VERSIONS
"""
}
//for i in $( ls *.svg | cut -f 2 -d "." ); do echo "STR_IMG $i /access/!{params.subdir}/plots/reviewer/!{group}/!{group}.${i}.svg" >> !{group}_rev.INFO; done
process reviewer {
tag "$group"
cpus 2
time '1h'
memory '1 GB'
// scratch true
// stageInMode 'copy'
// stageOutMode 'copy'
errorStrategy 'ignore'
container = "/fs1/resources/containers/REViewer_2021-06-07.sif"
publishDir "${OUTDIR}/plots/reviewer/${group}", mode: 'copy' , overwrite: 'true', pattern: '*.svg'
input:
set group, id, file(bam), file(bai), file(vcf) from reviewer
output:
file("*svg")
//set group, file("${group}_rev.INFO") into reviewer_INFO
set group, file("*versions.yml") into ch_reviewer_versions
shell:
version_str = reviewer_version(task)
'''
grep LocusId !{params.expansionhunter_catalog} | sed 's/[",^ ]//g' | cut -d':' -f2 | perl -na -e 'chomp; \
system("REViewer --reads !{bam} \
--vcf !{vcf} \
--reference !{genome_file} \
--catalog !{params.expansionhunter_catalog} \
--locus $_ \
--output-prefix !{id}");'
echo "!{version_str}" > "!{task.process}_versions.yml"
'''
stub:
version_str = reviewer_version(task)
"""
touch "${id}.svg"
echo "${version_str}" > "${task.process}_versions.yml"
"""
}
def reviewer_version(task) {
// This docstring looks different from others as it is used within the shell '''
// If spaces similarly to the others, this leads to additional whitespace above and below the version text
"""${task.process}:
reviewer: \$(echo \$(REViewer --version 2>&1) | sed 's/^.*REViewer v//')"""
}
// split multiallelic sites in expansionhunter vcf
// FIXME: Use env variable for picard path...
process vcfbreakmulti_expansionhunter {
publishDir "${OUTDIR}/vcf", mode: 'copy' , overwrite: 'true', pattern: '*.vcf.gz'
tag "$group"
time '1h'
memory '50 GB'
// scratch true
// stageInMode 'copy'
// stageOutMode 'copy'
input:
set group, id, file(eh_vcf_anno) from expansionhunter_vcf_anno
set group, id, sex, mother, father, phenotype, diagnosis, type, assay, clarity_sample_id, ffpe, analysis from meta_str.filter{ item -> item[7] == 'proband' }
output:
file("${group}.expansionhunter.vcf.gz") into expansionhunter_scout
set group, file("${group}_str.INFO") into str_INFO
set group, file("*versions.yml") into ch_vcfbreakmulti_expansionhunter_versions
script:
if (father == "") { father = "null" }
if (mother == "") { mother = "null" }
if (mode == "family") {
"""
java -jar /opt/conda/envs/CMD-WGS/share/picard-2.21.2-1/picard.jar RenameSampleInVcf INPUT=${eh_vcf_anno} OUTPUT=${eh_vcf_anno}.rename.vcf NEW_SAMPLE_NAME=${id}
vcfbreakmulti ${eh_vcf_anno}.rename.vcf > ${group}.expansionhunter.vcf.tmp
familyfy_str.pl --vcf ${group}.expansionhunter.vcf.tmp --mother $mother --father $father --out ${group}.expansionhunter.vcf
bgzip ${group}.expansionhunter.vcf
tabix ${group}.expansionhunter.vcf.gz
echo "STR ${params.accessdir}/vcf/${group}.expansionhunter.vcf.gz" > ${group}_str.INFO
${vcfbreakmulti_expansionhunter_version(task)}
"""
}
else {
"""