/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    nf-core/funcscan Nextflow base config file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    A 'blank slate' config file, appropriate for general use on most high performance
    compute environments. Assumes that all software is installed and available on
    the PATH. Runs in `local` mode - all jobs will be run on the logged in environment.
----------------------------------------------------------------------------------------
*/

process {

    cpus   = { check_max( 1    * task.attempt, 'cpus'   ) }
    memory = { check_max( 6.GB * task.attempt, 'memory' ) }
    time   = { check_max( 4.h  * task.attempt, 'time'   ) }

    errorStrategy = { task.exitStatus in ((130..145) + 104) ? 'retry' : 'finish' }
    maxRetries    = 1
    maxErrors     = '-1'

    // Process-specific resource requirements
    // NOTE - Please try and re-use the labels below as much as possible.
    //        These labels are used and recognised by default in DSL2 files hosted on nf-core/modules.
    //        If possible, it would be nice to keep the same label naming convention when
    //        adding in your local modules too.
    // See https://www.nextflow.io/docs/latest/config.html#config-process-selectors

    withLabel:process_single {
        cpus   = { check_max( 1                  , 'cpus'    ) }
        memory = { check_max( 6.GB * task.attempt, 'memory'  ) }
        time   = { check_max( 1.h  * task.attempt, 'time'    ) }
    }
    withLabel:process_low {
        cpus   = { check_max( 2     * task.attempt, 'cpus'    ) }
        memory = { check_max( 12.GB * task.attempt, 'memory'  ) }
        time   = { check_max( 1.h   * task.attempt, 'time'    ) }
    }
    withLabel:process_medium {
        cpus   = { check_max( 6     * task.attempt, 'cpus'    ) }
        memory = { check_max( 36.GB * task.attempt, 'memory'  ) }
        time   = { check_max( 1.h   * task.attempt, 'time'    ) }
    }
    withLabel:process_high {
        cpus   = { check_max( 12    * task.attempt, 'cpus'    ) }
        memory = { check_max( 72.GB * task.attempt, 'memory'  ) }
        time   = { check_max( 1.h  * task.attempt, 'time'     ) }
    }
    withLabel:process_long {
        time   = { check_max( 20.h  * task.attempt, 'time'    ) }
    }
    withLabel:process_high_memory {
        memory = { check_max( 200.GB * task.attempt, 'memory' ) }
    }
    withLabel:error_ignore {
        errorStrategy = 'ignore'
    }
    withLabel:error_retry {
        errorStrategy = 'retry'
        maxRetries    = 2
    }
    withName:CUSTOM_DUMPSOFTWAREVERSIONS {
        cache = false
    }

    /*
    * Resource specifications
    */

    withName: GUNZIP {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: UNTAR {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName:BIOAWK {
        cache = false
    }

    withName: PROKKA {
        memory = { check_max( 8.GB * task.attempt, 'memory' ) }
        cpus   = { check_max( 4    * task.attempt, 'cpus'    ) }
        time   = { check_max( 8.h  * task.attempt, 'time'    ) }
    }

    withName: PRODIGAL_GFF {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: PRODIGAL_GBK {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: BAKTA_BAKTA {
        memory = { check_max( 64.GB * task.attempt, 'memory' ) }
        cpus   = { check_max( 8    * task.attempt, 'cpus'    ) }
        time   = { check_max( 8.h  * task.attempt, 'time'    ) }
    }

    withName: ABRICATE_RUN {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = { check_max( 4    * task.attempt, 'cpus'    ) }
    }

    withName: AMRFINDERPLUS_RUN {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: DEEPARG_DOWNLOADDATA {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = 1
        time   = { check_max( 2.h  * task.attempt, 'time'     ) }
    }

    withName: DEEPARG_PREDICT {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: FARGENE {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = { check_max( 4    * task.attempt, 'cpus'    ) }
    }

    withName: RGI_MAIN {
        memory = { check_max( 28.GB * task.attempt, 'memory' ) }
        cpus   = { check_max( 4    * task.attempt, 'cpus'    ) }
    }

    withName: AMPIR {
        memory = { check_max( 8.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: AMPLIFY_PREDICT {
        memory = { check_max( 16.GB * task.attempt, 'memory' ) }
        cpus   = 1
        time   = { check_max( 24.h  * task.attempt, 'time'   ) }
    }

    withName: AMP_HMMER_HMMSEARCH {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = { check_max( 4    * task.attempt, 'cpus'    ) }
    }

    withName: MACREL_CONTIGS {
        memory = { check_max( 4.GB * task.attempt, 'memory'  ) }
        cpus   = { check_max( 4    * task.attempt, 'cpus'    ) }
    }

    withName: BGC_HMMER_HMMSEARCH {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = { check_max( 4    * task.attempt, 'cpus'    ) }
    }

    withName: ANTISMASH_ANTISMASHLITE {
        memory = { check_max( 64.GB * task.attempt, 'memory' ) }
        cpus   = { check_max( 8     * task.attempt, 'cpus'   ) }
        time   = { check_max( 12.h  * task.attempt, 'time'   ) }
    }

    withName: ANTISMASH_ANTISMASHLITEDOWNLOADDATABASES {
        memory = { check_max( 4.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: DEEPBGC_DOWNLOAD {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: DEEPBGC_PIPELINE {
        memory = { check_max( 2.GB * task.attempt, 'memory'  ) }
        cpus   = 1
        time   = { check_max( 24.h  * task.attempt, 'time'   ) }
    }

    withName: GECCO_RUN {
        memory = { check_max( 16.GB * task.attempt, 'memory' ) }
        cpus   = { check_max( 4    * task.attempt, 'cpus'    ) }
    }

    withName: HAMRONIZATION_ABRICATE {
        memory = { check_max( 4.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: HAMRONIZATION_AMRFINDERPLUS {
        memory = { check_max( 4.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: HAMRONIZATION_DEEPARG {
        memory = { check_max( 8.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: HAMRONIZATION_RGI {
        memory = { check_max( 4.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: HAMRONIZATION_FARGENE {
        memory = { check_max( 4.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: HAMRONIZATION_SUMMARIZE {
        memory = { check_max( 4.GB * task.attempt, 'memory'  ) }
        cpus   = 1
    }

    withName: AMPCOMBI {
        memory = { check_max( 8.GB * task.attempt, 'memory'  ) }
        time   = { check_max( 2.h   * task.attempt, 'time'   ) }
    }
}
