From 192fef094b57278549a662219e3e6783f0bc0b88 Mon Sep 17 00:00:00 2001 From: Laurent Modolo <laurent.modolo@ens-lyon.fr> Date: Tue, 18 May 2021 10:06:23 +0200 Subject: [PATCH] bowtie2: change file_id handling --- CONTRIBUTING.md | 15 +++++++++++---- src/nf_modules/bowtie2/main.nf | 14 ++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d3cb5d5e..0f03c1e8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -125,15 +125,22 @@ process fastp { Here `file_id` can be anything from a simple identifier to a list of several variables. In which case the first item of the List should be usable as a file prefix. So you have to keep that in mind if you want to use it to define output file names (you can test for that with `file_id instanceof List`). +In some case, the `file_id` may be a Map to have a cleaner access to the `file_id` content by explicit keywords. If you want to use information within the `file_id` to name outputs in your `script` section, you can use the following snipet: ```Groovy script: - if (file_id instanceof List){ - file_prefix = file_id[0] - } else { - file_prefix = file_id + switch(file_id) { + case {it instanceof List}: + file_prefix = file_id[0] + break + case {it instanceof Map}: + file_prefix = file_id.values()[0] + break + default: + file_id + break } ``` diff --git a/src/nf_modules/bowtie2/main.nf b/src/nf_modules/bowtie2/main.nf index 2b0cf963..20f66eb1 100644 --- a/src/nf_modules/bowtie2/main.nf +++ b/src/nf_modules/bowtie2/main.nf @@ -56,10 +56,16 @@ process mapping_fastq { index_id = ( index_file =~ /(.*)\.1\.bt2/)[0][1] } } - if (file_id instanceof List){ - file_prefix = file_id[0] - } else { - file_prefix = file_id + switch(file_id) { + case {it instanceof List}: + file_prefix = file_id[0] + break + case {it instanceof Map}: + file_prefix = file_id.values()[0] + break + default: + file_id + break } if (reads.size() == 2) -- GitLab