/*
 * -------------------------------------------------
 *  nf-core/rnaseq 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( 2, 'cpus' ) }
  memory = { check_max( 8.GB * task.attempt, 'memory' ) }
  time = { check_max( 4.h * task.attempt, 'time' ) }

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

  // Process-specific resource requirements
  withLabel: low_memory {
    memory = { check_max( 16.GB * task.attempt, 'memory' ) }
  }
  withLabel: mid_memory {
    cpus = { check_max (4, 'cpus')}
    memory = { check_max( 28.GB * task.attempt, 'memory' ) }
    time = { check_max( 8.h * task.attempt, 'time' ) }
  }
  withLabel: high_memory {
    cpus = { check_max (10, 'cpus')}
    memory = { check_max( 70.GB * task.attempt, 'memory' ) }
    time = { check_max( 8.h * task.attempt, 'time' ) }
  }

  withName: makeHISATindex {
    cpus = { check_max( 10, 'cpus' ) }
    memory = { check_max( 200.GB * task.attempt, 'memory' ) }
    time = { check_max( 5.h * task.attempt, 'time' ) }
  }
  withName: trim_galore {
    time = { check_max( 8.h * task.attempt, 'time' ) }
  }
  withName: sortmerna {
    cpus = { check_max( 16 * task.attempt, 'cpus' ) }
    time = { check_max( 24.h * task.attempt, 'time' ) }
    maxRetries = 2
  }
  withName: markDuplicates {
    // Actually the -Xmx value should be kept lower,
    // and is set through the markdup_java_options
    cpus = { check_max( 8, 'cpus' ) }
    memory = { check_max( 8.GB * task.attempt, 'memory' ) }
  }
  withLabel: salmon {
    cpus = { check_max( 8, 'cpus' ) }
    memory = { check_max( 16.GB * task.attempt, 'memory' ) }
  }
  withName: 'get_software_versions' {
    memory = { check_max( 2.GB * task.attempt, 'memory' ) }
    cache = false
  }
  withName: 'multiqc' {
    memory = { check_max( 2.GB * task.attempt, 'memory' ) }
    cache = false
  }
}

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