/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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.args = "--TMP_DIR ."
        ext.prefix = { "${meta.id}_multiplemetrics" }
    }

    withName: '.*QC_BAM:PICARD_COLLECTHSMETRICS' {
        ext.args = "--TMP_DIR ."
        ext.when = { !params.target_bed.equals(null) }
        ext.prefix = { "${meta.id}_hsmetrics" }
    }

    if (!params.skip_qualimap) {
        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'
        ext.prefix = { "${meta.id}_tidditcov" }
    }

    withName: '.*QC_BAM:CHROMOGRAPH_COV' {
        ext.args = '--euploid --step 500'
        ext.prefix = { "${meta2.id}_chromographcov" }
    }

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

    withName: '.*QC_BAM:NGSBITS_SAMPLEGENDER' {
        //  NGSBITS_SAMPLEGENDER needs a chrX and chrY in order to run so we skip it for the two test profiles
        ext.when = { !(workflow.profile.tokenize(',').intersect(['test', 'test_one_sample', 'test_sentieon']).size() >= 1) || workflow.stubRun }
        ext.prefix = { "${meta.id}_ngsbits_sex" }
        publishDir = [
            path: { "${params.outdir}/ngsbits_samplegender" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*QC_BAM:PICARD_COLLECTWGSMETRICS' {
        ext.args = "--TMP_DIR ."
        ext.when = { params.analysis_type.equals("wgs") && !params.aligner.equals("sentieon") }
        ext.prefix = { "${meta.id}_wgsmetrics" }
    }

    withName: '.*QC_BAM:PICARD_COLLECTWGSMETRICS_Y' {
        ext.args = "--TMP_DIR ."
        ext.when = { params.analysis_type.equals("wgs") && !params.aligner.equals("sentieon") }
        ext.prefix = { "${meta.id}_wgsmetrics_y" }
    }

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

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