comparison 0.2.0/workflows/cronology.nf @ 11:a5f31c44f8c9

planemo upload
author kkonganti
date Mon, 15 Jul 2024 16:11:44 -0400
parents
children
comparison
equal deleted inserted replaced
10:ddf7a172bf30 11:a5f31c44f8c9
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; conciseHelp; \
8 addPadding; wrapUpHelp } from "${params.routines}"
9 include { dpubmlstpyHelp } from "${params.toolshelp}${params.fs}dpubmlstpy"
10 include { fastpHelp } from "${params.toolshelp}${params.fs}fastp"
11 include { mashscreenHelp } from "${params.toolshelp}${params.fs}mashscreen"
12 include { tuspyHelp } from "${params.toolshelp}${params.fs}tuspy"
13 include { spadesHelp } from "${params.toolshelp}${params.fs}spades"
14 include { shovillHelp } from "${params.toolshelp}${params.fs}shovill"
15 include { polypolishHelp } from "${params.toolshelp}${params.fs}polypolish"
16 include { mashtreeHelp } from "${params.toolshelp}${params.fs}mashtree"
17 include { quastHelp } from "${params.toolshelp}${params.fs}quast"
18 include { prodigalHelp } from "${params.toolshelp}${params.fs}prodigal"
19 include { prokkaHelp } from "${params.toolshelp}${params.fs}prokka"
20 include { pirateHelp } from "${params.toolshelp}${params.fs}pirate"
21 include { mlstHelp } from "${params.toolshelp}${params.fs}mlst"
22 include { abricateHelp } from "${params.toolshelp}${params.fs}abricate"
23
24 // Exit if help requested before any subworkflows
25 if (params.help) {
26 log.info help()
27 exit 0
28 }
29
30 // Include any necessary modules and subworkflows
31 include { PROCESS_FASTQ } from "${params.subworkflows}${params.fs}process_fastq"
32 include { PRODKA } from "${params.subworkflows}${params.fs}prodka"
33 include { DOWNLOAD_PUBMLST_SCHEME } from "${params.modules}${params.fs}download_pubmlst_scheme${params.fs}main"
34 include { DOWNLOAD_REF_GENOME } from "${params.modules}${params.fs}download_ref_genome${params.fs}main"
35 include { FASTP } from "${params.modules}${params.fs}fastp${params.fs}main"
36 include { MASH_SCREEN } from "${params.modules}${params.fs}mash${params.fs}screen${params.fs}main"
37 include { TOP_UNIQUE_SEROVARS } from "${params.modules}${params.fs}top_unique_serovars${params.fs}main"
38 include { CAT_UNIQUE } from "${params.modules}${params.fs}cat${params.fs}unique${params.fs}main"
39 include { SPADES_ASSEMBLE } from "${params.modules}${params.fs}spades${params.fs}assemble${params.fs}main"
40 include { SHOVILL } from "${params.modules}${params.fs}shovill${params.fs}main"
41 include { BWA_IDX_MEM } from "${params.modules}${params.fs}custom${params.fs}bwa_idx_mem${params.fs}main"
42 include { POLYPOLISH } from "${params.modules}${params.fs}polypolish${params.fs}main"
43 include { QUAST } from "${params.modules}${params.fs}quast${params.fs}main"
44 include { RMLST_POST } from "${params.modules}${params.fs}rmlst${params.fs}main"
45 include { PIRATE } from "${params.modules}${params.fs}pirate${params.fs}main"
46 include { MASHTREE } from "${params.modules}${params.fs}mashtree${params.fs}main"
47 include { UPLOAD_MICROREACT } from "${params.modules}${params.fs}upload_microreact${params.fs}main"
48 include { MLST } from "${params.modules}${params.fs}mlst${params.fs}main"
49 include { ABRICATE_RUN } from "${params.modules}${params.fs}abricate${params.fs}run${params.fs}main"
50 include { ABRICATE_SUMMARY } from "${params.modules}${params.fs}abricate${params.fs}summary${params.fs}main"
51 include { TABLE_SUMMARY } from "${params.modules}${params.fs}cat${params.fs}tables${params.fs}main"
52 include { DUMP_SOFTWARE_VERSIONS } from "${params.modules}${params.fs}custom${params.fs}dump_software_versions${params.fs}main"
53 include { MULTIQC } from "${params.modules}${params.fs}multiqc${params.fs}main"
54
55 /*
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57 INPUTS AND ANY CHECKS FOR THE CRONOLOGY WORKFLOW
58 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59 */
60 def spades_custom_hmm = (params.spades_hmm ? file ( "${params.spades_hmm}" ) : false)
61 def reads_platform = 0
62 def abricate_dbs = [ 'ncbiamrplus', 'resfinder', 'megares', 'argannot' ]
63
64 reads_platform += (params.input ? 1 : 0)
65
66 if (params.upload_microreact) {
67 checkMetadataExists(params.microreact_api_key, 'Microreact API Key')
68 }
69
70 if (spades_custom_hmm && !spades_custom_hmm.exists()) {
71 stopNow("Please check if the following SPAdes' custom HMM directory\n" +
72 "path is valid:\n${params.spades_hmm}\nCannot proceed further!")
73 }
74
75 if (reads_platform < 1 || reads_platform == 0) {
76 stopNow("Please mention at least one absolute path to input folder which contains\n" +
77 "FASTQ files sequenced using the --input option.\n" +
78 "Ex: --input (Illumina or Generic short reads in FASTQ format)")
79 }
80
81 /*
82 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83 RUN THE CRONOLOGY WORKFLOW
84 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85 */
86
87 workflow CRONOLOGY {
88 main:
89 ch_mqc_custom_tbl = Channel.empty()
90 ch_dummy = Channel.fromPath("${params.dummyfile}")
91 ch_dummy2 = Channel.fromPath("${params.dummyfile2}")
92
93 log.info summaryOfParams()
94
95 PROCESS_FASTQ()
96
97 PROCESS_FASTQ.out.versions
98 .set { software_versions }
99
100 PROCESS_FASTQ.out.processed_reads
101 .map { meta, fastq ->
102 meta.sequence_sketch = (params.mash_sketch ?: null)
103 [meta, fastq]
104 }
105 .set { ch_processed_reads }
106
107 DOWNLOAD_PUBMLST_SCHEME( params.dpubmlstpy_org ?: null )
108
109 DOWNLOAD_REF_GENOME(
110 (params.ref_acc ? ['id': params.ref_acc] : null)
111 )
112
113 FASTP( ch_processed_reads )
114
115 FASTP.out.passed_reads
116 .set { ch_processed_reads }
117
118 FASTP.out.json
119 .map { meta, json -> [ json ] }
120 .collect()
121 .set { ch_multiqc }
122
123 MASH_SCREEN( ch_processed_reads )
124
125 TOP_UNIQUE_SEROVARS( MASH_SCREEN.out.screened )
126
127 TOP_UNIQUE_SEROVARS.out.tsv
128 .map { meta, tsv -> tsv }
129 .collectFile(
130 name: 'iTOL_metadata_w_dups.txt',
131 keepHeader: true,
132 skip: 4,
133 sort: true
134 )
135 .map { file ->
136 def meta = [:]
137 meta.id = 'Unique iTOL Metadata'
138 meta.skip_header = 4
139 [meta, file]
140 }
141 .concat(
142 TOP_UNIQUE_SEROVARS.out.popup
143 .map { meta, popup -> popup }
144 .collectFile(
145 name: 'iTOL_2_NCBI_Pathogens_w_dups.txt',
146 keepHeader: true,
147 skip: 3,
148 sort: true
149 )
150 .map { file ->
151 def meta = [:]
152 meta.id = 'Unique iTOL Popup'
153 meta.skip_header = 3
154 [meta, file]
155 }
156 )
157 .set { ch_uniq }
158
159 TOP_UNIQUE_SEROVARS.out.accessions
160 .map { meta, acc -> acc }
161 .splitText()
162 .collect()
163 .flatten()
164 .unique()
165 .collectFile(name: 'tree_genomes.txt')
166 .map { genomes -> [ [id: 'hitsTree'], genomes ]}
167 .set { ch_genomes_fofn }
168
169 CAT_UNIQUE( ch_uniq )
170
171 if (params.fq_single_end) {
172 SPADES_ASSEMBLE(
173 ch_processed_reads
174 .combine(ch_dummy)
175 .combine(ch_dummy2)
176 )
177
178 SPADES_ASSEMBLE.out.assembly
179 .set{ ch_assembly }
180
181 software_versions
182 .mix( SPADES_ASSEMBLE.out.versions.ifEmpty(null) )
183 .set { software_versions }
184 } else {
185 SHOVILL( ch_processed_reads )
186
187 SHOVILL.out.contigs
188 .set { ch_assembly }
189
190 software_versions
191 .mix( SHOVILL.out.versions.ifEmpty(null) )
192 .set { software_versions }
193 }
194
195 if (params.polypolish_run) {
196 BWA_IDX_MEM(
197 ch_assembly
198 .join( ch_processed_reads )
199 )
200
201 POLYPOLISH(
202 ch_assembly
203 .join( BWA_IDX_MEM.out.aligned_sam )
204 )
205
206 POLYPOLISH.out.polished
207 .set { ch_assembly }
208
209 software_versions
210 .mix(
211 BWA_IDX_MEM.out.versions,
212 POLYPOLISH.out.versions
213 )
214 .set { software_versions }
215 }
216
217 ch_assembly
218 .combine( DOWNLOAD_REF_GENOME.out.fasta )
219 .combine( DOWNLOAD_REF_GENOME.out.gff )
220 .multiMap { meta, consensus, fasta, gff ->
221 sample_fa: consensus
222 polished: [meta, consensus]
223 ref_fasta: [meta, fasta]
224 ref_gff: [meta, gff]
225 }
226 .set { ch_quast }
227
228 MASHTREE(
229 ch_genomes_fofn,
230 DOWNLOAD_REF_GENOME.out.fasta
231 .concat( ch_quast.sample_fa )
232 .collect()
233 )
234
235 if (params.upload_microreact) {
236 UPLOAD_MICROREACT(
237 MASHTREE.out.nwk
238 .map { meta, nwk ->
239 nwk
240 },
241 CAT_UNIQUE.out.csv
242 )
243
244 software_versions
245 .mix(
246 UPLOAD_MICROREACT.out.versions
247 )
248 .set { software_versions }
249 }
250
251 PRODKA(
252 ch_quast.ref_fasta,
253 ch_quast.polished
254 )
255
256 RMLST_POST( ch_assembly )
257
258 MLST (
259 ch_assembly
260 .combine( DOWNLOAD_PUBMLST_SCHEME.out.pubmlst_dir )
261 )
262
263 QUAST(
264 ch_quast.polished,
265 ch_quast.ref_fasta,
266 ch_quast.ref_gff
267 )
268
269 if (params.pirate_run) {
270 PIRATE(
271 PRODKA.out.prokka_gff
272 .map { meta, gff ->
273 tuple( [id: 'Predicted Genes'], gff )
274 }
275 .groupTuple(by: [0])
276 )
277
278 software_versions
279 .mix( PIRATE.out.versions )
280 .set { software_versions }
281 }
282
283 RMLST_POST.out.tsv
284 .map { meta, tsv -> [ 'rmlst', tsv] }
285 .groupTuple(by: [0])
286 .map { it -> tuple ( it[0], it[1].flatten() ) }
287 .set { ch_mqc_rmlst_tbl }
288
289 MLST.out.tsv
290 .map { meta, tsv -> [ 'mlst', tsv] }
291 .groupTuple(by: [0])
292 .map { it -> tuple ( it[0], it[1].flatten() ) }
293 .set { ch_mqc_custom_tbl }
294
295 ABRICATE_RUN ( ch_assembly, abricate_dbs )
296
297 ABRICATE_RUN.out.abricated
298 .map { meta, abres -> [ abricate_dbs, abres ] }
299 .groupTuple(by: [0])
300 .map { it -> tuple ( it[0], it[1].flatten() ) }
301 .set { ch_abricated }
302
303 ABRICATE_SUMMARY ( ch_abricated )
304
305 ch_mqc_custom_tbl
306 .concat (
307 ch_mqc_rmlst_tbl,
308 ABRICATE_SUMMARY.out.ncbiamrplus.map { it -> tuple ( it[0], it[1] )},
309 ABRICATE_SUMMARY.out.resfinder.map { it -> tuple ( it[0], it[1] )},
310 ABRICATE_SUMMARY.out.megares.map { it -> tuple ( it[0], it[1] )},
311 ABRICATE_SUMMARY.out.argannot.map { it -> tuple ( it[0], it[1] )},
312 )
313 .groupTuple(by: [0])
314 .map { it -> [ it[0], it[1].flatten() ]}
315 .set { ch_mqc_custom_tbl }
316
317 TABLE_SUMMARY ( ch_mqc_custom_tbl )
318
319 DUMP_SOFTWARE_VERSIONS (
320 software_versions
321 .mix(
322 DOWNLOAD_PUBMLST_SCHEME.out.versions,
323 DOWNLOAD_REF_GENOME.out.versions,
324 FASTP.out.versions,
325 MASH_SCREEN.out.versions,
326 TOP_UNIQUE_SEROVARS.out.versions,
327 CAT_UNIQUE.out.versions,
328 MASHTREE.out.versions,
329 POLYPOLISH.out.versions,
330 QUAST.out.versions,
331 PRODKA.out.versions,
332 RMLST_POST.out.versions,
333 MLST.out.versions,
334 ABRICATE_RUN.out.versions,
335 ABRICATE_SUMMARY.out.versions,
336 TABLE_SUMMARY.out.versions
337 )
338 .unique()
339 .collectFile(name: 'collected_versions.yml')
340 )
341
342 DUMP_SOFTWARE_VERSIONS.out.mqc_yml
343 .concat (
344 ch_multiqc,
345 TABLE_SUMMARY.out.mqc_yml,
346 PRODKA.out.prokka_txt.map { meta, txt -> txt },
347 QUAST.out.results.map { meta, res -> res }
348 )
349 .collect()
350 .set { ch_multiqc }
351
352 MULTIQC( ch_multiqc )
353 }
354
355 /*
356 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
357 ON COMPLETE, SHOW GORY DETAILS OF ALL PARAMS WHICH WILL BE HELPFUL TO DEBUG
358 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
359 */
360
361 workflow.onComplete {
362 if (workflow.success) {
363 sendMail()
364 }
365 }
366
367 workflow.onError {
368 sendMail()
369 }
370
371 /*
372 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
373 METHOD TO CHECK FILE EXISTENCE
374 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
375 */
376
377 def checkMetadataExists(file_path, msg) {
378 file_path_obj = file( file_path )
379
380 if (msg.toString().find(/(?i)KMA/)) {
381 if (!file_path_obj.parent.exists() || file_path_obj.parent.size() == 0) {
382 stopNow("Please check if your ${msg}\n" +
383 "[ ${file_path} ]\nexists and that the files are not of size 0.")
384 }
385 }
386 else if (!file_path_obj.exists() || file_path_obj.size() == 0) {
387 stopNow("Please check if your ${msg} file\n" +
388 "[ ${file_path} ]\nexists and is not of size 0.")
389 }
390 }
391
392 /*
393 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
394 HELP TEXT METHODS FOR CRONOLOGY WORKFLOW
395 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
396 */
397
398 def help() {
399
400 Map helptext = [:]
401 Map nH = [:]
402 Map fastpAdapterHelp = [:]
403 def uHelp = (params.help.getClass().toString() =~ /String/ ? params.help.tokenize(',').join(' ') : '')
404
405 Map defaultHelp = [
406 '--help dpubmlstpy' : 'Show dl_pubmlst_profiles_and_schemes.py CLI options',
407 '--help fastp' : 'Show fastp CLI options',
408 '--help spades' : 'Show spades CLI options',
409 '--help shovill' : 'Show shovill CLI options',
410 '--help polypolish' : 'Show polypolish CLI options',
411 '--help quast' : 'Show quast.py CLI options',
412 '--help prodigal' : 'Show prodigal CLI options',
413 '--help prokka' : 'Show prokka CLI options',
414 '--help pirate' : 'Show priate CLI options',
415 '--help mlst' : 'Show mlst CLI options',
416 '--help mash' : 'Show mash `screen` CLI options',
417 '--help tree' : 'Show mashtree CLI options',
418 '--help abricate' : 'Show abricate CLI options\n'
419 ]
420
421 fastpAdapterHelp['--fastp_use_custom_adapaters'] = "Use custom adapter FASTA with fastp on top of " +
422 "built-in adapter sequence auto-detection. Enabling this option will attempt to find and remove " +
423 "all possible Illumina adapter and primer sequences but will make the workflow run slow. " +
424 "Default: ${params.fastp_use_custom_adapters}"
425
426 if (params.help.getClass().toString() =~ /Boolean/ || uHelp.size() == 0) {
427 println conciseHelp('fastp,polypolish')
428 helptext.putAll(defaultHelp)
429 } else {
430 params.help.tokenize(',').each { h ->
431 if (defaultHelp.keySet().findAll{ it =~ /(?i)\b${h}\b/ }.size() == 0) {
432 println conciseHelp('fastp,polypolish')
433 stopNow("Tool [ ${h} ] is not a part of ${params.pipeline} pipeline.")
434 }
435 }
436
437 helptext.putAll(
438 fastqEntryPointHelp() +
439 (uHelp =~ /(?i)\bdpubmlstpy/ ? dpubmlstpyHelp(params).text : nH) +
440 (uHelp =~ /(?i)\bfastp/ ? fastpHelp(params).text + fastpAdapterHelp : nH) +
441 (uHelp =~ /(?i)\bmash/ ? mashscreenHelp(params).text : nH) +
442 (uHelp =~ /(?i)\btuspy/ ? tuspyHelp(params).text : nH) +
443 (uHelp =~ /(?i)\bspades/ ? spadesHelp(params).text : nH) +
444 (uHelp =~ /(?i)\bshovill/ ? shovillHelp(params).text : nH) +
445 (uHelp =~ /(?i)\bpolypolish/ ? polypolishHelp(params).text : nH) +
446 (uHelp =~ /(?i)\bquast/ ? quastHelp(params).text : nH) +
447 (uHelp =~ /(?i)\bprodigal/ ? prodigalHelp(params).text : nH) +
448 (uHelp =~ /(?i)\bprokka/ ? prokkaHelp(params).text : nH) +
449 (uHelp =~ /(?i)\bpirate/ ? pirateHelp(params).text : nH) +
450 (uHelp =~ /(?i)\bmlst/ ? mlstHelp(params).text : nH) +
451 (uHelp =~ /(?i)\btree/ ? mashtreeHelp(params).text : nH) +
452 (uHelp =~ /(?i)\babricate/ ? abricateHelp(params).text : nH) +
453 wrapUpHelp()
454 )
455 }
456
457 return addPadding(helptext)
458 }