From fa6ec7324596ee0b0c9f36b3e7f9510a763c0d0e Mon Sep 17 00:00:00 2001
From: Laurent Modolo <laurent.modolo@ens-lyon.fr>
Date: Tue, 5 Oct 2021 16:49:11 +0200
Subject: [PATCH] danpos: change channel cardinality

---
 src/nf_modules/danpos/main.nf | 64 ++++++++++++++++++-----------------
 src/nf_modules/ucsc/main.nf   | 27 +++++++++++++++
 2 files changed, 60 insertions(+), 31 deletions(-)

diff --git a/src/nf_modules/danpos/main.nf b/src/nf_modules/danpos/main.nf
index 350449e9..10d42f49 100644
--- a/src/nf_modules/danpos/main.nf
+++ b/src/nf_modules/danpos/main.nf
@@ -2,7 +2,7 @@ version = "v2.2.2_cv3"
 container_url = "biocontainers/danpos:${version}"
 
 include {
-  bigwig_to_wig
+  bigwig2_to_wig2
 } from "./../ucsc/main.nf"
 
 params.dpos = "--smooth_width 0 -n N "
@@ -18,8 +18,7 @@ process dpos_bam {
 
   input:
     tuple val(file_id), path(fastq)
-    tuple val(file_id), path(bam_ip)
-    tuple val(file_id), path(bam_wce)
+    tuple val(file_id), path(bam_ip), path(bam_wce)
 
   output:
     tuple file_id, "${file_prefix}/pooled/*.wig" into wig
@@ -55,10 +54,9 @@ danpos.py dpos -m ${m}
 workflow dpos_bw {
   take:
     fastq
-    bw_ip
-    bw_wce
+    bw
   main:
-    dpos_wig(fastq, bigwig_to_wig(bw_ip), bigwig_to_wig(bw_wce))
+    dpos_wig(fastq, bigwig2_to_wig2(bw))
   emit:
   wig = dpos_wig.out.wig
   folder = dpos_wig.out.folder
@@ -74,8 +72,7 @@ process dpos_wig {
 
   input:
     tuple val(file_id), path(fastq)
-    tuple val(file_id), path(wig_ip)
-    tuple val(file_id), path(wig_wce)
+    tuple val(file_id), path(wig_ip), path(wig_wce)
 
   output:
   tuple file_id, "${file_prefix}/pooled/*.wig" into wig
@@ -108,6 +105,22 @@ danpos.py dpos -m ${m}
 """
 }
 
+workflow dwig_bwvsbw {
+  take:
+    fastq
+    bw_a
+    bw_b
+  main:
+    dpos_wigvswig(
+      fastq,
+      bigwig2_to_wig2(bw_a),
+      bigwig2_to_wig2(bw_b),
+    )
+  emit:
+  wig = dpeak_wig.out.wig
+  folder = dpeak_wig.out.folder
+}
+
 process dpos_wigvswig {
   container = "${container_url}"
   label "big_mem_mono_cpus"
@@ -118,10 +131,8 @@ process dpos_wigvswig {
 
   input:
     tuple val(file_id), path(fastq)
-    tuple val(file_id), path(wig_ip_a)
-    tuple val(file_id), path(wig_wce_a)
-    tuple val(file_id), path(wig_ip_b)
-    tuple val(file_id), path(wig_wce_b)
+    tuple val(file_id), path(wig_ip_a), path(wig_wce_a)
+    tuple val(file_id), path(wig_ip_b), path(wig_wce_b)
 
   output:
   tuple file_id, "${file_prefix}/pooled/*.wig" into wig
@@ -167,8 +178,7 @@ process dpeak_bam {
 
   input:
     tuple val(file_id), path(fastq)
-    tuple val(file_id), path(bam_ip)
-    tuple val(file_id), path(bam_wce)
+    tuple val(file_id), path(bam_ip), path(bam_wce)
 
   output:
     tuple file_id, "${file_prefix}/pooled/*.wig" into wig
@@ -204,10 +214,9 @@ danpos.py dpeak -m ${m}
 workflow dpeak_bw {
   take:
     fastq
-    bw_ip
-    bw_wce
+    bw
   main:
-    dpeak_wig(fastq, bigwig_to_wig(bw_ip), bigwig_to_wig(bw_wce))
+    dpeak_wig(fastq, bigwig2_to_wig2(bw))
   emit:
   wig = dpeak_wig.out.wig
   folder = dpeak_wig.out.folder
@@ -224,8 +233,7 @@ process dpeak_wig {
 
   input:
     tuple val(file_id), path(fastq)
-    tuple val(file_id), path(wig_ip)
-    tuple val(file_id), path(wig_wce)
+    tuple val(file_id), path(wig_ip), path(wig_wce)
 
   output:
   tuple file_id, "${file_prefix}/pooled/*.wig" into wig
@@ -261,17 +269,13 @@ danpos.py dpeak -m ${m}
 workflow dpeak_bwvsbw {
   take:
     fastq
-    bw_ip_a
-    bw_wce_a
-    bw_ip_b
-    bw_wce_b
+    bw_a
+    bw_b
   main:
     dpeak_wigvswig(
       fastq,
-      bigwig_to_wig(bw_ip_a),
-      bigwig_to_wig(bw_wce_a),
-      bigwig_to_wig(bw_ip_b),
-      bigwig_to_wig(bw_wce_b)
+      bigwig2_to_wig2(bw_a),
+      bigwig2_to_wig2(bw_b),
     )
   emit:
   wig = dpeak_wig.out.wig
@@ -289,10 +293,8 @@ process dpeak_wigvswig {
 
   input:
     tuple val(file_id), path(fastq)
-    tuple val(file_id), path(wig_ip_a)
-    tuple val(file_id), path(wig_wce_a)
-    tuple val(file_id), path(wig_ip_b)
-    tuple val(file_id), path(wig_wce_b)
+    tuple val(file_id), path(wig_ip_a), path(wig_wce_a)
+    tuple val(file_id), path(wig_ip_b), path(wig_wce_b)
 
   output:
   tuple file_id, "${file_prefix}/pooled/*.wig" into wig
diff --git a/src/nf_modules/ucsc/main.nf b/src/nf_modules/ucsc/main.nf
index 7adf6a81..6e3ebc19 100644
--- a/src/nf_modules/ucsc/main.nf
+++ b/src/nf_modules/ucsc/main.nf
@@ -53,4 +53,31 @@ bigWigToWig ${params.bigwig_to_wig} - \
   ${bg} \
   ${bg.simpleName}.wig
 """
+}
+
+params.bigwig2_to_wig2 = ""
+params.bigwig2_to_wig2_out = ""
+process bigwig2_to_wig2 {
+  container = "${container_url}"
+  label "big_mem_mono_cpus"
+  tag "${file_id}"
+  if (params.bigwig_to_wig_out != "") {
+    publishDir "results/${params.bigwig_to_wig_out}", mode: 'copy'
+  }
+
+  input:
+  tuple val(file_id), path(bw_a), path(bw_b)
+
+  output:
+  tuple val(file_id), path("${bw_a.simpleName}.wig"), path("${bw_b.simpleName}.wig"), emit: wig
+
+  script:
+"""
+bigWigToWig ${params.bigwig_to_wig} - \
+  ${bw_a} \
+  ${bw_a.simpleName}.wig
+bigWigToWig ${params.bigwig_to_wig} - \
+  ${bw_b} \
+  ${bw_b.simpleName}.wig
+"""
 }
\ No newline at end of file
-- 
GitLab