kkonganti@0: // Define any required imports for this specific workflow kkonganti@0: import java.nio.file.Paths kkonganti@0: import nextflow.file.FileHelper kkonganti@0: kkonganti@0: // Include any necessary methods kkonganti@0: include { \ kkonganti@0: summaryOfParams; stopNow; fastqEntryPointHelp; sendMail; \ kkonganti@0: addPadding; wrapUpHelp } from "${params.routines}" kkonganti@0: include { kraken2Help } from "${params.toolshelp}${params.fs}kraken2" kkonganti@0: include { centrifugeHelp } from "${params.toolshelp}${params.fs}centrifuge" kkonganti@0: include { flyeHelp } from "${params.toolshelp}${params.fs}flye" kkonganti@0: include { serotypefinderHelp } from "${params.toolshelp}${params.fs}serotypefinder" kkonganti@0: include { seqsero2Help } from "${params.toolshelp}${params.fs}seqsero2" kkonganti@0: include { mlstHelp } from "${params.toolshelp}${params.fs}mlst" kkonganti@0: include { abricateHelp } from "${params.toolshelp}${params.fs}abricate" kkonganti@0: kkonganti@0: // Exit if help requested before any subworkflows kkonganti@0: if (params.help) { kkonganti@0: log.info help() kkonganti@0: exit 0 kkonganti@0: } kkonganti@0: kkonganti@0: // Include any necessary modules and subworkflows kkonganti@0: include { PROCESS_FASTQ } from "${params.subworkflows}${params.fs}process_fastq" kkonganti@0: include { FASTQC } from "${params.modules}${params.fs}fastqc${params.fs}main" kkonganti@0: include { CENTRIFUGE_CLASSIFY } from "${params.modules}${params.fs}centrifuge${params.fs}classify${params.fs}main" kkonganti@0: include { CENTRIFUGE_PROCESS } from "${params.modules}${params.fs}centrifuge${params.fs}process${params.fs}main" kkonganti@0: include { SEQKIT_GREP } from "${params.modules}${params.fs}seqkit${params.fs}grep${params.fs}main" kkonganti@0: include { FLYE_ASSEMBLE } from "${params.modules}${params.fs}flye${params.fs}assemble${params.fs}main" kkonganti@0: include { KRAKEN2_CLASSIFY } from "${params.modules}${params.fs}kraken2${params.fs}classify${params.fs}main" kkonganti@0: include { KRAKEN2_EXTRACT_CONTIGS } from "${params.modules}${params.fs}kraken2${params.fs}extract_contigs${params.fs}main" kkonganti@0: include { SEROTYPEFINDER } from "${params.modules}${params.fs}serotypefinder${params.fs}main" kkonganti@0: include { SEQSERO2 } from "${params.modules}${params.fs}seqsero2${params.fs}main" kkonganti@0: include { MLST } from "${params.modules}${params.fs}mlst${params.fs}main" kkonganti@0: include { ABRICATE_RUN } from "${params.modules}${params.fs}abricate${params.fs}run${params.fs}main" kkonganti@0: include { ABRICATE_SUMMARY } from "${params.modules}${params.fs}abricate${params.fs}summary${params.fs}main" kkonganti@0: include { TABLE_SUMMARY } from "${params.modules}${params.fs}cat${params.fs}tables${params.fs}main" kkonganti@0: include { MULTIQC } from "${params.modules}${params.fs}multiqc${params.fs}main" kkonganti@0: include { DUMP_SOFTWARE_VERSIONS } from "${params.modules}${params.fs}custom${params.fs}dump_software_versions${params.fs}main" kkonganti@0: kkonganti@0: kkonganti@0: kkonganti@0: /* kkonganti@0: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kkonganti@0: INPUTS AND ANY CHECKS FOR THE CENTRIFLAKEN WORKFLOW kkonganti@0: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kkonganti@0: */ kkonganti@0: kkonganti@0: def kraken2_db_dir = file ( "${params.kraken2_db}" ) kkonganti@0: def centrifuge_x = file ( "${params.centrifuge_x}" ) kkonganti@0: def reads_platform = 0 kkonganti@0: def abricate_dbs = [ 'ncbiamrplus', 'resfinder', 'megares', 'argannot' ] kkonganti@0: kkonganti@0: reads_platform += (params.flye_nano_raw ? 1 : 0) kkonganti@0: reads_platform += (params.flye_nano_corr ? 1 : 0) kkonganti@0: reads_platform += (params.flye_nano_hq ? 1 : 0) kkonganti@0: reads_platform += (params.flye_pacbio_raw ? 1 : 0) kkonganti@0: reads_platform += (params.flye_pacbio_corr ? 1 : 0) kkonganti@0: reads_platform += (params.flye_pacbio_hifi ? 1 : 0) kkonganti@0: kkonganti@0: if (!kraken2_db_dir.exists() || !centrifuge_x.getParent().exists()) { kkonganti@0: stopNow("Please check if the following absolute paths are valid:\n" + kkonganti@0: "${params.kraken2_db}\n${params.centrifuge_x}\n" + kkonganti@0: "Cannot proceed further!") kkonganti@0: } kkonganti@0: kkonganti@0: if (reads_platform > 1 || reads_platform == 0) { kkonganti@0: msg_0 = (reads_platform > 1 ? "only" : "at least") kkonganti@0: stopNow("Please mention ${msg_0} one read platform for use with the flye assembler\n" + kkonganti@0: "using any one of the following options:\n" + kkonganti@0: "--flye_nano_raw\n--flye_nano_corr\n--flye_nano_hq\n" + kkonganti@0: "--flye_pacbio_raw\n--flye_pacbio_corr\n--flye_pacbio_hifi") kkonganti@0: } kkonganti@0: kkonganti@0: if (params.centrifuge_extract_bug != params.kraken2_extract_bug) { kkonganti@0: stopNow("Please make sure that the bug to be extracted is same\n" + kkonganti@0: "for both --centrifuge_extract_bug and --kraken2_extract_bug options.") kkonganti@0: } kkonganti@0: kkonganti@0: /* kkonganti@0: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kkonganti@0: RUN THE CENTRIFLAKEN WORKFLOW kkonganti@0: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kkonganti@0: */ kkonganti@0: kkonganti@0: workflow CENTRIFLAKEN { kkonganti@0: main: kkonganti@0: ch_asm_filtered_contigs = Channel.empty() kkonganti@0: ch_mqc_custom_tbl = Channel.empty() kkonganti@0: kkonganti@0: log.info summaryOfParams() kkonganti@0: kkonganti@0: PROCESS_FASTQ() kkonganti@0: .processed_reads kkonganti@0: .map { kkonganti@0: meta, fastq -> kkonganti@0: meta.centrifuge_x = params.centrifuge_x kkonganti@0: meta.kraken2_db = params.kraken2_db kkonganti@0: [meta, fastq] kkonganti@0: } kkonganti@0: .set { ch_processed_reads } kkonganti@0: kkonganti@0: PROCESS_FASTQ kkonganti@0: .out kkonganti@0: .versions kkonganti@0: .set { software_versions } kkonganti@0: kkonganti@0: FASTQC ( ch_processed_reads ) kkonganti@0: kkonganti@47: CENTRIFUGE_CLASSIFY ( ch_processed_reads ) kkonganti@0: kkonganti@47: CENTRIFUGE_PROCESS ( kkonganti@0: CENTRIFUGE_CLASSIFY.out.report kkonganti@0: .join( CENTRIFUGE_CLASSIFY.out.output ) kkonganti@0: ) kkonganti@0: kkonganti@47: ch_processed_reads.join ( CENTRIFUGE_PROCESS.out.extracted ) kkonganti@0: .set { ch_centrifuge_extracted } kkonganti@0: kkonganti@0: SEQKIT_GREP ( ch_centrifuge_extracted ) kkonganti@0: kkonganti@0: FLYE_ASSEMBLE ( SEQKIT_GREP.out.fastx ) kkonganti@0: kkonganti@0: FLYE_ASSEMBLE kkonganti@0: .out kkonganti@0: .assembly kkonganti@0: .set { ch_flye_assembly } kkonganti@0: kkonganti@0: ch_flye_assembly.ifEmpty { [ false, false ] } kkonganti@0: kkonganti@47: KRAKEN2_CLASSIFY ( ch_flye_assembly ) kkonganti@0: kkonganti@0: KRAKEN2_EXTRACT_CONTIGS ( kkonganti@0: ch_flye_assembly kkonganti@0: .join( KRAKEN2_CLASSIFY.out.kraken_output ), kkonganti@0: params.kraken2_extract_bug kkonganti@0: ) kkonganti@0: kkonganti@0: KRAKEN2_EXTRACT_CONTIGS kkonganti@0: .out kkonganti@0: .asm_filtered_contigs kkonganti@0: .map { kkonganti@0: meta, fastq -> kkonganti@0: meta.organism = params.kraken2_extract_bug.split(/\s+/)[0].capitalize() kkonganti@0: meta.serotypefinder_db = params.serotypefinder_db kkonganti@0: [meta, fastq] kkonganti@0: } kkonganti@0: .set { ch_asm_filtered_contigs } kkonganti@0: kkonganti@0: SEROTYPEFINDER ( ch_asm_filtered_contigs ) kkonganti@0: kkonganti@0: SEQSERO2 ( ch_asm_filtered_contigs ) kkonganti@0: kkonganti@0: MLST ( ch_asm_filtered_contigs ) kkonganti@0: kkonganti@0: ABRICATE_RUN ( kkonganti@0: ch_asm_filtered_contigs, kkonganti@0: abricate_dbs kkonganti@0: ) kkonganti@0: kkonganti@0: ABRICATE_RUN kkonganti@0: .out kkonganti@0: .abricated kkonganti@0: .map { meta, abres -> [ abricate_dbs, abres ] } kkonganti@0: .groupTuple(by: [0]) kkonganti@0: .map { it -> tuple ( it[0], it[1].flatten() ) } kkonganti@0: .set { ch_abricated } kkonganti@0: kkonganti@0: ABRICATE_SUMMARY ( ch_abricated ) kkonganti@0: kkonganti@0: // ABRICATE_SUMMARY.out.ecoli_vf.set { ch_abricate_summary_ecoli_vf } kkonganti@0: // ch_abricate_summary_ecoli_vf.ifEmpty { [ false, false ] } kkonganti@0: kkonganti@0: CENTRIFUGE_CLASSIFY.out.kreport kkonganti@0: .map { meta, kreport -> [ kreport ] } kkonganti@0: .flatten() kkonganti@0: .concat ( kkonganti@0: KRAKEN2_CLASSIFY.out.kraken_report kkonganti@0: .map { meta, kreport -> [ kreport ] } kkonganti@0: .flatten(), kkonganti@0: FASTQC.out.zip kkonganti@0: .map { meta, zip -> [ zip ] } kkonganti@0: .flatten() kkonganti@0: ) kkonganti@0: .set { ch_mqc_classify } kkonganti@0: kkonganti@0: if (params.serotypefinder_run) { kkonganti@0: SEROTYPEFINDER kkonganti@0: .out kkonganti@0: .serotyped kkonganti@0: .map { meta, tsv -> [ 'serotypefinder', tsv ] } kkonganti@0: .groupTuple(by: [0]) kkonganti@0: .map { it -> tuple ( it[0], it[1].flatten() ) } kkonganti@0: .set { ch_mqc_custom_tbl } kkonganti@0: } else if (params.seqsero2_run) { kkonganti@0: SEQSERO2 kkonganti@0: .out kkonganti@0: .serotyped kkonganti@0: .map { meta, tsv -> [ 'seqsero2', tsv ] } kkonganti@0: .groupTuple(by: [0]) kkonganti@0: .map { it -> tuple ( it[0], it[1].flatten() ) } kkonganti@0: .set { ch_mqc_custom_tbl } kkonganti@0: } kkonganti@0: kkonganti@0: ch_mqc_custom_tbl kkonganti@0: .concat ( kkonganti@0: ABRICATE_SUMMARY.out.ncbiamrplus.map{ it -> tuple ( it[0], it[1] )}, kkonganti@0: ABRICATE_SUMMARY.out.resfinder.map{ it -> tuple ( it[0], it[1] )}, kkonganti@0: ABRICATE_SUMMARY.out.megares.map{ it -> tuple ( it[0], it[1] )}, kkonganti@0: ABRICATE_SUMMARY.out.argannot.map{ it -> tuple ( it[0], it[1] )}, kkonganti@0: ) kkonganti@0: .groupTuple(by: [0]) kkonganti@0: .map { it -> [ it[0], it[1].flatten() ]} kkonganti@0: .set { ch_mqc_custom_tbl } kkonganti@0: kkonganti@47: TABLE_SUMMARY ( ch_mqc_custom_tbl ) kkonganti@0: kkonganti@0: DUMP_SOFTWARE_VERSIONS ( kkonganti@0: software_versions kkonganti@0: .mix ( kkonganti@0: FASTQC.out.versions, kkonganti@0: CENTRIFUGE_CLASSIFY.out.versions, kkonganti@0: CENTRIFUGE_PROCESS.out.versions, kkonganti@0: SEQKIT_GREP.out.versions, kkonganti@0: FLYE_ASSEMBLE.out.versions.ifEmpty(null), kkonganti@0: KRAKEN2_CLASSIFY.out.versions.ifEmpty(null), kkonganti@0: KRAKEN2_EXTRACT_CONTIGS.out.versions.ifEmpty(null), kkonganti@0: SEROTYPEFINDER.out.versions.ifEmpty(null), kkonganti@0: SEQSERO2.out.versions.ifEmpty(null), kkonganti@0: MLST.out.versions.ifEmpty(null), kkonganti@0: ABRICATE_RUN.out.versions.ifEmpty(null), kkonganti@0: ABRICATE_SUMMARY.out.versions.ifEmpty(null), kkonganti@0: TABLE_SUMMARY.out.versions.ifEmpty(null) kkonganti@0: ) kkonganti@0: .unique() kkonganti@0: .collectFile(name: 'collected_versions.yml') kkonganti@0: ) kkonganti@0: kkonganti@0: DUMP_SOFTWARE_VERSIONS kkonganti@0: .out kkonganti@0: .mqc_yml kkonganti@0: .concat ( kkonganti@0: ch_mqc_classify, kkonganti@0: TABLE_SUMMARY.out.mqc_yml kkonganti@0: ) kkonganti@0: .collect() kkonganti@0: .set { ch_multiqc } kkonganti@0: kkonganti@47: MULTIQC ( ch_multiqc ) kkonganti@0: } kkonganti@0: kkonganti@0: /* kkonganti@0: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kkonganti@0: ON COMPLETE, SHOW GORY DETAILS OF ALL PARAMS WHICH WILL BE HELPFUL TO DEBUG kkonganti@0: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kkonganti@0: */ kkonganti@0: kkonganti@0: workflow.onComplete { kkonganti@0: if (workflow.success) { kkonganti@0: // CREATE APPROPRIATE DIRECTORIES AND MOVE AS REQUESTED BY STAKEHOLDER(S) kkonganti@0: // kkonganti@0: // Nextflow's .moveTo will error out if directories contain files and it kkonganti@0: // would be complex to include logic to skip directories kkonganti@0: // kkonganti@0: def final_intermediate_dir = "${params.output}${params.fs}${params.pipeline}-steps" kkonganti@0: def final_results_dir = "${params.output}${params.fs}${params.pipeline}-results" kkonganti@0: def kraken2_ext_contigs = file( "${final_intermediate_dir}${params.fs}kraken2_extract_contigs", type: 'dir' ) kkonganti@0: def final_intermediate = file( final_intermediate_dir, type: 'dir' ) kkonganti@0: def final_results = file( final_results_dir, type: 'dir' ) kkonganti@0: def pipeline_output = file( params.output, type: 'dir' ) kkonganti@0: kkonganti@0: if ( !final_intermediate.exists() ) { kkonganti@0: final_intermediate.mkdirs() kkonganti@0: kkonganti@0: FileHelper.visitFiles(Paths.get("${params.output}"), '*') { kkonganti@0: if ( !(it.name ==~ /^(${params.cfsanpipename}|multiqc|\.nextflow|${workflow.workDir.name}|${params.pipeline}).*/) ) { kkonganti@0: FileHelper.movePath( kkonganti@0: it, Paths.get( "${final_intermediate_dir}${params.fs}${it.name}" ) kkonganti@0: ) kkonganti@0: } kkonganti@0: } kkonganti@0: } kkonganti@0: kkonganti@0: if ( kraken2_ext_contigs.exists() && !final_results.exists() ) { kkonganti@0: final_results.mkdirs() kkonganti@0: kkonganti@0: FileHelper.movePath( kkonganti@0: Paths.get( "${final_intermediate_dir}${params.fs}kraken2_extract_contigs" ), kkonganti@0: Paths.get( "${final_results_dir}${params.fs}kraken2_extract_contigs" ) kkonganti@0: ) kkonganti@0: } kkonganti@0: kkonganti@0: sendMail() kkonganti@0: } kkonganti@0: } kkonganti@0: kkonganti@0: workflow.onError { kkonganti@0: sendMail() kkonganti@0: } kkonganti@0: kkonganti@0: /* kkonganti@0: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kkonganti@0: HELPER METHODS FOR CENTRIFLAKEN WORKFLOW kkonganti@0: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kkonganti@0: */ kkonganti@0: kkonganti@0: def help() { kkonganti@0: kkonganti@0: Map helptext = [:] kkonganti@0: kkonganti@47: helptext.putAll ( kkonganti@0: fastqEntryPointHelp() + kkonganti@0: kraken2Help(params).text + kkonganti@0: centrifugeHelp(params).text + kkonganti@0: flyeHelp(params).text + kkonganti@0: serotypefinderHelp(params).text + kkonganti@0: seqsero2Help(params).text + kkonganti@0: mlstHelp(params).text + kkonganti@0: abricateHelp(params).text + kkonganti@0: wrapUpHelp() kkonganti@0: ) kkonganti@0: kkonganti@0: return addPadding(helptext) kkonganti@0: }