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

//
// VCF2Cytosure workflow options
//

process {

    if ( params.analysis_type != "wes" && !params.skip_vcf2cytosure ) {

        withName: '.*GENERATE_CYTOSURE_FILES:TIDDIT_COV_VCF2CYTOSURE' {
            ext.args = { '-z 500' }
            ext.prefix = { "${meta.id}_cov" }
        }

        withName: '.*GENERATE_CYTOSURE_FILES:SPLIT_AND_FILTER_SV_VCF' {
            ext.args = { [
                "--samples ${meta.id}",
                '--output-type z',
                "--exclude 'gnomad_svAF > 0.05'"
                ].join(' ') }
            ext.prefix = { "${meta.id}" }
        }

        withName: '.*GENERATE_CYTOSURE_FILES:BCFTOOLS_REHEADER_SV_VCF' {
            beforeScript = { "echo ${meta.custid} > ${meta.custid}.txt" }
            ext.args   = { "--samples ${meta.custid}.txt" }
            ext.args2  = "--output-type v"
            ext.prefix = { "${meta.custid}" }
        }

        withName: '.*GENERATE_CYTOSURE_FILES:VCF2CYTOSURE' {
            ext.args = { [
                meta.sex.equals(1) ? '--sex male' : '--sex female',
                '--size 5000',
                '--maxbnd 5000'
                ].join(' ') }
            ext.prefix = { "${meta.custid}" ? "${meta.custid}" : "${meta.id}" }
            publishDir = [
                path: { "${params.outdir}/vcf2cytosure" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
            ]
        }
    }
}
