diff --git a/modules/nf-core/seqkit/sample/main.nf b/modules/nf-core/seqkit/sample/main.nf index 96ddc814db46..6b235e42ec29 100644 --- a/modules/nf-core/seqkit/sample/main.nf +++ b/modules/nf-core/seqkit/sample/main.nf @@ -11,7 +11,7 @@ process SEQKIT_SAMPLE { tuple val(meta), path(fastx) output: - tuple val(meta), path("${prefix}.${extension}"), emit: fastx + tuple val(meta), path("${prefix}*.${extension}"), emit: fastx tuple val("${task.process}"), val('seqkit'), eval("seqkit version | sed 's/^.*v//'"), emit: versions_seqkit, topic: versions when: @@ -20,35 +20,62 @@ process SEQKIT_SAMPLE { script: def args = task.ext.args ?: '' prefix = task.ext.prefix ?: "${meta.id}" + def fastx_list = fastx instanceof List ? fastx : [fastx] + def first_file = fastx_list[0].toString() extension = "fastq" - if ("${fastx}" ==~ /.+\.(fasta|fa|fas|fna|fsa)(\.gz)?/) { + if (first_file ==~ /.+\.(fasta|fa|fas|fna|fsa)(\.gz)?/) { extension = "fasta" } - extension = fastx.toString().endsWith('.gz') ? "${extension}.gz" : extension - if ("${prefix}.${extension}" == "${fastx}") { - error("Input and output names are the same, use \"task.ext.prefix\" to disambiguate!") + extension = first_file.endsWith('.gz') ? "${extension}.gz" : extension + + def cmds = [] + if (fastx_list.size() == 1) { + def out_name = "${prefix}.${extension}" + if (out_name == "${fastx_list[0]}") { + error("Input and output names are the same, use \"task.ext.prefix\" to disambiguate!") + } + cmds << "seqkit sample --threads ${task.cpus} ${args} ${fastx_list[0]} -o ${out_name}" + } else { + fastx_list.eachWithIndex { f, i -> + def out_name = "${prefix}_${i + 1}.${extension}" + if (out_name == "${f}") { + error("Input and output names are the same, use \"task.ext.prefix\" to disambiguate!") + } + cmds << "seqkit sample --threads ${task.cpus} ${args} ${f} -o ${out_name}" + } } """ - seqkit \\ - sample \\ - --threads ${task.cpus} \\ - ${args} \\ - ${fastx} \\ - -o ${prefix}.${extension} + ${cmds.join(' \\\n && ')} """ stub: prefix = task.ext.prefix ?: "${meta.id}" + def fastx_list = fastx instanceof List ? fastx : [fastx] + def first_file = fastx_list[0].toString() extension = "fastq" - if ("${fastx}" ==~ /.+\.fasta|.+\.fasta\.gz|.+\.fa|.+\.fa\.gz|.+\.fas|.+\.fas\.gz|.+\.fna|.+\.fna\.gz|.+\.fsa|.+\.fsa\.gz/) { + if (first_file ==~ /.+\.(fasta|fa|fas|fna|fsa)(\.gz)?/) { extension = "fasta" } - extension = fastx.toString().endsWith('.gz') ? "${extension}.gz" : extension - if ("${prefix}.${extension}" == "${fastx}") { - error("Input and output names are the same, use \"task.ext.prefix\" to disambiguate!") - } + extension = first_file.endsWith('.gz') ? "${extension}.gz" : extension def create_cmd = extension.endsWith('.gz') ? "echo '' | gzip >" : "touch" + + def stub_cmds = [] + if (fastx_list.size() == 1) { + def out_name = "${prefix}.${extension}" + if (out_name == "${fastx_list[0]}") { + error("Input and output names are the same, use \"task.ext.prefix\" to disambiguate!") + } + stub_cmds << "${create_cmd} ${out_name}" + } else { + fastx_list.eachWithIndex { f, i -> + def out_name = "${prefix}_${i + 1}.${extension}" + if (out_name == "${f}") { + error("Input and output names are the same, use \"task.ext.prefix\" to disambiguate!") + } + stub_cmds << "${create_cmd} ${out_name}" + } + } """ - ${create_cmd} ${prefix}.${extension} + ${stub_cmds.join('\n ')} """ }