/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Config file for defining DSL2 per module options and publishing paths
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Available keys to override module options:
        ext.args            = Additional arguments appended to command in module.
        ext.args2           = Second set of arguments appended to command in module (multi-tool modules).
        ext.args3           = Third set of arguments appended to command in module (multi-tool modules).
        ext.prefix          = File name prefix for output files.
        ext.when            = Conditional clause
----------------------------------------------------------------------------------------
*/

//
// General configuration options
//

process {

    withName: 'CUSTOM_DUMPSOFTWAREVERSIONS' {
        publishDir = [
            path: { "${params.outdir}/pipeline_info" },
            mode: params.publish_dir_mode,
            pattern: '*_versions.yml'
        ]
    }
}

//
// Read QC options
//

process {

    if (!params.skip_fastqc) {
        withName: '.*RAREDISEASE:FASTQC' {
            ext.args = '--quiet'
            publishDir = [
                path: { "${params.outdir}/fastqc/${meta.id}" },
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
            ]
        }
    }
}

//
// Smncopynumbercaller options
//

process {
    withName: '.*SMNCOPYNUMBERCALLER' {
        ext.args = {
        (params.genome == 'GRCh37') ? '--genome 37' : '--genome 38'
        }
        ext.prefix = { "${meta.id}" }
        publishDir = [
            path: { "${params.outdir}/smncopynumbercaller" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
        ]
    }
}

//
// Peddy options
//

process {
    withName: '.*:PEDDY' {
        publishDir = [
            path: { "${params.outdir}/peddy" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }
}

//
// Multiqc options
//

process {
    withName: '.*RAREDISEASE:MULTIQC' {
        ext.args   = { params.multiqc_title ? "--title \"$params.multiqc_title\"" : '' }
        publishDir = [
            path: { "${params.outdir}/multiqc" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }
}
