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