annotate 0.2.1/workflows/centriflaken_hy.nf @ 68:44d4e4078aaa

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