From 72ffaf953089c0259de9157fee10f690643ce469 Mon Sep 17 00:00:00 2001
From: Laurent Modolo <laurent@modolo.fr>
Date: Wed, 20 Mar 2019 18:19:14 +0100
Subject: [PATCH] macs2: add nf module file

---
 src/nf_modules/macs2/peak_calling.config | 36 ++++++++++++++++++
 src/nf_modules/macs2/peak_calling.nf     | 47 ++++++++++++++++++++++++
 src/nf_modules/macs2/tests.sh            |  8 ++++
 3 files changed, 91 insertions(+)
 create mode 100644 src/nf_modules/macs2/peak_calling.config
 create mode 100644 src/nf_modules/macs2/peak_calling.nf
 create mode 100755 src/nf_modules/macs2/tests.sh

diff --git a/src/nf_modules/macs2/peak_calling.config b/src/nf_modules/macs2/peak_calling.config
new file mode 100644
index 00000000..fa0c6d38
--- /dev/null
+++ b/src/nf_modules/macs2/peak_calling.config
@@ -0,0 +1,36 @@
+profiles {
+  docker {
+    docker.temp = 'auto'
+    docker.enabled = true
+    process {
+      withName: peak_calling {
+        container = "macs2:2.1.2"
+        cpus = 4
+      }
+    }
+  }
+  singularity {
+    singularity.enabled = true
+    process {
+      withName: peak_calling {
+        container = "file://bin/macs2:2.1.2.sif"
+        cpus = 4
+      }
+    }
+  }
+  psmn {
+    process{
+      withName: peak_calling {
+        beforeScript = "source /usr/share/lmod/lmod/init/bash; module use ~/privatemodules"
+        module = "macs2/2.1.2"
+        executor = "sge"
+        clusterOptions = "-m e -cwd -V"
+        cpus = 16
+        memory = "30GB"
+        time = "24h"
+        queue = 'E5-2670deb128A,E5-2670deb128B,E5-2670deb128C,E5-2670deb128D,E5-2670deb128E,E5-2670deb128F'
+        penv = 'openmp16'
+      }
+    }
+  }
+}
diff --git a/src/nf_modules/macs2/peak_calling.nf b/src/nf_modules/macs2/peak_calling.nf
new file mode 100644
index 00000000..1bd6a95c
--- /dev/null
+++ b/src/nf_modules/macs2/peak_calling.nf
@@ -0,0 +1,47 @@
+params.genome_size = "hs"
+params.control_tag = "control"
+log.info "bam files : ${params.bam}"
+log.info "genome size : ${params.genome_size}"
+
+Channel
+  .fromPath( params.bam )
+  .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
+  .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
+  .set { bam_files }
+
+/* split bam Channel into control and ip if "control" keyword is detected*/
+bam_files_control = Channel.create()
+bam_files_ip = Channel.create()
+bam_files.choice(
+  bam_files_control,
+  bam_files_ip ) { a -> a[0] =~ /.*${params.control_tag}.*/ ? 0 : 1 }
+
+process peak_calling {
+  tag "${file_id}"
+  publishDir "results/peak_calling/${file_id}", mode: 'copy'
+
+  input:
+    set file_id, file(file_ip) from bam_files_ip
+    set file_id_control, file(file_control) from bam_files_control.collect()
+
+  output:
+    file "*" into peak_output
+    file "*_report.txt" into peak_calling_report
+
+  script:
+/* remove --nomodel option for real dataset */
+"""
+macs2 callpeak \
+  --nomodel \
+  --treatment ${file_ip} \
+  --control ${file_control} \
+  --name ${file_id} \
+  --gsize ${params.genome_size} 2> \
+${file_ip}_macs2_report.txt
+
+if grep -q "ERROR" ${file_ip}_macs2_report.txt; then
+  echo "MACS2 error"
+  exit 1
+fi
+"""
+}
diff --git a/src/nf_modules/macs2/tests.sh b/src/nf_modules/macs2/tests.sh
new file mode 100755
index 00000000..1491b074
--- /dev/null
+++ b/src/nf_modules/macs2/tests.sh
@@ -0,0 +1,8 @@
+cp data/tiny_dataset/map/tiny_v2.bam data/tiny_dataset/map/tiny_v2_control.bam
+./nextflow src/nf_modules/macs2/peak_calling.nf \
+  -c src/nf_modules/macs2/peak_calling.config \
+  -profile docker \
+  -resume \
+  --bam "data/tiny_dataset/map/tiny_v2*.bam" \
+  --genome_size 129984 \
+  --control_tag "control"
-- 
GitLab