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

try {
    includeConfig "https://raw.githubusercontent.com/nf-core/modules/master/tests/config/test_data.config"
} catch (Exception e) {
    System.err.println("WARNING: Could not load nf-core/modules test data config")
}

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             = params.test_data['homo_sapiens']['genome']['dbsnp_146_hg38_vcf_gz']
    fasta             = params.test_data['homo_sapiens']['genome']['genome_fasta']
    germline_resource = params.test_data['homo_sapiens']['genome']['gnomad_r2_1_1_vcf_gz']
    intervals         = params.test_data['homo_sapiens']['genome']['genome_interval_list']
    known_indels      = params.test_data['homo_sapiens']['genome']['mills_and_1000g_indels_vcf_gz']
    snpeff_db         = 'WBcel235.105'
    snpeff_genome     = 'WBcel235'
    snpeff_version    = '5.1'
    vep_cache_version = 106
    vep_genome        = 'WBcel235'
    vep_species       = 'caenorhabditis_elegans'
    vep_version       = '106.1'

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

    // Ignore params that will throw warning through params validation
    schema_ignore_params = 'genomes,test_data,snpeff_version,vep_version'
}

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"
                ]
            ]
        }
    }

    if (params.tools && params.tools.split(',').contains('mutect2')) {
        withName: 'NFCORE_SAREK:SAREK:PAIR_VARIANT_CALLING:GATK_TUMOR_NORMAL_SOMATIC_VARIANT_CALLING:MUTECT2'{
            //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"
        params.enable_conda                      = true
        charliecloud.enabled                     = false
        docker.enabled                           = false
        podman.enabled                           = false
        shifter.enabled                          = false
        singularity.enabled                      = false
    } else if ("$PROFILE" == "docker") {
        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") {
        params.singularity_pull_docker_container = false
        singularity.autoMounts                   = true
        singularity.enabled                      = true
        charliecloud.enabled                     = false
        docker.enabled                           = false
        podman.enabled                           = false
        shifter.enabled                          = false
    }
}
