From 86ff02d6c1238e4599a2ad43e7c62b17e4900e9d Mon Sep 17 00:00:00 2001
From: Laurent Modolo <laurent@modolo.fr>
Date: Thu, 20 Dec 2018 18:25:48 +0100
Subject: [PATCH] SAMtools: Dockerfile ubuntu -> alpine

---
 src/docker_modules/SAMtools/1.7/Dockerfile | 26 +++++++++++++++++-----
 src/nf_modules/samblaster/dedup_sams.nf    | 18 ++++++++-------
 src/nf_modules/samblaster/tests.sh         |  2 +-
 3 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/src/docker_modules/SAMtools/1.7/Dockerfile b/src/docker_modules/SAMtools/1.7/Dockerfile
index ce910af..c6b8e7c 100644
--- a/src/docker_modules/SAMtools/1.7/Dockerfile
+++ b/src/docker_modules/SAMtools/1.7/Dockerfile
@@ -1,9 +1,25 @@
-FROM ubuntu:18.04
+FROM alpine:3.8
 MAINTAINER Laurent Modolo
 
 ENV SAMTOOLS_VERSION=1.7
-ENV PACKAGES samtools=${SAMTOOLS_VERSION}*
+ENV PACKAGES git \
+             make \
+             gcc \
+             musl-dev \
+             zlib-dev \
+             ncurses-dev \
+             bzip2-dev \
+             xz-dev
 
-RUN apt-get update && \
-    apt-get install -y --no-install-recommends ${PACKAGES} && \
-    apt-get clean
+RUN apk update && \
+    apk add ${PACKAGES}
+
+RUN git clone https://github.com/samtools/htslib.git && \
+cd htslib && \
+git checkout ${SAMTOOLS_VERSION}  && \
+cd .. && \
+git clone https://github.com/samtools/samtools.git && \
+cd samtools && \
+git checkout ${SAMTOOLS_VERSION} && \
+make && \
+cp samtools /usr/bin/
diff --git a/src/nf_modules/samblaster/dedup_sams.nf b/src/nf_modules/samblaster/dedup_sams.nf
index fd9f2b1..ae07c97 100644
--- a/src/nf_modules/samblaster/dedup_sams.nf
+++ b/src/nf_modules/samblaster/dedup_sams.nf
@@ -1,25 +1,27 @@
-params.sam = "$baseDir/data/sam/*.sam"
+params.sam = "$baseDir/data/sam/*.bam"
 
-log.info "sams files : ${params.sam}"
+log.info "bam files : ${params.bam}"
 
 Channel
-  .fromPath( params.sam )
-  .ifEmpty { error "Cannot find any sam files matching: ${params.sam}" }
+  .fromPath( params.bam )
+  .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" }
   .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]}
-  .set { sam_files }
+  .set { bam_files }
 
 process dedup_sam {
   tag "$file_id"
   cpus 4
 
   input:
-    set file_id, file(sam) from sam_files
+    set file_id, file(bam) from bam_files
 
   output:
-    set file_id, "*_dedup.sam*" into dedup_sam_files
+    set file_id, "*_dedup.bam*" into dedup_bam_files
   script:
 """
-samblaster --addMateTags -i ${sam} -o ${file_id}_dedup.sam
+samtools view -h ${bam} | \
+samblaster --addMateTags | \
+samtools view -Sb - > ${file_id}_dedub.bam
 """
 }
 
diff --git a/src/nf_modules/samblaster/tests.sh b/src/nf_modules/samblaster/tests.sh
index 63bbfc8..536f562 100755
--- a/src/nf_modules/samblaster/tests.sh
+++ b/src/nf_modules/samblaster/tests.sh
@@ -1,4 +1,4 @@
 ./nextflow src/nf_modules/samblaster/dedup_sams.nf \
   -c src/nf_modules/samblaster/dedup_sams.config \
   -profile docker \
-  --sam "data/tiny_dataset/map/tiny_v2.sam"
+  --bam "data/tiny_dataset/map/tiny_v2.bam"
-- 
GitLab