From 81a9ff871896148174f05a8a53872767cc77f0df Mon Sep 17 00:00:00 2001
From: Mia Croiset <mia.croiset@ens-lyon.fr>
Date: Tue, 5 Dec 2023 15:14:42 +0100
Subject: [PATCH] add hicstuff versions

---
 modules/local/hicstuff/align_bowtie2.nf   | 8 ++++++++
 modules/local/hicstuff/fragment_enzyme.nf | 6 ++++++
 subworkflows/local/hicstuff.nf            | 5 +++++
 workflows/hic.nf                          | 1 +
 4 files changed, 20 insertions(+)

diff --git a/modules/local/hicstuff/align_bowtie2.nf b/modules/local/hicstuff/align_bowtie2.nf
index 188836d..210c0d4 100644
--- a/modules/local/hicstuff/align_bowtie2.nf
+++ b/modules/local/hicstuff/align_bowtie2.nf
@@ -13,6 +13,7 @@ process BOWTIE2_ALIGNMENT {
 
     output:
     tuple val(meta), path ("*.bam"), emit: bam
+    path "versions.yml", emit: versions
 
     script:
     def prefix = task.ext.prefix ?: "${meta.id}"
@@ -26,6 +27,13 @@ process BOWTIE2_ALIGNMENT {
     bowtie2 $args -p $task.cpus -x \$INDEX -U $reads > ${prefix}.tmp
 
     samtools view -F 2048 -h -@ $task.cpus ${prefix}.tmp | samtools sort -n -@ $task.cpus -o ${prefix}.bam -
+
+    cat <<-END_VERSIONS > versions.yml
+    "${task.process}":
+        bowtie2: \$(echo \$(bowtie2 --version 2>&1) | sed 's/^.*bowtie2-align-s version //; s/ .*\$//')
+        samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
+        pigz: \$( pigz --version 2>&1 | sed 's/pigz //g' )
+    END_VERSIONS
     """
 
 }
diff --git a/modules/local/hicstuff/fragment_enzyme.nf b/modules/local/hicstuff/fragment_enzyme.nf
index 855bf48..b6d044a 100644
--- a/modules/local/hicstuff/fragment_enzyme.nf
+++ b/modules/local/hicstuff/fragment_enzyme.nf
@@ -13,6 +13,7 @@ process FRAGMENT_ENZYME {
     tuple val(meta), path(params.hicstuff_output_contigs) , emit: info_contigs
     tuple val(meta), path(params.hicstuff_output_frags), emit: fragments_list
     path("*.pdf"), optional: true
+    path "versions.yml", emit: versions
 
     script:
 
@@ -20,6 +21,11 @@ process FRAGMENT_ENZYME {
 
     """
     hicstuff_fragments.py -e ${digestion} -i ${fasta} ${args}
+
+    cat <<-END_VERSIONS > versions.yml
+    "${task.process}":
+        hicstuff: v3.1.3)
+    END_VERSIONS
     """
 
 }
diff --git a/subworkflows/local/hicstuff.nf b/subworkflows/local/hicstuff.nf
index d9c60ab..0b3072e 100644
--- a/subworkflows/local/hicstuff.nf
+++ b/subworkflows/local/hicstuff.nf
@@ -42,6 +42,7 @@ workflow HICSTUFF {
     chromosome_size
 
     main:
+    ch_versions = Channel.empty()
 
     // Align each mates separetly and add mates information in [meta]
     ch_reads_r1 = reads.map{ it -> pairToSingle(it,"R1") }
@@ -52,11 +53,13 @@ workflow HICSTUFF {
         ch_reads,
         index.collect()
     )
+    ch_versions = ch_versions.mix(BOWTIE2_ALIGNMENT.out.versions)
 
     FRAGMENT_ENZYME(
         digestion,
         fasta
     )
+    ch_versions = ch_versions.mix(FRAGMENT_ENZYME.out.versions)
 
     if (params.filter_pcr && params.filter_pcr_picard ){
         error "Error: filter_pcr and filter_pcr_picard can't both be true at the same time! Set one of them false in the config file"
@@ -68,6 +71,7 @@ workflow HICSTUFF {
             index
         )
         FILTER_PCR_DUP.out.bam.set{ new_ch_bam }
+        ch_versions = ch_versions.mix(FILTER_PCR_DUP.out.versions)
     }
     else {
 
@@ -130,4 +134,5 @@ workflow HICSTUFF {
 
     emit:
     cool = BUILD_MATRIX_COOL_ALT.out.matrix
+    versions = ch_versions
 }
diff --git a/workflows/hic.nf b/workflows/hic.nf
index 70c1f8d..6111170 100644
--- a/workflows/hic.nf
+++ b/workflows/hic.nf
@@ -230,6 +230,7 @@ workflow HIC {
     )
     ch_cool = HICSTUFF.out.cool
     ch_mqc = Channel.empty()
+    ch_versions = ch_versions.mix(HICSTUFF.out.versions)
   }
 
   //
-- 
GitLab