forked from evanfloden/dpa-analysis
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.nf
326 lines (256 loc) · 9.33 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
#!/usr/bin/env nextflow
/*
* Copyright (c) 2017-2019, Centre for Genomic Regulation (CRG) and the authors.
*
* This file is part of 'regressive-msa-analysis'.
*
* regressive-msa--analysis is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* regressive-msa-analysis is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with regressive-msa-analysis. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Main regressive-msa-analysis pipeline script
*
* @authors
* Evan Floden <[email protected]>
* Paolo Di Tommaso <[email protected]>
* Edgar Garriga
* Cedric Notredame
*/
/*
* defaults parameter definitions
*/
// input sequences to align in fasta format
params.seqs = "$baseDir/data/combined_seqs/seatoxin.fa"
// input reference sequences aligned in
params.refs = "$baseDir/data/refs/seatoxin.ref"
// input guide trees in Newick format. Or `false` to generate trees
//params.trees = "$baseDir/data/trees/*.CLUSTALO.dnd"
params.trees = false
// which alignment methods to run
params.align_method = "MAFFT-GINSI" //"UPP,MAFFT-SPARSECORE,MAFFT-FFTNS1,CLUSTALO,MAFFT-GINSI,PROBCONS,UPP"
// which tree methods to run if `trees` == `false`
params.tree_method = "CLUSTALO-RANDOM,CLUSTALO,MAFFT_PARTTREE" //,MAFFT-FFTNS1,MAFFT_PARTTREE"
// generate regressive alignments ?
params.regressive_align = true
// create standard alignments ?
params.standard_align = false
// create default alignments ?
params.default_align = false
// evaluate alignments ?
params.evaluate = true
// bucket sizes for regressive algorithm
params.buckets= '1000'
// output directory
params.output = "$baseDir/results"
log.info """\
R E G R E S S I V E M S A A n a l y s i s ~ version 0.1"
======================================="
Input sequences (FASTA) : ${params.seqs}
Input references (Aligned FASTA) : ${params.refs}
Input trees (NEWICK) : ${params.trees}
Output directory (DIRECTORY) : ${params.output}
Alignment methods : ${params.align_method}
Tree methods : ${params.tree_method}
Generate default alignments : ${params.default_align}
Generate standard alignments : ${params.standard_align}
Generate regressive alignments (DPA) : ${params.regressive_align}
Bucket Sizes for regressive alignments : ${params.buckets}
Perform evaluation? Requires reference : ${params.evaluate}
Output directory (DIRECTORY) : ${params.output}
"""
.stripIndent()
// Channels containing sequences
if ( params.seqs ) {
Channel
.fromPath(params.seqs)
.map { item -> [ item.baseName, item] }
.into { seqs; seqs2; seqs3 }
}
// Channels containing reference alignments for evaluation [OPTIONAL]
if( params.refs ) {
Channel
.fromPath(params.refs)
.map { item -> [ item.baseName, item] }
.set { refs }
}
// Channels for user provided trees or empty channel if trees are to be generated [OPTIONAL]
if ( params.trees ) {
Channel
.fromPath(params.trees)
.map { item -> [ item.baseName.tokenize('.')[0], item.baseName.tokenize('.')[1], item] }
.set { trees }
}
else {
Channel
.empty()
.set { trees }
}
tree_methods = params.tree_method
align_methods = params.align_method
/*
* GENERATE GUIDE TREES USING MEHTODS DEFINED WITH "--tree_method"
*
* NOTE: THIS IS ONLY IF GUIDE TREES ARE NOT PROVIDED BY THE USER
* BY USING THE `--trees` PARAMETER
*/
process generate_trees {
tag "${id}.${tree_method}"
publishDir "${params.output}/guide_trees", mode: 'copy', overwrite: true
input:
set val(id), \
file(seqs) \
from seqs
each tree_method from tree_methods.tokenize(',')
output:
set val(id), \
val(tree_method), \
file("${id}.${tree_method}.dnd") \
into treesGenerated
when:
!params.trees
script:
template "tree/generate_tree_${tree_method}.sh"
}
treesGenerated
.mix ( trees )
.combine ( seqs2, by:0 )
.into { seqsAndTreesForStandardAlignment; seqsAndTreesForRegressiveAlignment }
process standard_alignment {
tag "${id}.${align_method}.STD.NA.${tree_method}"
publishDir "${params.output}/alignments", mode: 'copy', overwrite: true
input:
set val(id), \
val(tree_method), \
file(guide_tree), \
file(seqs) \
from seqsAndTreesForStandardAlignment
each align_method from align_methods.tokenize(',')
when:
params.standard_align
output:
set val(id), \
val("${align_method}"), \
val(tree_method), val("std_align"), \
val("NA"), file("${id}.std.${align_method}.with.${tree_method}.tree.aln") \
into standard_alignments
script:
template "std_align/std_align_${align_method}.sh"
}
process regressive_alignment {
tag "${id}.${align_method}.DPA.${bucket_size}.${tree_method}"
publishDir "${params.output}/alignments", mode: 'copy', overwrite: true
publishDir "${params.output}/parents", mode: 'copy', overwrite: true, pattern: "*.parent.aln"
input:
set val(id), \
val(tree_method), \
file(guide_tree), \
file(seqs) \
from seqsAndTreesForRegressiveAlignment
each bucket_size from params.buckets.tokenize(',')
each align_method from align_methods.tokenize(',')
output:
set val(id), \
val("${align_method}"), \
val(tree_method), \
val("dpa_align"), \
val(bucket_size), \
file("${id}.dpa_${bucket_size}.${align_method}.with.${tree_method}.tree.aln") \
into regressive_alignments
file ("${id}.dpa_${bucket_size}.${align_method}.with.${tree_method}.tree.parent.aln") optional true into parent_alignments
when:
params.regressive_align
script:
template "dpa_align/dpa_align_${align_method}.sh"
}
process default_alignment {
tag "${id}.${align_method}.DEFAULT.NA.${align_method}"
publishDir "${params.output}/alignments", mode: 'copy', overwrite: true
input:
set val(id), file(seqs) from seqs3
each align_method from align_methods.tokenize(',')
when:
params.default_align
output:
set val(id), \
val("${align_method}"), \
val("DEFAULT"), val("default_align"), \
val("NA"), file("${id}.default.${align_method}.aln") \
into default_alignments
script:
template "default_align/default_align_${align_method}.sh"
}
// Create a channel that combines references and alignments to be evaluated
standard_alignments
.mix ( regressive_alignments )
.mix ( default_alignments )
.set { all_alignments }
refs
.cross ( all_alignments )
.map { it -> [it[0][0], it[1][1], it[1][2], it[1][3], it[1][4], it[1][5], it[0][1]] }
.set { toEvaluate }
process evaluate_aln {
tag "${id}.${align_method}.${tree_method}.${align_type}.${bucket_size}"
publishDir "${params.output}/individual_scores", mode: 'copy', overwrite: true
input:
set val(id), \
val(align_method), \
val(tree_method), \
val(align_type), \
val(bucket_size), \
file(test_alignment), \
file(ref_alignment) \
from toEvaluate
output:
set val(id), \
val(tree_method), \
val(align_method), \
val(align_type), \
val(bucket_size), \
file("*.sp"), \
file("*.tc"), \
file("*.col") \
into scores
when:
params.evaluate
script:
"""
## Sum-of-Pairs Score ##
t_coffee -other_pg aln_compare \
-al1 ${ref_alignment} \
-al2 ${test_alignment} \
-compare_mode sp \
| grep -v "seq1" | grep -v '*' | \
awk '{ print \$4}' ORS="\t" \
> "${id}.${align_type}.${bucket_size}.${align_method}.${tree_method}.sp"
## Total Column Score ##
t_coffee -other_pg aln_compare \
-al1 ${ref_alignment} \
-al2 ${test_alignment} \
-compare_mode tc \
| grep -v "seq1" | grep -v '*' | \
awk '{ print \$4}' ORS="\t" \
> "${id}.${align_type}.${bucket_size}.${align_method}.${tree_method}.tc"
## Column Score ##
t_coffee -other_pg aln_compare \
-al1 ${ref_alignment} \
-al2 ${test_alignment} \
-compare_mode column \
| grep -v "seq1" | grep -v '*' | \
awk '{ print \$4}' ORS="\t" \
> "${id}.${align_type}.${bucket_size}.${align_method}.${tree_method}.col"
"""
}
workflow.onComplete {
println (['bash','-c', "$baseDir/bin/cpu_calculate.sh ${params.output}/individual_scores"].execute().text)
println "Execution status: ${ workflow.success ? 'OK' : 'failed' } runName: ${workflow.runName}"
}