-
Notifications
You must be signed in to change notification settings - Fork 4
/
build_kraken.nf
163 lines (127 loc) · 2.92 KB
/
build_kraken.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
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
params.additional_dbs = ["bacteria", "archaea", "human", "viral", "plasmid", "UniVec_Core"]
params.max_db_size = 500
params.confidence = 0.3
params.max_threads = 20
params.rebuild = false
params.db = "${launchDir}/data/medi_db"
process setup_kraken_db {
cpus 1
memory "8 GB"
output:
path("medi_db")
"""
kraken2-build --download-taxonomy --db medi_db
"""
}
process add_sequences {
cpus 5
memory "16 GB"
publishDir "$baseDir/data"
input:
path(fasta)
path(db)
output:
path("$db")
"""
gunzip -c $fasta > ${fasta.baseName} && \
kraken2-build --add-to-library ${fasta.baseName} --db $db --threads ${task.cpus} && \
rm ${fasta.baseName}
"""
}
process add_existing {
cpus 4
memory "16 GB"
input:
path(db)
each group
output:
path("$db")
script:
if (group == "human")
"""
kraken2-build --download-library $group --db $db --no-mask --threads ${task.cpus}
"""
else
"""
kraken2-build --download-library $group --db $db --threads ${task.cpus}
"""
}
process build_kraken_db {
cpus params.max_threads
memory "${params.max_db_size} GB"
input:
path(db)
output:
path("$db")
"""
kraken2-build --build --db $db \
--threads ${task.cpus} \
--max-db-size ${(params.max_db_size as BigInteger) * (1000G**3)}
"""
}
process self_classify {
cpus 1
memory "${params.max_db_size} GB"
input:
path(db)
output:
path(db)
"""
kraken2 --db ${db} --threads ${task.cpus} \
--confidence ${params.confidence} \
--threads ${task.cpus} \
--memory-mapping ${db}/library/*/*.f*a > ${db}/database.kraken
"""
}
process build_bracken {
cpus 20
memory "64 GB"
publishDir "$baseDir/data"
input:
path(db)
output:
path("$db")
"""
bracken-build -d $db -t ${task.cpus} -k 35 -l 100 && \
bracken-build -d $db -t ${task.cpus} -k 35 -l 150
"""
}
process library {
cpus 1
memory "4 GB"
input:
path(db)
output:
path("$db/library/*/*.f*a")
"""
ls ${db}/library/*/*.f*a | wc -l
"""
}
process add_food_info {
cpus 1
memory "1 GB"
publishDir "$baseDir/data"
input:
path(db)
output:
path("$db")
"""
cp ${launchDir}/data/dbs/{food_matches.csv,food_contents.csv.gz} ${db}
"""
}
workflow {
if (!params.rebuild) {
Channel.fromPath("${baseDir}/data/sequences/*.fna.gz").set{food_sequences}
setup_kraken_db()
add_existing(setup_kraken_db.out, params.additional_dbs)
add_sequences(food_sequences, add_existing.out.last())
db = add_sequences.out.last()
} else {
db = Channel.fromPath(params.db)
}
build_kraken_db(db)
self_classify(build_kraken_db.out)
build_bracken(self_classify.out) | add_food_info
}