Skip to content

Commit

Permalink
Add Python environment (#11)
Browse files Browse the repository at this point in the history
* Add Python env
Fixes #10
  • Loading branch information
espenhgn authored Apr 19, 2024
1 parent d273846 commit 2c78524
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: hadolint
uses: reviewdog/action-hadolint@v1
with:
reporter: github-pr-review # Default is github-pr-check
fail_on_error: true
hadolint_ignore: SC2086
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
name: Lint
steps:
- name: Check out source repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python environment
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: flake8 Lint
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added Docker build push action to push images to GH container registry
- Added Python environment with basic dependencies for MiX3R (jupyter, numpy, pandas, scipy, matplotlib, numba, ++)

### Updated

Expand Down
34 changes: 28 additions & 6 deletions docker/dockerfiles/ldpred2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
update-ca-certificates

RUN apt-get update && apt-get install -y --no-install-recommends \
bzip2=1.0.8-5build1 \
cmake=3.22.1-1ubuntu1.22.04.2 \
curl=7.81.0-1ubuntu1.16 \
libatlas-base-dev=3.10.3-12ubuntu1 \
Expand All @@ -27,18 +28,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
node-shasum=1.0.2-3 \
patch=2.7.6-7build2 \
unzip=6.0-26ubuntu3.2 \
wget=1.21.2-2ubuntu1 \
zlib1g-dev=1:1.2.11.dfsg-2ubuntu9.2 \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# R dependencies
RUN R -e "install.packages(c('devtools', 'argparser', 'bigsnpr', 'data.table', 'optparse', 'stringr', 'R.utils', 'tidyverse'), dependencies=c('Depends', 'Imports', 'LinkingTo'))"
RUN R -e "install.packages(c('devtools', 'argparser', 'bigsnpr', 'data.table', 'essentials', 'eulerr', 'IRkernel', 'optparse', 'stringr', 'R.utils', 'tidyverse'), dependencies=c('Depends', 'Imports', 'LinkingTo'))"


# install plink 1.9
RUN wget -q --no-check-certificate https://github.com/chrchang/plink-ng/archive/refs/tags/v2.00a4.5.zip && \
RUN curl -sSL https://github.com/chrchang/plink-ng/archive/refs/tags/v2.00a4.5.zip -o v2.00a4.5.zip && \
unzip v2.00a4.5.zip

WORKDIR /tmp/plink-ng-2.00a4.5/1.9
Expand All @@ -56,7 +56,7 @@ RUN rm -rf v2.00a4.5.zip plink-ng-2.00a4.5

# install PRSice-2
COPY patches/*.diff /tmp/patches/
RUN wget -q --no-check-certificate https://github.com/choishingwan/PRSice/archive/refs/tags/2.3.5.zip && \
RUN curl -sSL https://github.com/choishingwan/PRSice/archive/refs/tags/2.3.5.zip -o 2.3.5.zip && \
unzip 2.3.5.zip

WORKDIR /tmp/PRSice-2.3.5
Expand All @@ -78,7 +78,29 @@ RUN cmake ../ && \
WORKDIR /tmp
RUN rm -rf 2.3.5.zip PRSice-2.3.5

WORKDIR /tmp/miniforge
RUN curl -sSL "https://github.com/conda-forge/miniforge/releases/download/24.3.0-0/Miniforge3-24.3.0-0-$("uname")-$("uname" "-m").sh" -o /tmp/miniforge.sh \
&& mkdir /root/.conda \
&& bash /tmp/miniforge.sh -bfp /usr/local \
&& rm -rf /tmp/miniforge.sh \
&& export PATH=$PATH:/opt/conda/bin

RUN mamba install \
python=3.11 \
conda-pack==0.7.1 \
numpy==1.26.4 \
scipy==1.13.0 \
numba==0.59.1 \
pandas==2.2.2 \
matplotlib-base==3.8.4 \
seaborn==0.13.2 \
notebook==7.1.3 \
--yes && \
mamba install icc_rt==2020.2 --channel numba --yes

# clean up
RUN rm -rf /tmp/*
RUN mamba clean -a -y && \
pip cache purge && \
rm -rf /tmp/*

WORKDIR /
WORKDIR /
39 changes: 39 additions & 0 deletions scripts/LDpred2/run_ldpred2_w_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# pull docker image and tag it as "ldpred2:latest"
docker pull --platform=linux/amd64 ghcr.io/comorment/ldpred2:latest
docker image tag ghcr.io/comorment/ldpred2:latest ldpred2:latest

bash # make sure you run bash locally, not zsh (which is the default shell in some systems - e.g. macOS)

# input/output files
export fileGeno=/REF/examples/prsice2/EUR.bed
export fileGenoRDS=EUR.rds
export fileSumstats=/REF/examples/prsice2/Height.gwas.txt.gz
export fileOut=Height

# set environmental variables. Replace $REPOS with
# the full path to the folder containing cloned "containers" and "ldpred2_ref" repositories
export REPOS=~/Repositories
export REFERENCE=$REPOS/containers/reference # clone of https://github.com/comorment/containers
export LDPRED2_REF=$REPOS/ldpred2_ref # clone of https://github.com/comorment/ldpred2_ref
export CONTAINER="ldpred2:latest"
export RSCRIPT="docker run --platform=linux/amd64 --mount type=bind,source=${PWD},target=/home --mount type=bind,source=${REFERENCE},target=/REF --mount type=bind,source=${LDPRED2_REF},target=/ldpred2_ref -w=/home/ ${CONTAINER} Rscript"

# run tasks
# $RSCRIPT /home/createBackingFile.R --file-input $fileGeno --file-output /home/$fileGenoRDS
$RSCRIPT createBackingFile.R --file-input $fileGeno --file-output $fileGenoRDS

# impute
$RSCRIPT imputeGenotypes.R --impute-simple mean0 --geno-file-rds $fileGenoRDS

# Generate PGS using LDPRED2-auto
$RSCRIPT ldpred2.R \
--ldpred-mode auto \
--col-stat OR \
--col-stat-se SE \
--stat-type OR \
--geno-file-rds $fileGenoRDS \
--sumstats $fileSumstats \
--out $fileOut.auto

Binary file removed scripts/LDpred2/score.png
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/extras/r.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ libraries_to_check <- c(
"devtools",
"data.table",
"dplyr",
"essentials",
"eulerr",
"ggplot2",
"grDevices",
"IRkernel",
"methods",
"optparse",
"R.utils",
Expand Down
16 changes: 16 additions & 0 deletions tests/test_ldpred2_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ def test_ldpred2_R_packages():
assert out.returncode == 0


def test_ldpred2_python3_packages():
packages = [
'notebook',
'numba',
'numpy',
'matplotlib',
'pandas',
'scipy',
'seaborn',
]
for pkg in packages:
call = f'{PREFIX} python3 -c "import {pkg}"'
out = subprocess.run(call, shell=True, check=True)
assert out.returncode == 0


def test_ldpred2_bin_prsice():
call = f'{PREFIX} PRSice --version'
out = subprocess.run(call.split(' '), check=True)
Expand Down

0 comments on commit 2c78524

Please sign in to comment.