From 67c4ff01fa733a562f16ceb7db3fcb4ab88f34a7 Mon Sep 17 00:00:00 2001
From: Laurent Modolo <laurent.modolo@ens-lyon.fr>
Date: Wed, 22 Aug 2018 16:54:02 +0200
Subject: [PATCH] SAMtools: update nf structure

---
 src/nf_modules/SAMtools/filter_bams.config    |  18 +++
 .../SAMtools/{tests => }/filter_bams.nf       |   9 +-
 src/nf_modules/SAMtools/index_bams.config     |  18 +++
 .../SAMtools/{tests => }/index_bams.nf        |  10 +-
 src/nf_modules/SAMtools/samtools.config       |  36 ------
 src/nf_modules/SAMtools/samtools.nf           | 117 ------------------
 src/nf_modules/SAMtools/sort_bams.config      |  18 +++
 .../SAMtools/{tests => }/sort_bams.nf         |   9 +-
 src/nf_modules/SAMtools/split_bams.config     |  18 +++
 src/nf_modules/SAMtools/split_bams.nf         |  27 ++++
 src/nf_modules/SAMtools/tests.sh              |  20 +++
 src/nf_modules/SAMtools/tests/split_bams.nf   |  26 ----
 src/nf_modules/SAMtools/tests/tests.sh        |  20 ---
 13 files changed, 136 insertions(+), 210 deletions(-)
 create mode 100644 src/nf_modules/SAMtools/filter_bams.config
 rename src/nf_modules/SAMtools/{tests => }/filter_bams.nf (67%)
 create mode 100644 src/nf_modules/SAMtools/index_bams.config
 rename src/nf_modules/SAMtools/{tests => }/index_bams.nf (63%)
 delete mode 100644 src/nf_modules/SAMtools/samtools.config
 delete mode 100644 src/nf_modules/SAMtools/samtools.nf
 create mode 100644 src/nf_modules/SAMtools/sort_bams.config
 rename src/nf_modules/SAMtools/{tests => }/sort_bams.nf (53%)
 create mode 100644 src/nf_modules/SAMtools/split_bams.config
 create mode 100644 src/nf_modules/SAMtools/split_bams.nf
 create mode 100755 src/nf_modules/SAMtools/tests.sh
 delete mode 100644 src/nf_modules/SAMtools/tests/split_bams.nf
 delete mode 100755 src/nf_modules/SAMtools/tests/tests.sh

diff --git a/src/nf_modules/SAMtools/filter_bams.config b/src/nf_modules/SAMtools/filter_bams.config
new file mode 100644
index 0000000..0666840
--- /dev/null
+++ b/src/nf_modules/SAMtools/filter_bams.config
@@ -0,0 +1,18 @@
+profiles {
+  docker {
+    docker.temp = 'auto'
+    docker.enabled = true
+    process {
+      $filter_bam {
+        container = "samtools:1.7"
+      }
+    }
+  }
+  sge {
+    process{
+      $filter_bam {
+        beforeScript = "module purge; module load SAMtools/1.7"
+      }
+    }
+  }
+}
diff --git a/src/nf_modules/SAMtools/tests/filter_bams.nf b/src/nf_modules/SAMtools/filter_bams.nf
similarity index 67%
rename from src/nf_modules/SAMtools/tests/filter_bams.nf
rename to src/nf_modules/SAMtools/filter_bams.nf
index 4902136..0812a19 100644
--- a/src/nf_modules/SAMtools/tests/filter_bams.nf
+++ b/src/nf_modules/SAMtools/filter_bams.nf
@@ -7,6 +7,7 @@ log.info "bed file : ${params.bed}"
 Channel
   .fromPath( params.bam )
   .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
+  .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
   .set { bam_files }
 Channel
   .fromPath( params.bed )
@@ -14,18 +15,18 @@ Channel
   .set { bed_files }
 
 process filter_bam {
-  tag "$bam.baseName"
+  tag "$file_id"
   cpus 4
 
   input:
-    file bam from bam_files
+    set file_id, file(bam) from bam_files
     file bed from bed_files
 
   output:
-    file "*_filtered.bam*" into filtered_bam_files
+    set file_id, "*_filtered.bam*" into filtered_bam_files
   script:
 """
-samtools view -@ ${task.cpus} -hb ${bam} -L ${bed} > ${bam.baseName}_filtered.bam
+samtools view -@ ${task.cpus} -hb ${bam} -L ${bed} > ${file_id}_filtered.bam
 """
 }
 
