How to create custom docker image to download bam files from SRA
1
0
Entering edit mode
4.2 years ago
MAPK ★ 2.1k

I am trying to create a docker image from docker file and entrypoint. However, it only generates <none>:<none>. This is my docker file and entrypoint.sh. Would someone please let me know what's missing here?

FROM openjdk:8-jre

LABEL maintainer="Maintainer <xxx@xxx.edu>"


LABEL org.label-schema.schema-version="1.0"
# LABEL org.label-schema.build-date=$BUILD_DATE
LABEL org.label-schema.name="testing/sratobam"
LABEL org.label-schema.description="Image for sratobam"


ENV SAMTOOLS_VERSION 1.9
ENV SRATOOL_VERSION 2.10.8

WORKDIR /tmp

RUN apt-get update -y \
  && apt-get install --no-install-recommends -y \
       wget \ 
       libxml-libxml-perl \
       make \
       gcc \
       g++ \
       libz-dev \
       libbz2-dev \
       liblzma-dev \
       ncurses-dev \
       libnss-sss \
       time \
  && wget -q https://github.com/lh3/bwa/releases/download/v${BWA_VERSION}/bwa-${BWA_VERSION}.tar.bz2 \
  && tar xjvf bwa-${BWA_VERSION}.tar.bz2 \
  && cd /tmp/bwa-${BWA_VERSION}/ \
  && make \
  && cp -av /tmp/bwa-${BWA_VERSION}/bwa /usr/bin/ \
  && cd /tmp \
  && wget -q https://github.com/samtools/samtools/releases/download/${SAMTOOLS_VERSION}/samtools-${SAMTOOLS_VERSION}.tar.bz2 \
  && tar xjvf samtools-${SAMTOOLS_VERSION}.tar.bz2 \
  && cd /tmp/samtools-${SAMTOOLS_VERSION}/ \
  && make \
  && cp -av /tmp/samtools-${SAMTOOLS_VERSION}/samtools /usr/bin/ \ 
  && cd /tmp \
  && wget -q http://ftp-trace.ncbi.nlm.nih.gov/sra/sdk/${SRATOOL_VERSION}/sratoolkit.${SRATOOL_VERSION}-ubuntu64.tar.gz \
  && tar -xvzf sratoolkit.${SRATOOL_VERSION}-ubuntu64.tar.gz \
  && cp /tmp/sratoolkit.${SRATOOL_VERSION}-ubuntu64/bin/sam-dump /usr/bin \
  && rm sratoolkit.${SRATOOL_VERSION}-ubuntu64.tar.gz \
  && ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime \
  && echo "America/Chicago" > /etc/timezone \
  && dpkg-reconfigure --frontend noninteractive tzdata \
  && apt-get clean all


# Copy the local dbGAP key file into the container
COPY XXX_XXXX.ngc /usr/local/bin

# And import the key to allow dbGaP downloads
RUN vdb-config --import XXX_XXXX.ngc
COPY ./entrypoint.sh /usr/local/bin/

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# CMD ["/bin/bash"]

entrypoint.sh

#!/bin/bash

VERSION="0.0.1"
# Entrypoint script for docker container testing/sratobam

GC_THREADS=2 
CACHING=0
if [ -z "${THREADS}" ]; then THREADS=8; fi  

DATE="/bin/date +%s"
display_date () {
    /bin/date -d @${1} +%Y%m%d_%H%M%S
}

date_diff () {
    earlier=${1}
    later=${2}
    diff=$((${later}-${earlier}))
    if [ ${diff} -gt 86400 ]; then
        date -u -d @$((${diff}-86400)) +"%jd%-Hh%-Mm%-Ss"
    else
        date -u -d @${diff} +"%-Hh%-Mm%-Ss"
    fi
}

quit () {
  echo "[$(display_date $(${DATE}))] Run failed at ${1} step, exit code: 1"
  if [ "${SHELLDROP}" -eq 1 ]; then echo "Dropping to shell"; exec "/bin/bash"; else exit 1; fi
}

