-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
379 lines (287 loc) · 13.9 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
#!/usr/bin/env nextflow
/*
========================================================================================
Train model on TCGA data
========================================================================================
*/
nextflow.enable.dsl = 2
////////////////////////////////////////////////////
/* -- Collect configuration parameters -- */
////////////////////////////////////////////////////
date = java.time.LocalDate.now()
params.name = ""
params.test_prop = 0.2
params.step = "train"
params.autoencoder = "No"
params.network_params = "a.txt"
params.network = "a.txt"
params.model = "a.txt"
params.config = "a.txt"
params.labels = "a.txt"
params.probes = "a.txt"
params.cpgmap = "a.txt"
params.cpgslist = "a.txt"
params.inputcpgs = "a.txt"
params.gene_mask = "a.txt"
params.checkpoints = "a.txt"
name = params.name
test_prop = params.test_prop
step = params.step
layer = params.layer
ch_input_hdf5 = Channel.fromPath(file("${params.hdf5_file}"))
ch_input_hdf5_se = Channel.fromPath(file("${params.hdf5_se_file}"))
network = file("${params.network}")
network_params = file("${params.network_params}")
model = file("${params.model}")
labels = file("${params.labels}")
probes = file("${params.probes}")
cpgmap = file("${params.cpgmap}")
dnn_structure = file("${params.cpgslist}")
input_cpgs = file("${params.inputcpgs}")
gene_mask = file("${params.gene_mask}")
checkpoints = file("${params.checkpoints}")
random_config = file("${params.config}")
params_name = "v1"
params_name = "${params.params_name}"
include { PY_DIVIDE_TRAIN_TEST } from '../modules/local/py_divide_training_test/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_trained/"])
include { RANDOM_SEARCH } from '../modules/local/random_search/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/random_search/"])
include { TRAIN_MODEL } from '../modules/local/py_train_model/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_trained/"])
include { PY_EXPORT_RESULTS } from '../modules/local/py_export_results/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_trained/"])
include { EXTRACT_MODEL_FEATURES } from '../modules/local/extract_model_features/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_features/"])
include { PY_EXTRACT_BIOMODEL_FEATURES } from '../modules/local/py_extract_biomodel_features/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_features/"])
include { PY_TRANSFER_INPUT_BIODNN } from '../modules/local/py_transfer_input_biodnn/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}/"])
include { PY_EXPORT_RESULTS_BIO } from '../modules/local/py_export_results_bio/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_trained/"])
include { PRUNE_MODEL } from '../modules/local/py_prune_model/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_trained/"])
include { TRANSFER_LEARNING } from '../modules/local/transfer_learning/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/transfer_learning/"])
include { PY_EXPORT_RESULTS as PY_EXPORT_RESULTS_TRANSFER} from '../modules/local/py_export_results/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_trained/"])
include { PY_EXPORT_RESULTS as PY_EXPORT_RESULTS_AUTOENCOD} from '../modules/local/py_export_results/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/autoencoder_trained/"])
include { PY_EXPORT_RESULTS as PY_EXPORT_RESULTS_AUTOENCOD2} from '../modules/local/py_export_results/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/autoencoder_trained/"])
include { R_FILTER_MISSINGS_HDF5 } from '../modules/local/r_filter_missings_hdf5/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { R_SELECT_AUTOSOMICCPG_HDF5 } from '../modules/local/r_select_autosomic_cpg_hdf5/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { R_FILTER_INVARIANTCPG_HDF5 } from '../modules/local/r_filter_invariantcpg_hdf5/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { R_SUBSTITUTE_MISSING_HDF5 } from '../modules/local/r_substitute_missing_hdf5/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { R_CPGS_MEDIANS } from '../modules/local/r_cpgs_medians/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { R_WRITE_PROJECT_LABELS } from '../modules/local/r_write_project_labels/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { R_WRITE_INPUT_CPGS } from '../modules/local/r_write_input_cpgs/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { R_SELECT_INPUTCPG_HDF5 } from '../modules/local/r_select_inputcpgs_hdf5/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { PY_RESHAPE_HDF5_2D } from '../modules/local/py_reshape_hdf5_2D/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { R_CONVERT2D_HDF5 } from '../modules/local/r_convert2D_hdf5/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { PY_RESHAPE_HDF5 } from '../modules/local/py_reshape_hdf5/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { PY_COMBINE_METHY_LABEL_HDF5 } from '../modules/local/py_combine_methy_label_hdf5/main.nf' addParams( options: [publish_dir: "preprocess/${name}/${params_name}"])
include { TRAIN_AUTOENCODER_MODEL } from '../modules/local/py_train_autoencoder_model/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/autoencoder_trained/"])
include { PY_TRAIN_DNN_BIOLOGICALMODEL } from '../modules/local/py_train_dnn_biologicalmodel/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_trained/"])
include { PY_CREATE_GENE_MASK } from '../modules/local/py_create_gene_mask/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_trained/"])
include { TRAIN_PATHWAY_MODEL } from '../modules/local/py_train_pathway_model/main.nf' addParams( options: [publish_dir: "${name}/${params_name}/model_trained/"])
workflow {
if (step == "preprocessCNN"){
ch_input = Channel.of("${name}").concat(ch_input_hdf5).concat(ch_input_hdf5_se)
WF_PREPROCESS_1D(ch_input)
}
if (step == "preprocessCNN_trans"){
ch_input = Channel.of("${name}").concat(ch_input_hdf5).concat(ch_input_hdf5_se)
WF_PREPROCESS_1D_TRANSF(ch_input, probes)
}
if (step == "preprocessDNN"){
ch_input = Channel.of("${name}").concat(ch_input_hdf5).concat(ch_input_hdf5_se)
WF_PREPROCESS_DNN(ch_input)
}
if (step == "preprocessDNN_trans"){
ch_input = Channel.of("${name}").concat(ch_input_hdf5).concat(ch_input_hdf5_se)
WF_PREPROCESS_DNN_TRANSF(ch_input, probes)
}
if (step == "preprocess2D"){
ch_input = Channel.of("${name}").concat(ch_input_hdf5).concat(ch_input_hdf5_se)
WF_PREPROCESS_2D(ch_input)
}
if (step == "random"){
WF_RANDOM_SEARCH(ch_input_hdf5, test_prop, network, random_config, name)
}
if (step == "train"){
WF_TRAIN_MODEL(ch_input_hdf5, test_prop, network, network_params, name, params.autoencoder)
}
if (step == "prune"){
WF_PRUNE_MODEL(ch_input_hdf5, test_prop, model, network_params, name, params.autoencoder)
}
if (step == "train_bio"){
WF_TRAIN_BIOLOGICALMODEL(ch_input_hdf5, test_prop, network, network_params, probes, cpgmap, name)
}
if (step == "train_biopathways"){
WF_TRAIN_PATHWAY(ch_input_hdf5, test_prop, network, network_params, probes, cpgmap, name, params.autoencoder)
}
if (step == "transfer"){
WF_TRANSFER_MODEL(ch_input_hdf5, test_prop, model, labels, name, layer)
}
if (step == "features"){
EXTRACT_MODEL_FEATURES(ch_input_hdf5, model)
}
if (step == "features_bio"){
ch_input = Channel.of("${name}").concat(ch_input_hdf5).concat(ch_input_hdf5_se)
WF_EXTRACT_DNN_TRANSF(ch_input, probes, gene_mask, checkpoints, network, network_params)
}
// if (step == "autoencoder"){
// // Old code for autoencoder after CNN
// // WF_AUTOENCODER_MODEL(ch_input_hdf5, test_prop, model, labels, name)
// WF_AUTOENCODER_MODEL(ch_input_hdf5, test_prop, network, network_params, name)
// }
}
workflow WF_RANDOM_SEARCH {
take:
ch_input_hdf5
test_prop
network
random_config
name
main:
PY_DIVIDE_TRAIN_TEST ( ch_input_hdf5, test_prop )
RANDOM_SEARCH( PY_DIVIDE_TRAIN_TEST.out.train.collect(), network, random_config, name)
}
workflow WF_TRAIN_BIOLOGICALMODEL {
take:
ch_input_hdf5
test_prop
network
network_params
probes
cpgmap
name
main:
PY_DIVIDE_TRAIN_TEST ( ch_input_hdf5, test_prop )
PY_CREATE_GENE_MASK(network_params, probes, cpgmap)
PY_TRAIN_DNN_BIOLOGICALMODEL( ch_input_hdf5, PY_DIVIDE_TRAIN_TEST.out.train, PY_DIVIDE_TRAIN_TEST.out.test, network, network_params, PY_CREATE_GENE_MASK.out.mask, name )
PY_EXPORT_RESULTS_BIO( ch_input_hdf5, PY_TRAIN_DNN_BIOLOGICALMODEL.out.history, PY_TRAIN_DNN_BIOLOGICALMODEL.out.labels, PY_DIVIDE_TRAIN_TEST.out.test, PY_CREATE_GENE_MASK.out.mask, PY_TRAIN_DNN_BIOLOGICALMODEL.out.checkpoints, network, network_params, name )
}
workflow WF_TRAIN_PATHWAY {
take:
ch_input_hdf5
test_prop
network
network_params
probes
pathmap
name
autoencoder
main:
PY_DIVIDE_TRAIN_TEST ( ch_input_hdf5, test_prop, autoencoder )
TRAIN_PATHWAY_MODEL( ch_input_hdf5, PY_DIVIDE_TRAIN_TEST.out.train, PY_DIVIDE_TRAIN_TEST.out.test, probes, pathmap, network, network_params, name )
PY_EXPORT_RESULTS( ch_input_hdf5, TRAIN_PATHWAY_MODEL.out.history, TRAIN_PATHWAY_MODEL.out.model, TRAIN_PATHWAY_MODEL.out.labels, PY_DIVIDE_TRAIN_TEST.out.test, name, autoencoder )
}
workflow WF_PRUNE_MODEL {
take:
ch_input_hdf5
test_prop
model
network_params
name
autoencoder
main:
PY_DIVIDE_TRAIN_TEST ( ch_input_hdf5, test_prop, autoencoder )
PRUNE_MODEL( ch_input_hdf5, PY_DIVIDE_TRAIN_TEST.out.train, PY_DIVIDE_TRAIN_TEST.out.test, model, network_params, name )
PY_EXPORT_RESULTS( ch_input_hdf5, PRUNE_MODEL.out.history, PRUNE_MODEL.out.model, PRUNE_MODEL.out.labels, PY_DIVIDE_TRAIN_TEST.out.test, name, autoencoder )
}
workflow WF_TRAIN_MODEL {
take:
ch_input_hdf5
test_prop
network
network_params
name
autoencoder
main:
PY_DIVIDE_TRAIN_TEST ( ch_input_hdf5, test_prop, autoencoder )
TRAIN_MODEL( ch_input_hdf5, PY_DIVIDE_TRAIN_TEST.out.train, PY_DIVIDE_TRAIN_TEST.out.test, network, network_params, name )
PY_EXPORT_RESULTS( ch_input_hdf5, TRAIN_MODEL.out.history, TRAIN_MODEL.out.model, TRAIN_MODEL.out.labels, PY_DIVIDE_TRAIN_TEST.out.test, name, autoencoder )
}
workflow WF_TRANSFER_MODEL {
take:
ch_input_hdf5
test_prop
model
labels
name
layer
main:
PY_DIVIDE_TRAIN_TEST ( ch_input_hdf5, test_prop )
TRANSFER_LEARNING( ch_input_hdf5, PY_DIVIDE_TRAIN_TEST.out.train, PY_DIVIDE_TRAIN_TEST.out.test, model, labels, name, layer )
PY_EXPORT_RESULTS_TRANSFER( ch_input_hdf5, TRANSFER_LEARNING.out.history, TRANSFER_LEARNING.out.model, TRANSFER_LEARNING.out.labels, PY_DIVIDE_TRAIN_TEST.out.test, name )
}
workflow WF_AUTOENCODER_MODEL {
take:
ch_input_hdf5
test_prop
model
params
// labels
name
// Old code for autoencoder after CNN
main:
PY_DIVIDE_TRAIN_TEST ( ch_input_hdf5, test_prop )
TRAIN_AUTOENCODER_MODEL( PY_DIVIDE_TRAIN_TEST.out.train, PY_DIVIDE_TRAIN_TEST.out.test, model, params, name )
// TRAIN_AUTOENCODER_MODEL( PY_DIVIDE_TRAIN_TEST.out.train, PY_DIVIDE_TRAIN_TEST.out.test, model, name )
// PY_EXPORT_RESULTS_AUTOENCOD( ch_input_hdf5, TRAIN_AUTOENCODER_MODEL.out.old_history, TRAIN_AUTOENCODER_MODEL.out.model_old, labels, PY_DIVIDE_TRAIN_TEST.out.test, name )
}
workflow WF_PREPROCESS_1D {
take:
ch_input_hdf5
main:
R_FILTER_MISSINGS_HDF5( ch_input_hdf5.collect() )
R_SUBSTITUTE_MISSING_HDF5( R_FILTER_MISSINGS_HDF5.out.res )
R_CPGS_MEDIANS( R_FILTER_MISSINGS_HDF5.out.res )
R_WRITE_PROJECT_LABELS( ch_input_hdf5.collect() )
PY_RESHAPE_HDF5( R_SUBSTITUTE_MISSING_HDF5.out.h5, R_WRITE_PROJECT_LABELS.out )
}
workflow WF_PREPROCESS_DNN {
take:
ch_input_hdf5
main:
R_FILTER_MISSINGS_HDF5( ch_input_hdf5.collect() )
R_SELECT_AUTOSOMICCPG_HDF5( R_FILTER_MISSINGS_HDF5.out.res )
R_SUBSTITUTE_MISSING_HDF5( R_SELECT_AUTOSOMICCPG_HDF5.out.res )
R_CPGS_MEDIANS( R_SELECT_AUTOSOMICCPG_HDF5.out.res )
R_WRITE_INPUT_CPGS( R_SELECT_AUTOSOMICCPG_HDF5.out.res )
R_WRITE_PROJECT_LABELS( ch_input_hdf5.collect() )
PY_COMBINE_METHY_LABEL_HDF5( R_SUBSTITUTE_MISSING_HDF5.out.h5, R_WRITE_PROJECT_LABELS.out )
}
workflow WF_PREPROCESS_2D {
take:
ch_input_hdf5
main:
R_FILTER_MISSINGS_HDF5( ch_input_hdf5.collect() )
R_SUBSTITUTE_MISSING_HDF5( R_FILTER_MISSINGS_HDF5.out.res )
R_CPGS_MEDIANS( R_FILTER_MISSINGS_HDF5.out.res )
R_WRITE_PROJECT_LABELS( ch_input_hdf5.collect() )
R_CONVERT2D_HDF5(R_SUBSTITUTE_MISSING_HDF5.out.res )
PY_RESHAPE_HDF5_2D( R_CONVERT2D_HDF5.out.res, R_WRITE_PROJECT_LABELS.out )
}
workflow WF_PREPROCESS_1D_TRANSF {
take:
ch_input_hdf5
probes
main:
R_SUBSTITUTE_MISSING_HDF5( ch_input_hdf5.collect() )
R_SELECT_INPUTCPG_HDF5( R_SUBSTITUTE_MISSING_HDF5.out.res , probes )
R_WRITE_PROJECT_LABELS( ch_input_hdf5.collect() )
PY_RESHAPE_HDF5( R_SELECT_INPUTCPG_HDF5.out.h5, R_WRITE_PROJECT_LABELS.out )
}
workflow WF_PREPROCESS_DNN_TRANSF {
take:
ch_input_hdf5
probes
main:
R_SUBSTITUTE_MISSING_HDF5( ch_input_hdf5.collect() )
R_SELECT_INPUTCPG_HDF5( R_SUBSTITUTE_MISSING_HDF5.out.res , probes )
R_WRITE_PROJECT_LABELS( ch_input_hdf5.collect() )
PY_COMBINE_METHY_LABEL_HDF5( R_SELECT_INPUTCPG_HDF5.out.h5, R_WRITE_PROJECT_LABELS.out )
}
workflow WF_EXTRACT_DNN_TRANSF {
take:
ch_input_hdf5
cpg_median
gene_mask
checkpoints
network
network_params
main:
R_SUBSTITUTE_MISSING_HDF5( ch_input_hdf5.collect() )
R_SELECT_INPUTCPG_HDF5( R_SUBSTITUTE_MISSING_HDF5.out.res , cpg_median )
PY_EXTRACT_BIOMODEL_FEATURES(R_SELECT_INPUTCPG_HDF5.out.h5, gene_mask, checkpoints, network, network_params)
}