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

process {

    withName: 'SENTIEON_HAPLOTYPER' {
        ext.prefix       = { meta.num_intervals <= 1 ? "${meta.id}.haplotyper" : "${meta.id}.haplotyper.${intervals.baseName}" }
        ext.when         = { params.tools && params.tools.split(',').contains('sentieon_haplotyper') }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/"},
            pattern: "*{vcf.gz,vcf.gz.tbi}",
            saveAs: { meta.num_intervals > 1 ? null : "sentieon_haplotyper/${meta.id}/${it}" }
        ]
    }

    withName: 'MERGE_SENTIEON_HAPLOTYPER_VCFS' {
        ext.prefix       = { params.joint_germline ? "${meta.id}.haplotyper.g" : "${meta.id}.haplotyper.unfiltered" }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/sentieon_haplotyper/${meta.id}/" },
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: 'MERGE_SENTIEON_HAPLOTYPER_GVCFS' {
        ext.prefix       = { "${meta.id}.haplotyper.g" }
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/sentieon_haplotyper/${meta.id}/" },
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    if (params.tools && params.tools.contains('sentieon_haplotyper')) {
        withName: '.*:SENTIEON_HAPLOTYPER_VCF_VARIANT_FILTERING_GATK:FILTERVARIANTTRANCHES' {
            ext.args         = { "--info-key CNN_1D" }
            ext.prefix       = { "${meta.id}.haplotyper" }
            publishDir       = [
                mode: params.publish_dir_mode,
                path: { "${params.outdir}/variant_calling/sentieon_haplotyper/${meta.id}/"},
                pattern: "*{vcf.gz,vcf.gz.tbi}"
            ]
        }
    }

}
