-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
executable file
·138 lines (116 loc) · 3.76 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
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { SINGLETON_INPUT } from './local_modules/singleton_input/main'
include { SAMTOOLS_MERGE } from './nf-core-modules/modules/nf-core/samtools/merge/main'
include { CNVKIT_BATCH } from './nf-core-modules/modules/nf-core/cnvkit/batch/main'
include { SEQUENZAUTILS_GCWIGGLE } from './nf-core-modules/modules/nf-core/sequenzautils/gcwiggle/main'
include { SEQUENZAUTILS_BAM2SEQZ } from './nf-core-modules/modules/nf-core/sequenzautils/bam2seqz/main'
//include { MERGE_REPLICATES } from './local_modules/merge_replicates'
include { SEQUENZAUTILS_SEQZBINNING } from './local_modules/sequenzautils/seqzbinning/main'
include { R_SEQUENZA } from './local_modules/rsequenza/main'
def helpMessage() {
log.info params.help_message
}
if (params.help) {
helpMessage()
exit 0
}
if (!params.reference) {
log.error "--reference is required"
exit 1
}
if (!params.intervals) {
log.error "--intervals is required"
exit 1
}
if (!params.tools) {
log.error "--tools is required"
exit 1
}
else {
params.toolslist = params.tools?.split(',') as List
}
if (!params.input_files) {
exit 1, "--input_files is required!"
}
else {
Channel
.fromPath(params.input_files)
.splitCsv(header: ['sample', 'tumor_bam', 'normal_bam'], sep: "\t")
.map{ row-> tuple([id: row.sample], row.tumor_bam, row.normal_bam) }
.set { input_files }
}
workflow {
tumor_bams = input_files
.map {
meta, tumor_bam, normal_bam ->
def fmeta = [:]
fmeta.id = meta.id + ".tumor"
fmeta.type = "tumor"
[fmeta, tumor_bam.tokenize(',')]
}
.branch{
single: it[1].size() == 1
multiple: it[1].size() > 1
}
normal_bams = input_files
.map {
meta, tumor_bam, normal_bam ->
def fmeta = [:]
fmeta.id = meta.id + ".normal"
fmeta.type = "normal"
[fmeta, normal_bam.tokenize(',')]
}
.branch{
single: it[1].size() == 1
multiple: it[1].size() > 1
}
SINGLETON_INPUT(tumor_bams.single.mix(normal_bams.single))
SAMTOOLS_MERGE(
tumor_bams.multiple.mix(normal_bams.multiple),
[[], []],
[[], []]
)
prepared_tumor_bams = SINGLETON_INPUT.out
.filter { it[0].type == "tumor" }
.mix(
SAMTOOLS_MERGE.out.bam
.filter { it[0].type == "tumor" }
).map {
meta, bam ->
def fmeta = [:]
fmeta.id = meta.id[0..-(meta.type.length() + 2)]
[fmeta, bam]
}
prepared_normal_bams = SINGLETON_INPUT.out
.filter { it[0].type == "normal" }
.mix(
SAMTOOLS_MERGE.out.bam
.filter { it[0].type == "normal" }
).map {
meta, bam ->
def fmeta = [:]
fmeta.id = meta.id[0..-(meta.type.length() + 2)]
[fmeta, bam]
}
ch_meta_tumor_normal = prepared_tumor_bams
.join(prepared_normal_bams, by: [0])
if (params.toolslist.contains('cnvkit')) {
// NOTE: it does not provide fasta.fai or CNVkit reference, but these are created every time
CNVKIT_BATCH(
ch_meta_tumor_normal,
params.reference,
[],
params.intervals,
[],
false
)
}
if (params.toolslist.contains('sequenza')) {
SEQUENZAUTILS_GCWIGGLE([[id:'reference'], params.reference])
wig = SEQUENZAUTILS_GCWIGGLE.out.wig.map { it[1] }
SEQUENZAUTILS_BAM2SEQZ(ch_meta_tumor_normal, params.reference, wig)
SEQUENZAUTILS_SEQZBINNING(SEQUENZAUTILS_BAM2SEQZ.out.seqz)
R_SEQUENZA(SEQUENZAUTILS_SEQZBINNING.out.seqz)
}
}