# trap "{ echo \"[$(display_date $(${DATE}))] Terminated by SIGTERM \"; quit \"${CUR_STEP}\"; }" SIGTERM
trap "echo \"[$(display_date $(${DATE}))] Terminated by SIGTERM \" && sleep 10s" SIGTERM

# Option for usage in docker
if [ "${SHELLDROP:=0}" -eq 1 ]; then echo "Dropping to shell"; exec "/bin/bash"; fi

# Mem
if [ -z "${MEM}" ]; then echo "WARNING, memory limit (in GB) not provided in variable \${MEM}; defaulting to 4G"; MEM=4; fi


# WORKDIR
if [ -z "${WORKDIR}" ]; then echo "WARNING, WORKDIR not provided in variable \${WORKDIR}"; fi

# SRAID
if [ -z "${SRAID}" ]; then echo "WARNING, SRAid not provided in variable \${SRAID}"; fi

if [ ! -z "${TIMING}" ]; then TIMING=(/usr/bin/time -v); fi


# Convert sra to bam
start=$(${DATE}); echo "[$(display_date ${start})] sratobam starting"
CUR_STEP="sratobam"
sam-dump ${SRAID} | samtools view -bS >  "${WORKDIR}/${SRAID}.bam"
exitcode="$?"
end=$(${DATE}); echo "[$(display_date ${end})] SRA to BAM finished, exit code: ${exitcode}, step time $(date_diff ${start} ${end})"


exit ${exitcode}
docker • 2.2k views
ADD COMMENT
1
Entering edit mode
  1. Why are you using a Java base image? use the ubuntu:latest
  2. Install samtools with apt
  3. Use the SRA binaries instead of building it
  4. Do you need to add dbGaP keys?
  5. in your entry point, the $SRAID variable is never assigned
ADD REPLY
0
Entering edit mode

Yes, I need to add dbGaP keys.

ADD REPLY
0
Entering edit mode

Just want to comment that I have had troubles in the past getting sra-toolkit installed and operating properly in a docker container. You may want to consider using the docker image provided by the developers at ncbi. See the wiki page here for instructions: https://github.com/ncbi/sra-tools/wiki/SRA-tools-docker

ADD REPLY
5
Entering edit mode
4.2 years ago
JC 13k

I guess you need something like this:

Dockerfile

FROM ubuntu:latest

ENV DEBIAN_FRONTEND noninteractive
RUN apt update && apt upgrade -y
RUN apt install -y samtools wget

# Add SRA toolkit binaries
WORKDIR /opt
ENV SRATOOLKIT_VERSION=2.10.8
RUN wget https://ftp-trace.ncbi.nlm.nih.gov/sra/sdk/${SRATOOLKIT_VERSION}/sratoolkit.${SRATOOLKIT_VERSION}-ubuntu64.tar.gz && \
    tar zxf sratoolkit.${SRATOOLKIT_VERSION}-ubuntu64.tar.gz && \
    rm sratoolkit.${SRATOOLKIT_VERSION}-ubuntu64.tar.gz
RUN ln -s /opt/sratoolkit.${SRATOOLKIT_VERSION}-ubuntu64/bin/sam-dump /usr/local/bin
RUN ln -s /opt/sratoolkit.${SRATOOLKIT_VERSION}-ubuntu64/bin/vdb-config /usr/local/bin

# Copy the local dbGAP key file into the container
COPY XXX_XXXX.ngc /opt
# And import the key to allow dbGaP downloads
RUN vdb-config --import /opt/XXX_XXXX.ngc

# define directory to mount
RUN mkdir /dump
WORKDIR /dump

# Add entrypoint
COPY entry.sh /usr/local/bin
RUN chmod +x /usr/local/bin/entry.sh
ENTRYPOINT /usr/local/bin/entry.sh

Entrypoint

#!/bin/bash

SRAID=$1
WORKDIR=/dump

sam-dump ${SRAID} | samtools view -bS >  "${WORKDIR}/${SRAID}.bam"

Execution

mkdir dump
docker run -it -v dump:/dump sradump SRRXXXXXX
ADD COMMENT

Login before adding your answer.

Traffic: 1859 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6