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

//LOFREQ

process {
    if (params.tools && params.tools.split(',').contains('lofreq')) {

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

        withName:'VCFTOOLS_TSTV_COUNT'{
            errorStrategy = 'ignore'
        }

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

}