diff --git a/src/nf_modules/SAMtools/index_bams.config b/src/nf_modules/SAMtools/index_bams.config
new file mode 100644
index 0000000..3b23601
--- /dev/null
+++ b/src/nf_modules/SAMtools/index_bams.config
@@ -0,0 +1,18 @@
+profiles {
+  docker {
+    docker.temp = 'auto'
+    docker.enabled = true
+    process {
+      $index_bam {
+        container = "samtools:1.7"
+      }
+    }
+  }
+  sge {
+    process{
+      $index_bam {
+        beforeScript = "module purge; module load SAMtools/1.7"
+      }
+    }
+  }
+}
diff --git a/src/nf_modules/SAMtools/tests/index_bams.nf b/src/nf_modules/SAMtools/index_bams.nf
similarity index 63%
rename from src/nf_modules/SAMtools/tests/index_bams.nf
rename to src/nf_modules/SAMtools/index_bams.nf
index bea5441..489b0f4 100644
--- a/src/nf_modules/SAMtools/tests/index_bams.nf
+++ b/src/nf_modules/SAMtools/index_bams.nf
@@ -5,14 +5,18 @@ log.info "bams files : ${params.bam}"
 Channel
   .fromPath( params.bam )
   .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
+  .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
   .set { bam_files }
 
 process index_bam {
-  tag "$bam.baseName"
+  tag "$file_id"
+
   input:
-    file bam from bam_files
+    set file_id, file(bam) from bam_files
+
   output:
-    file "*bam*" into indexed_bam_file
+    set file_id, "*.bam*" into indexed_bam_file
+
   script:
 """
 samtools index ${bam}
diff --git a/src/nf_modules/SAMtools/samtools.config b/src/nf_modules/SAMtools/samtools.config
deleted file mode 100644
index 001a77a..0000000
--- a/src/nf_modules/SAMtools/samtools.config
+++ /dev/null
@@ -1,36 +0,0 @@
-profiles {
-  docker {
-    docker.temp = 'auto'
-    docker.enabled = true
-    process {
-      $sort_bam {
-        container = "samtools:1.7"
-      }
-      $index_bam {
-        container = "samtools:1.7"
-      }
-      $split_bam {
-        container = "samtools:1.7"
-      }
-      $filter_bam {
-        container = "samtools:1.7"
-      }
-    }
-  }
-  sge {
-    process{
-      $sort_bam {
-        beforeScript = "module purge; module load SAMtools/1.7"
-      }
-      $index_bam {
-        beforeScript = "module purge; module load SAMtools/1.7"
-      }
-      $split_bam {
-        beforeScript = "module purge; module load SAMtools/1.7"
-      }
-      $filter_bam {
-        beforeScript = "module purge; module load SAMtools/1.7"
-      }
-    }
-  }
-}
diff --git a/src/nf_modules/SAMtools/samtools.nf b/src/nf_modules/SAMtools/samtools.nf
deleted file mode 100644
index f178bb0..0000000
--- a/src/nf_modules/SAMtools/samtools.nf
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
-* SAMtools :
-* Imputs : bam files
-* Output : bam files
-*/
-
-/*                      bams sorting                                     */
-params.bam = "$baseDir/data/bam/*.bam"
-
-log.info "bams files : ${params.bam}"
-
-Channel
-  .fromPath( params.bam )
-  .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
-  .set { bam_files }
-
-process sort_bam {
-  tag "$bam.baseName"
-  cpus 4
-
-  input:
-    file bam from bam_files
-
-  output:
-    file "*_sorted.bam" into sorted_bam_files
-
-  script:
-"""
-samtools sort -@ ${task.cpus} -O BAM -o ${bam.baseName}_sorted.bam ${bam}
-"""
-}
-
-/*                      bams indexing                                     */
-
-params.bam = "$baseDir/data/bam/*.bam"
-
-log.info "bams files : ${params.bam}"
-
-Channel
-  .fromPath( params.bam )
-  .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
-  .set { bam_files }
-
-process index_bam {
-  tag "$bam.baseName"
-  input:
-    file bam from bam_files
-  output:
-    file "*bam*" into indexed_bam_file
-  script:
-"""
-samtools index ${bam}
-"""
-}
-
-
-/*                      bams spliting                                     */
-params.bam = "$baseDir/data/bam/*.bam"
-
-log.info "bams files : ${params.bam}"
-
-Channel
-  .fromPath( params.bam )
-  .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
-  .set { bam_files }
-
-process split_bam {
-  tag "$bam.baseName"
-  cpus 2
-
-  input:
-    file bam from bam_files
-
-  output:
-    file "*_forward.bam*" into forward_bam_files
-    file "*_reverse.bam*" into reverse_bam_files
-  script:
-"""
-samtools view -hb -F 0x10 ${bam} > ${bam}_forward.bam &
-samtools view -hb -f 0x10 ${bam} > ${bam}_reverse.bam
-"""
-}
-
-
-/*                      bams filtering                                     */
-params.bam = "$baseDir/data/bam/*.bam"
-params.bed = "$baseDir/data/bam/*.bed"
-
-log.info "bams files : ${params.bam}"
-log.info "bed file : ${params.bed}"
-
-Channel
-  .fromPath( params.bam )
-  .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
-  .set { bam_files }
-Channel
-  .fromPath( params.bed )
-  .ifEmpty { error "Cannot find any bed file matching: ${params.bed}" }
-  .set { bed_files }
-
-process filter_bam {
-  tag "$bam.baseName"
-  cpus 4
-
-  input:
-    file bam from bam_files
-    file bed from bed_files
-
-  output:
-    file "*_filtered.bam*" into filtered_bam_files
-  script:
-"""
-samtools view -@ ${task.cpus} -hb ${bam} -L ${bed} > ${bam.baseName}_filtered.bam
-"""
-}
-
-
diff --git a/src/nf_modules/SAMtools/sort_bams.config b/src/nf_modules/SAMtools/sort_bams.config
new file mode 100644
index 0000000..d1a8c50
--- /dev/null
+++ b/src/nf_modules/SAMtools/sort_bams.config
@@ -0,0 +1,18 @@
+profiles {
+  docker {
+    docker.temp = 'auto'
+    docker.enabled = true
+    process {
+      $sort_bam {
+        container = "samtools:1.7"
+      }
+    }
+  }
+  sge {
+    process{
+      $sort_bam {
+        beforeScript = "module purge; module load SAMtools/1.7"
+      }
+    }
+  }
+}
diff --git a/src/nf_modules/SAMtools/tests/sort_bams.nf b/src/nf_modules/SAMtools/sort_bams.nf
similarity index 53%
rename from src/nf_modules/SAMtools/tests/sort_bams.nf
rename to src/nf_modules/SAMtools/sort_bams.nf
index 79a7590..ab5c7e5 100644
--- a/src/nf_modules/SAMtools/tests/sort_bams.nf
+++ b/src/nf_modules/SAMtools/sort_bams.nf
@@ -5,21 +5,22 @@ log.info "bams files : ${params.bam}"
 Channel
   .fromPath( params.bam )
   .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
+  .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
   .set { bam_files }
 
 process sort_bam {
-  tag "$bams.baseName"
+  tag "$file_id"
   cpus 4
 
   input:
-    file bam from bam_files
+    set file_id, file(bam) from bam_files
 
   output:
-    file "*_sorted.bam" into sorted_bam_files
+    set file_id, "*_sorted.bam" into sorted_bam_files
 
   script:
 """
-samtools sort -@ ${task.cpus} -O BAM -o ${bam.baseName}_sorted.bam ${bam}
+samtools sort -@ ${task.cpus} -O BAM -o ${file_id}_sorted.bam ${bam}
 """
 }
 
diff --git a/src/nf_modules/SAMtools/split_bams.config b/src/nf_modules/SAMtools/split_bams.config
new file mode 100644
index 0000000..28b548e
--- /dev/null
+++ b/src/nf_modules/SAMtools/split_bams.config
@@ -0,0 +1,18 @@
+profiles {
+  docker {
+    docker.temp = 'auto'
+    docker.enabled = true
+    process {
+      $split_bam {
+        container = "samtools:1.7"
+      }
+    }
+  }
+  sge {
+    process{
+      $split_bam {
+        beforeScript = "module purge; module load SAMtools/1.7"
+      }
+    }
+  }
+}
diff --git a/src/nf_modules/SAMtools/split_bams.nf b/src/nf_modules/SAMtools/split_bams.nf
new file mode 100644
index 0000000..f8ba6a5
--- /dev/null
+++ b/src/nf_modules/SAMtools/split_bams.nf
@@ -0,0 +1,27 @@
+params.bam = "$baseDir/data/bam/*.bam"
+
+log.info "bams files : ${params.bam}"
+
+Channel
+  .fromPath( params.bam )
+  .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
+  .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
+  .set { bam_files }
+
+process split_bam {
+  tag "$file_id"
+  cpus 2
+
+  input:
+    set file_id, file(bam) from bam_files
+
+  output:
+    set file_id, "*_forward.bam*" into forward_bam_files
+    set file_id, "*_reverse.bam*" into reverse_bam_files
+  script:
+"""
+samtools view -hb -F 0x10 ${bam} > ${file_id}_forward.bam &
+samtools view -hb -f 0x10 ${bam} > ${file_id}_reverse.bam
+"""
+}
+
diff --git a/src/nf_modules/SAMtools/tests.sh b/src/nf_modules/SAMtools/tests.sh
new file mode 100755
index 0000000..99a7ff3
--- /dev/null
+++ b/src/nf_modules/SAMtools/tests.sh
@@ -0,0 +1,20 @@
+nextflow src/nf_modules/SAMtools/sort_bams.nf \
+  -c src/nf_modules/SAMtools/sort_bams.config \
+  -profile docker \
+  --bam "data/tiny_dataset/map/tiny_v2.bam"
+
+nextflow src/nf_modules/SAMtools/index_bams.nf \
+  -c src/nf_modules/SAMtools/index_bams.config \
+  -profile docker \
+  --bam "data/tiny_dataset/map/tiny_v2.sort.bam"
+
+nextflow src/nf_modules/SAMtools/split_bams.nf \
+  -c src/nf_modules/SAMtools/split_bams.config \
+  -profile docker \
+  --bam "data/tiny_dataset/map/tiny_v2.bam"
+
+nextflow src/nf_modules/SAMtools/filter_bams.nf \
+  -c src/nf_modules/SAMtools/filter_bams.config \
+  -profile docker \
+  --bam "data/tiny_dataset/map/tiny_v2.bam" \
+  --bed "data/tiny_dataset/OLD/2genes.bed"
diff --git a/src/nf_modules/SAMtools/tests/split_bams.nf b/src/nf_modules/SAMtools/tests/split_bams.nf
deleted file mode 100644
index edc2086..0000000
--- a/src/nf_modules/SAMtools/tests/split_bams.nf
+++ /dev/null
@@ -1,26 +0,0 @@
-params.bam = "$baseDir/data/bam/*.bam"
-
-log.info "bams files : ${params.bam}"
-
-Channel
-  .fromPath( params.bam )
-  .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
-  .set { bam_files }
-
-process split_bam {
-  tag "$bam.baseName"
-  cpus 2
-
-  input:
-    file bam from bam_files
-
-  output:
-    file "*_forward.bam*" into forward_bam_files
-    file "*_reverse.bam*" into reverse_bam_files
-  script:
-"""
-samtools view -hb -F 0x10 ${bam} > ${bam}_forward.bam &
-samtools view -hb -f 0x10 ${bam} > ${bam}_reverse.bam
-"""
-}
-
diff --git a/src/nf_modules/SAMtools/tests/tests.sh b/src/nf_modules/SAMtools/tests/tests.sh
deleted file mode 100755
index e3e8099..0000000
--- a/src/nf_modules/SAMtools/tests/tests.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-nextflow src/nf_modules/SAMtools/tests/sort_bams.nf \
-  -c src/nf_modules/SAMtools/samtools.config \
-  -profile docker \
-  --bam "data/tiny_dataset/map/tiny_v2.bam"
-
-nextflow src/nf_modules/SAMtools/tests/index_bams.nf \
-  -c src/nf_modules/SAMtools/samtools.config \
-  -profile docker \
-  --bam "data/tiny_dataset/map/tiny_v2.sort.bam"
-
-nextflow src/nf_modules/SAMtools/tests/split_bams.nf \
-  -c src/nf_modules/SAMtools/samtools.config \
-  -profile docker \
-  --bam "data/tiny_dataset/map/tiny_v2.bam"
-
-nextflow src/nf_modules/SAMtools/tests/filter_bams.nf \
-  -c src/nf_modules/SAMtools/samtools.config \
-  -profile docker \
-  --bam "data/tiny_dataset/map/tiny_v2.bam" \
-  --bed "data/tiny_dataset/OLD/2genes.bed"
-- 
GitLab