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

//
// Sentieon SNV calling options
//

process {

    withName: '.*CALL_SNV_SENTIEON:.*' {
        ext.when = params.variant_caller.equals("sentieon")
    }

    withName: '.*CALL_SNV:CALL_SNV_SENTIEON:SENTIEON_DNASCOPE' {
        ext.prefix = { "${meta.id}_dnascope" }
        ext.args2  = { [
            params.variant_type      ? "--var_type ${params.variant_type}"  : '',
            params.pcr_amplification ? '' : "--pcr_indel_model NONE"
        ].join(" ") }
    }

    withName: '.*CALL_SNV:CALL_SNV_SENTIEON:SENTIEON_DNAMODELAPPLY' {
        ext.prefix = { "${meta.id}_dnamodelapply" }
    }

    withName: '.*CALL_SNV:CALL_SNV_SENTIEON:BCF_FILTER_ONE' {
        ext.args = "-s 'ML_FAIL' -i 'INFO/ML_PROB <= 0.95' -m x -Oz"
        ext.prefix = { "${meta.id}_mlfiltered_0.95" }
    }

    withName: '.*CALL_SNV:CALL_SNV_SENTIEON:BCF_FILTER_TWO' {
        ext.args = "-i FILTER='\"PASS\"' -m x -Oz"
        ext.prefix = { "${meta.id}_passed" }
    }

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

    withName: '.*CALL_SNV:CALL_SNV_SENTIEON:REMOVE_DUPLICATES_SEN' {
        ext.args = '--output-type z --rm-dup none'
        ext.prefix = { "${meta.id}_split_rmdup" }
        publishDir = [
            enabled: params.skip_mt_analysis,
            path: { "${params.outdir}/call_snv" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

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