-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalysis.nf
331 lines (236 loc) · 8.3 KB
/
Analysis.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
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
// nextflow.enable.configProcessNamesValidation = false
log.info """\
QTL Pipeline - Analysis
==============================
Output Directory : $params.outdir
Method : $params.pipeline_engine
Genotype File : $params.gds_list
Phenotype File : $params.phenotype_file
Analyzed Phenotypes: $params.phenotype_names
Covariates : $params.covariates
P-value Cutoff : $params.pval_cutoff
==============================
"""
// ##### Not used process to aviod warnings from sge.config ####################
process qc_filters {script:""" """}
process M_vcf_to_gds {script:""" """}
process M_write_gds_list {script:""" """}
process M_merge_gds {script:""" """}
process M_PCA {script:""" """}
process M_QTL_results_wrap {script:""" """}
process G_vcf_to_gds {script:""" """}
process G_write_gds_list {script:""" """}
process G_merge_gds {script:""" """}
process G_PCA_GRM {script:""" """}
process G_QTL_results_wrap {script:""" """}
process move_boxplot {script:""" """}
// ##### MatrixeQTL ############################################################
process M_get_shared_sampleid {
publishDir "${params.outdir}/1_data", mode: 'copy'
input:
tuple val(gds_example_name), val(gds_example)
output:
path '*'
path 'shared_sampleid.txt', emit: shared_sampleid
script:
"""
0_M_get_shared_sampleid.R $gds_example ${params.phenotype_file} ${params.covariates_file} ${params.userdef_sampleid_txtfile}
"""
}
process M_split_pheno {
publishDir "${params.outdir}/1_phenotype_data_chunk", mode: 'copy'
input:
path shared_sampleid
output:
path '*'
path 'phenodat_chunk*.rds', emit: phenodat_chunks
script:
"""
2_M_split_pheno.R ${params.phenotype_file} ${params.phenotype_names} ${params.max_pheno_parallel} $shared_sampleid
"""
}
process M_prepare_cvrt {
publishDir "${params.outdir}/1_data", mode: 'copy'
input:
path shared_sampleid
output:
path '1_cvrt.rds', emit: cvrt_use
path '*'
script:
"""
1_M_prepare_cvrt.R ${params.covariates_file} ${params.PC_rds} ${params.covariates} ${params.covariates_factor} $shared_sampleid
"""
}
process M_SNP_info {
publishDir "${params.outdir}/2_SNP_info", mode: 'copy'
input:
tuple val(gds_name), val(gds_file), file(shared_sampleid)
output:
tuple val(gds_name), path('SNPinfo_*.csv'), emit: SNP_info
path '*'
script:
"""
2_M_SNP_info.R $gds_name $gds_file $shared_sampleid ${params.snpset_assoc_txtfile}
"""
}
process M_QTL_analysis {
publishDir "${params.outdir}/3_individual_results", mode: 'copy'
maxForks params.max_forks_parallel
input:
tuple val(gds_name), val(gds_file), file(cvrt_use), file(shared_sampleid), file(pheno_rds)
output:
tuple val(gds_name), path('QTL_*.rds'), emit: QTL_assoc
path 'QTL_count_*.txt', emit: QTL_chunk_count
path '*'
script:
"""
3_M_matQTL.R $gds_name $gds_file $cvrt_use ${params.model_type} ${params.interaction_cvrt} ${params.pval_cutoff} $shared_sampleid ${params.snpset_assoc_txtfile} $pheno_rds ${params.draw_genopheno_boxplot} ${params.boxplot_p_cutoff}
"""
}
process M_merge_info_QTL {
publishDir "${params.outdir}/4_individual_results_SNPinfo", mode: 'copy'
input:
tuple val(gds_name), file(QTL_result), file(gds_info)
output:
path 'QTL_SNPinfo_*.rds'
path '*'
script:
"""
4_M_merge_info_QTL.R $gds_name $QTL_result $gds_info
"""
}
process M_QTL_count_wrap {
publishDir "${params.outdir}/5_Results_Summary", mode: 'move'
input:
path QTL_chunk_count
output:
path '*'
script:
"""
5_M_wrap_QTL_count.R $QTL_chunk_count
"""
}
// ##### GENESIS ###############################################################
process G_get_shared_sampleid {
publishDir "${params.outdir}/1_data", mode: 'copy'
input:
tuple val(gds_example_name), val(gds_example)
output:
path '*'
path 'shared_sampleid.txt', emit: shared_sampleid
script:
"""
0_G_get_shared_sampleid.R $gds_example ${params.phenotype_file} ${params.covariates_file} ${params.userdef_sampleid_txtfile}
"""
}
process G_split_pheno {
publishDir "${params.outdir}/1_phenotype_data", mode: 'copy'
input:
path shared_sampleid
output:
path 'phenodat_*.rds', emit: phenodat_rds
path '*'
script:
"""
1_G_split_pheno.R ${params.phenotype_file} ${params.phenotype_names} $shared_sampleid
"""
}
process G_prepare_cvrt {
publishDir "${params.outdir}/1_data", mode: 'copy'
input:
path shared_sampleid
output:
path '1_cvrt.rds', emit: cvrt_use
path '*'
script:
"""
1_G_prepare_cvrt.R ${params.covariates_file} ${params.PC_rds} ${params.covariates} ${params.covariates_factor} $shared_sampleid
"""
}
process G_SNP_info {
publishDir "${params.outdir}/2_SNP_info", mode: 'copy'
input:
tuple val(gds_name), val(gds_file), file(shared_sampleid)
output:
tuple val(gds_name), path('SNPinfo_*.csv'), emit: SNP_info
path '*'
script:
"""
2_G_SNP_info.R $gds_name $gds_file $shared_sampleid ${params.snpset_assoc_txtfile}
"""
}
process G_QTL_analysis {
publishDir "${params.outdir}/3_individual_results", mode: 'copy'
maxForks params.max_forks_parallel
input:
tuple val(gds_name), val(gds_file), file(cvrt_use), file(shared_sampleid), file(pheno_rds)
output:
tuple val(gds_name), path('assoc_*.rds'), emit: QTL_assoc
path 'count_*.txt', emit: QTL_results_count
path '*'
script:
"""
3_G_nullmod_assoc.R $gds_name $gds_file ${params.genotype_or_dosage} $cvrt_use ${params.GRM_rds} ${params.pval_cutoff} $shared_sampleid ${params.snpset_assoc_txtfile} $pheno_rds ${params.draw_genopheno_boxplot} ${params.boxplot_p_cutoff}
"""
}
process G_merge_info_QTL {
publishDir "${params.outdir}/4_individual_results_SNPinfo", mode: 'copy'
input:
tuple val(gds_name), file(QTL_result), file(gds_info)
output:
path 'assoc_SNPinfo_*.rds', emit: QTL_assoc_winfo
path '*'
val 'fin', emit: fin
script:
"""
4_G_merge_info_QTL.R $gds_name $QTL_result $gds_info
"""
}
process G_QTL_count_wrap {
publishDir "${params.outdir}/5_Results_Summary", mode: 'copy'
input:
path QTL_individual_count
output:
path '*'
script:
"""
echo -e 'phenotype\tgenotype_dat\tQTL_num\tdescription' > QTL_counts_summary.txt
cat $QTL_individual_count >> QTL_counts_summary.txt
"""
}
// ##### workflow ##############################################################
workflow {
genogds = Channel
.fromPath(params.gds_list)
.splitCsv(header: false)
.map {row -> tuple(row[0], row[1])}
genogds0 = Channel
.fromPath(params.gds_list)
.splitCsv(header: false, limit: 1)
.map {row -> tuple(row[0], row[1])}
if (params.pipeline_engine == "matrixeqtl" | params.pipeline_engine == "m") {
snpset_assoc_txtfile = channel.from("${params.snpset_assoc_txtfile}")
M_get_shared_sampleid(genogds0)
shared_sampleid = M_get_shared_sampleid.out.shared_sampleid
M_SNP_info(genogds.combine(shared_sampleid))
M_split_pheno(shared_sampleid)
M_prepare_cvrt(shared_sampleid)
cvrt_use = M_prepare_cvrt.out.cvrt_use
M_QTL_analysis(genogds.combine(cvrt_use).combine(shared_sampleid).combine(M_split_pheno.out.phenodat_chunks.flatten()))
M_merge_info_QTL(M_QTL_analysis.out.QTL_assoc.combine(M_SNP_info.out.SNP_info, by: 0))
M_QTL_count_wrap(M_QTL_analysis.out.QTL_chunk_count.collect())
}
if (params.pipeline_engine == "genesis" | params.pipeline_engine == "g") {
G_get_shared_sampleid(genogds0)
shared_sampleid = G_get_shared_sampleid.out.shared_sampleid
G_SNP_info(genogds.combine(shared_sampleid))
G_split_pheno(shared_sampleid)
G_prepare_cvrt(shared_sampleid)
cvrt_use = G_prepare_cvrt.out.cvrt_use
G_QTL_analysis(genogds.combine(cvrt_use).combine(shared_sampleid).combine(G_split_pheno.out.phenodat_rds.flatten()))
G_merge_info_QTL(G_QTL_analysis.out.QTL_assoc.combine(G_SNP_info.out.SNP_info, by: 0))
G_QTL_count_wrap(G_QTL_analysis.out.QTL_results_count.collect())
}
}