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

//
// Structural variant annotation options
//

process {

    if (!params.skip_sv_annotation) {
        withName: '.*ANNOTATE_STRUCTURAL_VARIANTS:.*' {
            publishDir = [
                enabled: false
            ]
        }

        withName: '.*ANNOTATE_STRUCTURAL_VARIANTS:SVDB_QUERY_BEDPE' {
            ext.when  = {!params.svdb_query_bedpedbs.equals(null)}
            ext.prefix = { "${meta.id}_bedpedb" }
        }

        withName: '.*ANNOTATE_STRUCTURAL_VARIANTS:SVDB_QUERY_DB' {
            ext.when  = {!params.svdb_query_dbs.equals(null)}
            ext.prefix = { "${meta.id}_vcfdb" }
        }

        withName: '.*ANNOTATE_STRUCTURAL_VARIANTS:PICARD_SORTVCF' {
            ext.prefix = { "${meta.id}_svdbquery" }
        }

        withName: '.*ANNOTATE_STRUCTURAL_VARIANTS:BCFTOOLS_VIEW' {
            ext.prefix = { "${meta.id}_view" }
        }

        withName: '.*ANNOTATE_STRUCTURAL_VARIANTS:ENSEMBLVEP_SV' {
            ext.args = { [
                '--dir_cache vep_cache',
                '--dir_plugins vep_cache/Plugins',
                '--plugin pLI,pLI_values.txt',
                '--appris --biotype --buffer_size 100 --canonical --cache --ccds',
                '--compress_output bgzip --distance 5000 --domains',
                '--exclude_predicted --force_overwrite --format vcf',
                '--fork 4 --hgvs --humdiv --max_sv_size 248956422 --merged',
                '--no_progress --numbers --per_gene --polyphen p',
                '--protein --offline --regulatory --sift p',
                '--symbol --tsl --uniprot --vcf'
            ].join(' ') }
            ext.prefix = { "${meta.id}_svdbquery_vep" }
            publishDir = [
                path: { "${params.outdir}/annotate_sv" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

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