From 676669189675806000c0ef373394f28bdd5c6e90 Mon Sep 17 00:00:00 2001
From: vvanoost <vincent.vanoosthuyse@ens-lyon.fr>
Date: Tue, 24 Jul 2018 13:23:49 +0200
Subject: [PATCH] Add Ban sorting from SAMtools

---
 src/RNAseq_sen1D.nf | 51 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/src/RNAseq_sen1D.nf b/src/RNAseq_sen1D.nf
index f9353bd..fd1858d 100644
--- a/src/RNAseq_sen1D.nf
+++ b/src/RNAseq_sen1D.nf
@@ -155,3 +155,54 @@ if grep -q "Error" ${pair_id}_bowtie2_report.txt; then
 fi
 """
 }
+
+/*                      bams sorting                                    */
+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                                     */
+
+process index_bam {
+  tag "$bam.baseName"
+  input:
+    file bam from sorted_bam_files
+  output:
+    file "*bam*" into indexed_bam_file
+  script:
+"""
+samtools index ${bam}
+"""
+}
+
+
+/*                      bams spliting                                     */
+
+process split_bam {
+  tag "$bam.baseName"
+  cpus 2
+
+  input:
+    file bam from indexed_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
+"""
+}
-- 
GitLab