2022-02-18 06:55:14 +00:00
/*
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
VALIDATE INPUTS
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
*/
def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params)
// Validate input parameters
WorkflowTaxprofiler.initialise(params, log)
// TODO nf-core: Add all file path parameters for the pipeline to the list below
// Check input path parameters to see if they exist
2022-02-19 11:36:08 +00:00
def checkPathParamList = [ params.input, params.databases, params.multiqc_config ]
2022-02-18 06:55:14 +00:00
for (param in checkPathParamList) { if (param) { file(param, checkIfExists: true) } }
// Check mandatory parameters
2022-02-19 11:36:08 +00:00
if (params.input ) { ch_input = file(params.input) } else { exit 1, 'Input samplesheet not specified!' }
if (params.databases) { ch_databases = file(params.databases) } else { exit 1, 'Input database sheet not specified!' }
2022-03-25 13:58:06 +00:00
if (params.shortread_clipmerge_mergepairs && params.run_malt ) log.warn "[nf-core/taxprofiler] warning: MALT does not except uncollapsed paired-reads. Pairs will be profiled as separate files."
2022-02-18 06:55:14 +00:00
/*
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
CONFIG FILES
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
*/
2022-03-23 13:57:56 +00:00
ch_multiqc_config = file("$projectDir/assets/multiqc_config.yml", checkIfExists: true)
2022-02-18 06:55:14 +00:00
ch_multiqc_custom_config = params.multiqc_config ? Channel.fromPath(params.multiqc_config) : Channel.empty()
/*
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
IMPORT LOCAL MODULES/SUBWORKFLOWS
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
*/
//
// SUBWORKFLOW: Consisting of a mix of local and nf-core/modules
//
2022-03-26 05:45:16 +00:00
include { INPUT_CHECK } from '../subworkflows/local/input_check'
2022-02-19 11:36:08 +00:00
2022-03-26 05:45:16 +00:00
include { DB_CHECK } from '../subworkflows/local/db_check'
2022-03-21 17:25:56 +00:00
include { SHORTREAD_PREPROCESSING } from '../subworkflows/local/shortread_preprocessing'
2022-03-26 05:45:16 +00:00
include { LONGREAD_PREPROCESSING } from '../subworkflows/local/longread_preprocessing'
2022-02-18 06:55:14 +00:00
/*
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
IMPORT NF-CORE MODULES/SUBWORKFLOWS
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
*/
//
// MODULE: Installed directly from nf-core/modules
//
include { FASTQC } from '../modules/nf-core/modules/fastqc/main'
include { MULTIQC } from '../modules/nf-core/modules/multiqc/main'
include { CUSTOM_DUMPSOFTWAREVERSIONS } from '../modules/nf-core/modules/custom/dumpsoftwareversions/main'
2022-02-18 15:51:01 +00:00
include { CAT_FASTQ } from '../modules/nf-core/modules/cat/fastq/main'
2022-03-03 16:42:02 +00:00
include { MALT_RUN } from '../modules/nf-core/modules/malt/run/main'
include { KRAKEN2_KRAKEN2 } from '../modules/nf-core/modules/kraken2/kraken2/main'
2022-02-18 15:51:01 +00:00
2022-02-18 06:55:14 +00:00
/*
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
RUN MAIN WORKFLOW
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
*/
// Info required for completion email and summary
def multiqc_report = []
workflow TAXPROFILER {
ch_versions = Channel.empty()
2022-03-26 20:54:50 +00:00
/*
SUBWORKFLOW: Read in samplesheet, validate and stage input files
*/
2022-02-18 06:55:14 +00:00
INPUT_CHECK (
ch_input
)
ch_versions = ch_versions.mix(INPUT_CHECK.out.versions)
2022-02-19 11:36:08 +00:00
DB_CHECK (
ch_databases
)
2022-03-26 20:54:50 +00:00
/*
MODULE: Run FastQC
*/
2022-03-24 14:35:09 +00:00
ch_input_for_fastqc = INPUT_CHECK.out.fastq.mix( INPUT_CHECK.out.nanopore ).dump(tag: "input_to_fastq")
2022-03-28 16:20:10 +00:00
2022-02-18 06:55:14 +00:00
FASTQC (
2022-03-24 14:35:09 +00:00
ch_input_for_fastqc
2022-02-18 06:55:14 +00:00
)
2022-03-28 16:20:10 +00:00
2022-02-18 06:55:14 +00:00
ch_versions = ch_versions.mix(FASTQC.out.versions.first())
CUSTOM_DUMPSOFTWAREVERSIONS (
ch_versions.unique().collectFile(name: 'collated_versions.yml')
)
2022-03-26 20:54:50 +00:00
/*
SUBWORKFLOW: PERFORM PREPROCESSING
*/
2022-03-21 18:52:50 +00:00
if ( params.shortread_clipmerge ) {
2022-03-21 19:28:09 +00:00
ch_shortreads_preprocessed = SHORTREAD_PREPROCESSING ( INPUT_CHECK.out.fastq ).reads
} else {
ch_shortreads_preprocessed = INPUT_CHECK.out.fastq
2022-02-18 15:51:01 +00:00
}
2022-03-21 18:52:50 +00:00
if ( params.longread_clip ) {
2022-03-21 17:17:08 +00:00
ch_longreads_preprocessed = LONGREAD_PREPROCESSING ( INPUT_CHECK.out.nanopore ).reads
.map { it -> [ it[0], [it[1]] ] }
2022-03-18 14:12:07 +00:00
ch_versions = ch_versions.mix(LONGREAD_PREPROCESSING.out.versions.first())
2022-03-21 17:17:08 +00:00
} else {
ch_longreads_preprocessed = INPUT_CHECK.out.nanopore
}
2022-03-18 14:12:07 +00:00
2022-03-26 20:54:50 +00:00
/*
COMBINE READS WITH POSSIBLE DATABASES
*/
2022-03-03 16:42:02 +00:00
2022-03-21 19:28:09 +00:00
// e.g. output [DUMP: reads_plus_db] [['id':'2612', 'run_accession':'combined', 'instrument_platform':'ILLUMINA', 'single_end':1], <reads_path>/2612.merged.fastq.gz, ['tool':'malt', 'db_name':'mal95', 'db_params':'"-id 90"'], <db_path>/malt90]
2022-03-28 14:38:10 +00:00
ch_input_for_profiling = ch_shortreads_preprocessed
2022-03-21 17:17:08 +00:00
.mix( ch_longreads_preprocessed )
2022-03-03 16:42:02 +00:00
.combine(DB_CHECK.out.dbs)
2022-03-28 14:38:10 +00:00
.dump(tag: "reads_plus_db_clean")
2022-03-03 16:42:02 +00:00
.branch {
malt: it[2]['tool'] == 'malt'
kraken2: it[2]['tool'] == 'kraken2'
unknown: true
}
2022-03-26 20:54:50 +00:00
/*
PREPARE PROFILER INPUT CHANNELS
*/
2022-03-03 16:42:02 +00:00
// We groupTuple to have all samples in one channel for MALT as database
// loading takes a long time, so we only want to run it once per database
2022-03-28 16:20:10 +00:00
// TODO document somewhere we only accept illumina short reads for MALT?
2022-03-03 16:42:02 +00:00
ch_input_for_malt = ch_input_for_profiling.malt
2022-03-28 16:20:10 +00:00
.dump(tag: "input_to_malt_prefilter")
.filter { it[0]['instrument_platform'] == 'ILLUMINA' }
.dump(tag: "input_to_malt_postfilter")
2022-03-03 16:42:02 +00:00
.map {
it ->
def temp_meta = [ id: it[2]['db_name']] + it[2]
def db = it[3]
[ temp_meta, it[1], db ]
}
.groupTuple(by: [0,2])
2022-03-26 20:54:50 +00:00
.dump(tag: "input_to_malt")
2022-03-03 16:42:02 +00:00
.multiMap {
it ->
reads: [ it[0], it[1].flatten() ]
db: it[2]
}
// We can run Kraken2 one-by-one sample-wise
ch_input_for_kraken2 = ch_input_for_profiling.kraken2
2022-03-26 20:54:50 +00:00
.dump(tag: "input_to_kraken")
2022-03-03 16:42:02 +00:00
.multiMap {
it ->
2022-03-28 14:38:10 +00:00
reads: [ it[0] + it[2], it[1] ]
2022-03-03 16:42:02 +00:00
db: it[3]
}
2022-03-26 20:54:50 +00:00
/*
MODULE: RUN PROFILING
*/
2022-03-21 18:52:50 +00:00
if ( params.run_malt ) {
MALT_RUN ( ch_input_for_malt.reads, params.malt_mode, ch_input_for_malt.db )
}
2022-02-19 11:36:08 +00:00
2022-03-21 18:52:50 +00:00
if ( params.run_kraken2 ) {
KRAKEN2_KRAKEN2 ( ch_input_for_kraken2.reads, ch_input_for_kraken2.db )
}
2022-02-19 11:36:08 +00:00
2022-03-26 20:54:50 +00:00
/*
MODULE: MultiQC
*/
2022-02-18 06:55:14 +00:00
workflow_summary = WorkflowTaxprofiler.paramsSummaryMultiqc(workflow, summary_params)
ch_workflow_summary = Channel.value(workflow_summary)
ch_multiqc_files = Channel.empty()
ch_multiqc_files = ch_multiqc_files.mix(Channel.from(ch_multiqc_config))
ch_multiqc_files = ch_multiqc_files.mix(ch_multiqc_custom_config.collect().ifEmpty([]))
ch_multiqc_files = ch_multiqc_files.mix(ch_workflow_summary.collectFile(name: 'workflow_summary_mqc.yaml'))
ch_multiqc_files = ch_multiqc_files.mix(CUSTOM_DUMPSOFTWAREVERSIONS.out.mqc_yml.collect())
ch_multiqc_files = ch_multiqc_files.mix(FASTQC.out.zip.collect{it[1]}.ifEmpty([]))
2022-03-21 18:52:50 +00:00
if (params.shortread_clipmerge) {
2022-03-21 17:25:56 +00:00
ch_multiqc_files = ch_multiqc_files.mix(SHORTREAD_PREPROCESSING.out.mqc)
2022-02-18 15:51:01 +00:00
}
2022-03-21 18:52:50 +00:00
if (params.longread_clip) {
ch_multiqc_files = ch_multiqc_files.mix(LONGREAD_PREPROCESSING.out.mqc)
}
2022-03-03 16:42:02 +00:00
if (params.run_kraken2) {
ch_multiqc_files = ch_multiqc_files.mix(KRAKEN2_KRAKEN2.out.txt.collect{it[1]}.ifEmpty([]))
ch_versions = ch_versions.mix(KRAKEN2_KRAKEN2.out.versions.first())
}
if (params.run_malt) {
ch_multiqc_files = ch_multiqc_files.mix(MALT_RUN.out.log.collect{it[1]}.ifEmpty([]))
ch_versions = ch_versions.mix(MALT_RUN.out.versions.first())
}
2022-02-18 06:55:14 +00:00
2022-03-03 17:04:03 +00:00
// TODO MALT results overwriting per database?
// TODO Versions for Karken/MALT not report?
2022-02-18 06:55:14 +00:00
MULTIQC (
ch_multiqc_files.collect()
)
multiqc_report = MULTIQC.out.report.toList()
ch_versions = ch_versions.mix(MULTIQC.out.versions)
}
/*
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
COMPLETION EMAIL AND SUMMARY
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
*/
workflow.onComplete {
if (params.email || params.email_on_fail) {
NfcoreTemplate.email(workflow, params, summary_params, projectDir, log, multiqc_report)
}
NfcoreTemplate.summary(workflow, params, log)
}
/*
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
THE END
2022-03-15 21:05:37 +00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-02-18 06:55:14 +00:00
*/