From 7a17de40700bbaac63c4375a7b9f0c0c123efb64 Mon Sep 17 00:00:00 2001
From: Laurent Modolo <laurent.modolo@ens-lyon.fr>
Date: Mon, 15 Feb 2021 16:26:23 +0100
Subject: [PATCH] update picard samtools and bwa for DSL2

---
 src/nf_modules/bwa/main.nf      | 45 +++++++++++++++++++++++++++++++++
 src/nf_modules/picard/main.nf   | 18 +++++++++++++
 src/nf_modules/samtools/main.nf | 17 +++++++++++++
 3 files changed, 80 insertions(+)
 create mode 100644 src/nf_modules/bwa/main.nf

diff --git a/src/nf_modules/bwa/main.nf b/src/nf_modules/bwa/main.nf
new file mode 100644
index 00000000..166be133
--- /dev/null
+++ b/src/nf_modules/bwa/main.nf
@@ -0,0 +1,45 @@
+version = "0.7.17"
+container_url = "lbmc/bwa:${version}"
+
+process index_fasta {
+  container = "${container_url}"
+  label "big_mem_mono_cpus"
+  tag "$file_id"
+
+  input:
+    tuple val(file_id), path(fasta)
+
+  output:
+    tuple val(fasta.simpleName), path("${fasta.simpleName}.*"), emit: index
+    file "*_bwa_report.txt", emit: report
+
+  script:
+"""
+bwa index -p ${fasta.simpleName} ${fasta} \
+&> ${fasta.simpleName}_bwa_report.txt
+"""
+}
+
+
+process mapping_fastq {
+  container = "${container_url}"
+  label "big_mem_multi_cpus"
+  tag "$file_id"
+
+  input:
+  tuple val(file_id), path(reads)
+  tuple val(index_id), path(index)
+
+  output:
+  tuple val(file_id), path("*.bam"), emit: bam
+  tuple val(file_id), path("${pair_id}_bwa_report.txt"), emit: report
+
+  script:
+"""
+bwa mem -t ${task.cpus} \
+${index_id} ${reads[0]} ${reads[1]} 2> \
+  ${file_id}_bwa_report.txt | \
+  sambamba view -S -t ${task/cpus} -f bam - > ${file_id}.bam
+"""
+}
+
diff --git a/src/nf_modules/picard/main.nf b/src/nf_modules/picard/main.nf
index a7326f3d..51725afa 100644
--- a/src/nf_modules/picard/main.nf
+++ b/src/nf_modules/picard/main.nf
@@ -24,3 +24,21 @@ PicardCommandLine MarkDuplicates \
   picard_${bam.baseName}.log
 """
 }
+
+process index_fasta {
+  container = "${container_url}"
+  label "big_mem_mono_cpus"
+  tag "$file_id"
+
+  input:
+    tuple val(file_id), file(fasta)
+  output:
+    tuple val(file_id), file("*.dict"), emit: index 
+
+  script:
+"""
+PicardCommandLine CreateSequenceDictionary \
+REFERENCE=${fasta} \
+OUTPUT=${fasta.simpleName}.dict
+"""
+}
diff --git a/src/nf_modules/samtools/main.nf b/src/nf_modules/samtools/main.nf
index 265f6c10..e3413fff 100644
--- a/src/nf_modules/samtools/main.nf
+++ b/src/nf_modules/samtools/main.nf
@@ -1,6 +1,23 @@
 version = "1.11"
 container_url = "lbmc/samtools:${version}"
 
+process index_fasta {
+  container = "${container_url}"
+  label "big_mem_mono_cpus"
+  tag "$file_id"
+
+  input:
+    tuple val(file_id), path(fasta)
+  output:
+    tuple val(file_id), path("*.fai"), emit: index
+
+  script:
+"""
+samtools faidx ${fasta}
+"""
+}
+
+
 process filter_bam {
   container = "${container_url}"
   label "big_mem_multi_cpus"
-- 
GitLab