Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the execution of dependent modules for generating test data #127

Merged
merged 6 commits into from
Oct 11, 2023

Conversation

lukfor
Copy link
Collaborator

@lukfor lukfor commented Oct 5, 2023

This pull PR enables the execution of dependent modules for generating test data (Fixes #70).

With these changes, it is now possible to specify processes in the setup method that need to be executed before the when block. The outputs of these processes can then be utilized to define parameters or map processes/workflows. The runmethod takes the processs or workflow name, the (relativ) path to the script file and the input mapping as arguments.

For example, the following testcase for the ABRICATE_SUMMARY module executes the ABRICATE_RUN module to generate the input data:

nextflow_process {

    name "Test process data"

    script "../main.nf"
    process "ABRICATE_SUMMARY"
    config "./nextflow.config"

    test("Should use process ABRICATE_RUN to generate input data") {

        setup {
            
            run("ABRICATE_RUN") {
                script "../../run/main.nf"
                process {
                    """
                    input[0] =  Channel.fromList([
                        tuple([ id:'test1', single_end:false ], // meta map
                            file(params.test_data['bacteroides_fragilis']['genome']['genome_fna_gz'], checkIfExists: true)),
                        tuple([ id:'test2', single_end:false ],
                            file(params.test_data['haemophilus_influenzae']['genome']['genome_fna_gz'], checkIfExists: true))
                    ])
                    """
                }
            }

        }



        when {
            process {
                """
                input[0] = ABRICATE_RUN.out.report.collect{ meta, report -> report }.map{ report -> [[ id: 'test_summary'], report]}
                """
            }
        }

        then {
            assert process.success
            assert snapshot(process.out).match()
        }
    }

}

The full example can be found here: https://github.com/askimed/nf-test/tree/features/dependencies/test-data/process/abricate

It is also possible to define the setup method globally for all tests as follows:

nextflow_process {

    name "Test process data"

    script "../main.nf"
    process "ABRICATE_SUMMARY"
    config "./nextflow.config"

    setup {

        run("ABRICATE_RUN") {
            script "../../run/main.nf"
            process {
                """
                input[0] =  Channel.fromList([
                    tuple([ id:'test1', single_end:false ], // meta map
                        file(params.test_data['bacteroides_fragilis']['genome']['genome_fna_gz'], checkIfExists: true)),
                    tuple([ id:'test2', single_end:false ],
                        file(params.test_data['haemophilus_influenzae']['genome']['genome_fna_gz'], checkIfExists: true))
                ])
                """
            }
        }

    }


    test("first test") {

        when {
            process {
                """
                input[0] = ABRICATE_RUN.out.report.collect{ meta, report -> report }.map{ report -> [[ id: 'test_summary'], report]}
                """
            }
        }
	    ...
    }
    
    test("second test") {

        when {
            process {
                """
                input[0] = ABRICATE_RUN.out.report.collect{ meta, report -> report }.map{ report -> [[ id: 'test_summary'], report]}
                """
            }
        }
		...
    }

}

Open tasks:

  • Write documentation

@maxulysse
Copy link

That looks amazing

@maxulysse
Copy link

@lukfor any ETA on this, even as a rc with no docs?

@lukfor
Copy link
Collaborator Author

lukfor commented Oct 10, 2023

I will create a release tomorrow.

@maxulysse
Copy link

I will create a release tomorrow.

Best news of the week

@lukfor lukfor merged commit 444371d into main Oct 11, 2023
2 checks passed
@lukfor lukfor deleted the features/dependencies branch October 11, 2023 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Individual Process Testing Where You can Use another process' output as input for the next one
2 participants