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

//
// SNV annotation options
//

process {
    withName: '.*ANNOTATE_SNVS:.*' {
        ext.when = !params.skip_snv_annotation
    }

    withName: '.*ANNOTATE_SNVS:VCFANNO' {
        ext.prefix = { "${meta.id}_vcfanno" }
        publishDir = [
            enabled: false
        ]
    }

    withName: '.*ANNOTATE_SNVS:BCFTOOLS_ROH' {
        ext.args = { "--samples ${meta.probands.join(",")} --skip-indels " }
        ext.prefix = { "${meta.id}_roh" }
    }

    withName: '.*ANNOTATE_SNVS:RHOCALL_ANNOTATE' {
        ext.args = { "--v14 " }
        ext.prefix = { "${meta.id}_rohann" }
    }

    withName: '.*ANNOTATE_SNVS:VCFANNO' {
        ext.prefix = { "${meta.id}_rohann_vcfanno" }
    }

    withName: '.*ANNOTATE_SNVS:UPD_SITES' {
        ext.prefix = { "${meta.id}_rohann_vcfanno_upd_sites" }
        ext.args = {"--af-tag GNOMADAF --proband ${meta.upd_child} --mother ${meta.mother} --father ${meta.father} sites"}
    }

    withName: '.*ANNOTATE_SNVS:UPD_REGIONS' {
        ext.prefix = { "${meta.id}_rohann_vcfanno_upd_regions" }
        ext.args = {"--af-tag GNOMADAF --proband ${meta.upd_child} --mother ${meta.mother} --father ${meta.father} regions --min-size 5 --min-sites 1"}
        ext.when = { !(workflow.profile.tokenize(',').intersect(['test', 'test_one_sample']).size() >= 1) || workflow.stubRun }
    }

    withName: '.*ANNOTATE_SNVS:CHROMOGRAPH_SITES' {
        ext.prefix = { "${meta7.id}_rohann_vcfanno_upd_sites_chromograph" }
        ext.args = { "--euploid" }
        tag =  {"${meta7.id}"}
        publishDir = [
            path: { "${params.outdir}/annotate_snv" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*ANNOTATE_SNVS:CHROMOGRAPH_REGIONS' {
        ext.prefix = { "${meta6.id}_rohann_vcfanno_upd_regions_chromograph" }
        ext.args = { '--euploid' }
        ext.when = { !(workflow.profile.tokenize(',').intersect(['test', 'test_one_sample']).size() >= 1) || workflow.stubRun }
        tag =  {"${meta6.id}"}
        publishDir = [
            path: { "${params.outdir}/annotate_snv" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*ANNOTATE_SNVS:BCFTOOLS_VIEW' {
        ext.prefix = { "${meta.id}_rohann_vcfanno_filter" }
        ext.args = { '--output-type z --exclude "INFO/GNOMADAF > 0.70 | INFO/GNOMADAF_popmax > 0.70" ' }
    }

    withName: '.*ANNOTATE_SNVS:GATK4_SELECTVARIANTS' {
        ext.prefix = { "${meta.id}_${intervals.simpleName}" }
    }

    withName: '.*ANNOTATE_SNVS:ENSEMBLVEP_SNV' {
        ext.prefix = { "${vcf.simpleName}_rohann_vcfanno_filter_vep" }
        ext.args   = [
            '--dir_plugins vep_cache/Plugins',
            '--plugin LoFtool,vep_cache/LoFtool_scores.txt',
            '--plugin pLI,vep_cache/pLI_values_107.txt',
            '--plugin SpliceAI,snv=vep_cache/spliceai_21_scores_raw_snv_-v1.3-.vcf.gz,indel=vep_cache/spliceai_21_scores_raw_snv_-v1.3-.vcf.gz',
            '--plugin MaxEntScan,vep_cache/fordownload,SWA,NCSS',
            '--distance 5000',
            '--buffer_size 20000',
            '--format vcf --max_sv_size 248956422',
            '--appris --biotype --cache --canonical --ccds --compress_output bgzip',
            '--domains --exclude_predicted --force_overwrite',
            '--hgvs --humdiv --no_progress --no_stats --numbers',
            '--merged --polyphen p --protein --offline --regulatory --sift p --symbol --tsl',
            '--uniprot --vcf'
        ].join(' ')
    }

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

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

}
