-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.nf
255 lines (204 loc) · 7.38 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
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
camitax_version = 'v0.7.0'
println """
▄████▄ ▄▄▄ ███▄ ▄███▓ ██▓▄▄▄█████▓ ▄▄▄ ▒██ ██▒
▒██▀ ▀█ ▒████▄ ▓██▒▀█▀ ██▒▓██▒▓ ██▒ ▓▒▒████▄ ▒▒ █ █ ▒░
▒▓█ ▄ ▒██ ▀█▄ ▓██ ▓██░▒██▒▒ ▓██░ ▒░▒██ ▀█▄ ░░ █ ░
▒▓▓▄ ▄██▒░██▄▄▄▄██ ▒██ ▒██ ░██░░ ▓██▓ ░ ░██▄▄▄▄██ ░ █ █ ▒
▒ ▓███▀ ░ ▓█ ▓██▒▒██▒ ░██▒░██░ ▒██▒ ░ ▓█ ▓██▒▒██▒ ▒██▒
░ ░▒ ▒ ░ ▒▒ ▓▒█░░ ▒░ ░ ░░▓ ▒ ░░ ▒▒ ▓▒█░▒▒ ░ ░▓ ░
░ ▒ ▒ ▒▒ ░░ ░ ░ ▒ ░ ░ ▒ ▒▒ ░░░ ░▒ ░
░ ░ ▒ ░ ░ ▒ ░ ░ ░ ▒ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░
░ ${camitax_version?:''}
"""
params.i = 'input'
params.x = 'fasta'
params.db = "camitax/db"
params.dada2_db = 'rdp'
workflow {
files = Channel
.fromPath("${params.i}/*.${params.x}")
.map { file -> [file.baseName, file] }
db = Channel.fromPath( "${params.db}", type: 'dir').first()
mash(db, files)
prodigal(files)
centrifuge(db, prodigal.out.fna_centrifuge)
kaiju(db, prodigal.out.faa_kaiju)
checkm(db, files)
dada2_lineage = dada2(db, checkm.out.rRNA_fasta)
id_collection = mash.out.mash_ANImax .join(
mash.out.mash_ANImax_taxIDs) .join(
dada2.out.dada2_lineage) .join(
centrifuge.out.centrifuge_taxIDs) .join(
kaiju.out.kaiju_taxIDs) .join(
checkm.out.checkm_lineage) .join(
prodigal.out.genes_cnt)
taxonomy(db, id_collection)
summary(taxonomy.out.camitax_summaries.collect())
}
/********
* (A) Genome-distance based assignment
*/
process mash {
tag "${id}"
publishDir "data/${id}"
input:
file db
tuple val(id), file(genome)
output:
tuple val(id), path("${id}.mash.ANImax.txt"), emit: mash_ANImax
tuple val(id), path("${id}.mash.taxIDs.txt"), emit: mash_ANImax_taxIDs
script:
mash_index = "${db}/mash/RefSeq_20190108.msh"
"""
mash dist ${mash_index} ${genome} | sort -gk3 > ${id}.mash.sorted
head -n 1 ${id}.mash.sorted | awk '{print 1-\$3}' > ${id}.mash.ANImax.txt
awk '\$3 <= 0.05' ${id}.mash.sorted | cut -f1 -d'_' > ${id}.mash.taxIDs.txt
"""
}
/********
* (B) 16S rRNA gene-based assignment, and
* (D) Phylogenetic placement
*/
process checkm {
tag "${id}"
publishDir "data/${id}"
input:
file db
tuple val(id), file(genome)
output:
tuple val(id), path("${id}.ssu.fna"), emit: rRNA_fasta
tuple val(id), path("${id}.checkm.tsv"), emit: checkm_lineage
script:
checkm_db = "${db}/checkm/"
"""
# Extract 16S rRNA gene sequences with Nhmmer
checkm ssu_finder -t ${task.cpus} -x ${params.x} ${genome} . ssu_finder 2>&1
ln -s ssu_finder/ssu.fna ${id}.ssu.fna
# Phylogenetic placement onto reduced reference tree
checkm lineage_wf -t ${task.cpus} --reduced_tree -x ${params.x} . checkm
checkm qa -q -o 2 --tab_table checkm/lineage.ms checkm > ${id}.checkm.tsv
"""
}
process dada2 {
tag "${id}"
publishDir "data/${id}"
input:
file db
tuple val(id), file(genome)
output:
tuple val(id), path("${id}.dada2.txt"), emit: dada2_lineage
script:
if ( params.dada2_db == 'silva' ) {
dada2_train_set = "${db}/dada2/silva_nr_v132_train_set.fa.gz"
dada2_species_assignment = "${db}/dada2/silva_species_assignment_v132.fa.gz"
} else if ( params.dada2_db == 'rdp' ) {
dada2_train_set = "${db}/dada2/rdp_train_set_16.fa.gz"
dada2_species_assignment = "${db}/dada2/rdp_species_assignment_16.fa.gz"
} else
error "Invalid database for dada2 specified: ${params.dada2_db}"
"""
#!/usr/bin/env Rscript
library(dada2)
set.seed(42)
seqs <- paste(Biostrings::readDNAStringSet("${genome}"))
tt <- data.frame(Batman = "NA;NA;NA;NA;NA;NA;NA")
try(tt <- addSpecies(assignTaxonomy(seqs, "${dada2_train_set}", minBoot=80), "${dada2_species_assignment}"))
write.table(tt, "${id}.dada2.txt", quote=F, sep=";", row.names=F, col.names=F)
"""
}
/********
* (C) Gene homology-based assignment(s)
*/
process prodigal {
tag "${id}"
publishDir "data/${id}"
input:
tuple val(id), file(genome)
output:
tuple val(id), path("${id}.genes.faa"), emit: faa_kaiju
tuple val(id), path("${id}.genes.fna"), emit: fna_centrifuge
tuple val(id), path("${id}.genes.cnt"), emit: genes_cnt
"""
prodigal -a ${id}.genes.faa -d ${id}.genes.fna -i ${genome}
grep -c "^>" ${id}.genes.faa > ${id}.genes.cnt
"""
}
process centrifuge {
tag "${id}"
publishDir "data/${id}"
input:
file db
tuple val(id), file(genes)
output:
tuple val(id), path("${id}.centrifuge.taxIDs.txt"), emit: centrifuge_taxIDs
script:
centrifuge_index = "${db}/centrifuge/proGenomes_20190108"
"""
centrifuge -p ${task.cpus} -f -x ${centrifuge_index} ${genes} > ${id}.centrifuge.out
awk '\$4+1 > 250' ${id}.centrifuge.out | cut -f3 > ${id}.centrifuge.taxIDs.txt
"""
}
process kaiju {
tag "${id}"
publishDir "data/${id}"
input:
file db
tuple val(id), file(genes)
output:
tuple val(id), path("${id}.kaiju.taxIDs.txt"), emit: kaiju_taxIDs
script:
kaiju_index = "${db}/kaiju/proGenomes_20190108.fmi"
ncbi_nodes = "${db}/taxonomy/nodes_20190108.dmp"
"""
kaiju -p -z ${task.cpus} -t ${ncbi_nodes} -f ${kaiju_index} -i ${genes} > ${id}.kaiju.out
grep "^C" ${id}.kaiju.out | cut -f3 > ${id}.kaiju.taxIDs.txt
"""
}
process taxonomy {
tag "${id}"
publishDir "data/${id}"
input:
file db
tuple val(id), file(mash_ANImax), file(mash_taxIDs), file(dada2_lineage), file(centrifuge_taxIDs), file(kaiju_taxIDs), file(checkm_lineage), file(genes_cnt)
output:
tuple val(id), path("${id}.summary"), emit: camitax_summaries
script:
mash_ids = "${db}/mash/RefSeq_20190108.ids"
ncbi_names = "${db}/taxonomy/names_20190108.dmp"
ncbi_nodes = "${db}/taxonomy/nodes_20190108.dmp"
"""
camitaxonomy.py --names ${ncbi_names} \
--nodes ${ncbi_nodes} \
--mash ${mash_taxIDs} \
--dada2 ${dada2_lineage} \
--centrifuge ${centrifuge_taxIDs} \
--kaiju ${kaiju_taxIDs} \
--checkm ${checkm_lineage} \
--known ${mash_ids} \
--animax ${mash_ANImax} \
--genes ${genes_cnt} \
${id} > ${id}.summary
"""
}
process summary {
tag 'The Final Countdown'
publishDir 'data'
input:
file summaryList
output:
file "camitax.tsv"
"""
for summary in ${summaryList}
do
head -n 1 \$summary > camitax.tsv
break
done
for summary in ${summaryList}
do
tail -n +2 \$summary >> camitax.tsv
done
"""
}