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

// CNVKIT

process {

    withName: 'CNVKIT_BATCH' {
        ext.args   = { params.wes ? "--method hybrid --diagram --scatter" : "--method wgs --diagram --scatter" }
        ext.when   = { params.tools && params.tools.split(',').contains('cnvkit') }
        publishDir = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/cnvkit/${meta.id}/" },
            pattern: "*{bed,cnn,cnr,cns,pdf,png}"
        ]
    }

    withName: '.*:BAM_VARIANT_CALLING_CNVKIT:CNVKIT_CALL' {
        ext.when   = { params.tools && params.tools.split(',').contains('cnvkit') }
        publishDir = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/cnvkit/${meta.id}/" },
            pattern: "*{cns}"
        ]
    }
    withName: '.*:BAM_VARIANT_CALLING_GERMLINE_ALL:BAM_VARIANT_CALLING_CNVKIT:CNVKIT_CALL' {
        ext.prefix = { "${cns.baseName}.germline.call" }
        ext.args   = "--filter ci"
    }
    withName: '.*:BAM_VARIANT_CALLING_SOMATIC_ALL:BAM_VARIANT_CALLING_CNVKIT:CNVKIT_CALL' {
        ext.prefix = { "${cns.baseName}.somatic.call" }
    }
    withName: '.*:BAM_VARIANT_CALLING_TUMOR_ONLY_ALL:BAM_VARIANT_CALLING_CNVKIT:CNVKIT_CALL' {
        ext.prefix = { "${cns.baseName}.tumor_only.call" }
    }

    withName: 'CNVKIT_EXPORT' {
        ext.args = "vcf"
        ext.prefix = { "${meta.id}.cnvcall" }
        ext.when   = { params.tools && params.tools.split(',').contains('cnvkit') }
        publishDir = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/cnvkit/${meta.id}/" },
            pattern: "*{vcf}"
        ]
    }

    withName: 'CNVKIT_GENEMETRICS' {
        ext.prefix = { "${cnr.baseName}.genemetrics" }
        ext.when   = { params.tools && params.tools.split(',').contains('cnvkit') }
        publishDir = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/cnvkit/${meta.id}/" },
            pattern: "*{tsv}"
        ]
    }
}
