// Profile config names for nf-core/configs

params {
  // Specific nf-core/configs params
  config_profile_contact = 'Friederike Hanssen (@FriederikeHanssen)'
  config_profile_description = 'nf-core/sarek CFC profile provided by nf-core/configs'
}

// Specific nf-core/sarek process configuration
process {
  withName:'StrelkaSingle|Strelka|StrelkaBP|MantaSingle|Manta' {
    cpus = { check_resource( 20 * task.attempt) }
    memory = { check_resource( 59.GB * task.attempt) }
  }
  withName:'MSIsensor_scan|MSIsensor_msi' {
    memory = { check_resource( 55.GB * task.attempt ) }

  }
  withName:BamQC {
    memory = { check_resource( 372.GB * task.attempt) }
  }

  withName:MapReads{
    cpus = { check_resource( 20 * task.attempt ) }
    memory = { check_resource( 59.GB * task.attempt) }
  }
}

def check_resource(obj) {
    try {
      if (obj.getClass() == nextflow.util.MemoryUnit && obj.compareTo(params.max_memory as nextflow.util.MemoryUnit) == 1)
        return params.max_memory as nextflow.util.MemoryUnit
      else if (obj.getClass() == nextflow.util.Duration && obj.compareTo(params.max_time as nextflow.util.Duration) == 1)
        return params.max_time as nextflow.util.Duration
      else if (obj.getClass() == java.lang.Integer)
        return Math.min(obj, params.max_cpus as int)
      else
        return obj
    } catch (all) {
        println "   ### ERROR ###   Max params max_memory:'${params.max_memory}', max_time:'${params.max_time}' or max_cpus:'${params.max_cpus}'  is not valid! Using default value: $obj"
    }
}