/***************************************************************************************************
 * nf-core/mag v5.0.0 custom configuration (final)
 * Author: leonorfe
 * DB paths + Bowtie2 resource caps + SLURM-ready profile
 ***************************************************************************************************/

params {
  /*******************************
   * Database paths
   *******************************/
  gtdb_db           = '/gpfs1/data/db/gtdb/226.0-data'
  checkm_db         = '/data/mie/shared/dbs/checkm-db/2015_01'
  genomad_db        = '/gpfs1/data/db/genomad/v1.7'
  metaeuk_mmseqs_db = 'UniRef90'

  /*******************************
   * Default thresholds
   *******************************/
  gtdbtk_min_completeness = 50.0
  gtdbtk_max_contamination = 10.0

  /*******************************
   * Generic pipeline parameters
   *******************************/
  outdir            = './results'
  publish_dir_mode  = 'copy'

  /*******************************
   * Safety rails (optional)
   *******************************/
  max_memory = '250 GB'
  max_cpus   = 64
  max_time   = '7d'
}

/***************************************************************************************************
 * Executor and default resource limits (match SLURM script: --cpus-per-task=5, ~10G/core)
 ***************************************************************************************************/
process { 
 executor = 'local'  
 cpus   = 16      
 memory   = '200GB'
 errorStrategy = 'retry'
 maxRetries = 1 

// clusterOptions = '--cpus-per-task=16 --mem=200G -t 10-24:00:00'

   * Specific process resource tuning
   *******************************/

  // --- Bowtie2 PhiX removal ---
  withName: 'NFCORE_MAG:MAG:SHORTREAD_PREPROCESSING:BOWTIE2_PHIX_REMOVAL_BUILD' {
    cpus   = 2
    memory = '4 GB'
    time   = '2h'
  }
  withName: 'NFCORE_MAG:MAG:SHORTREAD_PREPROCESSING:BOWTIE2_PHIX_REMOVAL_ALIGN' {
    cpus   = 4
    memory = '8 GB'
    time   = '6h'
  }

  // A bit more headroom for heavy steps
  withName: 'NFCORE_MAG:MAG:GTDBTK:GTDBTK_CLASSIFYWF' {
    memory = '32 GB'
    time   = '24h'
  }
  withName: 'NFCORE_MAG:MAG:CHECKM2:PREDICT' {
    memory = '24 GB'
    time   = '24h'
  }
  withName: 'NFCORE_MAG:MAG:GENOMAD:ENDTOEND' {
    memory = '24 GB'
    time   = '24h'
  }
  withName: '.*BOWTIE2_ASSEMBLY_BUILD.*' {
    cpus = 15
  }
  withName: 'NFCORE_MAG:MAG:ASSEMBLY:SHORTREAD_ASSEMBLY:METASPADES' {
    memory = '120 GB'
    cpus   = 16
   }  
}

/***************************************************************************************************
 * Singularity setup
 ***************************************************************************************************/
singularity {
  enabled    = true
  autoMounts = true
}

profiles {
  singularity {
    process {
      withName: '.*' {
        containerOptions = '-B /data:/data -B /gpfs1:/gpfs1 -B /work:/work'
      }
    }
  }

  // Optional: submit each process as its own SLURM job
  slurm {
    process.executor = 'slurm'
  }
}

/***************************************************************************************************
 * Reporting
 ***************************************************************************************************/
timeline {
  enabled = true
}
trace {
  enabled = true
  fields  = 'task_id,process,tag,cpus,time,memory,attempt,exit,status'
}
report {
  enabled = true
}
