From b25a6418a9362ce94d8412b1b1fa7c7caa8dc4c7 Mon Sep 17 00:00:00 2001
From: Laurent Modolo <laurent@modolo.fr>
Date: Wed, 19 Dec 2018 16:27:14 +0100
Subject: [PATCH] deepTools: add compute_matrix module

---
 src/nf_modules/deepTools/bam_to_bigwig.config |  7 ++--
 src/nf_modules/deepTools/bam_to_bigwig.nf     |  1 -
 .../deepTools/compute_matrix.config           | 25 +++++++++++
 src/nf_modules/deepTools/compute_matrix.nf    | 41 +++++++++++++++++++
 src/nf_modules/deepTools/tests.sh             |  2 +-
 5 files changed, 71 insertions(+), 5 deletions(-)
 create mode 100644 src/nf_modules/deepTools/compute_matrix.config
 create mode 100644 src/nf_modules/deepTools/compute_matrix.nf

diff --git a/src/nf_modules/deepTools/bam_to_bigwig.config b/src/nf_modules/deepTools/bam_to_bigwig.config
index 90eada5d..c1b71cb0 100644
--- a/src/nf_modules/deepTools/bam_to_bigwig.config
+++ b/src/nf_modules/deepTools/bam_to_bigwig.config
@@ -28,9 +28,10 @@ profiles {
         module = "deepTools/3.0.2"
         executor = "sge"
         clusterOptions = "-m e -cwd -V"
-        memory = "20GB"
-        time = "12h"
-        queue = 'monointeldeb128'
+        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/deepTools/bam_to_bigwig.nf b/src/nf_modules/deepTools/bam_to_bigwig.nf
index 012de76a..3507337d 100644
--- a/src/nf_modules/deepTools/bam_to_bigwig.nf
+++ b/src/nf_modules/deepTools/bam_to_bigwig.nf
@@ -1,5 +1,4 @@
 params.bam = "$baseDir/data/bam/*.bam"
-params.bamidx = "$baseDir/data/bam/*.idx"
 
 log.info "bams files : ${params.bam}"
 
diff --git a/src/nf_modules/deepTools/compute_matrix.config b/src/nf_modules/deepTools/compute_matrix.config
new file mode 100644
index 00000000..cb32bf55
--- /dev/null
+++ b/src/nf_modules/deepTools/compute_matrix.config
@@ -0,0 +1,25 @@
+profiles {
+  docker {
+    docker.temp = 'auto'
+    docker.enabled = true
+    process {
+      withName: compute_matrix {
+        container = "deeptools:3.0.2"
+      }
+    }
+  }
+  psmn {
+    process{
+      withName: bam_to_bigwig {
+        beforeScript = "source /usr/share/lmod/lmod/init/bash; module use ~/privatemodules"
+        module = "deepTools/3.0.2"
+        executor = "sge"
+        clusterOptions = "-m e -cwd -V"
+        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/deepTools/compute_matrix.nf b/src/nf_modules/deepTools/compute_matrix.nf
new file mode 100644
index 00000000..53b4b195
--- /dev/null
+++ b/src/nf_modules/deepTools/compute_matrix.nf
@@ -0,0 +1,41 @@
+params.bam = "$baseDir/data/bigwig/*.bw"
+params.bed = "$baseDir/data/annot/*.bed"
+
+log.info "bigwig files : ${params.bw}"
+log.info "bed files : ${params.bed}"
+
+Channel
+  .fromPath( params.bw )
+  .ifEmpty { error "Cannot find any bigwig files matching: ${params.bw}" }
+  .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
+  .set { bw_files }
+
+Channel
+  .fromPath( params.bed )
+  .ifEmpty { error "Cannot find any bed files matching: ${params.bed}" }
+  .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
+  .set { bed_files }
+
+process compute_matrix {
+  tag "$file_id"
+  cpus 4
+  echo true
+  publishDir "results/mapping/region_matrix/", mode: 'copy'
+
+  input:
+    set bw_file_id, file(bw) from bw_files.collect()
+    set bed_file_id, file(bed) from bed_files.collect()
+
+  output:
+    set bed_file_id, "*.mat.gz" into region_matrix
+
+  script:
+"""
+computeMatrix scale-regions -S ${bw} \
+  -p ${task.cpus} \
+  -R ${bed} \
+  --beforeRegionStartLength 100 \
+  --afterRegionStartLength 100 \
+  -o ${bed_file_id}.mat.gz
+"""
+}
diff --git a/src/nf_modules/deepTools/tests.sh b/src/nf_modules/deepTools/tests.sh
index 46816151..63b8434e 100755
--- a/src/nf_modules/deepTools/tests.sh
+++ b/src/nf_modules/deepTools/tests.sh
@@ -2,5 +2,5 @@
 
 ./nextflow src/nf_modules/deepTools/bam_to_bigwig.nf -c src/nf_modules/deepTools/bam_to_bigwig.config -profile docker --bam "data/tiny_dataset/map/tiny_v2.sort.bam"
 
-./nextflow src/nf_modules/deepTools/compute_matrix.nf -c src/nf_modules/deepTools/compute_matrix.config -profile docker --bam "results/mapping/bigwig/*.bw"
+./nextflow src/nf_modules/deepTools/compute_matrix.nf -c src/nf_modules/deepTools/compute_matrix.config -profile docker --bw "results/mapping/bigwig/*.bw" --bed "data/tiny_dataset/annot/tiny.bed"
 
-- 
GitLab