diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f093e9e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +images +.gitignore +LICENSE +data/hg38.phyloP100way.bw \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7d87985 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,102 @@ +# This Dockerfile builds a container image for StrVCTVRE, a tool for structural variant classification. +# It uses micromamba to manage dependencies and sets up the environment for running StrVCTVRE. +# It's also been built for use with Docker and Apptainer, so it can be run on HPC clusters. +FROM mambaorg/micromamba:ubuntu24.04 AS micromamba + +FROM ubuntu:24.04 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + wget \ + curl \ + ca-certificates \ + && apt-get clean autoclean \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* \ + && rm -f /var/cache/apt/archives/*.deb + +############################################################# +######################### General ########################### +############################################################# +RUN mkdir -p /software; chmod a+rwx -R /software; mkdir /software/strvctvre + +WORKDIR /software/strvctvre + +COPY . . + +# The console script (`StrVCTVRE = "StrVCTVRE:main"`) imports `main` from the +# module, but the committed StrVCTVRE.py runs argparse + all logic at module +# level and defines no `main()`. Wrap the entire script in `def main():` and add +# a `__main__` guard, in-place in the image so the repo source stays untouched. +RUN awk '\ +BEGIN { print "def main():" } \ +{ if ($0 ~ /^[[:space:]]*$/) print $0; else print " " $0 } \ +END { print ""; print "if __name__ == \"__main__\":"; print " main()" } \ +' /software/strvctvre/StrVCTVRE.py > /tmp/StrVCTVRE.py \ + && mv /tmp/StrVCTVRE.py /software/strvctvre/StrVCTVRE.py + +# Update CERTs if building on VPN +# RUN wget -P /tmp/ +# ARG CURL_CA_BUNDLE=/tmp/ + +# Install micromamba first +# Adding micromamba to existing image: https://micromamba-docker.readthedocs.io/en/latest/advanced_usage.html#adding-micromamba-to-an-existing-docker-image +# https://github.com/mamba-org/micromamba-docker/blob/main/debian.Dockerfile + +# if your image defaults to a non-root user, then you may want to make the +# next 3 ARG commands match the values in your image. You can get the values +# by running: docker run --rm -it my/image id -a +ARG MAMBA_USER=root +ARG MAMBA_USER_ID=0 +ARG MAMBA_USER_GID=0 +ENV MAMBA_USER=$MAMBA_USER +ENV MAMBA_ROOT_PREFIX="/software/conda" +ENV MAMBA_EXE="/bin/micromamba" +## conda env name (must match `name:` in environment_py3.yml) +ENV ENV_NAME=StrVCTVRE_py_3 +#ENV MAMBA_SKIP_ACTIVATE=1; We want to activate, but just not the base + +COPY --from=micromamba "$MAMBA_EXE" "$MAMBA_EXE" +COPY --from=micromamba /usr/local/bin/_activate_current_env.sh /usr/local/bin/_activate_current_env.sh +COPY --from=micromamba /usr/local/bin/_dockerfile_shell.sh /usr/local/bin/_dockerfile_shell.sh +COPY --from=micromamba /usr/local/bin/_entrypoint.sh /usr/local/bin/_entrypoint.sh +COPY --from=micromamba /usr/local/bin/_dockerfile_initialize_user_accounts.sh /usr/local/bin/_dockerfile_initialize_user_accounts.sh +COPY --from=micromamba /usr/local/bin/_dockerfile_setup_root_prefix.sh /usr/local/bin/_dockerfile_setup_root_prefix.sh + +RUN /usr/local/bin/_dockerfile_initialize_user_accounts.sh && \ + /usr/local/bin/_dockerfile_setup_root_prefix.sh + +RUN --mount=type=cache,target=/software/conda/pkgs \ + micromamba create -y -f /software/strvctvre/environment_py3.yml && \ + micromamba clean --all --yes + +# Install StrVCTVRE in editable mode so that it's available as a console script (e.g. `StrVCTVRE --help` vs `python StrVCTVRE.py --help`) +RUN --mount=type=cache,target=/software/conda/pkgs \ + micromamba run -n $ENV_NAME pip --trusted-host pypi.org --trusted-host files.pythonhosted.org install -e . + +WORKDIR /software/ +############################################################# +############################################################# +############################################################# +# Add the micromamba activation script to the system-wide bashrc so that the environment is activated for all users on run/exec for apptainer and docker. +RUN echo "source /usr/local/bin/_activate_current_env.sh" >> /etc/bash.bashrc && \ + echo "source /usr/local/bin/_activate_current_env.sh" >> .bash_env && \ + echo "source /etc/bash.bashrc" >> .bash_env + +# any calls to bash will load this environment (e.g. docker/apptainer exec bash -c "cmd") +ENV BASH_ENV=/software/.bash_env + +RUN chmod +x /software/strvctvre/strvctvre_entrypoint.sh + +ENV PATH=/software/strvctvre:/software:$PATH + +WORKDIR /software/strvctvre +# The `pip install -e .` above installs the `StrVCTVRE` console script, but +# setuptools flat-layout auto-discovery picks up the `data/` dir as the package +# instead of the top-level StrVCTVRE.py module, so `from StrVCTVRE import main` +# fails at runtime. Put the repo on PYTHONPATH so the module is importable. +ENV PYTHONPATH=/software/strvctvre + +ENTRYPOINT ["/software/strvctvre/strvctvre_entrypoint.sh"] + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/README.md b/README.md index 106498c..bfc0ed5 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,36 @@ Structural variant impact predictor developed by Andrew Sharo, Zhiqiang Hu, and ### \*\*New\*\*: Visit our [Web Server](https://strvctvre.berkeley.edu) to annotate vcf or bed files with StrVCTVRE scores, or query a single SV +## Run with Docker (optional) + +A `Dockerfile` is provided as an alternative to installing Python, conda, and the required packages manually (i.e. it replaces steps 1–4 below). From the cloned repository, build the image with: +```bash +git clone --depth 1 https://github.com/andrewSharo/StrVCTVRE +cd StrVCTVRE +docker build --platform linux/amd64 -t strvctvre:v1.10 . +``` +This docker image creates a console script that can be run with the command `StrVCTVRE`. + +The `--platform linux/amd64` flag is required, including on Apple Silicon / ARM machines, where it builds under emulation. + +The image does **not** include the 9.2GB `hg38.phyloP100way.bw` file (see step 3). Download it separately and mount the folder containing it (and a folder for your input/output) into the container. For example, to annotate a vcf file: +```bash +cd data +wget http://hgdownload.cse.ucsc.edu/goldenpath/hg38/phyloP100way/hg38.phyloP100way.bw +cd .. + +# Try the test data +docker run --rm --platform linux/amd64 \ + -v $(pwd)/data:/software/strvctvre/data \ + -v /path/to/your/files:/io \ + strvctvre:v1.10 StrVCTVRE -i data/test.vcf.gz -o /io/output.vcf +``` + +## Run with apptainer/snakemake (optional) +Snakemake runs apptainer exec mode. By default apptainer will mount the current working directory and use it as in the container +as the current working directory. This means that you should have the data folder system linked in snakemake's working directory +for the StrVCTVRE console script (or StrVCTVRE.py) to find the hg38.phyloP100way.bw file. + ## To run StrVCTVRE, follow these steps: ### 1. Download and install Python 3 (if not done already) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..18b251c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "StrVCTVRE" +version = "0.1.0" +dependencies = [] # your dependencies here + +[project.scripts] +StrVCTVRE = "StrVCTVRE:main" \ No newline at end of file diff --git a/strvctvre_entrypoint.sh b/strvctvre_entrypoint.sh new file mode 100755 index 0000000..b6a328a --- /dev/null +++ b/strvctvre_entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# StrVCTVRE container entrypoint. +# Activates the conda environment, then warns if the required phyloP +# conservation file is missing (it is ~9.2GB and is NOT baked into the image). + +IGreen='\033[0;92m' # Green +On_Red='\033[41m' # Red +Color_Off='\033[0m' # Text Reset + +# Path StrVCTVRE.py checks by default; override at runtime with -p. +PHYLOP_FILE="${PHYLOP_FILE:-data/hg38.phyloP100way.bw}" + +if [ ! -s "${PHYLOP_FILE}" ]; then + echo -e "${IGreen}The phyloP conservation file was not found at:\n ${PHYLOP_FILE}${Color_Off}" + echo -e "${IGreen}StrVCTVRE requires hg38.phyloP100way.bw (~9.2GB). Download it from UCSC:${Color_Off}" + echo -e "${IGreen} https://hgdownload.cse.ucsc.edu/goldenpath/hg38/phyloP100way/hg38.phyloP100way.bw${Color_Off}" + echo -e "${On_Red}\tMount it into the container (e.g. docker: -v /host/data; apptainer: --bind /host/data)${Color_Off}" + echo -e "${On_Red}\tor pass its path to StrVCTVRE.py with -p.${Color_Off}" +fi + +# Run whatever command was passed to the container (e.g. python StrVCTVRE.py ...), +# or drop into an interactive shell if none was given. +if [ "$#" -gt 0 ]; then + source /usr/local/bin/_activate_current_env.sh + exec "$@" +else + exec /bin/bash +fi