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

//
// General configuration options
//

process {
    withName: 'GUNZIP|COMBINE_UNIPROT|DOWNLOAD_PDBMMCIF' {
        publishDir = [
            path: {"${params.outdir}/DBs/${params.mode}/${params.alphafold2_mode}"},
            mode: 'symlink',
            saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
        ]
    }
}

if (params.alphafold2_mode == 'standard') {
    process {
        withName: 'RUN_ALPHAFOLD2' {
            ext.args   = [
                params.use_gpu ? '--use_gpu_relax=true' : '--use_gpu_relax=false',
                params.max_template_date ? "--max_template_date ${params.max_template_date}" : ''
            ].join(' ').trim()
            publishDir = [
                path: { "${params.outdir}/${params.mode}/${params.alphafold2_mode}" },
                mode: 'copy',
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
            ]
        }
    }
}


if (params.alphafold2_mode == 'split_msa_prediction') {
    process {
        withName: 'RUN_ALPHAFOLD2_MSA' {
            ext.args =  params.max_template_date ? "--max_template_date ${params.max_template_date}" : ''
            publishDir = [
                path: { "${params.outdir}/${params.mode}/${params.alphafold2_mode}" },
                mode: 'copy',
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }

        withName: 'RUN_ALPHAFOLD2_PRED' {
            ext.args   = params.use_gpu ? '--use_gpu_relax=true' : '--use_gpu_relax=false'
            publishDir = [
                path: { "${params.outdir}/${params.mode}/${params.alphafold2_mode}" },
                mode: 'copy',
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
            ]
        }
    }
}
