refactor: Minimize Dockerfile layers

This commit is contained in:
Thomas A. Christensen II 2023-08-09 16:02:46 -05:00
parent a1d0348697
commit 108fb0dc5b
Signed by: millironx
GPG key ID: 09335146883990B9
2 changed files with 89 additions and 86 deletions

View file

@ -6,18 +6,18 @@ ENV R_HOME=/usr/local/lib/R
ENV TZ=Etc/UTC
ENV SAMTOOLS_VERSION=1.2
# Install R basic dependencies
RUN apt-get update && \
RUN <<END_RUN_CMD
# Install R
apt-get update
apt-get install --no-install-recommends -y \
sed \
curl \
ca-certificates
RUN curl -L "https://github.com/rocker-org/rocker-versioned2/archive/refs/tags/R${ROCKER_VERSION}.tar.gz" | tar xvz
RUN ./rocker-versioned2-R${ROCKER_VERSION}/scripts/install_R.sh
RUN rm -rf rocker-versioned2-R${ROCKER_VERSION}
curl -L "https://github.com/rocker-org/rocker-versioned2/archive/refs/tags/R${ROCKER_VERSION}.tar.gz" | tar xvz
./rocker-versioned2-R${ROCKER_VERSION}/scripts/install_R.sh
rm -rf rocker-versioned2-R${ROCKER_VERSION}
# Install BioPerl
RUN apt-get update && \
# Install BioPerl
apt-get update
apt-get install --no-install-recommends -y \
curl \
perl \
@ -26,33 +26,91 @@ RUN apt-get update && \
make \
libexpat1-dev \
libssl-dev \
zlib1g-dev
RUN cpanm -n -v Bio::Seq Bio::SeqIO Perl4::CoreLibs
zlib1g-dev \
libncurses5-dev
cpanm -n -v Bio::Seq Bio::SeqIO Perl4::CoreLibs
# Install R packages
RUN install2.r --error --skipinstalled BiocManager
RUN R -e "BiocManager::install(c('Biostrings', 'seqinr'))"
# Install R packages
install2.r --error --skipinstalled BiocManager
R -e "BiocManager::install(c('Biostrings', 'seqinr'))"
# Install samtools
RUN apt-get update && \
apt-get install --no-install-recommends -y libncurses5-dev
RUN curl -L "https://github.com/samtools/samtools/releases/download/${SAMTOOLS_VERSION}/samtools-${SAMTOOLS_VERSION}.tar.bz2" | tar xvj
RUN cd samtools-${SAMTOOLS_VERSION} && make && make install && cd ..
RUN rm -rf samtools-${SAMTOOLS_VERSION}
# Install samtools
curl -L "https://github.com/samtools/samtools/releases/download/${SAMTOOLS_VERSION}/samtools-${SAMTOOLS_VERSION}.tar.bz2" | tar xvj
cd samtools-${SAMTOOLS_VERSION} && make && make install && cd ..
rm -rf samtools-${SAMTOOLS_VERSION}
# Cleanup
RUN apt-get remove -y \
build-essential \
make
# Install viquas
mkdir /viquas && \
curl -L "https://master.dl.sourceforge.net/project/viquas/ViQuaS1.3.tar.gz" | tar xvz -C /viquas --strip-components=1
# Install Viquas
RUN apt-get update && apt-get install --no-install-recommends -y curl
RUN mkdir /viquas && curl -L "https://master.dl.sourceforge.net/project/viquas/ViQuaS1.3.tar.gz" | tar xvz -C /viquas --strip-components=1
RUN apt-get remove -y curl
# Cleanup
apt-get remove -y \
build-essential \
make \
curl
rm -rf /var/lib/apt/lists
END_RUN_CMD
# Add wrapper script
COPY viquas /usr/bin/viquas
RUN chmod +x /usr/bin/viquas
RUN mkdir /work
RUN <<END_RUN_CMD
cat << 'EOF' > /usr/bin/viquas
#!/bin/sh
USAGE="
USAGE:
viquas reference.fsa reads.bam [o r perform_richness diversity_region_length]
"
NUM_ARGS=$#
case $NUM_ARGS in
2)
;;
6)
;;
*)
echo "${USAGE}"
echo "Incorrect number of arguments: expecting 2 or 6"
exit 1
esac
PWD_BACKUP=$PWD
if [ ! -f "${1}" ]; then
echo "Error: ${1} is not a file"
exit 1
fi
if [ ! -f "${2}" ]; then
echo "Error: ${2} is not a file"
exit 1
fi
REFERENCE_FILE=$(basename "${1}")
BAM_FILE=$(basename "${2}")
cp "${1}" /viquas
cp "${2}" /viquas
cd /viquas || exit 1
case $NUM_ARGS in
2)
Rscript /viquas/ViQuaS.R "${REFERENCE_FILE}" "${BAM_FILE}"
;;
6)
Rscript /viquas/ViQuaS.R "${REFERENCE_FILE}" "${BAM_FILE}" "${@[3:]}"
;;
*)
echo "${USAGE}"
echo "Incorrect number of arguments: expecting 2 or 6"
exit 1
esac
mv /viquas/ViQuaS-Spectrum.fa "${PWD_BACKUP}"
mv /viquas/ViQuaS-Richness.txt "${PWD_BACKUP}" 2> /dev/null
cd "${PWD_BACKUP}" || exit 1
EOF
chmod +x /usr/bin/viquas
mkdir /work
END_RUN_CMD
ENTRYPOINT [ "viquas" ]

View file

@ -1,55 +0,0 @@
#!/bin/sh
USAGE="
USAGE:
viquas reference.fsa reads.bam [o r perform_richness diversity_region_length]
"
NUM_ARGS=$#
case $NUM_ARGS in
2)
;;
6)
;;
*)
echo "${USAGE}"
echo "Incorrect number of arguments: expecting 2 or 6"
exit 1
esac
PWD_BACKUP=$PWD
if [ ! -f "${1}" ]; then
echo "Error: ${1} is not a file"
exit 1
fi
if [ ! -f "${2}" ]; then
echo "Error: ${2} is not a file"
exit 1
fi
REFERENCE_FILE=$(basename "${1}")
BAM_FILE=$(basename "${2}")
cp "${1}" /viquas
cp "${2}" /viquas
cd /viquas || exit 1
case $NUM_ARGS in
2)
Rscript /viquas/ViQuaS.R "${REFERENCE_FILE}" "${BAM_FILE}"
;;
6)
Rscript /viquas/ViQuaS.R "${REFERENCE_FILE}" "${BAM_FILE}" "${@[3:]}"
;;
*)
echo "${USAGE}"
echo "Incorrect number of arguments: expecting 2 or 6"
exit 1
esac
mv /viquas/ViQuaS-Spectrum.fa "${PWD_BACKUP}"
mv /viquas/ViQuaS-Richness.txt "${PWD_BACKUP}" 2> /dev/null
cd "${PWD_BACKUP}" || exit 1