-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_training.nf
306 lines (225 loc) · 7.25 KB
/
01_training.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
#!/usr/bin/env nextflow
/* COHORTS SUMMART */
COHORTS_SUMMARY = Channel.fromPath("${INTOGEN_DATASETS}/cohorts.tsv")
COHORTS_SUMMARY.into{ COHORTS_SUMMARY1; COHORTS_SUMMARY2; COHORTS_SUMMARY3; COHORTS_SUMMARY4}
/* DRIVERS SUMMARY */
DRIVERS_SUMMARY = Channel.fromPath("${INTOGEN_DATASETS}/drivers.tsv")
DRIVERS_SUMMARY_V = DRIVERS_SUMMARY.first()
/* SATURATION ANALYSIS */
SATURATION_INCHANNEL = Channel.fromPath("${VEP_SATURATION}/*.vep.gz")
/* CLUSTL */
CLUSTL_OUT = Channel.fromPath("${INTOGEN_DATASETS}/steps/oncodriveclustl/*.clusters_results.tsv")
CLUSTL_OUT.into{ CLUSTL_OUT1; CLUSTL_OUT2 }
process GroupFeaturesCLUSTL {
tag "Group features OncodriveCLUSTL"
label "boostdm"
publishDir "${OUTPUT}/features_group", mode: 'copy'
input:
path inputs from CLUSTL_OUT1.collect()
path cohorts from COHORTS_SUMMARY1
output:
path output into CLUSTL_GROUP
script:
output = "clustl.tsv.gz"
"""
runner.sh features/group.py group-clustl \
--output ${output} \
--threshold 0.05 \
--cohorts ${cohorts} \
${inputs}
"""
}
CLUSTL_GROUP_V = CLUSTL_GROUP.first()
OUT_ONCODRIVECLUSTL_CLUSTERS = CLUSTL_OUT2.map{it -> [it.baseName.split('\\.')[0], it]}
/* HOTMAPS */
HOTMAPS_OUT = Channel.fromPath("${INTOGEN_DATASETS}/steps/hotmaps/*.clusters.gz")
HOTMAPS_OUT.into{ HOTMAPS_OUT1; HOTMAPS_OUT2 }
process GroupFeaturesHotMAPS {
tag "Group features HotMAPS"
label "boostdm"
publishDir "${OUTPUT}/features_group", mode: 'copy'
input:
path inputs from HOTMAPS_OUT1.collect()
path cohorts from COHORTS_SUMMARY2
output:
path output into HOTMAPS_GROUP
script:
output = "hotmaps.tsv.gz"
"""
runner.sh features/group.py group-hotmaps \
--output ${output} \
--threshold 0.05 \
--cohorts ${cohorts} \
${inputs}
"""
}
HOTMAPS_GROUP_V = HOTMAPS_GROUP.first()
OUT_HOTMAPS_CLUSTERS = HOTMAPS_OUT2.map{it -> [it.baseName.split('\\.')[0], it]}
process RenameHotMAPS {
tag "Rename HotMAPS clusters file ${cohort}"
input:
tuple val(cohort), path(input) from OUT_HOTMAPS_CLUSTERS
output:
tuple val(cohort), path(output) into OUT_HOTMAPS_CLUSTERS_RENAMED
script:
output = "${cohort}.hotmapsclusters.gz"
"""
ln -s ${input} ${output}
"""
}
/* SMREGIONS */
SMREGIONS_OUT = Channel.fromPath("${INTOGEN_DATASETS}/steps/smregions/*.smregions.tsv.gz")
SMREGIONS_OUT.into{ SMREGIONS_OUT1; SMREGIONS_OUT2 }
process GroupFeaturesSMRegions {
tag "Group features SMRegions"
label "boostdm"
publishDir "${OUTPUT}/features_group", mode: 'copy'
input:
path inputs from SMREGIONS_OUT1.collect()
path cohorts from COHORTS_SUMMARY3
output:
path output into SMREGIONS_GROUP
script:
output = "smregions.tsv.gz"
"""
runner.sh features/group.py group-smregions \
--output ${output} \
--threshold 0.1 \
--cohorts ${cohorts} \
${inputs}
"""
}
SMREGIONS_GROUP_V = SMREGIONS_GROUP.first() // convert to value channel
process RenameSMREGIONS {
tag "Rename SMRegions file ${cohort}"
input:
path input from SMREGIONS_OUT2
output:
tuple val(cohort), path(output) into OUT_SMREGIONS
script:
cohort = input.baseName.split('\\.')[0]
output = "${cohort}.smregions.gz"
"""
ln -s ${input} ${output}
"""
}
/* DNDS */
DNDS_FILES = Channel.fromPath("${INTOGEN_DATASETS}/steps/dndscv/*.dndscv.tsv.gz")
OUT_DNDSCV = DNDS_FILES.map{it -> [it.baseName.split('\\.')[0], it]}
DNDS_ANNOTMUTS_FILES = Channel.fromPath("${INTOGEN_DATASETS}/steps/dndscv/*.dndscv_annotmuts.tsv.gz")
DNDS_ANNOTMUTS_FILES.into{ DNDS_ANNOTMUTS_FILES1; DNDS_ANNOTMUTS_FILES2 }
OUT_DNDSCV_ANNOTMUTS = DNDS_ANNOTMUTS_FILES1.map{it -> [it.baseName.split('\\.')[0], it]}
/* MutRate */
MUTRATE_FILES = Channel.fromPath("${INTOGEN_DATASETS}/steps/boostDM/mutrate/*.mutrate.json")
OUT_MUTRATE = MUTRATE_FILES.map{it -> [it.baseName.split('\\.')[0], it]}
/* Create datasets */
CREATE_DATASETS_INCHANNEL = OUT_DNDSCV.join(OUT_DNDSCV_ANNOTMUTS).join(OUT_MUTRATE)
process CreateDatasets {
tag "Creating datasets ${cohort}"
label "boostdm"
publishDir "${OUTPUT}/create_datasets", mode: 'copy'
input:
tuple val(cohort), path(dndscv), path(dndscvAnnotMuts), path(mutrate) from CREATE_DATASETS_INCHANNEL
path driversSummary from DRIVERS_SUMMARY_V
path groupCLUSTL from CLUSTL_GROUP_V
path groupHotMAPS from HOTMAPS_GROUP_V
path groupSMRegions from SMREGIONS_GROUP_V
output:
tuple val(cohort), path(output) into IN_CV
script:
output = "${cohort}.regression_data.tsv"
"""
runner.sh annotations/cohort.py \
--cohort ${cohort} \
--dndscv-path ${dndscv} \
--dndscv-annotmuts-path ${dndscvAnnotMuts} \
--mutrate-path ${mutrate} \
--clustl-group-path ${groupCLUSTL} \
--hotmaps-group-path ${groupHotMAPS} \
--smregions-group-path ${groupSMRegions} \
--splits ${params.boostdm.bootstrapSplits} \
--threshold ${params.boostdm.xsThresh} \
--out ${output}
"""
}
process SplitCV {
tag "Cross validation splits ${cohort}"
label "boostdm"
publishDir "${OUTPUT}/splitcv", mode: 'copy'
input:
tuple val(cohort), path(input) from IN_CV
output:
tuple val(cohort), path(output) into OUT_CV
script:
output = "${cohort}.cvdata.pickle.gz"
// TODO add random seed
"""
runner.sh cvdata/cohort.py \
--input_path ${input} \
--output_path ${output} \
--splits ${params.boostdm.bootstrapSplits} \
--cv ${params.boostdm.cvFraction}
"""
}
// get only file names
OUT_CV_COHORTS = OUT_CV.map{ it -> it[1] }
process SplitCVMetacohort {
tag 'Creating the cross validation splits for metacohorts'
label "boostdm"
publishDir "${OUTPUT}", mode: 'copy'
input:
path(input) from OUT_CV_COHORTS.collect()
output:
path("splitcv_meta/*/*.cvdata.pickle.gz") into OUT_CV_META
script:
"""
runner.sh cvdata/meta.py \
--cores ${task.cpus} \
--output_path splitcv_meta \
--input_path .
"""
}
OUT_CV_META_R = OUT_CV_META.flatten().map{it -> [it.parent.baseName, it.baseName.split('\\.')[0], it]}
/* Training models */
process TrainingMeta {
tag "Training model ${ttype}-${gene}"
label "boostdm"
publishDir "${OUTPUT}/training_meta", mode: 'copy'
memory { task.memory * task.attempt }
errorStrategy { task.attempt > 3 ? 'ignore': 'retry' }
input:
tuple val(ttype), val(gene), path(input) from OUT_CV_META_R
output:
tuple val(ttype), val(gene), path(output) optional true into OUT_TRAIN_META
script:
// TODO add seed
output = "${ttype}/${gene}.models.pickle.gz"
"""
mkdir ${ttype}
runner.sh training.py \
--splits ${input} \
--cores ${task.cpus} \
--min-rows ${params.boostdm.minimumRows} \
--output ${output}
"""
}
/* Cross-validation */
process CrossValidation {
tag "Evaluating model ${ttype}-${gene}"
label "boostdm"
publishDir "${OUTPUT}/evaluation", mode: 'copy'
memory { task.memory * task.attempt }
errorStrategy { task.attempt > 3 ? 'ignore': 'retry' }
input:
tuple val(ttype), val(gene), path(input) from OUT_TRAIN_META
output:
tuple val(ttype), val(gene), path(output) into OUT_EVAL_META
script:
output = "${ttype}/${gene}.eval.pickle.gz"
"""
mkdir ${ttype}
runner.sh evaluation/auto.py \
--model ${input} \
--output ${output}
"""
}