/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Nextflow config file for running minimal tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Defines input files and everything required to run a fast and simple pipeline test.

    Use as follows:
        nextflow run nf-core/sarek -profile test,<extra_test_profile>,<docker/singularity> --outdir <OUTDIR>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

params {
    config_profile_name        = 'Test profile'
    config_profile_description = 'Minimal test dataset to check pipeline function'

    // Limit resources so that this can run on GitHub Actions
    max_cpus   = 2
    max_memory = '6.5GB'
    max_time   = '8.h'

    // Input data
    input = "${projectDir}/tests/csv/3.0/fastq_single.csv"

    // Small reference genome
    genome            = null
    igenomes_ignore   = true
    dbsnp             = "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/genome/vcf/dbsnp_146.hg38.vcf.gz"
    fasta             = "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/genome/genome.fasta"
    germline_resource = "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/genome/vcf/gnomAD.r2.1.1.vcf.gz"
    intervals         = "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/genome/genome.interval_list"
    known_indels      = "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/genome/vcf/mills_and_1000G.indels.vcf.gz"
    snpeff_cache      = null
    snpeff_db         = 105
    snpeff_genome     = 'WBcel235'
    vep_cache         = null
    vep_cache_version = 110
    vep_genome        = 'WBcel235'
    vep_species       = 'caenorhabditis_elegans'

    // default params
    split_fastq       = 0         // no FASTQ splitting
    tools             = 'strelka' // Variant calling with Strelka

    // Ignore params that will throw warning through params validation
    validationSchemaIgnoreParams = 'genomes'
}

process {

    withName:'.*:FREEC_SOMATIC'{
        ext.args = {
            [
                "sample":[
                    inputformat: "pileup",
                    mateorientation: "FR"
                ],
                "general":[
                    bedgraphoutput: "TRUE",
                    noisydata: "TRUE",
                    minexpectedgc: "0",
                    readcountthreshold: "1",
                    sex: meta.sex,
                    window: "10",
                    ],
                "control":[
                    inputformat: "pileup",
                    mateorientation: "FR"
                ]
            ]
        }
    }

    withName: '.*:MUTECT2_PAIRED'{
        //sample name from when the test data was generated
        ext.args = { "--f1r2-tar-gz ${task.ext.prefix}.f1r2.tar.gz --normal-sample normal" }
    }

    withName: '.*:FILTERVARIANTTRANCHES'{
        ext.args = { "--info-key CNN_1D --indel-tranche 0" }
    }
}


// Enable container engines/virtualisation envs for CI testing
// only works when specified with the profile ENV
// otherwise tests can be done with the regular provided profiles
if (System.getenv('PROFILE')) {
    if ("$PROFILE" == "conda") {
        conda.createTimeout                      = "120 min"
        conda.enabled                            = true
        charliecloud.enabled                     = false
        docker.enabled                           = false
        podman.enabled                           = false
        shifter.enabled                          = false
        singularity.enabled                      = false
    } else if ("$PROFILE" == "docker") {
        conda.enabled                            = false
        docker.enabled                           = true
        docker.userEmulation                     = { params.use_gatk_spark ? false : true }.call()
        charliecloud.enabled                     = false
        podman.enabled                           = false
        shifter.enabled                          = false
        singularity.enabled                      = false
    } else if ("$PROFILE" == "singularity") {
        conda.enabled                            = false
        singularity.autoMounts                   = true
        singularity.enabled                      = true
        charliecloud.enabled                     = false
        docker.enabled                           = false
        podman.enabled                           = false
        shifter.enabled                          = false
    }
}
