-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingularity
More file actions
305 lines (267 loc) · 9.97 KB
/
Singularity
File metadata and controls
305 lines (267 loc) · 9.97 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
Bootstrap: docker
From: ubuntu:18.04
%files
#/home-local/kimm58/AtlasToDiffusionReg/code/get_transforms.sh /
#The following should run as long as you ran git pull for the repository
FILES/JHUEVE3/Labels_JHU_MNI_SS_WMPM_Type-III.txt /FILES/JHUEVE3/Labels_JHU_MNI_SS_WMPM_Type-III.txt
FILES/JHUEVE3/Atlas_JHU_MNI_SS_WMPM_Type-III.nii.gz /FILES/JHUEVE3/Atlas_JHU_MNI_SS_WMPM_Type-III.nii.gz
FILES/JHUEVE3/template.nii.gz /FILES/JHUEVE3/template.nii.gz
FILES/MNI152/template.nii.gz /FILES/MNI152/template.nii.gz
FILES/T1_seg.txt /FILES/T1_seg.txt
%help
https://github.com/MASILab/AtlasToDiffusionReg
%post -c /bin/bash
cd /
# Prepare directories for installing applications
mkdir -p APPS
mkdir -p INSTALLERS
# Update all libraries
apt-get -y update
# Install xvfb
apt-get -y install xvfb
# Install ghostscript for pdf management
apt-get -y install ghostscript
#####
# Install MRTrix3
apt-get -y install git g++ python python-numpy libeigen3-dev zlib1g-dev libqt4-opengl-dev libgl1-mesa-dev libfftw3-dev libtiff5-dev python3-distutils
cd APPS
git clone https://github.com/MRtrix3/mrtrix3.git
cd mrtrix3
git checkout 3.0.3
./configure
./build
cd /
# Install FSL
apt-get -y install python wget ca-certificates libglu1-mesa libgl1-mesa-glx libsm6 libice6 libxt6 libpng16-16 libxrender1 libxcursor1 libxinerama1 libfreetype6 libxft2 libxrandr2 libgtk2.0-0 libpulse0 libasound2 libcaca0 libopenblas-base bzip2 dc bc
#wget -O /INSTALLERS/fslinstaller.py "https://fsl.fmrib.ox.ac.uk/fsldownloads/fslinstaller.py"
#wget -O /INSTALLERS/fslinstaller.py "https://git.fmrib.ox.ac.uk/fsl/installer/-/raw/3.3.0/fslinstaller.py?inline=false"
wget -O /INSTALLERS/fslinstaller.py "https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/releases/fslinstaller.py"
cd /INSTALLERS
chmod +x fslinstaller.py
python fslinstaller.py -d /APPS/fsl -V 6.0.6 -o 2>&1 | tee /tmp/fslinstaller_build.log
cat /tmp/fslinstaller_build.log
cd /
# Install Convert3D (stable build 1.0.0)
apt-get -y install wget tar
wget -O /INSTALLERS/c3d-1.0.0-Linux-x86_64.tar.gz "https://downloads.sourceforge.net/project/c3d/c3d/1.0.0/c3d-1.0.0-Linux-x86_64.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fc3d%2Ffiles%2Fc3d%2F1.0.0%2Fc3d-1.0.0-Linux-x86_64.tar.gz%2Fdownload&ts=1571934949"
tar -xf /INSTALLERS/c3d-1.0.0-Linux-x86_64.tar.gz -C /APPS/
cd /
# Install ANTs (and compatible CMake)
apt-get -y install build-essential libssl-dev
# CMake: The latest ANTs requires newer version of cmake than can be installed
# through apt-get, so we need to build higher version of cmake from source
cd /INSTALLERS
mkdir cmake_install
cd cmake_install
wget https://github.com/Kitware/CMake/releases/download/v3.23.0-rc2/cmake-3.23.0-rc2.tar.gz
tar -xf cmake-3.23.0-rc2.tar.gz
cd cmake-3.23.0-rc2/
./bootstrap
make
make install
cd /
# ANTS
cd /INSTALLERS
mkdir ants_installer
cd ants_installer
git clone https://github.com/ANTsX/ANTs.git
cd ANTs/
git checkout efa80e3f582d78733724c29847b18f3311a66b54
mkdir ants_build
cd ants_build
cmake /INSTALLERS/ants_installer/ANTs -DCMAKE_INSTALL_PREFIX=/APPS/ants
make 2>&1 | tee build.log
cd ANTS-build
make install 2>&1 | tee install.log
cd /
# ##new commands
# cd /INSTALLERS
# wget https://github.com/Kitware/CMake/releases/download/v3.23.0/cmake-3.23.0.tar.gz
# tar -xf cmake-3.23.0.tar.gz
# cd cmake-3.23.0
# ./bootstrap
# make
# make install
# cd /
# cd /INSTALLERS
# apt-get update && apt-get install -y \
# zlib1g-dev \
# libbz2-dev \
# liblzma-dev \
# libpng-dev \
# libtiff-dev \
# libjpeg-dev \
# libexpat1-dev \
# libssl-dev \
# libcurl4-openssl-dev \
# build-essential \
# git \
# wget
# git clone https://github.com/ANTsX/ANTs.git
# cd ANTs
# git checkout efa80e3f582d78733724c29847b18f3311a66b54
# mkdir build
# cd build
# cmake .. \
# -DCMAKE_INSTALL_PREFIX=/APPS/ants \
# -DBUILD_SHARED_LIBS=ON \
# -DZLIB_INCLUDE_DIR=/usr/include \
# -DZLIB_LIBRARY=/usr/lib/x86_64-linux-gnu/libz.so
# make 2>&1 | tee build.log
# #cd ANTS-build
# make install 2>&1 | tee install.log
# cd /
########
# Install FreeSurfer
#apt-get -y install bc binutils libgomp1 perl psmisc sudo tar tcsh unzip uuid-dev vim-common libjpeg62-dev
#wget -O /INSTALLERS/freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.0.tar.gz "https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/6.0.0/freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.0.tar.gz"
#tar -C /APPS -xzvf /INSTALLERS/freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.0.tar.gz
#echo "This is a dummy license file. Please bind your freesurfer license file to this file." > /APPS/freesurfer/license.txt
#cd /
# Make custom folders
mkdir -p INPUTS
mkdir -p SUPPLEMENTAL
mkdir -p OUTPUTS
mkdir -p CODE
# Set Permissions
chmod 755 /INPUTS
chmod 755 /SUPPLEMENTAL
chmod 755 /APPS
chmod 775 /OUTPUTS
chmod 755 /CODE
# Install source code
cd /
apt-get -y install git gcc libpq-dev python-dev python-pip python3 python3-dev python3-pip python3-venv python3-wheel
cd /INSTALLERS
#git clone https://github.com/MASILab/PreQual.git
git clone https://github.com/MASILab/AtlasToDiffusionReg.git
cd AtlasToDiffusionReg
#git checkout main
#Write all your scripts in a folder on github repo and then move them into the corresponding folders in this singularity
#mv src/APPS/* /APPS
mv src/CODE/* /CODE
#mv src/SUPPLEMENTAL/* /SUPPLEMENTAL
#cd /APPS/synb0
#python3.6 -m venv pytorch
#source pytorch/bin/activate
#pip3 install wheel
#pip install -r /INSTALLERS/PreQual/venv/pip_install_synb0.txt
#deactivate
cd /CODE
python3 -m venv venv
source venv/bin/activate
pip3 install wheel
pip install -r /INSTALLERS/AtlasToDiffusionReg/venv/pip_install.txt
deactivate
cd /
# Clean up
rm -r /INSTALLERS
%environment
# MRTrix3
export PATH="/APPS/mrtrix3/bin:$PATH"
# FSL
FSLDIR=/APPS/fsl
. ${FSLDIR}/etc/fslconf/fsl.sh
PATH=${FSLDIR}/bin:${PATH}
export FSLDIR PATH
# Convert3D
export PATH="/APPS/c3d-1.0.0-Linux-x86_64/bin:$PATH"
# ANTs
export ANTSPATH=/APPS/ants/bin/
export PATH=${ANTSPATH}:$PATH
# FreeSurfer
#export FREESURFER_HOME=/APPS/freesurfer
#source $FREESURFER_HOME/SetUpFreeSurfer.sh # For us, only synb0 needs it so will put in that script.
# CUDA
#export CPATH="/usr/local/cuda/include:$CPATH"
#export PATH="/usr/local/cuda/bin:$PATH"
#export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"
#export CUDA_HOME="/usr/local/cuda"
%runscript
#everything below this will run when you call singularity run xxx.simg
#this creates the PDF, figure out later
#xvfb-run -a --server-num=$((65536+$$)) --server-args="-screen 0 1600x1280x24 -ac" bash /CODE/run_dtiQA.sh /INPUTS /OUTPUTS "$@"
#v1.5: added the low/high for the bval threshold instead of hard coding it in
low=0
high=1500
atlastype=""
# Loop through all arguments
while [ "$#" -gt 0 ]; do
case "$1" in
--low)
low=$(echo "$2" | cut -d '.' -f 1)
shift 2
;;
--high)
high=$(echo "$2" | cut -d '.' -f 1)
shift 2
;;
--EVE3|--MNI|--custom)
atlas_type="$1" # Capture the atlas type instead of relying on $1 later
shift
;;
--) # End of options
shift
break
;;
-*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done
case "$atlas_type" in
--EVE3)
echo "Registering to EVE3 Atlas."
ln -s /FILES/JHUEVE3/template.nii.gz /INPUTS/template.nii.gz
ln -s /FILES/JHUEVE3/Atlas_JHU_MNI_SS_WMPM_Type-III.nii.gz /INPUTS/Atlas_JHU_MNI_SS_WMPM_Type-III.nii.gz
ln -s /FILES/JHUEVE3/Labels_JHU_MNI_SS_WMPM_Type-III.txt /INPUTS/Labels_JHU_MNI_SS_WMPM_Type-III.txt
;;
--MNI)
echo "Registering to MNI152 Atlas."
ln -s /FILES/MNI152/template.nii.gz /INPUTS/template.nii.gz
;;
--custom)
echo "Registering to custom template. Ensure that there is a file named 'template.nii.gz' in the inputs directory."
echo "Also, if you want to register Atlases, make sure there are corresponding Atlas* and Labels* files in the inputs directory."
;;
*)
echo "Invalid arguments."
echo "USAGE: singularity run <BINDS> <SIMG> [--EVE3|--MNI|--custom] [--low <val>] [--high <val>]"
exit 1
;;
esac
#if [ ! -f /INPUTS/template.nii.gz ]; then
# ln -s /FILES/template.nii.gz /INPUTS/template.nii.gz
# ln -s /FILES/Atlas_JHU_MNI_SS_WMPM_Type-III.nii.gz /INPUTS/Atlas_JHU_MNI_SS_WMPM_Type-III.nii.gz
# ln -s /FILES/Labels_JHU_MNI_SS_WMPM_Type-III.txt /INPUTS/Labels_JHU_MNI_SS_WMPM_Type-III.txt
#fi
seglink="False"
if [ ! -e /INPUTS/T1_seg.txt ]; then
ln -s /FILES/T1_seg.txt /INPUTS/T1_seg.txt
seglink="True"
fi
cd /CODE
bash get_transforms.sh
bash apply_transforms.sh
#bash activate_venv.sh
python3 extract_single_shell.py --u_thresh $high --l_thresh $low
bash calc_scalars.sh
python3 calc_metrics_per_roi.py
python3 create_QA_png.py
deactivate
case "$atlas_type" in
--EVE3)
echo "Registering to EVE3 Atlas."
rm /INPUTS/template.nii.gz
rm /INPUTS/Atlas_JHU_MNI_SS_WMPM_Type-III.nii.gz
rm /INPUTS/Labels_JHU_MNI_SS_WMPM_Type-III.txt
;;
--MNI)
echo "Registering to MNI152 Atlas."
rm /INPUTS/template.nii.gz
;;
esac
if [ "$seglink" = "True" ]; then
rm /INPUTS/T1_seg.txt
fi