/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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/demultiplex -profile test,<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.GB'
    max_time   = '6.h'

    // Input data
    input = "${projectDir}/assets/inputs/flowcell_input.csv"
    demultiplexer = 'bclconvert'

}

process {
    withName: BCLCONVERT {
        ext.args = {[
            meta.lane ? "--bcl-only-lane ${meta.lane}" : "",
            "--force",
            "--first-tile-only true"
        ].join(" ").trim()}
    }
    publishDir = [
        [
            // Gather and write InterOp files
            path: { "${params.outdir}/${meta.id}/InterOp" },
            mode: params.publish_dir_mode,
            pattern: "**.bin",
            saveAs: {filename -> filename.split("/")[-1] }
        ],
        [
            // Fetch RunInfo.xml
            path: { "${params.outdir}/${meta.id}" },
            mode: params.publish_dir_mode,
            pattern: "RunInfo.xml",
            overwrite: true,
            saveAs: {filename -> filename.split("/")[-1] }
        ],
        [
            // Gather and write Reports
            path: { meta.lane ? "${params.outdir}/${meta.id}/L00${meta.lane}" : "${params.outdir}/${meta.id}" },
            mode: params.publish_dir_mode,
            pattern: "Reports",
            saveAs: {filename -> filename.split("/")[-1] }
        ],
        [
            path: { "${params.outdir}/${meta.id}" },
            pattern: "**.fastq.gz",
        ]
    ]
}
