comparison 0.4.0/workflows/centriflaken.nf @ 101:ce6d9548fe89

"planemo upload"
author kkonganti
date Thu, 04 Aug 2022 10:45:55 -0400
parents
children 17890124001d
comparison
equal deleted inserted replaced
100:9d9537c907bd 101:ce6d9548fe89
1 // Define any required imports for this specific workflow
2 import java.nio.file.Paths
3 import nextflow.file.FileHelper
4
5 // Include any necessary methods
6 include { \
7 summaryOfParams; stopNow; fastqEntryPointHelp; sendMail; \
8 addPadding; wrapUpHelp } from "${params.routines}"
9 include { kraken2Help } from "${params.toolshelp}${params.fs}kraken2"
10 include { centrifugeHelp } from "${params.toolshelp}${params.fs}centrifuge"
11 include { flyeHelp } from "${params.toolshelp}${params.fs}flye"
12 include { serotypefinderHelp } from "${params.toolshelp}${params.fs}serotypefinder"
13 include { seqsero2Help } from "${params.toolshelp}${params.fs}seqsero2"
14 include { mlstHelp } from "${params.toolshelp}${params.fs}mlst"
15 include { abricateHelp } from "${params.toolshelp}${params.fs}abricate"
16
17 // Exit if help requested before any subworkflows
18 if (params.help) {
19 log.info help()
20 exit 0
21 }
22
23 // Include any necessary modules and subworkflows
24 include { PROCESS_FASTQ } from "${params.subworkflows}${params.fs}process_fastq"
25 include { FASTQC } from "${params.modules}${params.fs}fastqc${params.fs}main"
26 include { CENTRIFUGE_CLASSIFY } from "${params.modules}${params.fs}centrifuge${params.fs}classify${params.fs}main"
27 include { CENTRIFUGE_PROCESS } from "${params.modules}${params.fs}centrifuge${params.fs}process${params.fs}main"
28 include { SEQKIT_GREP } from "${params.modules}${params.fs}seqkit${params.fs}grep${params.fs}main"
29 include { FLYE_ASSEMBLE } from "${params.modules}${params.fs}flye${params.fs}assemble${params.fs}main"
30 include { KRAKEN2_CLASSIFY } from "${params.modules}${params.fs}kraken2${params.fs}classify${params.fs}main"
31 include { KRAKEN2_EXTRACT_CONTIGS } from "${params.modules}${params.fs}kraken2${params.fs}extract_contigs${params.fs}main"
32 include { SEROTYPEFINDER } from "${params.modules}${params.fs}serotypefinder${params.fs}main"
33 include { SEQSERO2 } from "${params.modules}${params.fs}seqsero2${params.fs}main"
34 include { MLST } from "${params.modules}${params.fs}mlst${params.fs}main"
35 include { ABRICATE_RUN } from "${params.modules}${params.fs}abricate${params.fs}run${params.fs}main"
36 include { ABRICATE_SUMMARY } from "${params.modules}${params.fs}abricate${params.fs}summary${params.fs}main"
37 include { TABLE_SUMMARY } from "${params.modules}${params.fs}cat${params.fs}tables${params.fs}main"
38 include { MULTIQC } from "${params.modules}${params.fs}multiqc${params.fs}main"
39 include { DUMP_SOFTWARE_VERSIONS } from "${params.modules}${params.fs}custom${params.fs}dump_software_versions${params.fs}main"
40
41
42
43 /*
44 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45 INPUTS AND ANY CHECKS FOR THE CENTRIFLAKEN WORKFLOW
46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47 */
48
49 def kraken2_db_dir = file ( "${params.kraken2_db}" )
50 def centrifuge_x = file ( "${params.centrifuge_x}" )
51 def reads_platform = 0
52 def abricate_dbs = [ 'ncbiamrplus', 'resfinder', 'megares', 'argannot' ]
53
54 reads_platform += (params.flye_nano_raw ? 1 : 0)
55 reads_platform += (params.flye_nano_corr ? 1 : 0)
56 reads_platform += (params.flye_nano_hq ? 1 : 0)
57 reads_platform += (params.flye_pacbio_raw ? 1 : 0)
58 reads_platform += (params.flye_pacbio_corr ? 1 : 0)
59 reads_platform += (params.flye_pacbio_hifi ? 1 : 0)
60
61 if (!kraken2_db_dir.exists() || !centrifuge_x.getParent().exists()) {
62 stopNow("Please check if the following absolute paths are valid:\n" +
63 "${params.kraken2_db}\n${params.centrifuge_x}\n" +
64 "Cannot proceed further!")
65 }
66
67 if (reads_platform > 1 || reads_platform == 0) {
68 msg_0 = (reads_platform > 1 ? "only" : "at least")
69 stopNow("Please mention ${msg_0} one read platform for use with the flye assembler\n" +
70 "using any one of the following options:\n" +
71 "--flye_nano_raw\n--flye_nano_corr\n--flye_nano_hq\n" +
72 "--flye_pacbio_raw\n--flye_pacbio_corr\n--flye_pacbio_hifi")
73 }
74
75 if (params.centrifuge_extract_bug != params.kraken2_extract_bug) {
76 stopNow("Please make sure that the bug to be extracted is same\n" +
77 "for both --centrifuge_extract_bug and --kraken2_extract_bug options.")
78 }
79
80 /*
81 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82 RUN THE CENTRIFLAKEN WORKFLOW
83 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
84 */
85
86 workflow CENTRIFLAKEN {
87 main:
88 ch_asm_filtered_contigs = Channel.empty()
89 ch_mqc_custom_tbl = Channel.empty()
90
91 log.info summaryOfParams()
92
93 PROCESS_FASTQ()
94 .processed_reads
95 .map {
96 meta, fastq ->
97 meta.centrifuge_x = params.centrifuge_x
98 meta.kraken2_db = params.kraken2_db
99 [meta, fastq]
100 }
101 .set { ch_processed_reads }
102
103 PROCESS_FASTQ
104 .out
105 .versions
106 .set { software_versions }
107
108 FASTQC ( ch_processed_reads )
109
110 CENTRIFUGE_CLASSIFY ( ch_processed_reads )
111
112 CENTRIFUGE_PROCESS (
113 CENTRIFUGE_CLASSIFY.out.report
114 .join( CENTRIFUGE_CLASSIFY.out.output )
115 )
116
117 ch_processed_reads.join ( CENTRIFUGE_PROCESS.out.extracted )
118 .set { ch_centrifuge_extracted }
119
120 SEQKIT_GREP ( ch_centrifuge_extracted )
121
122 FLYE_ASSEMBLE ( SEQKIT_GREP.out.fastx )
123
124 FLYE_ASSEMBLE
125 .out
126 .assembly
127 .set { ch_flye_assembly }
128
129 ch_flye_assembly.ifEmpty { [ false, false ] }
130
131 KRAKEN2_CLASSIFY ( ch_flye_assembly )
132
133 KRAKEN2_EXTRACT_CONTIGS (
134 ch_flye_assembly
135 .join( KRAKEN2_CLASSIFY.out.kraken_output ),
136 params.kraken2_extract_bug
137 )
138
139 KRAKEN2_EXTRACT_CONTIGS
140 .out
141 .asm_filtered_contigs
142 .map {
143 meta, fastq ->
144 meta.organism = params.kraken2_extract_bug.split(/\s+/)[0].capitalize()
145 meta.serotypefinder_db = params.serotypefinder_db
146 [meta, fastq]
147 }
148 .set { ch_asm_filtered_contigs }
149
150 SEROTYPEFINDER ( ch_asm_filtered_contigs )
151
152 SEQSERO2 ( ch_asm_filtered_contigs )
153
154 MLST ( ch_asm_filtered_contigs )
155
156 ABRICATE_RUN (
157 ch_asm_filtered_contigs,
158 abricate_dbs
159 )
160
161 ABRICATE_RUN
162 .out
163 .abricated
164 .map { meta, abres -> [ abricate_dbs, abres ] }
165 .groupTuple(by: [0])
166 .map { it -> tuple ( it[0], it[1].flatten() ) }
167 .set { ch_abricated }
168
169 ABRICATE_SUMMARY ( ch_abricated )
170
171 // ABRICATE_SUMMARY.out.ecoli_vf.set { ch_abricate_summary_ecoli_vf }
172 // ch_abricate_summary_ecoli_vf.ifEmpty { [ false, false ] }
173
174 CENTRIFUGE_CLASSIFY.out.kreport
175 .map { meta, kreport -> [ kreport ] }
176 .flatten()
177 .concat (
178 KRAKEN2_CLASSIFY.out.kraken_report
179 .map { meta, kreport -> [ kreport ] }
180 .flatten(),
181 FASTQC.out.zip
182 .map { meta, zip -> [ zip ] }
183 .flatten()
184 )
185 .set { ch_mqc_classify }
186
187 if (params.serotypefinder_run) {
188 SEROTYPEFINDER
189 .out
190 .serotyped
191 .map { meta, tsv -> [ 'serotypefinder', tsv ] }
192 .groupTuple(by: [0])
193 .map { it -> tuple ( it[0], it[1].flatten() ) }
194 .set { ch_mqc_custom_tbl }
195 } else if (params.seqsero2_run) {
196 SEQSERO2
197 .out
198 .serotyped
199 .map { meta, tsv -> [ 'seqsero2', tsv ] }
200 .groupTuple(by: [0])
201 .map { it -> tuple ( it[0], it[1].flatten() ) }
202 .set { ch_mqc_custom_tbl }
203 }
204
205 ch_mqc_custom_tbl
206 .concat (
207 ABRICATE_SUMMARY.out.ncbiamrplus.map{ it -> tuple ( it[0], it[1] )},
208 ABRICATE_SUMMARY.out.resfinder.map{ it -> tuple ( it[0], it[1] )},
209 ABRICATE_SUMMARY.out.megares.map{ it -> tuple ( it[0], it[1] )},
210 ABRICATE_SUMMARY.out.argannot.map{ it -> tuple ( it[0], it[1] )},
211 )
212 .groupTuple(by: [0])
213 .map { it -> [ it[0], it[1].flatten() ]}
214 .set { ch_mqc_custom_tbl }
215
216 TABLE_SUMMARY ( ch_mqc_custom_tbl )
217
218 DUMP_SOFTWARE_VERSIONS (
219 software_versions
220 .mix (
221 FASTQC.out.versions,
222 CENTRIFUGE_CLASSIFY.out.versions,
223 CENTRIFUGE_PROCESS.out.versions,
224 SEQKIT_GREP.out.versions,
225 FLYE_ASSEMBLE.out.versions.ifEmpty(null),
226 KRAKEN2_CLASSIFY.out.versions.ifEmpty(null),
227 KRAKEN2_EXTRACT_CONTIGS.out.versions.ifEmpty(null),
228 SEROTYPEFINDER.out.versions.ifEmpty(null),
229 SEQSERO2.out.versions.ifEmpty(null),
230 MLST.out.versions.ifEmpty(null),
231 ABRICATE_RUN.out.versions.ifEmpty(null),
232 ABRICATE_SUMMARY.out.versions.ifEmpty(null),
233 TABLE_SUMMARY.out.versions.ifEmpty(null)
234 )
235 .unique()
236 .collectFile(name: 'collected_versions.yml')
237 )
238
239 DUMP_SOFTWARE_VERSIONS
240 .out
241 .mqc_yml
242 .concat (
243 ch_mqc_classify,
244 TABLE_SUMMARY.out.mqc_yml
245 )
246 .collect()
247 .set { ch_multiqc }
248
249 MULTIQC ( ch_multiqc )
250 }
251
252 /*
253 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
254 ON COMPLETE, SHOW GORY DETAILS OF ALL PARAMS WHICH WILL BE HELPFUL TO DEBUG
255 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
256 */
257
258 workflow.onComplete {
259 if (workflow.success) {
260 // CREATE APPROPRIATE DIRECTORIES AND MOVE AS REQUESTED BY STAKEHOLDER(S)
261 //
262 // Nextflow's .moveTo will error out if directories contain files and it
263 // would be complex to include logic to skip directories
264 //
265 def final_intermediate_dir = "${params.output}${params.fs}${params.pipeline}-steps"
266 def final_results_dir = "${params.output}${params.fs}${params.pipeline}-results"
267 def kraken2_ext_contigs = file( "${final_intermediate_dir}${params.fs}kraken2_extract_contigs", type: 'dir' )
268 def final_intermediate = file( final_intermediate_dir, type: 'dir' )
269 def final_results = file( final_results_dir, type: 'dir' )
270 def pipeline_output = file( params.output, type: 'dir' )
271
272 if ( !final_intermediate.exists() ) {
273 final_intermediate.mkdirs()
274
275 FileHelper.visitFiles(Paths.get("${params.output}"), '*') {
276 if ( !(it.name ==~ /^(${params.cfsanpipename}|multiqc|\.nextflow|${workflow.workDir.name}|${params.pipeline}).*/) ) {
277 FileHelper.movePath(
278 it, Paths.get( "${final_intermediate_dir}${params.fs}${it.name}" )
279 )
280 }
281 }
282 }
283
284 if ( kraken2_ext_contigs.exists() && !final_results.exists() ) {
285 final_results.mkdirs()
286
287 FileHelper.movePath(
288 Paths.get( "${final_intermediate_dir}${params.fs}kraken2_extract_contigs" ),
289 Paths.get( "${final_results_dir}${params.fs}kraken2_extract_contigs" )
290 )
291 }
292
293 sendMail()
294 }
295 }
296
297 workflow.onError {
298 sendMail()
299 }
300
301 /*
302 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
303 HELPER METHODS FOR CENTRIFLAKEN WORKFLOW
304 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305 */
306
307 def help() {
308
309 Map helptext = [:]
310
311 helptext.putAll (
312 fastqEntryPointHelp() +
313 kraken2Help(params).text +
314 centrifugeHelp(params).text +
315 flyeHelp(params).text +
316 serotypefinderHelp(params).text +
317 seqsero2Help(params).text +
318 mlstHelp(params).text +
319 abricateHelp(params).text +
320 wrapUpHelp()
321 )
322
323 return addPadding(helptext)
324 }