/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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: '.*ALIGN:.*' {
        publishDir = [
            enabled: false
        ]
    }

    if (!params.skip_fastp) {
        withName: '.*ALIGN:FASTP' {
            ext.args = { [
                params.min_trimmed_length ? "--length_required ${params.min_trimmed_length}" : '',
                '--correction',
                '--overrepresentation_analysis'
            ].join(' ').trim() }
            publishDir = [
                path: { "${params.outdir}/trimming" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }
    }

    if (params.save_mapped_as_cram) {
        withName: '.*ALIGN:SAMTOOLS_VIEW' {
            ext.args   = { '--output-fmt cram --write-index' }
            ext.prefix = { "${meta.id}_sorted_md" }
            publishDir = [
                path: { "${params.outdir}/alignment" },
                mode: params.publish_dir_mode,
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }
    }
}
