/*
 * -------------------------------------------------
 *  nf-core/eager Nextflow base config file
 * -------------------------------------------------
 * A 'blank slate' config file, appropriate for general
 * use on most high performace 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( 7.GB * task.attempt, 'memory' ) }
  time = { check_max( 24.h * task.attempt, 'time' ) }

  errorStrategy = { task.exitStatus in [143,137,104,134,139, 140] ? 'retry' : 'finish' }
  maxRetries = 3
  maxErrors = '-1'

  // Process-specific resource requirements
  // NOTE - Only one of the labels below are used in the fastqc process in the main script.
  //        If possible, it would be nice to keep the same label naming convention when
  //        adding in your processes.
  // See https://www.nextflow.io/docs/latest/config.html#config-process-selectors

  // Generic resource requirements - s(ingle)c(ore)/m(ulti)c(ore)

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

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

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

  withLabel:'mc_small'{
      cpus = { check_max( 2 * task.attempt, 'cpus' ) }
      memory = { check_max( 4.GB * task.attempt, 'memory' ) }
      time = { check_max( 4.h * task.attempt, 'time' ) }
  }

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

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

  withLabel:'mc_huge'{
      cpus = { check_max( 32 * task.attempt, 'cpus' ) }
      memory = { check_max( 256.GB * task.attempt, 'memory' ) }
      time = { check_max( 4.h * task.attempt, 'time' ) }
  }

  // Process-specific resource requirements (others leave at default, e.g. Fastqc)
  withName:get_software_versions {
    cache = false
  }

  withName:qualimap{
    errorStrategy = { task.exitStatus in [1,143,137,104,134,139, 140] ? 'retry' : task.exitStatus in [255] ? 'ignore' : 'finish' }
  }

  withName:preseq {
    errorStrategy = 'ignore'
  }

  withName:damageprofiler {
    errorStrategy = { task.exitStatus in [1,143,137,104,134,139, 140] ? 'retry' : 'finish' }
  }

  // Add 1 retry for certain java tools as not enough heap space java errors gives exit code 1
  withName: dedup {
    errorStrategy = { task.exitStatus in [1,143,137,104,134,139, 140] ? 'retry' : 'finish' } 
  }
  
  withName: markduplicates {
    errorStrategy = { task.exitStatus in [143,137, 140] ? 'retry' : 'finish' } 
  }

  // Add 1 retry as not enough heapspace java error gives exit code 1
  withName: malt {
    errorStrategy = { task.exitStatus in [1,143,137,104,134,139, 140] ? 'retry' : 'finish' } 
  }

  // other process specific exit statuses
  withName: nuclear_contamination {
    errorStrategy = { task.exitStatus in [143,137,104,134,139, 140] ? 'ignore' : 'retry' }
  }

}

params {
  // Defaults only, expecting to be overwritten
  max_memory = 128.GB
  max_cpus = 16
  max_time = 240.h
  igenomes_base = 's3://ngi-igenomes/igenomes/'
}
