diff --git a/modules/nf-core/custom/filterbam/main.nf b/modules/nf-core/custom/filterbam/main.nf new file mode 100644 index 0000000000000000000000000000000000000000..0f63be60330d928711dff04923ea7e3d562e5b76 --- /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