/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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            = Conditional clause
----------------------------------------------------------------------------------------
*/

process {

    withName: '.*CALL_MOBILE_ELEMENTS:.*' {
        publishDir = [
            enabled: false
        ]
    }

    withName: '.*CALL_MOBILE_ELEMENTS:ME_SPLIT_ALIGNMENT' {
        ext.args   = { [
            '--output-fmt bam',
            '--fetch-pairs'
            ].join(' ') }
        ext.args2  = { "${meta.interval}" }
        ext.prefix = { "${meta.id}_${meta.interval}" }
    }

    withName: '.*CALL_MOBILE_ELEMENTS:RETROSEQ_DISCOVER' {
        ext.prefix = { "${meta.id}_${meta.interval}_retroseq_discover" }
    }

    withName: '.*CALL_MOBILE_ELEMENTS:RETROSEQ_CALL' {
        ext.args = { '--soft' }
        ext.prefix = { "${meta.id}_${meta.interval}_retroseq_call" }
    }

    withName: '.*CALL_MOBILE_ELEMENTS:BCFTOOLS_REHEADER_ME' {
        ext.args = "--temp-prefix ."
        ext.args2 = { '--output-type v' }
        ext.prefix = { "${meta.id}_${meta.interval}_retroseq_reheader" }
    }

    withName: '.*CALL_MOBILE_ELEMENTS:BCFTOOLS_SORT_ME' {
        ext.args = { '--output-type z --temp-dir ./' }
        ext.prefix = { "${meta.id}_${meta.interval}_retroseq_sort" }
    }

    withName: '.*CALL_MOBILE_ELEMENTS:BCFTOOLS_CONCAT_ME' {
        ext.args = { '--output-type z --allow-overlaps' }
        ext.prefix = { "${meta.id}_mobile_elements" }
    }

    withName: '.*CALL_MOBILE_ELEMENTS:SVDB_MERGE_ME' {
        ext.args = { '--bnd_distance 150 --overlap 0.5' }
        ext.prefix = { "${meta.id}_mobile_elements" }
        publishDir = [
            path: { "${params.outdir}/call_mobile_elements" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }

    withName: '.*CALL_MOBILE_ELEMENTS:TABIX_ME' {
        publishDir = [
            path: { "${params.outdir}/call_mobile_elements" },
            mode: params.publish_dir_mode,
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
        ]
    }
}
