forked from NorwegianVeterinaryInstitute/Bifrost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asm_annot.nf
283 lines (226 loc) · 8.33 KB
/
asm_annot.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
#!/usr/bin/env nextflow
// This script is part of the Bifrost pipeline. Please see
// the accompanying LICENSE document for licensing issues,
// and the WIKI for this repo for instructions.
// Which version do we have?
if (workflow.commitId) {
version = "v0.2.0 $workflow.revision"
}
else {
version = "v0.2.0 local"
}
log.info ''
log.info "================================================="
log.info " Bifrost assembly module version ${version}"
log.info "================================================="
log.info "Reads : ${params.reads}"
log.info "#files in read set : ${params.setsize}"
log.info "Results can be found in : ${params.out_dir}"
log.info "================================================="
log.info ""
// First, define the input data that go into input channels
Channel
.fromFilePairs( params.reads, size:params.setsize )
.ifEmpty { error "Cannot find any reads matching: ${params.reads}" }
.into{fastqc_reads; read_pairs}
// run_fastq and run_multiqc are exactly the same as qc_track
process run_fastqc {
publishDir "${params.out_dir}/fastqc", mode: "${params.savemode}"
tag { pair_id }
label 'one'
input:
set pair_id, file(reads) from fastqc_reads
output:
file "$pair_id" into fastqc_multiqc
"""
mkdir ${pair_id}
fastqc -q ${reads} -o ${pair_id} -t $task.cpus
"""
}
// if there are more than two data files, we need to cat them together
// because spades becomes complicated with more than two files
process collate_data {
// Note, not publishing these because that would mean
// triple copies of the files on the system
tag {pair_id}
label 'one'
input:
set pair_id, file(reads) from read_pairs
output:
set pair_id, file("${pair_id}*_concat.fq.gz") into (reads, pilon_reads)
"""
shopt -s extglob
cat ${pair_id}*_?(R)1[_.]*.gz > ${pair_id}_R1_concat.fq.gz
cat ${pair_id}*_?(R)2[_.]*.gz > ${pair_id}_R2_concat.fq.gz
"""
}
/*
* Strip PhiX with bbmap
*/
process run_strip {
publishDir "${params.out_dir}/bbduk",
saveAs: {filename -> filename.endsWith('.gz') ? null:filename},
mode: "${params.savemode}"
tag { pair_id }
input:
set pair_id, file(reads) from reads
output:
set pair_id, file("${pair_id}*_concat_stripped.fq.gz") into reads_stripped
file "${pair_id}_bbduk_output.log"
file "${pair_id}_stats.txt"
file "${pair_id}_stats.txt" into bbduk_stats_stripped_multiqc
"""
bbduk.sh threads=$task.cpus ref=${params.stripgenome} \
in1=${pair_id}_R1_concat.fq.gz \
in2=${pair_id}_R2_concat.fq.gz \
outm=${pair_id}_matched.fq.gz \
out1=${pair_id}_R1_concat_stripped.fq.gz \
out2=${pair_id}_R2_concat_stripped.fq.gz \
k=31 hdist=1 stats=${pair_id}_stats.txt &> ${pair_id}_bbduk_output.log
"""
}
/*
* Remove adapter sequences and low quality base pairs with Trimmomatic
*/
process run_trim {
publishDir "${params.out_dir}/bbduk_trimmed", mode: "${params.savemode}"
tag { pair_id }
input:
set pair_id, file(reads) from reads_stripped
output:
set pair_id, file("${pair_id}*_concat_stripped_trimmed.fq.gz") into (reads_trimmed, trimmed_fastqc)
file "${pair_id}_stripped_trimmed_*.log"
file "${pair_id}_stripped_trimmed_stderr.log" into bbduk_trimmed_multiqc
"""
trimmomatic PE -threads $task.cpus -trimlog ${pair_id}_concat_stripped_trimmed.log ${pair_id}*_concat_stripped.fq.gz \
-baseout ${pair_id}_trimmed.fq.gz ILLUMINACLIP:${params.adapter_dir}/${params.adapters}:${params.illuminaClipOptions} \
LEADING:${params.leading} TRAILING:${params.trailing} \
SLIDINGWINDOW:${params.slidingwindow} \
MINLEN:${params.minlen} \
2> ${pair_id}_stripped_trimmed_stderr.log 1> ${pair_id}_stripped_trimmed_stdout.log
mv ${pair_id}_trimmed_1P.fq.gz ${pair_id}_R1_concat_stripped_trimmed.fq.gz
mv ${pair_id}_trimmed_2P.fq.gz ${pair_id}_R2_concat_stripped_trimmed.fq.gz
cat ${pair_id}_trimmed_1U.fq.gz ${pair_id}_trimmed_2U.fq.gz > ${pair_id}_S_concat_stripped_trimmed.fq.gz
"""
}
process run_fastqc_trimmed {
publishDir "${params.out_dir}/fastqc_bbduk_trimmed", mode: "${params.savemode}"
tag { pair_id }
label 'one'
input:
set pair_id, file(reads) from trimmed_fastqc
output:
file "$pair_id"
file "${pair_id}" into fastqc_bbduk_trimmed_multiqc
"""
mkdir ${pair_id}
fastqc -q ${reads} -o ${pair_id} -t $task.cpus
"""
}
/*
* Build assembly with SPAdes
*/
process run_spadesasm {
publishDir "${params.out_dir}/spades", mode: "${params.savemode}"
tag { pair_id }
label 'longtime'
input:
set pair_id, file(reads) from reads_trimmed
output:
set pair_id, file("${pair_id}_spades_scaffolds_min${params.min_contig_len}.fasta") \
into (assembly_results, tobwa_results)
file "${pair_id}_spades_scaffolds.fasta"
file "${pair_id}_spades.log"
// For 2022 version, params.careful was removed to do --isolate and --only-assembler
"""
spades.py --cov-cutoff=${params.cov_cutoff} \
-1 ${pair_id}_R1_concat_stripped_trimmed.fq.gz \
-2 ${pair_id}_R2_concat_stripped_trimmed.fq.gz \
-s ${pair_id}_S_concat_stripped_trimmed.fq.gz \
-t $task.cpus --isolate --only-assembler \
-o ${pair_id}_spades
filter_fasta_length.py -i ${pair_id}_spades/scaffolds.fasta \
-o ${pair_id}_spades_scaffolds_min${params.min_contig_len}.fasta \
-m ${params.min_contig_len}
cp ${pair_id}_spades/scaffolds.fasta ${pair_id}_spades_scaffolds.fasta
cp ${pair_id}_spades/spades.log ${pair_id}_spades.log
"""
}
// integrate pilon. I need to have a mapping step, followed by a pilon
// step.
/*
* Map reads to the spades assembly
*/
process run_bwamem {
publishDir "${params.out_dir}/bwamem", mode: "${params.savemode}"
tag { pair_id }
label 'longtime'
input:
set pair_id, file("${pair_id}_spades_scaffolds_min${params.min_contig_len}.fasta"), \
file(reads) from tobwa_results.join(pilon_reads)
output:
set pair_id, file("${pair_id}_mapped_sorted.bam"), \
file("${pair_id}_mapped_sorted.bam.bai") into bwamem_results
file "${pair_id}_bwa.log"
"""
bwa index ${pair_id}_spades_scaffolds_min${params.min_contig_len}.fasta
bwa mem -t $task.cpus ${pair_id}_spades_scaffolds_min${params.min_contig_len}.fasta \
*.fq.gz 2> ${pair_id}_bwa.log| samtools sort -o ${pair_id}_mapped_sorted.bam -
samtools index ${pair_id}_mapped_sorted.bam
"""
}
/*
* Incorporating pilon_reads
*/
process run_pilon {
publishDir "${params.out_dir}/pilon", mode: "${params.savemode}"
tag { pair_id }
input:
set pair_id, file("${pair_id}_mapped_sorted.bam"), \
file("${pair_id}_mapped_sorted.bam.bai"), \
file("${pair_id}_spades_scaffolds_min${params.min_contig_len}.fasta") \
from bwamem_results.join(assembly_results)
output:
set pair_id, file("${pair_id}_pilon_spades.*") into pilon_results
file "${pair_id}_pilon_spades.fasta" into asms_for_quast
"""
export _JAVA_OPTIONS=$task.javaopts
pilon --threads $task.cpus --genome ${pair_id}_spades_scaffolds_min${params.min_contig_len}.fasta \
--bam ${pair_id}_mapped_sorted.bam --output ${pair_id}_pilon_spades \
--changes --vcfqe &> ${pair_id}_pilon_spades.log
"""
}
/*
* Evaluate ALL assemblies with QUAST
*/
process run_quast {
// The output here is a directory in and of itself
// thus not creating a new one
publishDir "${params.out_dir}/", mode: "${params.savemode}"
tag { pair_id }
input:
file asm_list from asms_for_quast.toSortedList()
output:
file quast_evaluation_all into quast_evaluation_all
file quast_evaluation_all into quast_multiqc
"""
quast --threads $task.cpus -o quast_evaluation_all \
-g ${params.quast_genes} -R ${params.quast_ref} ${asm_list}
"""
}
process run_multiqc_final {
publishDir "${params.out_dir}/multiqc_final", mode: "${params.savemode}"
tag {"multiqc"}
label 'one'
input:
file "fastqc_output/*" from fastqc_multiqc.collect()
file "bbduk/*" from bbduk_stats_stripped_multiqc.collect()
file "bbduk_trimmed/*" from bbduk_trimmed_multiqc.collect()
file "bbduk_trimmed_fastqc/*" from fastqc_bbduk_trimmed_multiqc.collect()
file quast_evaluation_all from quast_multiqc
output:
file("*")
"""
multiqc --fullnames --config ${params.multiqc_config} .
"""
}