annotate 0.4.0/workflows/centriflaken_hy.nf @ 101:ce6d9548fe89

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