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

// DEEPVARIANT

process {

    withName: 'DEEPVARIANT' {
        ext.args   = { params.wes ?  "--model_type WES" : "--model_type WGS" }
        ext.prefix = { meta.num_intervals <= 1 ? "${meta.id}.deepvariant" : "${meta.id}.deepvariant.${intervals.simpleName}" }
        ext.when   = { params.tools && params.tools.split(',').contains('deepvariant') }
        publishDir = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/" },
            pattern: "*{vcf.gz,vcf.gz.tbi}",
            saveAs: { meta.num_intervals > 1 ? null : "deepvariant/${meta.id}/${it}" }
        ]
    }

    withName: 'MERGE_DEEPVARIANT_.*' {
        ext.prefix = { "${meta.id}.deepvariant" }
        publishDir = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/variant_calling/deepvariant/${meta.id}/" },
            pattern: "*{vcf.gz,vcf.gz.tbi}"
        ]
    }

    withName: 'MERGE_DEEPVARIANT_GVCF' {
        ext.prefix = { "${meta.id}.deepvariant.g" }
    }

}
