-
Notifications
You must be signed in to change notification settings - Fork 4
/
hash-cgMLST.nf
316 lines (235 loc) · 7.87 KB
/
hash-cgMLST.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
#!/usr/bin/env nextflow
// parameters
params.seqlist = "example_input.csv"
params.outputPath = "example_output"
params.krakendb = "minikraken2" //location of minikrakenDB
params.runSkesa = 0
params.aoSpades = 1
def firstFive( str ) {
return str.substring(0,5)
}
// initial logging
log.info "\n"
log.info "hash-cgMLST -- version 0.1"
log.info "Input sequence list : ${params.seqlist}"
log.info "Output path : ${params.outputPath}"
log.info "Container engine : ${workflow.containerEngine}"
log.info "\n"
// rename input parameters
outputPath = file(params.outputPath)
krakendb = file(params.krakendb)
runSkesa = params.runSkesa
aoSpades = params.aoSpades
spadesReadCorrection = ""
if (aoSpades==1) {
spadesReadCorrection = "--only-assembler"
}
//location for bbduk adapter sequences
bbduk_adapaters = "/opt/conda/opt/bbmap-38.22-1/resources/adapters.fa" //path within docker/singularity image
// set up initial channel based on CSV file
Channel
.fromPath(params.seqlist)
.splitCsv(header:true)
.map{ row-> tuple(row.file_type, row.file_name, row.fq1, row.fq2) }
.set { samples_ch }
process fetchReads {
input:
set file_type, file_name, fq1, fq2 from samples_ch
output:
set file_type, file_name, file("*") into reads_ch
executor = 'local'
tag "$file_name"
script:
if (file_type=="bam") {
"""
scp -P 8081 ana:/mnt/microbio/ndm-hicf/ogre/pipeline_output/${file_name}/MAPPING/103e39d6-096c-46da-994d-91c5acbda565_R00000003/STD/${file_name}_v3.bam in.bam || scp -P 8081 ana:/mnt/microbio/ndm-hicf/ogre/pipeline_output/${file_name}/MAPPING/103e39d6-096c-46da-994d-91c5acbda565_R00000003/STD/${file_name}_v2.bam in.bam
"""
}
else if (file_type=="ebi") {
"""
${baseDir}/bin/download_ebi.py -a ${file_name} -o .
mv *_1.fastq.gz in.1.fq.gz
mv *_2.fastq.gz in.2.fq.gz
"""
}
else if (file_type=="local") {
f1 = file(fq1)
f2 = file(fq2)
"""
ln -s $f1 in.1.fq.gz
ln -s $f2 in.2.fq.gz
"""
}
}
process makeFastQ {
input:
set file_type, file_name, file("*") from reads_ch
output:
set file_name, file("in.1.fq.gz"), file("in.2.fq.gz") into fq_ch
tag "$file_name"
script:
if (file_type=="bam") {
"""
samtools sort -@${task.cpus} -n -o sorted.bam in.bam
bedtools bamtofastq -i sorted.bam \
-fq in.1.fq \
-fq2 in.2.fq
rm sorted.bam
gzip in.1.fq
gzip in.2.fq
"""
}
else {
"""
"""
}
}
//split raw reads into 3 channels - for QC and assembly and kraken2
fq_ch.into { fq_ch1; fq_ch2; fq_ch3}
process kraken2 {
input:
set file_name, file("in.1.fq.gz"), file("in.2.fq.gz") from fq_ch3
output:
file "*"
tag "$file_name"
publishDir "${outputPath}/${firstFive(file_name)}", mode: 'copy', pattern: "${file_name}*"
"""
kraken2 --report ${file_name}_kraken.txt --db ${krakendb} --paired in.1.fq.gz in.2.fq.gz > /dev/null
"""
}
process rawFastQC {
input:
set file_name, file("in.1.fq.gz"), file("in.2.fq.gz") from fq_ch1
output:
file "*"
tag "$file_name"
publishDir "${outputPath}/${firstFive(file_name)}", mode: 'copy', pattern: "${file_name}*"
"""
cat in.1.fq.gz in.2.fq.gz > ${file_name}.raw.fq.gz
fastqc --threads ${task.cpus} ${file_name}.raw.fq.gz > ${file_name}_raw_fastqc_log.txt
rm ${file_name}.raw.fq.gz
"""
}
//adapter trimming with bbDuk
process bbDuk {
input:
set file_name, file("in.1.fq.gz"), file("in.2.fq.gz") from fq_ch2
output:
set file_name, file("clean.1.fq.gz"), file("clean.2.fq.gz") into bbduk_out_ch
file("${file_name}_base_qual.txt")
file("${file_name}_length.txt")
tag "$file_name"
memory '8 GB' //not able to use 16GB standard
publishDir "${outputPath}/${firstFive(file_name)}", mode: 'copy', pattern: "${file_name}*"
"""
bbduk.sh in1=in.1.fq.gz in2=in.2.fq.gz out1=clean.1.fq out2=clean.2.fq \
ref=$bbduk_adapaters ktrim=r k=23 mink=11 hdist=1 tpe tbo \
qtrim=rl trimq=30 \
qchist=${file_name}_base_qual.txt \
lhist=${file_name}_length.txt \
-Xmx${task.memory.toGiga()}g threads=${task.cpus}
gzip clean.1.fq
gzip clean.2.fq
"""
}
//split cleaned reads into 2 channels - for QC and assembly
bbduk_out_ch.into { bbduk_out_ch1; bbduk_out_ch2; bbduk_out_ch3;}
process cleanFastQC {
input:
set file_name, file("clean.1.fq.gz"), file("clean.2.fq.gz") from bbduk_out_ch1
output:
file "*"
tag "$file_name"
publishDir "${outputPath}/${firstFive(file_name)}", mode: 'copy', pattern: "${file_name}*"
"""
cat clean.1.fq.gz clean.2.fq.gz > ${file_name}.clean.fq.gz
fastqc --threads ${task.cpus} ${file_name}.clean.fq.gz > ${file_name}_clean_fastqc_log.txt
rm ${file_name}.clean.fq.gz
"""
}
process spades {
input:
set file_name, file("clean.1.fq.gz"), file("clean.2.fq.gz") from bbduk_out_ch2
output:
set file_name, file("${file_name}_spades_contigs.fa") into spades_out
tag "$file_name"
publishDir "${outputPath}/${firstFive(file_name)}", mode: 'copy', pattern: "${file_name}_*"
"""
spades.py --careful ${spadesReadCorrection} -o spades -1 clean.1.fq.gz -2 clean.2.fq.gz \
-t ${task.cpus} -m ${task.memory.toGiga()}
cp spades/contigs.fasta ${file_name}_spades_contigs.fa
cp spades/assembly_graph.fastg ${file_name}_spades_assembly_graph.fastg
cp spades/assembly_graph_with_scaffolds.gfa ${file_name}_spades_assembly_graph_with_scaffolds.gfa
cp spades/spades.log ${file_name}_spades.log
#remove spades directory to save space
rm -rf spades*
"""
}
//split assembly into 2 channels - for cgmlst and mslt
spades_out.into { spades_out_ch1; spades_out_ch2; }
process cgmlst {
input:
set file_name, file("${file_name}_spades_contigs.fa") from spades_out_ch1
output:
file "${file_name}_spades_cgmlst.*"
tag "$file_name"
publishDir "${outputPath}/${firstFive(file_name)}", mode: 'copy', pattern: "${file_name}_spades_cgmlst.*"
"""
#get stats
/opt/conda/opt/bbmap-38.22-1/stats.sh in=${file_name}_spades_contigs.fa > ${file_name}_spades_cgmlst.stats
/opt/conda/opt/bbmap-38.22-1/statswrapper.sh in=${file_name}_spades_contigs.fa > ${file_name}_spades_cgmlst.statlog
#run hash cgmlst
${baseDir}/bin/getCoreGenomeMLST.py -f ${file_name}_spades_contigs.fa \
-n ${file_name}_spades \
-s ${baseDir}/ridom_scheme/files \
-d ${baseDir}/ridom_scheme/ridom_scheme.fasta \
-o ${file_name}_spades \
-b blastn
"""
}
process mlst {
input:
set file_name, file("${file_name}_spades_contigs.fa") from spades_out_ch2
output:
file "${file_name}_mlst.txt"
tag "$file_name"
publishDir "${outputPath}/${firstFive(file_name)}", mode: 'copy', pattern: "${file_name}_mlst.txt"
"""
mlst --scheme cdifficile --legacy ${file_name}_spades_contigs.fa > ${file_name}_mlst.txt
"""
}
if (runSkesa==1) {
//run skesa and generate cgmlst from that too
process skesa {
input:
set file_name, file("clean.1.fq.gz"), file("clean.2.fq.gz") from bbduk_out_ch3
output:
set file_name, file("${file_name}_skesa_contigs.fa") into skesa_out
tag "$file_name"
publishDir "${outputPath}/${firstFive(file_name)}", mode: 'copy', pattern: "${file_name}_*"
"""
skesa --fastq clean.1.fq.gz,clean.2.fq.gz \
--cores ${task.cpus} --memory ${task.memory.toGiga()} > ${file_name}_skesa_contigs.fa
"""
}
process cgmlst_skesa {
input:
set file_name, file("${file_name}_skesa_contigs.fa") from skesa_out
output:
file "${file_name}_skesa_cgmlst.*"
tag "$file_name"
publishDir "${outputPath}/${firstFive(file_name)}", mode: 'copy', pattern: "${file_name}_skesa_cgmlst.*"
"""
#get stats
/opt/conda/opt/bbmap-38.22-1/stats.sh in=${file_name}_skesa_contigs.fa > ${file_name}_skesa_cgmlst.stats
/opt/conda/opt/bbmap-38.22-1/statswrapper.sh in=${file_name}_skesa_contigs.fa > ${file_name}_skesa_cgmlst.statlog
#run hash cgmlst
${baseDir}/bin/getCoreGenomeMLST.py -f ${file_name}_skesa_contigs.fa \
-n ${file_name}_skesa \
-s ${baseDir}/ridom_scheme/files \
-d ${baseDir}/ridom_scheme/ridom_scheme.fasta \
-o ${file_name}_skesa \
-b blastn
"""
}
}