From 28a831bfacb47d84c2780d15977da8a306efabb7 Mon Sep 17 00:00:00 2001
From: Laurent Modolo <laurent@modolo.fr>
Date: Fri, 29 Jan 2021 15:07:16 +0100
Subject: [PATCH] nf_modules: update output tuple to handle list as file_id

---
 src/nf_modules/bedtools/main.nf  |  4 ++--
 src/nf_modules/bowtie2/main.nf   | 14 +++++++-------
 src/nf_modules/deeptools/main.nf |  7 ++++---
 src/nf_modules/kallisto/main.nf  |  4 ++--
 src/nf_modules/macs2/main.nf     |  6 +++---
 src/nf_modules/sambamba/main.nf  |  8 +++++---
 6 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/nf_modules/bedtools/main.nf b/src/nf_modules/bedtools/main.nf
index 4d3e4e1f..bd4a1890 100644
--- a/src/nf_modules/bedtools/main.nf
+++ b/src/nf_modules/bedtools/main.nf
@@ -12,7 +12,7 @@ process fasta_from_bed {
   path bed
 
   output:
-  path "*_extracted.fasta", emit: fasta
+  tuple val(bed.baseName), path("*_extracted.fasta"), emit: fasta
 
   script:
 """
@@ -50,7 +50,7 @@ process bam_to_fastq_pairedend {
   tuple val(bam_id), path(bam)
 
   output:
-  tuple val(bam.baseName), path("*.fastq"), emit: fastq
+  tuple val(bam_id), path("*.fastq"), emit: fastq
 
   script:
 """
diff --git a/src/nf_modules/bowtie2/main.nf b/src/nf_modules/bowtie2/main.nf
index e17e7f24..22465bae 100644
--- a/src/nf_modules/bowtie2/main.nf
+++ b/src/nf_modules/bowtie2/main.nf
@@ -78,8 +78,8 @@ process mapping_fastq_singleend {
   tuple val(file_id), path(reads)
 
   output:
-  set file_id, "*.bam", emit: bam
-  file "*_report.txt", emit: report
+  tuple val(file_id), path("*.bam"), emit: bam
+  path "*_report.txt", emit: report
 
   script:
   index_id = index[0]
@@ -93,13 +93,13 @@ bowtie2 --very-sensitive \
   -p ${task.cpus} \
   -x ${index_id} \
   -U ${reads} 2> \
-  ${file_id}_bowtie2_mapping_report_tmp.txt | \
-  samtools view -Sb - > ${file_id}.bam
+  ${reads.baseName}_bowtie2_mapping_report_tmp.txt | \
+  samtools view -Sb - > ${reads.baseName}.bam
 
-if grep -q "Error" ${file_id}_bowtie2_mapping_report_tmp.txt; then
+if grep -q "Error" ${reads.baseName}_bowtie2_mapping_report_tmp.txt; then
   exit 1
 fi
-tail -n 19 ${file_id}_bowtie2_mapping_report_tmp.txt > \
-  ${file_id}_bowtie2_mapping_report.txt
+tail -n 19 ${reads.baseName}_bowtie2_mapping_report_tmp.txt > \
+  ${reads.baseName}_bowtie2_mapping_report.txt
 """
 }
diff --git a/src/nf_modules/deeptools/main.nf b/src/nf_modules/deeptools/main.nf
index ba2be7c5..3d012796 100644
--- a/src/nf_modules/deeptools/main.nf
+++ b/src/nf_modules/deeptools/main.nf
@@ -33,7 +33,8 @@ process bam_to_bigwig {
 
   script:
 """
-bamCoverage -p ${task.cpus} --ignoreDuplicates -b ${bam} -o ${file_id}.bw
+bamCoverage -p ${task.cpus} --ignoreDuplicates -b ${bam} \
+  -o ${bam.simpleName}.bw
 """
 }
 
@@ -57,7 +58,7 @@ computeMatrix scale-regions -S ${bw} \
   -R ${bed} \
   --beforeRegionStartLength 100 \
   --afterRegionStartLength 100 \
-  -o ${bed_file_id}.mat.gz
+  -o ${bed.simpleName}.mat.gz
 """
 }
 
@@ -81,7 +82,7 @@ https://deeptools.readthedocs.io/en/develop/content/tools/plotProfile.html
 """
 plotProfile -m ${matrix} \
   --plotFileFormat=pdf \
-  -out ${file_id}.pdf \
+  -out ${matrix.simpleName}.pdf \
   --plotType=fill \
   --perGroup \
   --plotTitle "${params.title}"
diff --git a/src/nf_modules/kallisto/main.nf b/src/nf_modules/kallisto/main.nf
index 5b0a150f..0517a1b5 100644
--- a/src/nf_modules/kallisto/main.nf
+++ b/src/nf_modules/kallisto/main.nf
@@ -57,7 +57,7 @@ process mapping_fastq_singleend {
   tuple val(file_id), path(reads)
 
   output:
-  path "${pair_id}", emit: counts
+  tuple val(file_id), path("${pair_id}"), emit: counts
   path "*_report.txt", emit: report
 
   script:
@@ -66,6 +66,6 @@ mkdir ${file_id}
 kallisto quant -i ${index} -t ${task.cpus} --single \
 --bias --bootstrap-samples 100 -o ${file_id} \
 -l ${params.mean} -s ${params.sd} \
-${reads} &> ${file_id}_kallisto_mapping_report.txt
+${reads} &> ${reads.simpleName}_kallisto_mapping_report.txt
 """
 }
diff --git a/src/nf_modules/macs2/main.nf b/src/nf_modules/macs2/main.nf
index 9748cdc6..e30e0ee2 100644
--- a/src/nf_modules/macs2/main.nf
+++ b/src/nf_modules/macs2/main.nf
@@ -22,11 +22,11 @@ macs2 callpeak \
   --call-summits "True"\
   --control ${file_control} \
   --keep-dup "auto" \
-  --name ${file_id} \
+  --name ${bam_ip.simpleName} \
   --gsize ${params.genome_size} 2> \
-  ${file_ip}_macs2_report.txt
+  ${bam_ip.simpleName}_macs2_report.txt
 
-if grep -q "ERROR" ${file_ip}_macs2_report.txt; then
+if grep -q "ERROR" ${bam_ip.simpleName}_macs2_report.txt; then
   echo "MACS2 error"
   exit 1
 fi
diff --git a/src/nf_modules/sambamba/main.nf b/src/nf_modules/sambamba/main.nf
index eb9bbb46..e07210bb 100644
--- a/src/nf_modules/sambamba/main.nf
+++ b/src/nf_modules/sambamba/main.nf
@@ -31,7 +31,7 @@ process sort_bam {
 
   script:
 """
-sambamba sort -t ${task.cpus} -o ${file_id}_sorted.bam ${bam}
+sambamba sort -t ${task.cpus} -o ${bam.baseName}_sorted.bam ${bam}
 """
 }
 
@@ -49,7 +49,9 @@ process split_bam {
     tuple val(file_id), path("*_reverse.bam*"), emit: bam_reverse
   script:
 """
-sambamba view -t ${task.cpus} -h -F "strand == '+'" ${bam} > ${file_id}_forward.bam
-sambamba view -t ${task.cpus} -h -F "strand == '-'" ${bam} > ${file_id}_reverse.bam
+sambamba view -t ${task.cpus} -h -F "strand == '+'" ${bam} > \
+  ${bam.baseName}_forward.bam
+sambamba view -t ${task.cpus} -h -F "strand == '-'" ${bam} > \
+  ${bam.baseName}_reverse.bam
 """
 }
-- 
GitLab