Hi everyone, I have a doubt about resolving file p...
# nf-test
a
Hi everyone, I have a doubt about resolving file paths in nf-test. In my nf-test, I defined a
config
, a
when
and a
then
block: - The
config
block describes some named `process`es - The
then
block defines some `assert`ions - The
when
block defines - Some `params`: - The .bam and .bai files of some alignment - The .fa and .fa.fai files of a reference genome - The output directory - And one
process
, which uses the above parameters All the tests pass. However, I would like to avoid hard-coding the path to the reference genome in the above
params
block: it would be better to move it to some file, so that multiple tests can reuse it. My first thought was to extend the file pointed by the above
config
block, by adding:
Copy code
params {
    fasta    = "./results/reference-genome/hg38.fa"
    fai      = "./results/reference-genome/hg38.fa.fai"
}
..and then use
params.fasta
and
params.fai
in the
process
block. However, this leads to the error:
Copy code
Caused by:
    Process `PARAPHASE` input file name collision -- There are multiple input files for each of the following file names: null
The path to the files is correct, but it seems that nf-test cannot resolve them. So I added a
println
statement to the
process
to see the resolved path, and then re-run the test using
--verbose
. Still, both files cannot be seen:
Copy code
> DEBUG: params.fasta = null
> DEBUG: params.fai = null
...so can it be that my new
params
block gets over-written by the former
params
in the
when
block? After all, both files specify a
params
block now. I therefore moved the new
params
block in the new file
conf/reference.config
, and imported the new file at the very top of my test:
config "conf/reference.config"
. Still no luck. I get the same error. What am I missing?
m
Can you share some more code?
I don't think you should have a config block
a
Sure, here's the
nextflow.config
file pointed by the
config
block of my
main.nf.test
file (below).
Copy code
process {
    withName: SAMTOOLS_INDEX {
        ext.args = '-c'
    }
}

process {
    withName: PARAPHASE {
        ext.args = { params.targetGene }  // let the test run specify the target gene
    }
}

params {
    reference_fasta = '/data/reference-genome/hg38.fa'
    reference_fai   = '/data/reference-genome/hg38.fa.fai'
}
This config file is imported by the
main.nf.test
file in order to run the test against one gene (see my previous thread). Here above I added a
params
block that specifies where to find my local copy of the human reference genome.
This is my
main.nf.test
, which calls the above file:
Copy code
nextflow_process {

    name "Test Process PARAPHASE"
    script "modules/local/paraphase/main.nf"
    process "PARAPHASE"

    // Test the paraphase process against the GBA gene.
    def gene="GBA"
    def sample="RevioEPT2-YF26-46"

    test("Should run paraphase tests against sample \"${sample}\" and gene \"${gene}\".") {

        // Run samtools index to create the input .bai file.
        setup {
            run("SAMTOOLS_INDEX") {
                script "modules/nf-core/samtools/index/main.nf"
                process { ... }
            }
        }

        // Run paraphase against the GBA gene.
        config "${baseDir}/tests/nextflow.config"

        when {
            params {
                outdir          = "${baseDir}/results"
                targetGene      = "-g ${gene}"  // specify the target gene
                //fasta           = "${outdir}/reference-genome/hg38.fa"
                //fai             = "${outdir}/reference-genome/hg38.fa.fai"
            }
            process {
                """
                input[0] = Channel.of([
                    [ id: "${sample}", single_end: false ], // meta map
                    file(
                        "${params.outdir}/${sample}/${sample}-ready.bam",
                        checkIfExists: true, checkIfEmpty: false
                    ),
                    file(
                        "${params.outdir}/${sample}/${sample}-ready.bam.bai",
                        checkIfExists: true, checkIfEmpty: false
                    )
                ])

                //input[1] = file("${params.fasta}")
                //input[2] = file("${params.fai}")
                input[1] = file("${params.reference_fasta}")
                input[2] = file("${params.reference_fai}")
                input[3] = []
                """
            }
        }

        then {
            // Paraphase runs as expected.
            assert process.success
            ...
        }
    }
    ...
In this file I commented some
params
in the
when
block, which I expect to be taken from the above config.
However, when I run the test case, I obtain the error
Copy code
Caused by:
    Process `PARAPHASE` input file name collision -- There are multiple input files for each of the following file names: null
The above represents my first attempt at moving the path to the reference genome out of the
when
block. As second attempt, I moved the
params
section from
nextflow.config
to a dedicated file
reference.config
, and called this file from within `main.nf.test`:
Copy code
nextflow_process {

    name "Test Process PARAPHASE"
    script "modules/local/paraphase/main.nf"
    process "PARAPHASE"
    config "reference.config"

    ...
However, I obtained the same error
m
I can see you use `${outdir}/reference-genome/hg38.fa`for the references
but outdir isn't defined, since it should be
params.outdir
I would really recommend to use only
Copy code
outdir = "$outputDir"
for outdir
as nf-test relies on its own outdir that is relative
but since this is for a nextflow process and not a pipeline, you should not even need to use such a params
for me the input for what comes after your setup should be the channel