From 4aa3ea2e98637710ae4e100e817e48c719c6a9b2 Mon Sep 17 00:00:00 2001
From: Mia Croiset <mia.croiset@ens-lyon.fr>
Date: Fri, 3 Feb 2023 09:46:54 +0100
Subject: [PATCH] TEST correction alignement meta chunck

---
 conf/hicstuff.config               |  4 +++
 subworkflows/local/hicstuff_sub.nf | 42 ++++++++++++++++++++++++++++++
 workflows/hic.nf                   | 10 +++----
 workflows/hicstuff.nf              |  7 ++---
 4 files changed, 55 insertions(+), 8 deletions(-)
 create mode 100644 subworkflows/local/hicstuff_sub.nf

diff --git a/conf/hicstuff.config b/conf/hicstuff.config
index 4af147d..6e20d06 100644
--- a/conf/hicstuff.config
+++ b/conf/hicstuff.config
@@ -5,6 +5,10 @@ process {
         mode: 'copy',
         saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
     ]
+
+    withName: 'BOWTIE2_ALIGNMENT' {
+        ext.prefix = { "${meta.id}_${meta.chunk}_${meta.mates}" }
+    }
 }
 
 params {
diff --git a/subworkflows/local/hicstuff_sub.nf b/subworkflows/local/hicstuff_sub.nf
new file mode 100644
index 0000000..dfb160b
--- /dev/null
+++ b/subworkflows/local/hicstuff_sub.nf
@@ -0,0 +1,42 @@
+
+include { BOWTIE2_ALIGNMENT } from '../../modules/local/hicstuff/align_bowtie2'
+
+// Paired-end to Single-end
+def pairToSingle(row, mates) {
+    def meta = row[0].clone()
+    meta.single_end = true
+    meta.mates = mates
+    if (mates == "R1") {
+        return [meta, [ row[1][0]] ]
+    }else if (mates == "R2"){
+        return [meta, [ row[1][1]] ]
+    }
+}
+
+// Single-end to Paired-end
+def singleToPair(row){
+    def meta = row[0].clone()
+    meta.remove('mates')
+    meta.single_end = false
+    return [ meta, row[1] ]
+}
+
+workflow HICSTUFF_SUB {
+
+    take:
+    reads
+    index
+    ligation_site
+
+    main:
+
+    // Align each mates separetly and add mates information in [meta]
+    ch_reads_r1 = reads.map{ it -> pairToSingle(it,"R1") }
+    ch_reads_r2 = reads.map{ it -> pairToSingle(it,"R2") }
+    ch_reads = ch_reads_r1.concat(ch_reads_r2)
+
+    BOWTIE2_ALIGNMENT(
+        ch_reads,
+        index.collect()
+    )
+}
diff --git a/workflows/hic.nf b/workflows/hic.nf
index faa6a59..50c6a0a 100644
--- a/workflows/hic.nf
+++ b/workflows/hic.nf
@@ -51,7 +51,7 @@ if (params.res_tads && !params.skip_tads){
 }else{
   ch_tads_res=Channel.empty()
   if (!params.skip_tads){
-    log.warn "[nf-core/hic] Hi-C resolution for TADs calling not specified. See --res_tads" 
+    log.warn "[nf-core/hic] Hi-C resolution for TADs calling not specified. See --res_tads"
   }
 }
 
@@ -61,7 +61,7 @@ if (params.res_dist_decay && !params.skip_dist_decay){
 }else{
   ch_ddecay_res = Channel.empty()
   if (!params.skip_dist_decay){
-    log.warn "[nf-core/hic] Hi-C resolution for distance decay not specified. See --res_dist_decay" 
+    log.warn "[nf-core/hic] Hi-C resolution for distance decay not specified. See --res_dist_decay"
   }
 }
 
@@ -71,7 +71,7 @@ if (params.res_compartments && !params.skip_compartments){
 }else{
   ch_comp_res = Channel.empty()
   if (!params.skip_compartments){
-    log.warn "[nf-core/hic] Hi-C resolution for compartment calling not specified. See --res_compartments" 
+    log.warn "[nf-core/hic] Hi-C resolution for compartment calling not specified. See --res_compartments"
   }
 }
 
@@ -96,7 +96,7 @@ ch_multiqc_custom_methods_description = params.multiqc_methods_description ? fil
 //
 // MODULE: Local to the pipeline
 //
-include { HIC_PLOT_DIST_VS_COUNTS } from '../modules/local/hicexplorer/hicPlotDistVsCounts' 
+include { HIC_PLOT_DIST_VS_COUNTS } from '../modules/local/hicexplorer/hicPlotDistVsCounts'
 include { MULTIQC } from '../modules/local/multiqc'
 
 //
@@ -236,7 +236,7 @@ workflow HIC {
       .filter{ it[0].resolution == it[2] }
       .map { it -> [it[0], it[1]]}
       .set{ ch_cool_tads }
-                                                                                                                                                                                                            
+
     TADS(
       ch_cool_tads
     )
diff --git a/workflows/hicstuff.nf b/workflows/hicstuff.nf
index e411e18..0a760cf 100644
--- a/workflows/hicstuff.nf
+++ b/workflows/hicstuff.nf
@@ -24,7 +24,7 @@ Channel.fromPath( params.fasta )
 
 include { INPUT_CHECK } from '../subworkflows/local/input_check'
 include { PREPARE_GENOME } from '../subworkflows/local/prepare_genome'
-include { BOWTIE2_ALIGNMENT } from '../modules/local/hicstuff/align_bowtie2'
+include { HICSTUFF_SUB } from '../subworkflows/local/hicstuff_sub'
 
 workflow HICSTUFF {
     INPUT_CHECK (
@@ -34,8 +34,9 @@ workflow HICSTUFF {
         ch_fasta,
         ch_restriction_site
     )
-    BOWTIE2_ALIGNMENT(
+    HICSTUFF_SUB(
         INPUT_CHECK.out.reads,
-        PREPARE_GENOME.out.index
+        PREPARE_GENOME.out.index,
+        ch_ligation_site
     )
 }
-- 
GitLab