forked from darcyabjones/pclust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphmm.nf
executable file
·382 lines (298 loc) · 8.73 KB
/
phmm.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
380
381
382
#!/usr/bin/env nextflow
/*
vim: syntax=groovy
-*- mode: groovy;-*-
*/
def helpMessage() {
log.info"""
=================================
pclust/phmm
=================================
Usage:
abaaab
Mandatory Arguments:
--clusters <glob pattern>
Options:
--nopdb Don't search for matches in PDB
--nopfam Don't search for matches in PFam
--noscop Don't search for matches in SCOP
--nouniref Don't search for matches in uniref
Database download options:
--hhpdb Use this directory containing hhsuite PDB database.
--hhpfam Use this directory containing hhsuite PFam database.
--hhscop Use this directory containing hhsuite SCOP database.
--hhuniref Use this directory containing hhsuite Uniref database.
Any of these options will prevent download of db and use path instead.
Outputs:
""".stripIndent()
}
if (params.help){
helpMessage()
exit 0
}
params.clusters = false
params.nopdb = false
params.nopfam = false
params.noscop = false
params.nouniref = false
params.hhpdb = false
params.hhscop = false
params.hhuniref = false
params.hhpfam = false
if ( params.clusters ) {
clusters = Channel
.fromPath(params.clusters, type: 'dir', checkIfExists: true, glob: false)
.first()
} else {
log.info "Hey I need some MSAs to use please."
exit 1
}
/*
* Get the databases ready.
* Downloads them if they don't exist already.
*/
if ( !params.nouniref && params.hhuniref ) {
hhunirefDatabase = Channel
.fromPath( params.hhuniref, type: 'dir', checkIfExists: true, glob: false)
.first()
} else if ( !params.nouniref ) {
process downloadHHUniref {
label "download"
storeDir "${params.outdir}/databases"
output:
file "hhuniref" into hhunirefDatabase
"""
mkdir -p hhuniref
cd hhuniref
wget -c http://wwwuser.gwdg.de/~compbiol/uniclust/2018_08/uniclust30_2018_08_hhsuite.tar.gz
tar -zxf uniclust30_2018_08_hhsuite.tar.gz
mv uniclust30_2018_08/* ./
rm -rf -- uniclust30_2018_08
"""
}
}
if ( !params.nopdb && params.hhpdb ) {
hhpdbDatabase = Channel
.fromPath( params.hhpdb, type: 'dir', checkIfExists: true, glob: false )
.first()
} else if ( !params.nopdb ) {
process downloadHHPDB {
label "download"
storeDir "${params.outdir}/databases"
output:
file "hhpdb" into hhpdbDatabase
"""
mkdir -p hhpdb
cd hhpdb
wget -c http://wwwuser.gwdg.de/%7Ecompbiol/data/hhsuite/databases/hhsuite_dbs/pdb70_from_mmcif_181017.tar.gz
tar -zxf pdb70_from_mmcif_181017.tar.gz
"""
}
}
if ( !params.noscop && params.hhscop ) {
hhscopDatabase = Channel
.fromPath( params.hhscop, type: 'dir', checkIfExists: true, glob: false )
.first()
} else if ( !params.noscop ) {
process downloadHHSCOP {
label "download"
storeDir "${params.outdir}/databases"
output:
file "hhscop" into hhscopDatabase
"""
mkdir -p hhscop
cd hhscop
wget -c http://wwwuser.gwdg.de/%7Ecompbiol/data/hhsuite/databases/hhsuite_dbs/scop90_01Mar17.tgz
tar -zxf scop90_01Mar17.tgz
"""
}
}
if ( !params.nopfam && params.hhpfam ) {
hhpfamDatabase = Channel
.fromPath( params.hhpfam, type: 'dir', checkIfExists: true, glob: false )
.first()
} else if ( !params.nopfam ) {
process downloadHHPFAM {
label "download"
storeDir "${params.outdir}/databases"
output:
file "hhpfam" into hhpfamDatabase
"""
mkdir -p hhpfam
cd hhpfam
wget -c http://wwwuser.gwdg.de/%7Ecompbiol/data/hhsuite/databases/hhsuite_dbs/pfamA_31.0.tgz
tar -zxf pfamA_31.0.tgz
"""
}
}
/*
* Run the database searches.
*/
process decompressDB {
label "hhsuite"
input:
file "clusters" from clusters
output:
file "decompressed" into decompressed
"""
mkdir -p decompressed
a3m_database_extract \
-i clusters/db_ca3m \
-o decompressed/db_a3m \
-d clusters/db_sequence \
-q clusters/db_header
"""
}
process splitDB {
label "python"
input:
file "clusters" from decompressed
output:
// NB we rely on the data, index order of this glob, throughout.
// Changing it will cause errors.
file "subset_*.ff{data,index}" into splitClusters mode flatten
"""
ffdb.py split -n 10000 -b "subset_{index}.{ext}" clusters/db_a3m.ff{data,index}
"""
}
splitClusters
.map { [it.getSimpleName(), it] }
.groupTuple(by: 0, size: 2)
.map { bn, files -> [bn, files[0], files[1]] }
.into {
clusters4Search;
clusters4Uniref;
clusters4Pfam;
clusters4Scop;
clusters4Pdb;
}
/*
* Search each cluster hmm against all other clusters.
*/
process searchClusters {
label "hhsuite"
tag { name }
cpus = 16
input:
set val(name), file("subset.ffdata"), file("subset.ffindex") from clusters4Search
file "clusters" from clusters
output:
set val("clusters"), file("${name}.ffdata"), file("${name}.ffindex") into clusterSearchResults
script:
CPU_PER_TASK = 4
NTASKS = task.cpus.intdiv(CPU_PER_TASK)
INPUT = "subset"
OUTPUT = name
DB = "clusters"
template "hhblits_mpi_sensitive.sh"
}
if ( !params.nouniref ) {
/*
* Search for shorter matches in the uniref database.
*/
process searchUniref {
label "hhblits"
tag { name }
input:
set val(name), file("subset.ffdata"), file("subset.ffindex") from clusters4Uniref
file "uniref" from hhunirefDatabase
output:
set val("uniref"), file("${name}.ffdata"), file("${name}.ffindex") into unirefSearchResults
script:
CPU_PER_TASK = 2
NTASKS = task.cpus.intdiv(CPU_PER_TASK)
INPUT = "subset"
OUTPUT = name
DB = "uniref"
NITER = 1
template "hhblits_mpi.sh"
}
} else {
unirefSearchResults = Channel.empty()
}
if ( !params.nopfam ) {
/*
* Search for pfam domains.
*/
process searchPfam {
label "hhblits"
tag { name }
input:
set val(name), file("subset.ffdata"), file("subset.ffindex") from clusters4Pfam
file "pfam" from hhpfamDatabase
output:
set val("pfam"), file("${name}.ffdata"), file("${name}.ffindex") into pfamSearchResults
script:
CPU_PER_TASK = 2
NTASKS = task.cpus.intdiv(CPU_PER_TASK)
INPUT = "subset"
OUTPUT = name
DB = "pfam"
template "hhblits_mpi_sensitive.sh"
}
} else {
pfamSearchResults = Channel.empty()
}
if ( !params.noscop ) {
/*
* Search for SCOP matches.
*/
process searchScop {
label "hhblits"
tag { name }
input:
set val(name), file("subset.ffdata"), file("subset.ffindex") from clusters4Scop
file "scop" from hhscopDatabase
output:
set val("scop"), file("${name}.ffdata"), file("${name}.ffindex") into scopSearchResults
script:
CPU_PER_TASK = 2
NTASKS = task.cpus.intdiv(CPU_PER_TASK)
INPUT = "subset"
OUTPUT = name
DB = "scop"
template "hhblits_mpi_sensitive.sh"
}
} else {
scopSearchResults = Channel.empty()
}
if ( !params.nopdb ) {
/*
* Search for PDB matches.
*/
process searchPdb {
label "hhblits"
tag { name }
input:
set val(name), file("subset.ffdata"), file("subset.ffindex") from clusters4Pdb
file "pdb" from hhpdbDatabase
output:
set val("pdb"), file("${name}.ffdata"), file("${name}.ffindex") into pdbSearchResults
script:
CPU_PER_TASK = 2
NTASKS = task.cpus.intdiv(CPU_PER_TASK)
INPUT = "subset"
OUTPUT = name
DB = "pdb"
template "hhblits_mpi_sensitive.sh"
}
} else {
pdbSearchResults = Channel.empty()
}
/*
* Collect the search results into a single database.
*/
process collectSearchResults {
label "python"
tag { db }
input:
set val(db), file("*") from clusterSearchResults
.concat(unirefSearchResults, pfamSearchResults, scopSearchResults, pdbSearchResults)
.flatMap { db, data, index -> [[db, data], [db, index]] }
.groupTuple(by: 0)
output:
set val(db), file("${db}_results.ffdata"), file("${db}_results.ffindex") into searchResults
"""
ffdb.py combine -d "${db}_results.ffdata" -i "${db}_results.ffindex" *.{ffdata,ffindex}
"""
}