CAT: Use meta map and supply output file name via modules.config (#1446)

* Use meta map and supply output file name via modules.config

* Remove all def declarations to make it work

* update tests & remove extra .

* fix ze tests

* update meta.yml with meta map info

* add tag line now that meta is available
This commit is contained in:
FriederikeHanssen 2022-03-25 14:01:57 +01:00 committed by GitHub
parent e786457fb0
commit 3d31fa4d04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 29 deletions

View file

@ -1,4 +1,5 @@
process CAT_CAT { process CAT_CAT {
tag "$meta.id"
label 'process_low' label 'process_low'
conda (params.enable_conda ? "conda-forge::pigz=2.3.4" : null) conda (params.enable_conda ? "conda-forge::pigz=2.3.4" : null)
@ -7,12 +8,11 @@ process CAT_CAT {
'quay.io/biocontainers/pigz:2.3.4' }" 'quay.io/biocontainers/pigz:2.3.4' }"
input: input:
path files_in tuple val(meta), path(files_in)
val file_out
output: output:
path "${file_out}*" , emit: file_out tuple val(meta), path("${prefix}"), emit: file_out
path "versions.yml" , emit: versions path "versions.yml" , emit: versions
when: when:
task.ext.when == null || task.ext.when task.ext.when == null || task.ext.when
@ -29,16 +29,18 @@ process CAT_CAT {
// | gzipped | ungzipped | zcat | | // | gzipped | ungzipped | zcat | |
// | ungzipped | gzipped | cat | pigz | // | ungzipped | gzipped | cat | pigz |
def in_zip = file_list[0].endsWith('.gz') // Use input file ending as default
def out_zip = file_out.endsWith('.gz') prefix = task.ext.prefix ?: "${meta.id}${file_list[0].substring(file_list[0].lastIndexOf('.'))}"
def command1 = (in_zip && !out_zip) ? 'zcat' : 'cat' out_zip = prefix.endsWith('.gz')
def command2 = (!in_zip && out_zip) ? "| pigz -c -p $task.cpus $args2" : '' in_zip = file_list[0].endsWith('.gz')
command1 = (in_zip && !out_zip) ? 'zcat' : 'cat'
command2 = (!in_zip && out_zip) ? "| pigz -c -p $task.cpus $args2" : ''
""" """
$command1 \\ $command1 \\
$args \\ $args \\
${file_list.join(' ')} \\ ${file_list.join(' ')} \\
$command2 \\ $command2 \\
> $file_out > ${prefix}
cat <<-END_VERSIONS > versions.yml cat <<-END_VERSIONS > versions.yml
"${task.process}": "${task.process}":

View file

@ -12,13 +12,15 @@ tools:
tool_dev_url: None tool_dev_url: None
licence: ["GPL-3.0-or-later"] licence: ["GPL-3.0-or-later"]
input: input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- files_in: - files_in:
type: file type: file
description: List of compressed / uncompressed files description: List of compressed / uncompressed files
pattern: "*" pattern: "*"
- file_out:
type: value
description: Full name of output file with or without .gz extension
output: output:
- versions: - versions:
@ -32,3 +34,4 @@ output:
authors: authors:
- "@erikrikarddaniel" - "@erikrikarddaniel"
- "@FriederikeHanssen"

View file

@ -2,53 +2,60 @@
nextflow.enable.dsl = 2 nextflow.enable.dsl = 2
include { CAT_CAT } from '../../../../modules/cat/cat/main.nf' include { CAT_CAT } from '../../../../modules/cat/cat/main.nf'
include { CAT_CAT as CAT_UNZIPPED_ZIPPED } from '../../../../modules/cat/cat/main.nf'
include { CAT_CAT as CAT_ZIPPED_UNZIPPED } from '../../../../modules/cat/cat/main.nf'
workflow test_cat_unzipped_unzipped { workflow test_cat_unzipped_unzipped {
input = [ input = [
file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true), [ id:'test', single_end:true ], // meta map
file(params.test_data['sarscov2']['genome']['genome_sizes'], checkIfExists: true) [ file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true),
file(params.test_data['sarscov2']['genome']['genome_sizes'], checkIfExists: true) ]
] ]
CAT_CAT ( input, 'cat.txt' ) CAT_CAT ( input )
} }
workflow test_cat_zipped_zipped { workflow test_cat_zipped_zipped {
input = [ input = [
file(params.test_data['sarscov2']['genome']['genome_gff3_gz'], checkIfExists: true), [ id:'test', single_end:true ], // meta map
file(params.test_data['sarscov2']['genome']['contigs_genome_maf_gz'], checkIfExists: true) [file(params.test_data['sarscov2']['genome']['genome_gff3_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['genome']['contigs_genome_maf_gz'], checkIfExists: true)]
] ]
CAT_CAT ( input, 'cat.txt.gz' ) CAT_CAT ( input )
} }
workflow test_cat_zipped_unzipped { workflow test_cat_zipped_unzipped {
input = [ input = [
file(params.test_data['sarscov2']['genome']['genome_gff3_gz'], checkIfExists: true), [ id:'test', single_end:true ], // meta map
file(params.test_data['sarscov2']['genome']['contigs_genome_maf_gz'], checkIfExists: true) [file(params.test_data['sarscov2']['genome']['genome_gff3_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['genome']['contigs_genome_maf_gz'], checkIfExists: true)]
] ]
CAT_CAT ( input, 'cat.txt' ) CAT_ZIPPED_UNZIPPED ( input )
} }
workflow test_cat_unzipped_zipped { workflow test_cat_unzipped_zipped {
input = [ input = [
file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true), [ id:'test', single_end:true ], // meta map
file(params.test_data['sarscov2']['genome']['genome_sizes'], checkIfExists: true) [file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true),
file(params.test_data['sarscov2']['genome']['genome_sizes'], checkIfExists: true)]
] ]
CAT_CAT ( input, 'cat.txt.gz' ) CAT_UNZIPPED_ZIPPED ( input )
} }
workflow test_cat_one_file_unzipped_zipped { workflow test_cat_one_file_unzipped_zipped {
input = [ input = [
file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true), [ id:'test', single_end:true ], // meta map
file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true)
] ]
CAT_CAT ( input, 'cat.txt.gz' ) CAT_UNZIPPED_ZIPPED ( input )
} }

View file

@ -2,4 +2,12 @@ process {
publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }
withName: CAT_UNZIPPED_ZIPPED {
ext.prefix = 'cat.txt.gz'
}
withName: CAT_ZIPPED_UNZIPPED {
ext.prefix = 'cat.txt'
}
} }

View file

@ -4,7 +4,7 @@
- cat - cat
- cat/cat - cat/cat
files: files:
- path: output/cat/cat.txt - path: output/cat/test.fasta
md5sum: f44b33a0e441ad58b2d3700270e2dbe2 md5sum: f44b33a0e441ad58b2d3700270e2dbe2
- name: cat zipped zipped - name: cat zipped zipped
@ -13,7 +13,7 @@
- cat - cat
- cat/cat - cat/cat
files: files:
- path: output/cat/cat.txt.gz - path: output/cat/test.gz
- name: cat zipped unzipped - name: cat zipped unzipped
command: nextflow run ./tests/modules/cat/cat -entry test_cat_zipped_unzipped -c ./tests/config/nextflow.config -c ./tests/modules/cat/cat/nextflow.config command: nextflow run ./tests/modules/cat/cat -entry test_cat_zipped_unzipped -c ./tests/config/nextflow.config -c ./tests/modules/cat/cat/nextflow.config