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

// PREPARE INTERVALS

process {

    withName: 'BUILD_INTERVALS' {
        ext.args   = { "-v FS='\t' -v OFS='\t' '{ print \$1, \"0\", \$2 }'" }
        ext.suffix = { "bed" }
    }

    withName: 'CREATE_INTERVALS_BED' {
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/reference/intervals" },
            pattern: "*bed",
            saveAs: { params.save_reference || params.build_only_index ? it : null }
        ]
    }

    withName: 'GATK4_INTERVALLISTTOBED' {
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/reference/intervals" },
            pattern: "*bed",
            saveAs: { params.save_reference || params.build_only_index ? it : null }
        ]
    }

    withName: 'TABIX_BGZIPTABIX_INTERVAL_SPLIT|TABIX_BGZIPTABIX_INTERVAL_COMBINED' {
        ext.prefix       = {"${meta.id}"}
        publishDir       = [
            mode: params.publish_dir_mode,
            path: { "${params.outdir}/reference/intervals" },
            pattern: "*bed.gz",
            saveAs: { params.save_reference || params.build_only_index ? it : null }
        ]
    }
}
