/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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
----------------------------------------------------------------------------------------
*/

//
// Bam QC options
//

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

    withName: '.*QC_BAM:PICARD_COLLECTMULTIPLEMETRICS' {
        ext.prefix = { "${meta.id}_multiplemetrics" }
    }

    withName: '.*QC_BAM:PICARD_COLLECTHSMETRICS' {
        ext.when = { params.target_bed }
        ext.prefix = { "${meta.id}_hsmetrics" }
    }

    withName: '.*QC_BAM:QUALIMAP_BAMQC' {
        ext.prefix = { "${meta.id}_qualimap" }
    }

    withName: '.*QC_BAM:TIDDIT_COV' {
        ext.args = '-z 500 -w'
        ext.prefix = { "${meta.id}_tidditcov" }
    }

    withName: '.*QC_BAM:UCSC_WIGTOBIGWIG' {
        ext.args = '-clip'
    }

    withName: '.*QC_BAM:MOSDEPTH' {
        ext.args = '--d4'
        ext.prefix = { "${meta.id}_mosdepth" }
    }

    withName: '.*QC_BAM:PICARD_COLLECTWGSMETRICS' {
        ext.when = params.aligner.equals("bwamem2")
        ext.prefix = { "${meta.id}_wgsmetrics" }
    }

    withName: '.*QC_BAM:PICARD_COLLECTWGSMETRICS_Y' {
        ext.when = params.aligner.equals("bwamem2")
        ext.prefix = { "${meta.id}_wgsmetrics_y" }
    }

    withName: '.*QC_BAM:SENTIEON_WGSMETRICS' {
        ext.when = params.aligner.equals("sentieon")
        ext.prefix = { "${meta.id}_wgsmetrics" }
    }

    withName: '.*QC_BAM:SENTIEON_WGSMETRICS_Y' {
        ext.when = params.aligner.equals("sentieon")
        ext.prefix = { "${meta.id}_wgsmetrics_y" }
    }
}
