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

//
// Repeat expansion calling options
//

process {
    withName: '.*CALL_REPEAT_EXPANSIONS:.*' {
        ext.when = { params.analysis_type != "wes" }
        publishDir = [
            enabled: false
        ]
    }

    withName: '.*CALL_REPEAT_EXPANSIONS:EXPANSIONHUNTER' {
        ext.args =  { ("${meta.sex}" == '1') ? '--sex male' : '--sex female' }
        ext.prefix = { "${meta.id}_exphunter" }
    }

    withName: '.*CALL_REPEAT_EXPANSIONS:SAMTOOLS_SORT' {
        ext.prefix = { "${meta.id}_exphunter_sorted" }
        publishDir = [
            path: { "${params.outdir}/repeat_expansions" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
        ]
    }

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

    withName: '.*CALL_REPEAT_EXPANSIONS:BCFTOOLS_REHEADER_EXP' {
        ext.args = "--temp-prefix ."
        ext.prefix = { "${meta.id}_reheader" }
    }

    withName: '.*CALL_REPEAT_EXPANSIONS:RENAMESAMPLE_EXP' {
        publishDir = [
            path: { "${params.outdir}/repeat_expansions" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null :
                filename.contains('_renam.vcf.gz') ? "${meta.id}_repeat_expansion.vcf.gz" :
                filename },
        ]
    }

    withName: '.*CALL_REPEAT_EXPANSIONS:TABIX_EXP_RENAME' {
        publishDir = [
            path: { "${params.outdir}/repeat_expansions" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null :
                filename.contains('_renam.vcf.gz.tbi') ? "${meta.id}_repeat_expansion.vcf.gz.tbi" :
                filename },
        ]
    }

    withName: '.*CALL_REPEAT_EXPANSIONS:SPLIT_MULTIALLELICS_EXP' {
        ext.args = '--output-type z --multiallelics -both'
        ext.prefix = { "${meta.id}_split_exp" }
    }

    withName: '.*CALL_REPEAT_EXPANSIONS:SVDB_MERGE_REPEATS' {
        ext.args = {"--notag"}
    }

    withName: '.*CALL_REPEAT_EXPANSIONS:STRANGER' {
        ext.prefix = { "${meta.id}_stranger" }
    }

    withName: '.*CALL_REPEAT_EXPANSIONS:COMPRESS_STRANGER' {
        ext.prefix = { "${meta.id}_repeat_expansion_stranger" }
        ext.args   = '--output-type z'
        publishDir = [
            path: { "${params.outdir}/repeat_expansions" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
        ]
    }

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