/*
 * -------------------------------------------------
 *  Base Nextflow config file
 * -------------------------------------------------
 * This file contains basic process requirement setup
 * It DOES NOT contain any config for cluster, so will run
 * in default mode by itself. It should be used with
 * the max_memory, max_cpus and max_time params for
 * customising hardware limits
 */

process {

  container = params.container

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

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

  // Resource requirements
  withName:makeBismarkIndex {
    cpus = { check_max( 8 * task.attempt, 'cpus') }
    memory = { check_max( 64.GB * task.attempt, 'memory') }
    time = { check_max( 36.h * task.attempt, 'time') }
  }
  withName:trim_galore {
    cpus = { check_max( 2 * task.attempt, 'cpus') }
    memory = { check_max( 16.GB * task.attempt, 'memory') }
    time = { check_max( 1.d * task.attempt, 'time') }
  }
  withName:bismark_align {
    cpus = { check_max( 12 * task.attempt, 'cpus') }
    memory = { check_max( 64.GB * task.attempt, 'memory') }
    time = { check_max( 8.d * task.attempt, 'time') }
  }
  withName:bismark_deduplicate {
    cpus = { check_max( 8 * task.attempt, 'cpus') }
    memory = { check_max( 64.GB * task.attempt, 'memory') }
    time = { check_max( 2.d * task.attempt, 'time') }
  }
  withName:bismark_methXtract {
    cpus = { check_max( 12 * task.attempt, 'cpus') }
    memory = { check_max( 32.GB * task.attempt, 'memory') }
    time = { check_max( 1.d * task.attempt, 'time') }
  }
  withName:qualimap {
    cpus = { check_max( 4 * task.attempt, 'cpus') }
    memory = { check_max( 32.GB * task.attempt, 'memory') }
    time = { check_max( 6.h * task.attempt, 'time') }
  }
  withName:get_software_versions {
    validExitStatus = [0,1]
    errorStrategy = 'ignore'
  }

  withName:bwamem_align {
    cpus = { check_max( 8 * task.attempt, 'cpus') }
    memory = { check_max( 64.GB * task.attempt, 'memory') }
    time = { check_max( 6.d * task.attempt, 'time') }
  }
  withName:samtools_sort_index_flagstat {
    cpus = { check_max( 4 * task.attempt, 'cpus') }
    memory = { check_max( 32.GB * task.attempt, 'memory') }
    time = { check_max( 1.d * task.attempt, 'time') }
  }
  withName:markDuplicates {
    cpus = { check_max( 4 * task.attempt, 'cpus') }
    memory = { check_max( 32.GB * task.attempt, 'memory') }
    time = { check_max( 2.d * task.attempt, 'time') }
  }
  withName:methyldackel {
    cpus = { check_max( 6 * task.attempt, 'cpus') }
    memory = { check_max( 48.GB * task.attempt, 'memory') }
    time = { check_max( 1.d * task.attempt, 'time') }
  }
}

// Defaults config params, may be overwritten by later configs
params {
  max_memory = 128.GB
  max_cpus = 16
  max_time = 240.h
  igenomes_base = 's3://ngi-igenomes/igenomes/'
}
