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

// CONTROLFREEC

process {

    withName: 'ASSESS_SIGNIFICANCE' {
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/controlfreec/${meta.id}/" },
            pattern: "*{.p.value.txt}"
        ]
    }

    withName: 'FREEC_.*' {
        ext.when         = { params.tools && params.tools.split(',').contains('controlfreec') }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/controlfreec/${meta.id}/" },
            pattern: "*{BedGraph,cpn,txt,_CNVs}"
        ]
    }

    withName: 'FREEC2BED' {
        ext.args = { "${params.cf_ploidy}" }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/controlfreec/${meta.id}/" },
            pattern: "*bed"
        ]
    }

    withName: 'FREEC2CIRCOS' {
        ext.args = { "${params.cf_ploidy}" }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/controlfreec/${meta.id}/" },
            pattern: "*circos.txt"
        ]
    }

    withName: 'MAKEGRAPH' {
        ext.args = { "${params.cf_ploidy}" }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/controlfreec/${meta.id}/" },
            pattern: "*png"
        ]
    }

// TUMOR_ONLY_VARIANT_CALLING
    withName: 'FREEC_TUMORONLY' {
        ext.args = {[
                "sample":[
                    inputformat: 'pileup',
                    mateorientation: 'FR'
                ],
                "general" :[
                    bedgraphoutput: "TRUE",
                    breakpointthreshold: params.wes ? "1.2" : "0.8", //Values taken from Freec example configs
                    breakpointtype: params.wes ? "4" : "2", // Values taken from Freec example configs
                    coefficientofvariation: params.cf_coeff,
                    contamination: params.cf_contamination ?: "",
                    contaminationadjustment: params.cf_contamination_adjustment ? "TRUE" : "",
                    forcegccontentnormalization: params.wes ? "1" : "0",
                    minimalsubclonepresence: params.wes ? "30" : "20",
                    noisydata: params.wes ? "TRUE" : "FALSE",
                    ploidy: params.cf_ploidy,
                    printNA:  params.wes ? "FALSE" : "TRUE",
                    readcountthreshold:  params.wes ? "50" : "10",
                    sex: meta.sex,
                    //uniquematch: not set
                    window: params.cf_window ?: ""
                    ],
                "BAF":[
                    minimalcoverageperposition: params.cf_mincov ?: "",
                    minimalqualityperposition: params.cf_minqual ?: "",
                    //"shiftinquality": (optional)not set
                ]
            ]
        }
    }

// PAIR_VARIANT_CALLING
    withName: 'FREEC_SOMATIC' {
        ext.args = {[
                "sample":[
                    inputformat: 'pileup',
                    mateorientation: 'FR'
                ],
                "control":[
                    inputformat: "pileup",
                    mateorientation: "FR"
                ],
                "general" :[
                    bedgraphoutput: "TRUE",
                    breakpointthreshold: params.wes ? "1.2" : "0.8", //Values taken from Freec example configs
                    breakpointtype: params.wes ? "4" : "2", // Values taken from Freec example configs
                    coefficientofvariation: params.cf_coeff,
                    contamination: params.cf_contamination ?: "",
                    contaminationadjustment: params.cf_contamination_adjustment ? "TRUE" : "",
                    forcegccontentnormalization: params.wes ? "1" : "0",
                    minimalsubclonepresence: params.wes ? "30" : "20",
                    noisydata: params.wes ? "TRUE" : "FALSE",
                    ploidy: params.cf_ploidy,
                    printNA:  params.wes ? "FALSE" : "TRUE",
                    readcountthreshold:  params.wes ? "50" : "10",
                    sex: meta.sex,
                    //uniquematch: not set
                    window: params.cf_window ?: ""
                    ],
                "BAF":[
                    minimalcoverageperposition: params.cf_mincov ?: "",
                    minimalqualityperposition: params.cf_minqual ?: "",
                    //"shiftinquality": (optional)not set
                ]
            ]
        }
    }
}
