/*
 * -------------------------------------------------
 *  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
  $makeBismarkIndex {
    cpus = { check_max( 8 * task.attempt, 'cpus') }
    memory = { check_max( 64.GB * task.attempt, 'memory') }
    time = { check_max( 36.h * task.attempt, 'time') }
  }
  $fastqc {
    errorStrategy = { task.exitStatus in [143,137] ? 'retry' : 'ignore' }
  }
  $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') }
  }
  $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') }
  }
  $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') }
  }
  $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') }
  }
  $bismark_report {
    errorStrategy = { task.exitStatus in [143,137] ? 'retry' : 'ignore' }
  }
  $bismark_summary {
    errorStrategy = { task.exitStatus in [143,137] ? 'retry' : 'ignore' }
  }
  $qualimap {
    cpus = { check_max( 4 * task.attempt, 'cpus') }
    memory = { check_max( 32.GB * task.attempt, 'memory') }
    time = { check_max( 6.h * task.attempt, 'time') }
    errorStrategy = { task.exitStatus in [143,137] ? 'retry' : 'ignore' }
  }
  $get_software_versions {
    validExitStatus = [0,1]
    executor = 'local'
    errorStrategy = 'ignore'
  }
  $multiqc {
    executor = 'local'
    errorStrategy = { task.exitStatus in [143,137] ? 'retry' : 'ignore' }
  }

  $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') }
  }
  $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') }
  }
  $markDuplicates {
    cpus = { check_max( 4 * task.attempt, 'cpus') }
    memory = { check_max( 32.GB * task.attempt, 'memory') }
    time = { check_max( 2.d * task.attempt, 'time') }
  }
  $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/'
}
