/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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"

    // No AWS iGenomes
    genome          = null
    igenomes_ignore = true

    // Small reference genome
    bcftools_annotations       = "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/sarscov2/illumina/vcf/test2.vcf.gz"
    bcftools_annotations_index = "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/sarscov2/illumina/vcf/test2.vcf.gz.tbi"
    bcftools_header_lines      = "${projectDir}/tests/config/bcfann_test_header.txt"
    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"
    ngscheckmate_bed           = "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/genome/chr21/germlineresources/SNP_GRCh38_hg38_wChr.bed"
    snpeff_cache               = null
    snpeff_db                  = 105
    snpeff_genome              = 'WBcel235'
    vep_cache                  = null
    vep_cache_version          = 110
    vep_genome                 = 'WBcel235'
    vep_species                = 'caenorhabditis_elegans'

    // Sentieon
    sentieon_dnascope_model    = "s3://ngi-igenomes/igenomes/Homo_sapiens/GATK/GRCh38/Annotation/Sentieon/SentieonDNAscopeModel1.1.model"

    // 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
    }
}
