annotate 0.3.0/workflows/centriflaken_hy.nf @ 99:d38841ae3a57

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