From 8e6edae0391adc5ca669b2869ca3b55fc3f9d8b8 Mon Sep 17 00:00:00 2001
From: Xavier Grand <xavier.grand@ens-lyon.fr>
Date: Wed, 13 Oct 2021 08:59:13 +0200
Subject: [PATCH] Test ChIPseq CTCF

---
 src/nf_modules/bowtie2/main.nf | 70 ++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/src/nf_modules/bowtie2/main.nf b/src/nf_modules/bowtie2/main.nf
index 4a670f17..e31f560c 100644
--- a/src/nf_modules/bowtie2/main.nf
+++ b/src/nf_modules/bowtie2/main.nf
@@ -100,3 +100,73 @@ process mapping_fastq {
     ${file_prefix}_bowtie2_mapping_report.txt
   """
 }
+
+
+
+process mapping_fastq_chipster {
+  container = "${container_url}"
+  label "big_mem_multi_cpus"
+  tag "$file_id"
+  if (params.mapping_fastq_out != "") {
+    publishDir "results/${params.mapping_fastq_out}", mode: 'copy'
+  }
+
+  input:
+  tuple val(index_id), path(index)
+  tuple val(file_id), path(reads), val(condition), val(type)
+
+  output:
+  tuple val(file_id), path("*.bam"), val(condition), val(type), emit: bam
+  path "*_report.txt", emit: report
+
+  script:
+  index_id = index[0]
+  for (index_file in index) {
+    if (index_file =~ /.*\.1\.bt2/ && !(index_file =~ /.*\.rev\.1\.bt2/)) {
+        index_id = ( index_file =~ /(.*)\.1\.bt2/)[0][1]
+    }
+  }
+  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_prefix = file_id
+    break
+  }
+
+  if (reads.size() == 2)
+  """
+  bowtie2 ${params.mapping_fastq} \
+    -p ${task.cpus} \
+    -x ${index_id} \
+    -1 ${reads[0]} \
+    -2 ${reads[1]} 2> \
+    ${file_prefix}_bowtie2_mapping_report_tmp.txt | \
+    samtools view -Sb - > ${file_prefix}.bam
+
+  if grep -q "Error" ${file_prefix}_bowtie2_mapping_report_tmp.txt; then
+    exit 1
+  fi
+  tail -n 19 ${file_prefix}_bowtie2_mapping_report_tmp.txt > \
+    ${file_prefix}_bowtie2_mapping_report.txt
+  """
+  else
+  """
+  bowtie2 ${params.mapping_fastq} \
+    -p ${task.cpus} \
+    -x ${index_id} \
+    -U ${reads} 2> \
+    ${file_prefix}_bowtie2_mapping_report_tmp.txt | \
+    samtools view -Sb - > ${file_prefix}.bam
+
+  if grep -q "Error" ${file_prefix}_bowtie2_mapping_report_tmp.txt; then
+    exit 1
+  fi
+  tail -n 19 ${file_prefix}_bowtie2_mapping_report_tmp.txt > \
+    ${file_prefix}_bowtie2_mapping_report.txt
+  """
+}
-- 
GitLab