From b150868bdf5726985a4e57dc386955627251dafc Mon Sep 17 00:00:00 2001
From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr>
Date: Mon, 5 Jun 2023 13:57:46 +0200
Subject: [PATCH] modules/nf-core/custom/filterbam/main.nf: add new module

---
 modules/nf-core/custom/filterbam/main.nf | 25 ++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 modules/nf-core/custom/filterbam/main.nf

diff --git a/modules/nf-core/custom/filterbam/main.nf b/modules/nf-core/custom/filterbam/main.nf
new file mode 100644
index 0000000..0f63be6
--- /dev/null
+++ b/modules/nf-core/custom/filterbam/main.nf
@@ -0,0 +1,25 @@
+process FILTER_PAIR {
+    tag "$meta1.id"
+    label 'process_high' //medium
+
+    conda "bioconda::samtools=1.17"
+    container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
+        'https://depot.galaxyproject.org/singularity/samtools:1.17--h00cdaf9_0' :
+        'quay.io/biocontainers/samtools:1.17--h00cdaf9_0' }"
+
+    input:
+    tuple val(meta1), path(bam1), val(meta2), path(bam2)
+
+    output:
+    tuple val(meta1), path("*_1paired.bam"), val(meta2), path("*_2paired.bam"), emit: bam
+
+    script:
+    """
+    samtools view ${bam1} | cut -f1 | sort | uniq > names1.txt
+    samtools view ${bam2} | cut -f1 | sort | uniq > names2.txt
+    cat names1.txt names2.txt| sort | uniq -c | grep "     2" | sed "s/^      2 //g" > common_reads.txt
+    samtools view -h -N common_reads.txt ${bam1} -O BAM > ${meta1.id}_1paired.bam
+    samtools view -h -N common_reads.txt ${bam2} -O BAM > ${meta2.id}_2paired.bam
+
+    """
+}
\ No newline at end of file
-- 
GitLab