/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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   = When to run the module.
----------------------------------------------------------------------------------------
*/

// SENTIEON JOINT_GERMLINE

process {

    withName: 'SENTIEON_GVCFTYPER' {
        ext.args         = { "--allow-old-rms-mapping-quality-annotation-data" }
        ext.prefix       = { meta.intervals_name }
        publishDir       = [
            enabled: false
        ]
    }

    if (params.tools && params.tools.contains('sentieon_haplotyper') && params.joint_germline) {
        withName: 'NFCORE_SAREK:SAREK:BAM_VARIANT_CALLING_GERMLINE_ALL:BAM_JOINT_CALLING_GERMLINE_SENTIEON:BCFTOOLS_SORT' {
            ext.prefix       = { vcf.baseName - ".vcf" + ".sort" }
            publishDir       = [
                enabled: false
            ]
        }

        withName: 'NFCORE_SAREK:SAREK:BAM_VARIANT_CALLING_GERMLINE_ALL:BAM_JOINT_CALLING_GERMLINE_SENTIEON:MERGE_GENOTYPEGVCFS' {
            ext.prefix       = "joint_germline"
            publishDir       = [
                mode: params.publish_dir_mode,
                path: { "${params.outdir}/variant_calling/sentieon_haplotyper/joint_variant_calling/" },
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
                pattern: "*{vcf.gz,vcf.gz.tbi}"
            ]
        }
    }

    withName: 'SENTIEON_VARCAL_INDEL' {
        ext.prefix = { "${meta.id}_INDEL" }
        ext.args   = "--annotation QD --annotation MQRankSum --annotation ReadPosRankSum --annotation FS --annotation SOR --annotation DP --var_type INDEL"
        publishDir = [
            enabled: false
        ]
    }

    withName: 'SENTIEON_APPLYVARCAL_INDEL' {
        ext.prefix    = { "joint_germline_recalibrated" }
        ext.args      = '--sensitivity 99.9 --var_type INDEL'
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/sentieon_haplotyper/joint_variant_calling/"},
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
            pattern: "*{vcf.gz,vcf.gz.tbi}"
        ]
    }

    withName: 'SENTIEON_VARCAL_SNP' {
        ext.prefix = { "${meta.id}_SNP" }
        ext.args   = "--annotation QD --annotation MQRankSum --annotation ReadPosRankSum --annotation FS --annotation SOR --annotation DP --var_type SNP"
        publishDir = [
            enabled: false
        ]
    }

    withName: 'SENTIEON_APPLYVARCAL_SNP' {
        ext.prefix    = { "${meta.id}_SNP" }
        ext.args      = '--sensitivity 99.9 --var_type SNP'
    }

}
