/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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: '.*POSTPROCESS_MT_CALLS:GATK4_MERGEVCFS_LIFT_UNLIFT_MT' {
        ext.prefix = { "${meta.id}_merged_liftunlift" }
    }

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

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

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

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

    withName: '.*POSTPROCESS_MT_CALLS:ADD_VARCALLER_TO_BED' {
        ext.args2   = '-s 1 -b 2 -e 3'
    }

    withName: '.*POSTPROCESS_MT_CALLS:BCFTOOLS_ANNOTATE' {
        ext.args = "-c CHROM,FROM,TO,FOUND_IN --output-type z"
        ext.prefix = { "${meta.id}_mitochondria" }
        publishDir = [
            path: { "${params.outdir}/call_snv/mitochondria" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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

}
