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

//
// Score and rank structural variants
//

process {
    withName: '.*RANK_VARIANTS_SV:.*' {
        ext.when = !params.skip_sv_annotation
        publishDir = [
            enabled: false
        ]
    }

    withName: '.*RANK_VARIANTS_SV:GENMOD_ANNOTATE' {
        ext.args = {
            (params.genome == 'GRCh37') ? '--annotate_regions --genome-build 37' : '--annotate_regions --genome-build 38'
        }
    }

    withName: '.*RANK_VARIANTS_SV:GENMOD_SCORE' {
        ext.args = " --rank_results "
    }

    withName: '.*RANK_VARIANTS_SV:GENMOD_COMPOUND' {
        ext.prefix = { "${meta.id}_ranked_sv" }
    }

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

//
// Score and rank SNVs
//

process {
    withName: '.*RANK_VARIANTS_SNV:.*' {
        ext.when = !params.skip_snv_annotation
        publishDir = [
            enabled: false
        ]
    }

    withName: '.*RANK_VARIANTS_SNV:GENMOD_ANNOTATE' {
        ext.args = {
            (params.genome == 'GRCh37') ? '--annotate_regions --genome-build 37' : '--annotate_regions --genome-build 38'
        }
    }

    withName: '.*RANK_VARIANTS_SNV:GENMOD_MODELS' {
        ext.args = " --whole_gene "
    }

    withName: '.*RANK_VARIANTS_SNV:GENMOD_SCORE' {
        ext.args = " --rank_results "
    }

    withName: '.*RANK_VARIANTS_SNV:GENMOD_COMPOUND' {
        ext.prefix = { "${meta.id}_ranked_snv" }
    }

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