-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathparallel_integron_finder.nf
More file actions
executable file
·268 lines (234 loc) · 8.77 KB
/
parallel_integron_finder.nf
File metadata and controls
executable file
·268 lines (234 loc) · 8.77 KB
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
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
/*************************
* Default options
*************************/
params.gbk = false
params.pdf = false
params['local-max']= false
params['func-annot'] = false
params['distance-threshold'] = false
params['union-integrases'] = false
params['path-func-annot'] = false
params['attc-model'] = false
params['evalue-attc'] = false
params['keep-palindrome'] = false
params['no-proteins'] = false
params['promoter-attI'] = false
params['max-attc-size'] = false
params['min-attc-size'] = false
params.circ = false
params.linear = false
params['topology-file'] = false
params['keep-tmp'] = false
params['calin-threshold'] = false
params.gembase = false
params['gembase-path'] = false
params['cmsearch'] = false
params['hmmsearch'] = false
params['prodigal'] = false
params.debug = false
/****************************************
* parameter not really used in the wf *
* used to improve UI *
*****************************************/
params.help = false
params.profile = false
/****************************************
* real parameters *
*****************************************/
gbk = params.gbk ? ' --gbk' : ''
pdf = params.pdf ? ' --pdf' : ''
local_max = params['local-max'] ? ' --local-max' : ''
func_annot = params['func-annot'] ? ' --func-annot' : ''
path_func_annot = params['path-func-annot'] ? " --path-func-annot ${params['path-func-annot']}" : ''
dist_thr = params['distance-threshold'] ? " --distance-thresh ${params['distance-threshold']}" : ''
union_integrases = params['union-integrases'] ? ' --union-integrase' : ''
attc_model = params['attc-model'] ? " --attc-model ${params['attc-model']}" : ''
evalue_attc = params['evalue-attc'] ? " --evalue-attc ${params['evalue-attc']}" : ''
keep_palindrome = params['keep-palindrome'] ? ' --keep-palindrome' : ''
no_proteins = params['no-proteins'] ? ' --no-proteins' : ''
promoter = params['promoter-attI'] ? ' --promoter-attI' : ''
max_attc_size = params['max-attc-size'] ? " --max-attc-size ${params['max-attc-size']}" : ''
min_attc_size = params['min-attc-size'] ? " --min-attc-size ${params['min-attc-size']}" : ''
circ = params.circ ? ' --circ' : ''
linear = params.linear ? '--linear' : ''
topology_file = params['topology-file'] ? " --topology-file ${params['topology-file']}" : ''
keep_tmp = params['keep-tmp'] ? ' --keep-tmp' : ''
calin_threshold = params['calin-threshold'] ? " --calin-threshold ${params['calin-threshold']}" : ''
gembase = params.gembase
gembase_path = params['gembase-path'] ? " --gembase-path ${params['gembase-path']}" : ''
cmsearch = params['cmsearch'] ? " --cmsearch ${params['cmsearch']}" : ''
hmmsearch = params['hmmsearch'] ? " --hmmsearch ${params['hmmsearch']}" : ''
prodigal = params['prodigal'] ? " --prodigal ${params['prodigal']}" : ''
debug = params.debug ? '-vv' : ''
if (params.help){
msg = '''
parallel_integron_finder available options:
--gbk
--pdf
--local-max
--func-annot
--distance-threshold
--union-integrases
--path-func-annot
--attc-model
--evalue-attc
--keep-palindrome
--no-proteins
--promoter-attI
--max-attc-size
--min-attc-size
--circ
--linear
--topology-file
--keep-tmp
--calin-threshold
--gembase-path
--replicons
--cmsearch
--prodigal
--hmmsearch
Please refer to the integron_finder documentation for the meaning of each options.
'''
println(msg)
System.exit(0)
}
if (params.profile){
throw new Exception("The integron_finder option '--profile' does not exists. May be you want to use the nextflow option '-profile'.")
}
if (! params.replicons){
throw new Exception("The option '--replicons' is mandatory.")
}
if (params.circ && params.linear){
throw new Exception("The options '--linear' and '--circ' are mutually exclusive.")
}
if (params.gembase){
throw new Exception("The options '--gembase' is not available for parallel_integron_finder. Use '--gembase-path' instead")
}
if (params['gembase-path']){
// need to compute the abspath to gembase
// the integron_finder step will be compute in the work subdirectory
file = new File(params['gembase-path'])
gembase_path = file.getCanonicalPath();
gembase_path = " --gembase-path ${gembase_path}"
gembase = " --gembase"
} else {
gembase_path = ''
gembase = ''
}
if (params.replicons.contains(',')){
paths = params.replicons.tokenize(',')
} else {
paths = params.replicons
}
/****************************************
* The Process *
****************************************/
process split{
input:
path replicons_files
output:
tuple(val("${replicons_files.baseName}"),path("split_gem/*.fst"), stdout)
script:
"""
integron_split --mute ${replicons_files} --outdir split_gem | wc -w
"""
}
process integron_finder{
input:
tuple( val(id_input), path(one_replicon), val (nb_chunks))
val gbk
val pdf
val local_max
val func_annot
val path_func_annot
val circ
val linear
val topology_file
val dist_thr
val union_integrases
val attc_model
val evalue_attc
val keep_palindrome
val no_proteins
val promoter
val max_attc_size
val min_attc_size
val keep_tmp
val calin_threshold
val gembase
val gembase_path
val debug
val cmsearch
val hmmsearch
val prodigal
output:
tuple val(id_input), path("Results_Integron_Finder_${one_replicon.baseName}")
script:
/*******************************************************************************************************
For sequential IF the default topology behavior is
if there is only one replicon in the replicon file then the topology is circular
if there are several replicons in the replicon file then the topology is linear
but for parallelisation we split replicon files in as file as replicon so the default topology is always circular.
To restore the same behavior we need to analyse the number of replicon per file and force the topology
********************************************************************************************************/
nb_chunks = nb_chunks as int
if (params.circ){
topo = '--circ'
} else if (params.linear){
topo = '--linear'
} else if (nb_chunks == 1) {
topo = '--circ'
} else {
topo = '--linear'
}
"""
integron_finder ${local_max}${func_annot}${path_func_annot}${dist_thr}${union_integrases}${attc_model}${evalue_attc}${keep_palindrome}${no_proteins}${promoter}${max_attc_size}${min_attc_size}${calin_threshold}${topo}${topology_file}${gbk}${pdf}${keep_tmp} --cpu ${task.cpus} ${gembase}${gembase_path}${cmsearch}${hmmsearch}${prodigal} --mute ${debug} ${one_replicon}
"""
}
process merge_results{
input:
tuple(val(input_id), path(all_chunk_results))
output:
tuple(val(input_id), path("${result_dir}/*"))
script:
result_dir = "Results_Integron_Finder_${input_id}"
if (result_dir == all_chunk_results){
// manage case where there is one file with one sequence
// in this case resilt_dir and all_chunk_results are ==
// and integron_merge raise an error
// it does not change the final result
// as the files will be copied in current_dir/${result_dir} see subscribe in workflow
result_dir = "${result_dir}_merged"
}
"""
integron_merge "${result_dir}" "${input_id}" ${all_chunk_results}
"""
}
/****************************************
* The Workflow *
****************************************/
workflow {
replicons_files = Channel.fromPath(paths)
replicons = split(replicons_files).transpose()
results_per_replicon = integron_finder(replicons, gbk, pdf, local_max, func_annot, path_func_annot,
circ, linear, topology_file, dist_thr, union_integrases, attc_model, evalue_attc,
keep_palindrome, no_proteins, promoter, max_attc_size, min_attc_size,keep_tmp,
calin_threshold, gembase, gembase_path, debug, cmsearch, hmmsearch, prodigal )
grouped_results = results_per_replicon.groupTuple(by:0)
results = merge_results(grouped_results)
results.transpose().subscribe{
it ->
result_dir = "Results_Integron_Finder_${it[0]}"
it[1].copyTo("${result_dir}/" + it[1].name);
}
}
workflow.onComplete {
if ( workflow.success )
println("\nDone!")
}
workflow.onError {
println "Oops .. something went wrong"
println "Pipeline execution stopped with the following message: ${workflow.errorMessage}"
}