/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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   = When to run the module.
----------------------------------------------------------------------------------------
*/

// PREPARE_RECALIBRATION

process {

    withName: 'GATK4_BASERECALIBRATOR|GATK4_BASERECALIBRATOR_SPARK' {
        ext.prefix       = { meta.num_intervals <= 1 ? "${meta.id}.recal" : "${meta.id}_${intervals.simpleName}.recal" }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/preprocessing/" },
            pattern: "*table",
            saveAs: { meta.num_intervals > 1 ? null : "recal_table/${meta.id}/${it}" }
        ]
    }

    withName: 'GATK4_GATHERBQSRREPORTS' {
        ext.prefix       = {"${meta.id}.recal"}
        ext.when         = { meta.num_intervals > 1 }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/preprocessing/recal_table/${meta.id}/" },
            pattern: "*table",
        ]
    }
}
