-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.nf
335 lines (245 loc) · 6.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
327
328
329
330
331
332
333
334
335
#!/usr/bin/env nextflow
params.vendor = "$baseDir/vendor"
params.search = ""
params.keywords = ""
params.help = ""
if( params.help ) {
usage = file("$baseDir/usage.txt")
print usage.text
return
}
hmmDir = file(params.input)
outputDir = file(params.output)
ncbiDB = file(params.ncbi)
genomeFaa = file(params.genome)
keywordsFile = ""
if(params.keywords){
keywordsFile = file(params.keywords)
}
searchFile = ""
if(params.search){
searchFile = file(params.search)
}
process bootstrap {
executor 'local'
input:
params.vendor
output:
file allHmm
shell:
if(outputDir.exists())
exit(0, "Directory ${outputDir} already exists. Please remove it or assign another output directory.")
else
outputDir.mkdir()
"""
#!/bin/bash
if [ ! -d !{params.vendor} ]
then
make -C !{baseDir} install
fi
cat !{hmmDir}/*.hmm > allHmm
${params.hmm_press} allHmm
"""
}
fastaChunk = Channel.create()
list = Channel.fromPath(genomeFaa).splitFasta(by:6000,file:true).collectFile();
list.spread(allHmm).into(fastaChunk)
process hmmFolderScan {
cpus "${params.hmm_cpu}"
memory '8 GB'
cache false
maxForks 6000
input:
val chunk from fastaChunk
output:
file domtblout
script:
fastaChunkFile = chunk[0]
hmm = chunk[1]
"""
#!/bin/sh
${params.hmm_scan} -E ${params.hmm_evalue} --domtblout domtblout --cpu ${params.hmm_cpu} -o allOut ${hmm} ${fastaChunkFile}
"""
}
params.num = 1
num = params.num
process uniqer {
cache false
input:
file domtblout
params.num
output:
file outputFasta into fastaFiles
"""
$baseDir/scripts/uniquer.sh $num domtblout outputFasta
"""
}
uniq_lines = Channel.create()
uniq_overview = Channel.create()
fastaFiles.filter({it -> java.nio.file.Files.size(it)!=0}).tap(uniq_overview).flatMap{ file -> file.readLines() }.into(uniq_lines)
process getFasta {
executor 'local'
cpus 2
memory '1 GB'
input:
val contigLine from uniq_lines
output:
file 'uniq_out'
shell:
'''
#!/bin/sh
contig=`echo "!{contigLine} " | cut -d ' ' -f 4`
grep "$contig " !{genomeFaa} > uniq_header
buffer=`cat uniq_header | cut -c 2-`
contig=`echo $buffer | cut -d" " -f1`
awk -v p="$buffer" 'BEGIN{ ORS=""; RS=">"; FS="\\n" } $1 == p { print ">" $0 }' !{genomeFaa} > !{baseDir}/$contig.faa
awk -v p="$buffer" 'BEGIN{ ORS=""; RS=">"; FS="\\n" } $1 == p { print ">" $0 }' !{genomeFaa} > uniq_out
'''
}
uniq_seq = Channel.create()
uniq_seqHtml = Channel.create()
uniq_out.separate( uniq_seq, uniq_seqHtml ) { a -> [a, a] }
process blastSeqTxt {
cpus 4
memory '8 GB'
input:
file uniq_seq
output:
file blast_out
script:
order = "6 qseqid sseqid pident length mismatch gapopen qstart qend sstart send evalue bitscore sallacc salltitles staxids sallseqid"
/*
* blast all fasta sequences against the ncbi database. A special output format is used, to make the data usable for the next pipeline.
*/
shell:
'''
#!/bin/sh
contig=`grep ">" !{uniq_seq} | cut -d" " -f1 | cut -c 2-`
!{params.blastp} -db !{ncbiDB} -outfmt '!{order}' -query "!{uniq_seq}" -out "!{baseDir}/$contig.txt" -num_threads !{params.blast_cpu}
echo "$contig" > blast_out
'''
}
blast_all = Channel.create()
blast_out
.collectFile()
.into(blast_all)
process blastSeqHtml {
cpus 4
memory '8 GB'
input:
file uniq_seqHtml
/*
* blast all fasta sequences against the ncbi database. The output is html formated, to get it legible for people.
*/
shell:
'''
#!/bin/sh
contig=`grep ">" !{uniq_seqHtml} | cut -d" " -f1 | cut -c 2-`
!{params.blastp} -db !{ncbiDB} -query "!{uniq_seqHtml}" -html -out "!{outputDir}/$contig.html" -num_threads !{params.blast_cpu}
'''
}
PYTHON="$baseDir/vendor/python/bin/python"
coverages = Channel.create()
coverages.bind(params.cov.split(',').collect{file(it)}.join(' '))
bam = Channel.from(params.bam)
sortedIndexedBam = bam.flatMap{ files -> files.split(',')}
process bamToCoverage {
cpus 2
memory '4 GB'
input:
val bam from sortedIndexedBam
output:
file coverage into coverages
when:
bam != ''
script:
"""
#!/bin/sh
$PYTHON scripts/bam_to_coverage.py ${params.sortedIndexedBam} > coverage
"""
}
coverageFiles = Channel.create()
coverages.toList().into(coverageFiles)
uniq_overview = uniq_overview.collectFile()
process createOverview {
cpus 2
memory '4 GB'
input:
file blast_all
file uniq_overview
val coverageFiles
output:
val outputDir + '/overview.txt' into over
shell:
'''
#!/bin/sh
searchParam=""
if [ -n !{params.search} ]
then
searchParam="--search=!{searchFile}"
fi
!{PYTHON} !{baseDir}/scripts/create_overview.py -u !{uniq_overview} -faa !{baseDir} -o !{outputDir} ${searchParam} -c !{coverageFiles.join(' ')}
'''
}
process linkSearch {
cpus 2
memory '4 GB'
input:
val x from over
outputDir
output:
val outputDir into inputF
"""
#!/bin/sh
$PYTHON $baseDir/scripts/link_search.py -o ${x} -out ${outputDir}
"""
}
process folderToPubmed {
executor 'local'
cpus 2
memory '4 GB'
input:
val inp from inputF
outputDir
output:
val outputDir + '/all.pubHits' into pub
val outputDir + '/overview.txt' into over2
shell:
'''
#!/bin/sh
keywords=""
if [ -f !{keywordsFile} ]
then
keywords=!{keywordsFile}
else
emptyKeywords="keywords.txt"
touch $emptyKeywords
keywords=$emptyKeywords
fi
echo $keywords
sh !{baseDir}/scripts/FolderToPubmed.sh !{inp} !{outputDir} !{baseDir}/scripts/UrltoPubmedID.sh ${keywords}
'''
}
process linkAssignment {
cpus 2
memory '6 GB'
input:
val x from over2
val p from pub
output:
val outputDir + '/overview_new.txt' into overNew
"""
#!/bin/sh
$PYTHON $baseDir/scripts/link_assignment.py -o ${x} -pub ${p}
"""
}
process buildHtml {
cpus 2
memory '3 GB'
input:
val overview from overNew
"""
#!/bin/sh
$PYTHON $baseDir/scripts/web/controller.py -o ${overview} -out ${outputDir} -conf $baseDir/scripts/web/config.yaml -templates $baseDir/scripts/web/app/templates
"""
}