Alter process output folders for results

Hi! I have probably a very basic question.

There is a process output like this:
path “work_subdir/*.fasta” where work_subdir is unavoidable.

And workflow output like this:
output { ch_out { path { 'result_subdir' } }

How to avoid work_subdir in the results and achieve this structure
results/result_subdir/*.fasta
instead of
results/result_subdir/work_subdir/*.fasta ?

You can modify the contents of a channel before publishing with the map operator.

I think this transformation will do what you want.

    ch_out = PROCESS.out.dir.map { dir -> dir.listFiles() }

Or to refine it further

    ch_out = PROCESS.out.dir.map { dir -> dir.listFiles().findAll { file -> file.name.endsWith('.fasta') }

Thanks for the fast answer! I feel that the direction is right, but my knowledge of nextflow is not enough to implement this correctly :slight_smile: I currently made it to the setup below, but it emits a list of files with entire paths that still include work_subdir that still makes it to results/result_subdir folder.

output:
path ("work_subdir"), emit: dir
publish:
ch_out = PROCESS.out.dir.flatMap { dir -> dir.listFiles() }
output { ch_out { path {'result_subdir'} } }

My apologies. I should have verified the answer. It was still incomplete and needed the closure to rename the file.

workflow {
    main:
    TASK()

    publish:
    fasta = TASK.out.fasta_dir.flatMap { dir -> dir.listFiles() }.view()
}

process TASK {
    script:
    """
    mkdir subdir
    touch subdir/seq{1..3}.fasta
    """

    output:
    path "subdir", emit: fasta_dir
}

output {
    fasta {
        path { file ->
            file >> "fasta/${file.getName()}"
        }
    }
}
% tree results 
results
└── fasta
    ├── seq1.fasta
    ├── seq2.fasta
    └── seq3.fasta
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.