annotate 0.4.2/workflows/centriflaken_hy.nf @ 105:52045ea4679d

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