forked from nickjer/singularity-r
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSingularity-r
212 lines (166 loc) · 6.39 KB
/
Singularity-r
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#BootStrap: docker
#From: debian:bookworm-20240904-slim
BootStrap: localimage
From: debian-baseimage.sif
%labels
Maintainer Moritz Lell
git_repository https://github.com/mlell/singularity-r
%help
The containers are accompanied by helper scripts that make your project available at a
pre-defined path regardless of where the files lie on your machine. This way, using absolute
paths do not lead to reproducibility issues. So, if you create your analyis, be sure to refer
to a file with a path starting with
/proj/PATH/TO/YOUR/FILE
The directory /proj will be translated to your project root directory. The section "How to obtain"
describes how to set your project root directory.
A possibility to include external files and folders is also available which enables to clearly
document the dependencies of your work. It is also described in the next section.
1 Setup after download
======================
After downloading this container, move it to its own directory and extract
the auxilliary scripts by calling
singularity run -B "$PWD" --pwd "$PWD" CONTAINERNAME.sif setup
2 Project directory
===================
Change working directory into the root directory of your analysis and
call (replace upper-case parts):
/PATH/TO/CONTAINER/createproject"
This creates a script in this directory from which you can call the
programs in the container. From there, your files will be found under
the path "/proj", independently from your machine. This makes it easier
for others to rerun your analysis because your machine-specific file
paths are not visible from within the container.
%setup
set -ue
if [ -z "${DEBUG-}" ]; then
# make sure git status can run without error
git status -s &>/dev/null
# If git status -s outputs anything, we have a dirty working dir
if [ ! "$(git status -s | wc -l)" = "0" ]; then
echo "Working dir dirty!" >&2
exit 1
fi
# Working dir is clean, record the commit hash inside the container
git rev-parse HEAD >"$SINGULARITY_ROOTFS/commit"
else
echo "debug" > "$SINGULARITY_ROOTFS/commit"
fi
%environment
export LANGUAGE=en_US
export LANG=en_US.UTF-8
# overwrite possible host LC_* variables when called without --containenv or --contain
export LC_ALL=en_US.UTF-8
# Disable renv sandboxing where a project is decoupled from system-wide installed libraries.
# This is not needed as the system libraries are frozen in the container and we install an
# adapter package that mimics the R BH package and links to system libraries. That would not
# work if the system libraries are not used by renv
export RENV_CONFIG_SANDBOX_ENABLED=FALSE
export OMP_NUM_THREADS=1
%post
# Software versions
export LANGUAGE=en_US
export LANG=en_US.UTF-8
# overwrite possible host LC_* variables when called without --containenv or --contain
export LC_ALL=en_US.UTF-8
# Get dependencies
# Disable check for recent release file, as we build an old snapshot
apt-get update -o Acquire::Check-Valid-Until=false
apt-get install -y --no-install-recommends \
locales curl gpg dirmngr gpg-agent
# Configure default locale
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen -a
# Install R
# Installed packages:
# * R
# * Python + libpython headers for package compilation
# * Library headers inspired by CRAN SystemRequirements fields:
# - for tidyverse: libcairo, libxml
# - Linear algebra:
# libarmadillo
# - handle netCDF and HDF files (CRAN: netcdf4, sf, gdal,...)
# libnetcdf, libgdal, libproj, libudunits2
# - Other geo stuff:
# libgeotiff
# - Fast Fourier Transform: libfftw
# - image manipulation
# libtiff5 libjpeg (Pseudo-package ->libjpeg-turbo)
# librsvg
# imagemagick
# - Glyph rendering and Unicode:
# harfbuzz libicu
# - Compression: zlib1g bzip zstd zip
# - Nonlinear Optimizationn: libnlopt0
# - Systems Biology ML: libsbml5
# - GNU Scientific Library: gsl
# - Cryptography: libsodium
# - BUGS Monte Carlo language: jags
# - Linear Programming: glpk
# - CDO Climate data library libcdi
# - Grid computing scheduler:
# libzmq3 libopenmpi
# - DBMS: libpq (libmariaclientdb <-version mismatch during install)
# - Non-root package installation: apt-rdepends
apt-get install -y --no-install-recommends \
gcc-11 \
r-base \
r-base-core \
r-base-dev \
r-recommended \
r-base-html \
r-doc-html \
libpython3-all-dev python3-pip \
libcurl4-openssl-dev \
libssl-dev \
man nano graphviz apt-rdepends \
procps imagemagick cmake \
jags less \
libxml2-dev \
libcairo2-dev \
libxt-dev \
libarmadillo-dev \
libnetcdf-dev libhdf5-dev\
gdal-bin libgdal-dev \
proj-bin libproj-dev \
libudunits2-dev \
libgeotiff-dev \
libfftw3-dev \
libtiff-dev libjpeg-dev librsvg2-dev libpng-dev \
libharfbuzz-dev libicu-dev\
zlib1g-dev libbz2-dev libzstd-dev libzip-dev\
libnlopt-dev \
libsbml5-dev \
libgsl-dev \
libsodium-dev \
libglpk-dev \
libcdi-dev \
libzmq3-dev libopenmpi-dev libcoarrays-openmpi-dev \
libpq-dev \
r-cran-bh
#libmariadbclient-dev
# r-cran-bh is a dummy package with no content, but it depends on libboost-dev.
# Therefore, the system Boost headers are reused instead of installing them again
# with the CRAN BH package. (libgdal-dev) depends on libboost-dev anyway)
# Install pandoc separately, for the github release has 1/10 the file size of the
# Debian package
curl -L https://github.com/jgm/pandoc/releases/download/2.14.1/pandoc-2.14.1-1-amd64.deb --output /tmp/pandoc.deb
dpkg -I /tmp/pandoc.deb
rm /tmp/pandoc.deb
# Add a default CRAN mirror
echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl')" >> /usr/lib/R/etc/Rprofile.site
# Set default python version
ln -s python3 /usr/bin/python
# Clean up
umount /var/lib/apt
umount /var/cache/apt
# Write the current git commit as label
echo "git_commit $(cat /commit)" >> "$SINGULARITY_LABELS"
rm /commit
echo -n "R_Version " >> "$SINGULARITY_LABELS"
Rscript -e "cat(toString(getRversion()),'\n')" >> "$SINGULARITY_LABELS"
%apprun R
exec R "${@}"
%apprun Rscript
exec Rscript "${@}"
%apprun python
exec python "${@}"