StackOverflowError when chaining modules for nf-test

I’m submitting a module for nf-core (see PR). My nf-test takes the output file from my first module preparesegmentation and uses it as input for my second module runsegmentationontile. I have checked the nf-test docs on writing chained modules and am using a similar structure. Here is my test:

    test("nuclei - json, images") {

        setup {
            run("VIZGENPOSTPROCESSING_PREPARESEGMENTATION") {
                script "../../preparesegmentation/main.nf"
                params {
                    module_args = '--tile-size 200 --tile-overlap 20'
                }
                process {
                    """
                    // Create test directory and files before process execution
                    testDir = file("tmpdir", type: 'dir')
                    testDir.mkdir()

                    // Download source file
                    sourceUrl = 'https://github.com/nf-core/test-datasets/raw/modules/data/imaging/segmentation/nuclear_image.tif'
                    sourceFile = file(sourceUrl)

                    // Create renamed copies
                    sourceFile.copyTo(file("\${testDir}/mosaic_DAPI_z3.tif"))
                    sourceFile.copyTo(file("\${testDir}/mosaic_PolyT_z3.tif"))

                    // Create transform file
                    transformFile = file("\${testDir}/micron_to_mosaic_pixel_transform.csv")
                    transformFile.text = "2 0 0\\n0 2 0\\n0 0 1"

                    input[0] = [
                        [ id:'test' ],
                        testDir,
                        transformFile
                    ]
                    input[1] = file('https://raw.githubusercontent.com/Vizgen/vpt-plugin-cellpose2/refs/heads/develop/example_analysis_algorithm/cellpose2_nuclei.json', checkIfExists: true)
                    input[2] = "mosaic_(?P<stain>[\\\\w|-]+)_z(?P<z>[0-9]+).tif"
                    """
                }
            }
        }

        when {
            process {
                """
                input[0] = [
                    [ id:'test' ],
                    file("tmpdir", type: 'dir'),
                    VIZGENPOSTPROCESSING_PREPARESEGMENTATION.out.segmentation_files[0][1], // Segmentation parameters
                    0 // Tile index
                ]
                input[1] = file('https://raw.githubusercontent.com/Vizgen/vpt-plugin-cellpose2/refs/heads/develop/example_analysis_algorithm/cellpose2_nuclei.json', checkIfExists: true)
                input[2] = []
                """
            }
        }

However, I can’t seem to get the main nf-test to pass (see here):

Assertion failed: 

assert process.success
       |       |
       |       false
       VIZGENPOSTPROCESSING_RUNSEGMENTATIONONTILE

java.lang.RuntimeException: Process has no output channels. process.out can not be used.

and in my nextflow.log:

 ERROR ~ Unexpected error [StackOverflowError]

I can get the test to work by removing the setup block and using a config file on disk, so it is something to do with the module chaining. I know my first module works correctly and passes nf-test, creating the correct output file so I am quite puzzled by this error. I have also tried using map and take in case it was some issue with accessing the channel using [0], but this leads to the same issue. Any ideas?

This error suggests that the when block is not correct and as it’s not running successfully, there is no output channels to assert. As you said it works with actual files and without the setup, I’d say what you’re receving from your previous process (in the setup block) is probably different from what you’re feeding with the actual files. Could you please check that this is not the case?

Thanks, the problem was with the when block. Accessing VIZGENPOSTPROCESSING_PREPARESEGMENTATION.out.segmentation_files[0] seems to throw this error, although I am not sure exactly why. If I use channel operators to retrieve the output, as well as construct the whole segmentation input channel it works. Here’s my solution:

        when {
            process {
                """
                VIZGENPOSTPROCESSING_PREPARESEGMENTATION.out.segmentation_files
                    .flatten()
                    .last()
                    .set { segmentation_params_ch }

                Channel.of([
                    [ id:'test' ],
                    file("tmpdir", type: 'dir'),
                ])
                .combine(segmentation_params_ch) // segmentation params JSON file
                .combine(Channel.of(0)) // tile_index
                .set { seg_input_ch }

                input[0] = seg_input_ch
                input[1] = file('https://raw.githubusercontent.com/Vizgen/vpt-plugin-cellpose2/refs/heads/develop/example_analysis_algorithm/cellpose2_nuclei.json', checkIfExists: true)
                input[2] = []
                """
            }
        }
1 Like