/*
 * -------------------------------------------------
 *  nf-core/methylseq Nextflow config file
 * -------------------------------------------------
 * Default config options for all environments.
 * Cluster-specific config options should be saved
 * in the conf folder and imported under a profile
 * name here.
 */


// Configurable variables
params {

  container = 'nfcore/methylseq:1.2' // Container slug. Stable releases should specify release tag!!

  // Pipeline options
  aligner = 'bismark'
  saveReference = false
  saveTrimmed = false
  saveAlignedIntermediates = false
  reads = "data/*_R{1,2}.fastq.gz"
  singleEnd = false
  outdir = './results'
  multiqc_config = "$baseDir/conf/multiqc_config.yaml"
  notrim = false
  nodedup = false
  unmapped = false
  non_directional = false
  comprehensive = false
  relaxMismatches = false
  numMismatches = 0.6
  // 0.6 will allow a penalty of bp * -0.6
  // For 100bp reads, this is -60. Mismatches cost -6, gap opening -5 and gap extension -2
  // So -60 would allow 10 mismatches or ~ 8 x 1-2bp indels
  // Bismark default is 0.2 (L,0,-0.2), Bowtie2 default is 0.6 (L,0,-0.6)
  mindepth = 0
  ignoreFlags = false
}

profiles {

  standard {
    includeConfig 'conf/base.config'
    includeConfig 'conf/igenomes.config'
  }
  conda { process.conda = "$baseDir/environment.yml" }
  docker { docker.enabled = true }
  singularity { singularity.enabled = true }
  uppmax {
    includeConfig 'conf/base.config'
    includeConfig 'conf/uppmax.config'
    includeConfig 'conf/igenomes.config'
  }
  uppmax_devel {
    includeConfig 'conf/base.config'
    includeConfig 'conf/uppmax.config'
    includeConfig 'conf/uppmax-devel.config'
    includeConfig 'conf/igenomes.config'
  }
  aws {
    includeConfig 'conf/base.config'
    includeConfig 'conf/aws.config'
    includeConfig 'conf/igenomes.config'
  }
  test {
    includeConfig 'conf/base.config'
    includeConfig 'conf/test.config'
  }
  none {
    // Don't load any config (for use with custom home configs)
  }

}


// Capture exit codes from upstream processes when piping
process.shell = ['/bin/bash', '-euo', 'pipefail']

timeline {
  enabled = true
  file = "${params.outdir}/pipeline_info/MethylSeq_timeline.html"
}
report {
  enabled = true
  file = "${params.outdir}/pipeline_info/MethylSeq_report.html"
}
trace {
  enabled = true
  file = "${params.outdir}/pipeline_info/MethylSeq_trace.txt"
}
dag {
  enabled = true
  file = "${params.outdir}/pipeline_info/MethylSeq_dag.svg"
}

manifest {
  name = 'nf-core/methylseq'
  author = 'Phil Ewels'
  description = 'Methylation (Bisulfite-Sequencing) Best Practice analysis pipeline, part of the nf-core community.'
  version = '1.2'
  nextflowVersion = '>=0.32.0'
  homePage = 'https://github.com/nf-core/methylseq'
  mainScript = 'main.nf'
}

// Function to ensure that resource requirements don't go beyond
// a maximum limit
def check_max(obj, type) {
  if(type == 'memory'){
    try {
      if(obj.compareTo(params.max_memory as nextflow.util.MemoryUnit) == 1)
        return params.max_memory as nextflow.util.MemoryUnit
      else
        return obj
    } catch (all) {
      println "   ### ERROR ###   Max memory '${params.max_memory}' is not valid! Using default value: $obj"
      return obj
    }
  } else if(type == 'time'){
    try {
      if(obj.compareTo(params.max_time as nextflow.util.Duration) == 1)
        return params.max_time as nextflow.util.Duration
      else
        return obj
    } catch (all) {
      println "   ### ERROR ###   Max time '${params.max_time}' is not valid! Using default value: $obj"
      return obj
    }
  } else if(type == 'cpus'){
    try {
      return Math.min( obj, params.max_cpus as int )
    } catch (all) {
      println "   ### ERROR ###   Max cpus '${params.max_cpus}' is not valid! Using default value: $obj"
      return obj
    }
  }
}
