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

//
// Mitochondrial annotation options
//

process {

    withName: '.*ANALYSE_MT:MERGE_ANNOTATE_MT:GATK4_MERGEVCFS_LIFT_UNLIFT_MT' {
        ext.prefix = { "${meta.id}_merged" }
    }

    withName: '.*ANALYSE_MT:MERGE_ANNOTATE_MT:GATK4_VARIANTFILTRATION_MT' {
        ext.prefix = { "${meta.id}_filt" }
    }

    withName: '.*ANALYSE_MT:MERGE_ANNOTATE_MT:SPLIT_MULTIALLELICS_MT' {
        ext.args = '--output-type z --multiallelics -both'
        ext.prefix = { "${meta.id}_split" }
    }

    withName: '.*ANALYSE_MT:MERGE_ANNOTATE_MT:REMOVE_DUPLICATES_MT' {
        ext.args = '--output-type z --rm-dup none'
        ext.prefix = { "${meta.id}_split_rmdup" }
    }

    withName: '.*ANALYSE_MT:MERGE_ANNOTATE_MT:BCFTOOLS_MERGE_MT' {
        ext.args = '--output-type z'
        ext.prefix = { "${meta.id}_merge_mt" }
    }

    withName: '.*ANALYSE_MT:MERGE_ANNOTATE_MT:ENSEMBLVEP_MT' {
        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 0',
            '--buffer_size 20000',
            '--format vcf --fork 4 --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 --vcf',
            '--uniprot'
        ].join(' ')
    }

    withName: '.*ANALYSE_MT:MERGE_ANNOTATE_MT:ZIP_TABIX_HMTNOTE' {
        ext.prefix = { "${meta.id}_vep_vcfanno_hmtnote_mt" }
        publishDir = [
            path: { "${params.outdir}/annotate_mt" },
            mode: params.publish_dir_mode,
            pattern: "*{vcf.gz,vcf.gz.tbi}",
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*ANALYSE_MT:MERGE_ANNOTATE_MT:HMTNOTE_ANNOTATE' {
        ext.prefix = { "${meta.id}_vep_vcfanno_hmtnote_mt" }
        ext.args = '--offline'
        publishDir = [
            enabled: false
        ]
    }

    withName: '.*ANALYSE_MT:MERGE_ANNOTATE_MT:HAPLOGREP2_CLASSIFY_MT' {
        ext.prefix = { "${meta.id}_haplogrep" }
        publishDir = [
            path: { "${params.outdir}/annotate_mt" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

}
