File size: 8,381 Bytes
0f780df
 
91286ea
 
fe05433
be36a29
b57dfed
e5e5d7f
1e6b426
 
91286ea
 
ed40db5
 
1e6b426
ed40db5
e5e5d7f
 
 
a423382
a0778d0
a423382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0778d0
a423382
 
a0778d0
a423382
 
 
cd77af7
a0778d0
a510bc4
a423382
 
 
 
 
 
a0778d0
a510bc4
a0778d0
 
a510bc4
a0778d0
f2d99d8
cd77af7
 
 
f2d99d8
 
cd77af7
 
 
f2d99d8
fe05433
 
 
 
b57dfed
45a0eed
 
87a4433
45a0eed
 
 
 
91286ea
 
 
87a4433
91286ea
 
 
 
938c5af
 
 
 
 
 
 
91286ea
 
3654487
91286ea
 
4713282
 
 
 
 
b25f64d
 
4713282
 
91286ea
fe05433
91286ea
b57dfed
fe05433
6f14e02
 
fe05433
 
91286ea
5338cb6
1e6b426
5338cb6
2bc9abd
 
 
 
 
 
5338cb6
 
 
2bc9abd
 
143c4fd
2bc9abd
 
 
 
1189d33
 
 
91286ea
8cd0d93
fe05433
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# bookworm pin = gcc 12; trixie's gcc 14 turns fpocket's legacy C warnings into hard errors
FROM python:3.11-slim-bookworm

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential gcc g++ wget ca-certificates git libnetcdf-dev \
    openbabel libgl1 libgomp1 libopenblas-dev \
    libcairo2 libpango-1.0-0 libpangocairo-1.0-0 \
    libxml2 libxslt1.1 samtools \
    r-base-core r-bioc-org.hs.eg.db r-cran-biocmanager r-bioc-go.db r-bioc-deseq2 r-bioc-tximport r-bioc-complexheatmap r-cran-ggplot2 r-cran-jsonlite r-cran-circlize \
    r-cran-bh r-cran-rcpp r-cran-data.table r-cran-cowplot r-cran-fastmatch && \
    rm -rf /var/lib/apt/lists/*

# Mouse annotations are absent from Debian/Ubuntu apt repositories.
RUN Rscript -e 'BiocManager::install("org.Mm.eg.db", ask = FALSE, update = FALSE); stopifnot(requireNamespace("org.Mm.eg.db", quietly = TRUE))'
RUN Rscript -e 'BiocManager::install("fgsea", ask = FALSE, update = FALSE); stopifnot(requireNamespace("fgsea", quietly = TRUE))'

# Verify the deterministic RNA-seq statistical runtime at image-build time.
RUN Rscript -e 'suppressPackageStartupMessages({library(DESeq2); library(ComplexHeatmap); library(ggplot2); library(jsonlite); library(circlize)}); cat("DESeq2", as.character(packageVersion("DESeq2")), "ComplexHeatmap", as.character(packageVersion("ComplexHeatmap")), "\n")'

# Gnina (CNN-based rescoring) — OFF BY DEFAULT, and the reason is not image size.
#
# Verified on this base image (python:3.11-slim-bookworm, CPU-only):
#   * The v1.3.2 release asset "gnina.1.3.2" (1,426,790,536 bytes) downloads
#     fine, but the official CPU build is still linked against cuDNN and aborts
#     at load time:
#         gnina: error while loading shared libraries:
#         libcudnn.so.9: cannot open shared object file: No such file or directory
#   * libcudnn9 is not in Debian bookworm. It lives only in NVIDIA's CUDA apt
#     repository, whose signing key the image cannot currently verify
#     (NO_PUBKEY A4B469963BF863CC), so enabling gnina fails the build.
#   * Its OpenCL requirement is otherwise satisfiable: pocl provides a working CPU
#     device (verified via clinfo), so the blocker is the cuDNN link, not OpenCL.
#
# Rather than ship a ~1.4 GB binary that cannot execute, or bake a third-party GPU
# repository with a rotating GPG key into a CPU image, rescoring uses the
# Vina/Python fallback and says so. To enable on a host that genuinely provides
# cuDNN, build with --build-arg INSTALL_GNINA=1.
ARG INSTALL_GNINA=0
RUN if [ "$INSTALL_GNINA" = "0" ]; then \
        echo "gnina skipped (INSTALL_GNINA=0): CPU build requires cuDNN, see comment above"; \
        echo "  CNN rescoring falls back to the Vina/Python path and reports it as such"; \
    else \
        apt-get update && apt-get install -y --no-install-recommends \
            ocl-icd-libopencl1 pocl-opencl-icd clinfo && \
        rm -rf /var/lib/apt/lists/*; \
        wget -q "https://github.com/gnina/gnina/releases/download/v1.3.2/gnina.1.3.2" -O /usr/local/bin/gnina && \
        chmod +x /usr/local/bin/gnina || { echo "ERROR: gnina download failed"; exit 1; }; \
        echo "gnina: size $(stat -c %s /usr/local/bin/gnina) bytes"; \
        gnina --version 2>&1 | head -3 || true; \
        if ! gnina --version >/dev/null 2>&1; then \
            echo "ERROR: gnina cannot execute here. Its CPU build links libcudnn.so.9,"; \
            echo "       which a CPU-only image does not provide. Install cuDNN or set INSTALL_GNINA=0."; \
            exit 1; \
        fi; \
        if ! clinfo -l 2>/dev/null | grep -qi "pocl\|portable computing language"; then \
            echo "ERROR: no CPU OpenCL platform visible; gnina would fail at run time."; \
            exit 1; \
        fi; \
        echo "gnina: installed and a CPU OpenCL device is available"; \
    fi

# MAFFT (local MSA) — portable Linux package, faster and more reliable than remote EBI endpoints.
# mafft.bat resolves its helpers from `dirname $0`, so a symlink makes it look for
# /usr/local/bin/mafftdir and fail (exit 127) — hence the exec wrapper, not a symlink.
RUN wget -q "https://mafft.cbrc.jp/alignment/software/mafft-7.526-linux.tgz" -O /tmp/mafft.tgz && \
    tar xzf /tmp/mafft.tgz -C /opt && \
    printf '#!/bin/sh\nexec /opt/mafft-linux64/mafft.bat "$@"\n' > /usr/local/bin/mafft && \
    chmod +x /usr/local/bin/mafft && \
    rm /tmp/mafft.tgz && mafft --version || echo "mafft download skipped (optional)"

# fpocket (pocket detection) — not packaged in Debian repos; build from source
RUN git clone --depth 1 --branch 4.2.3 https://github.com/Discngine/fpocket /tmp/fpocket && \
    make -C /tmp/fpocket && make -C /tmp/fpocket install && \
    rm -rf /tmp/fpocket

# minimap2 (for NGS read alignment)
RUN wget -q https://github.com/lh3/minimap2/releases/download/v2.28/minimap2-2.28_x64-linux.tar.bz2 -O /tmp/minimap2.tar.bz2 && \
    tar xjf /tmp/minimap2.tar.bz2 -C /tmp --no-same-owner && \
    cp /tmp/minimap2-2.28_x64-linux/minimap2 /usr/local/bin/minimap2 && \
    chmod +x /usr/local/bin/minimap2 && \
    rm -rf /tmp/minimap2*

# Download pre-compiled PhyML binary from bioconda
RUN wget -qO /tmp/phyml.tar.bz2 \
      https://anaconda.org/bioconda/phyml/3.3.20220408/download/linux-64/phyml-3.3.20220408-h9bc3f66_3.tar.bz2 && \
    tar xjf /tmp/phyml.tar.bz2 -C /tmp --no-same-owner && \
    cp /tmp/bin/phyml /usr/local/bin/phyml && \
    chmod +x /usr/local/bin/phyml && \
    rm -rf /tmp/phyml.tar.bz2 /tmp/bin

# IQ-TREE2 (ultrafast bootstrap — 10-100x faster than PhyML for bootstrap)
RUN wget -q https://github.com/iqtree/iqtree2/releases/download/v2.3.6/iqtree-2.3.6-Linux-intel.tar.gz -O /tmp/iqtree.tar.gz && \
    tar xzf /tmp/iqtree.tar.gz -C /opt && \
    cp /opt/iqtree-2.3.6-Linux-intel/bin/iqtree2 /usr/local/bin/iqtree2 && \
    chmod +x /usr/local/bin/iqtree2 && \
    rm -rf /tmp/iqtree.tar.gz /opt/iqtree-2.3.6-Linux-intel

# Download pre-compiled AutoDock Vina binary from GitHub releases
RUN wget -q "https://github.com/ccsb-scripps/AutoDock-Vina/releases/download/v1.2.7/vina_1.2.7_linux_x86_64" -O /usr/local/bin/vina && \
    echo "f31f774f723bba7bbe6e9d1c47577020eea9a8da16424284c043d22593570644  /usr/local/bin/vina" | sha256sum -c - && \
    chmod +x /usr/local/bin/vina

# Local reference searches remain usable during external BLAST queue delays.
# The provisioner retains the exact release and source/index checksums.
RUN apt-get update && apt-get install -y --no-install-recommends ncbi-blast+ && \
    rm -rf /var/lib/apt/lists/*
COPY scripts/provision_local_blast.py /opt/bionexus/provision_local_blast.py
RUN pip install --no-cache-dir 'requests>=2.32,<3' && \
    python /opt/bionexus/provision_local_blast.py /opt/bionexus/reference/swissprot
ENV BIONEXUS_BLAST_DB_ROOT=/opt/bionexus/reference/swissprot BIONEXUS_BLAST_THREADS=2

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN python -c "import cairosvg; from PIL import Image; print('figure export renderer ready')"

# Primer3 is required by design and nearest-neighbour thermodynamic QC.
RUN pip install --no-cache-dir "primer3-py==2.3.1"

COPY . .

RUN Rscript tests/test_go_enrichment.R
RUN Rscript tests/test_preranked_gsea.R

# Exercise the bundled R analysis and figure export during every backend build.
# The 221-gene SALS subset is a regression fixture, not a biological result.
RUN mkdir -p /tmp/rnaseq-smoke && \
    Rscript app/rnaseq/deseq2_analysis.R \
      app/data/rnaseq/Cer_SALS_every100_validation_subset.tsv \
      app/data/rnaseq/Cer_SALS_metadata.tsv \
      /tmp/rnaseq-smoke condition healthy SALS "" 0.05 1 10 8:40 human && \
    test -s /tmp/rnaseq-smoke/go_enrichment_all.tsv && \
    test -s /tmp/rnaseq-smoke/go_gene_mapping.tsv && \
    test -s /tmp/rnaseq-smoke/analysis_summary.json && \
    test -s /tmp/rnaseq-smoke/pca.svg && \
    test -s /tmp/rnaseq-smoke/dispersion_plot.svg && \
    test -s /tmp/rnaseq-smoke/volcano.svg && \
    test -s /tmp/rnaseq-smoke/deseq2_all_results.tsv && \
    rm -rf /tmp/rnaseq-smoke

RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser

EXPOSE 7860
ENV BIONEXUS_EXPRESSION_BACKEND=auto RUN_EXPRESSION_WORKER=true
CMD ["sh", "-c", "python -c 'import openmm; print(\"OpenMM\", openmm.__version__)' && uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860}"]