-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
345 lines (232 loc) · 6.07 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
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
// Define the output folder for the final results
params.outputFolder = "./output_results"
workflow {
def input_gff = Channel.fromPath(params.gff_folder + '/*.{gff,gff3}')
input_gff.view()
// Create output structure
MAKE_OUT_FOLDERS()
// get general stats
GET_GFF_STATS(input_gff)
// run gff compare on genes with an exon chain longer than >200bp
FILTER_ISOFORM(input_gff)
KEEP_LONG_GENE(FILTER_ISOFORM.out)
SELECT_BASIC_STRUCTURE(KEEP_LONG_GENE.out)
GET_GFF_STATS_LONG(SELECT_BASIC_STRUCTURE.out)
GFFCOMPARE(SELECT_BASIC_STRUCTURE.out, SELECT_BASIC_STRUCTURE.out.collect())
// run BUSCO
EXTRACT_SEQ(input_gff, params.ref)
DW_BUSCO_LINEAGE(params.lineage)
RUN_BUSCO(EXTRACT_SEQ.out, DW_BUSCO_LINEAGE.out)
// aggregate results
AGGREGATE_GFF(GFFCOMPARE.out.collect())
AGGREGATE_BUSCO(RUN_BUSCO.out.collect())
AGGREGATE_STATS(GET_GFF_STATS.out.collect(),GET_GFF_STATS_LONG.out.collect())
}
process MAKE_OUT_FOLDERS{
publishDir params.outputFolder , mode: 'copy'
output:
path BUSCO
path gffcompare
path summary_stat
script:
"""
mkdir -p BUSCO
mkdir -p gffcompare
mkdir -p summary_stat
"""
}
process GET_GFF_STATS{
publishDir params.outputFolder , mode: 'copy'
cache 'lenient'
label 'agat'
input:
path gff
output:
path "summary_stat/full/${gff.baseName}_agat_stat.txt"
script:
"""
mkdir -p summary_stat/full
agat_sq_stat_basic.pl -i ${gff} -o summary_stat/full/${gff.baseName}_agat_stat.txt
"""
}
process SELECT_BASIC_STRUCTURE{
// This process is to keep only basic feature of the gene
// such as gene, mRNA and exon
// This might cause problem when mRNA is labeled as transcript
cache 'lenient'
input:
path gff
output:
path "${gff.baseName}_basicelements.gff3"
script:
"""
awk '\$3 == "gene" || \$3 == "mRNA" || \$3 == "exon"' ${gff} > ${gff.baseName}_basicelements.gff3
cut -f 3 ${gff.baseName}_basicelements.gff3 | sort | uniq -c # This is for debugging purpose
"""
}
process FILTER_ISOFORM{
cache 'lenient'
label 'agat'
memory { 4.GB * task.attempt }
errorStrategy { task.exitStatus == 140 ? 'retry' : 'terminate' }
input:
path gff
output:
path "${gff.baseName}_longisoforms.gff3"
script:
"""
cut -f 3 ${gff} | sort | uniq -c
agat_sp_keep_longest_isoform.pl -gff ${gff} -o ${gff.baseName}_longisoforms.gff3
cut -f 3 ${gff.baseName}_longisoforms.gff3 | sort | uniq -c # This is for debugging purpose
"""
}
process KEEP_LONG_GENE{
cache 'lenient'
label 'agat'
memory { 4.GB * task.attempt }
errorStrategy { task.exitStatus == 140 ? 'retry' : 'terminate' }
input:
path gff
output:
path "${gff.baseName}_200plus.gff3"
script:
"""
agat_sp_filter_gene_by_length.pl -gff ${gff} --size 200 --test ">" -o ${gff.baseName}_200plus.gff3
"""
}
process GET_GFF_STATS_LONG{
publishDir params.outputFolder , mode: 'copy'
cache 'lenient'
label 'agat'
input:
path gff
output:
path "summary_stat/long/${gff.baseName}_agat_stat.txt"
script:
"""
mkdir -p summary_stat/long
agat_sq_stat_basic.pl -i ${gff} -o summary_stat/long/${gff.baseName}_agat_stat.txt
"""
}
process GFFCOMPARE{
cache 'lenient'
label 'gffcompare'
publishDir params.outputFolder , mode: 'copy'
input:
path ref
val test
output:
path "gffcompare/all_samples/${ref.baseName}.stats"
script:
"""
gffcompare -T -r ${ref} ${test.join(' ')} -o ${ref.baseName}
mkdir -p gffcompare/all_samples
cp ${ref.baseName}.stats gffcompare/all_samples
"""
}
process AGGREGATE_GFF{
cache 'lenient'
label 'python'
publishDir params.outputFolder , mode: 'copy'
input:
val gff_stats
output:
path "gffcompare/summary/*"
script:
"""
mkdir -p gffcompare/summary
hostname
python ${baseDir}/bin/aggregate_gffcompare.py \
--gffcompare ${gff_stats.join(' ')} \
--out_label gffcompare/summary/combined_gffcompare
"""
}
process EXTRACT_SEQ{
cache 'lenient'
label 'agat'
input:
path gff
path ref
output:
path "${gff.baseName}_transcripts.fa"
script:
"""
agat_sp_extract_sequences.pl \
-f ${ref} \
-g ${gff} \
-t exon \
-o ${gff.baseName}_transcripts.fa \
--merge
"""
}
process DW_BUSCO_LINEAGE {
cache 'lenient'
label 'busco'
input:
val lineage
output:
path "dw_lineage/lineages/${lineage}"
script:
"""
mkdir dw_lineage
busco --download_path dw_lineage --download ${lineage}
"""
}
process RUN_BUSCO{
cache 'lenient'
label 'busco'
cpus 4
publishDir params.outputFolder , mode: 'copy'
input:
path transcripts
val lineage
output:
path "BUSCO/all_samples/short_summary.specific.${lineage.baseName}.BUSCO_${transcripts}.json"
script:
"""
busco \
-m transcriptome \
-i ${transcripts} \
-l ${lineage} \
--offline \
--cpu 4 \
-o BUSCO_${transcripts}
mkdir -p BUSCO/all_samples
mv BUSCO_${transcripts}/short_summary.specific.${lineage.baseName}.BUSCO_${transcripts}.json BUSCO/all_samples
"""
}
process AGGREGATE_BUSCO{
cache 'lenient'
label 'python'
publishDir params.outputFolder , mode: 'copy'
input:
val BUSCO_stats
output:
path "BUSCO/summary/combined_BUSCO_results.csv"
script:
"""
mkdir -p BUSCO/summary
python ${baseDir}/bin/aggregate_BUSCO.py \
--busco ${BUSCO_stats.join(' ')} \
--out BUSCO/summary/combined_BUSCO_results.csv
"""
}
process AGGREGATE_STATS{
cache 'lenient'
label 'python'
publishDir params.outputFolder , mode: 'copy'
input:
val full_stats
val long_stats
output:
path "summary_stat/summary_stats_combined.csv"
script:
"""
mkdir -p summary_stat
python ${baseDir}/bin/aggregate_stats.py \
--stats ${full_stats.join(' ')} ${long_stats.join(' ')} \
--out summary_stat/summary_stats_combined.csv
"""
}