/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    nf-core/sarek 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 {

    // TODO nf-core: Check the defaults for all processes
    cpus   = { 1      * task.attempt }
    memory = { 6.GB   * task.attempt }
    time   = { 4.h    * task.attempt }

    // memory errors which should be retried. otherwise error out
    errorStrategy = { task.exitStatus in ((130..145) + 104) ? 'retry' : 'finish' }
    maxRetries    = 1
    maxErrors     = '-1'

    // Process-specific resource requirements
    // See https://www.nextflow.io/docs/latest/config.html#config-process-selectors
    withLabel:error_ignore {
        errorStrategy = 'ignore'
    }
    withLabel:error_retry {
        errorStrategy = 'retry'
        maxRetries    = 2
    }
    withLabel:process_single {
        cpus   = { 1                   }
        memory = { 6.GB * task.attempt }
        time   = { 4.h  * task.attempt }
    }
    withLabel:process_low {
        cpus   = { 2     * task.attempt }
        memory = { 12.GB * task.attempt }
        time   = { 4.h   * task.attempt }
    }
    withLabel:process_medium {
        cpus   = { 6     * task.attempt }
        memory = { 36.GB * task.attempt }
        time   = { 8.h   * task.attempt }
    }
    withLabel:process_high {
        cpus   = { 12    * task.attempt }
        memory = { 72.GB * task.attempt }
        time   = { 16.h  * task.attempt }
    }
    withLabel:process_long {
        time   = { 20.h  * task.attempt }
    }
    withLabel:process_high_memory {
        memory = { 200.GB * task.attempt }
    }
    withName: 'UNZIP.*|UNTAR.*|TABIX.*|BUILD_INTERVALS|CREATE_INTERVALS_BED|VCFTOOLS|BCFTOOLS.*|SAMTOOLS_INDEX' {
        cpus   = { 1    * task.attempt }
        memory = { 1.GB * task.attempt }
    }
    withName: 'FASTQC'{
        cpus   = { 4    * task.attempt }
        memory = { 4.GB * task.attempt }
    }
    withName: 'FASTP'{
        cpus   = { 12   * task.attempt }
        memory = { 4.GB * task.attempt }
    }
    withName: 'BWAMEM1_MEM|BWAMEM2_MEM' {
        cpus   = { 24    * task.attempt }
        memory = { 30.GB * task.attempt }
    }
    withName:'CNVKIT_BATCH' {
        label  = "process_high"
        memory = { 36.GB * task.attempt }
    }
    withName: 'GATK4_MARKDUPLICATES|GATK4SPARK_MARKDUPLICATES' {
        cpus   = { 6     * task.attempt }
        memory = { 30.GB * task.attempt }
    }
    withName:'GATK4_APPLYBQSR|GATK4SPARK_APPLYBQSR|GATK4_BASERECALIBRATOR|GATK4SPARK_BASERECALIBRATOR|GATK4_GATHERBQSRREPORTS'{
        cpus   = { 2    * task.attempt }
        memory = { 4.GB * task.attempt }
    }
    withName:'MOSDEPTH'{
        cpus   = { 4    * task.attempt }
        memory = { 4.GB * task.attempt }
    }
    withName:'STRELKA.*|MANTA.*' {
        cpus   = { 10   * task.attempt }
        memory = { 8.GB * task.attempt }
    }
    withName:'SAMTOOLS_CONVERT'{
        memory = { 4.GB * task.attempt }
    }
    withName:'GATK4_MERGEVCFS'{
        cpus   = { 2    * task.attempt }
        memory = { 4.GB * task.attempt }
    }
    withName: 'MULTIQC' {
        cpus   = { 4     * task.attempt }
        memory = { 12.GB * task.attempt }
    }
}
