-
Notifications
You must be signed in to change notification settings - Fork 2
/
hcp_struct
executable file
·360 lines (276 loc) · 10.8 KB
/
hcp_struct
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/bin/bash
SCRIPT_NAME=$(basename "${0}")
DEFAULT_STUDY_DIR="${HOME}/data/HCPYA"
DEFAULT_GRADIENT_COEFFS_DIR="${HOME}/projects/HCPpipelinesPrereqs/gradient_coefficients_files"
DEFAULT_FREESURFER_LICENSE_DIR="${HOME}/projects/HCPpipelinesPrereqs/FreeSurferLicense"
usage()
{
cat <<EOF
${SCRIPT_NAME}:
This script demonstrates how to run Structural Preprocessing related applications
available within the HCPprocessPipelines.simg Singularity container or within the
corresponding HCPprocessPipelinesSandbox on HCP-YA subjects.
Usage: ${SCRIPT_NAME} PARAMETER ...
PARAMETERS are: [ ] = optional; < > = user supplied value
[--help] : show this usage information and exit
Path to study directory
-----------------------
[--study-dir=<path-to-study-directory>]
The specified path will be bound (i.e. mounted) from your system
to a known location (/study) in the container or sandbox. This is
where the study data must be found within the container or sandbox.
It is assumed that your study directory contains subdirectories that
correspond to your subject IDs.
If you do not specify a study directory, the study directory will
default to: ${DEFAULT_STUDY_DIR}.
Path to gradient coefficients files
-----------------------------------
[--gradient-coeffs-dir=<path-to-gradient-coefficients-directory>]
The specified path will be bound (i.e. mounted) from your system
to a known location (/export/HCP/gradient_coefficient_files) in the
container or sandbox. This is where the gradient coefficients
files must be found within the container or sandbox.
This gradient coefficients files directory must contain the
proprietary gradient coefficients files for any scanners used in
collecting your image data files.
If you do not specify a gradient coefficients files directory, it will
default to: ${DEFAULT_GRADIENT_COEFFS_DIR}.
NOTE: The path to the gradient coefficients files is only necessary
for actual processing of data. If you are running a completion
check, you can allow this to take its default value even if that
value is incorrect.
Path to FreeSurfer license file
-------------------------------
[--freesurfer-license-dir=<path-to-freesurfer-license-directory>]
The specified path will be bound (i.e. mounted) from your system
to a known location (/export/freesurfer_license) in the container
or sandbox. This is where the FreeSurfer license file must be
found within the container or sandbox.
If you do not specify a FreeSurfer license directory, it will
default to: ${DEFAULT_FREESURFER_LICENSE_DIR}.
NOTE: The path to the FreeSurfer license file is only necessary
for actual processing of data. If you are running a completion
check, you can allow this to take its default value even if that
value is incorrect.
Specification of environment
----------------------------
You must specify whether to perform the requested processing
in the Singularity Container (HCPprocessPipelines.simg) or
in the Singularity Sandbox (HCPprocessPipelinesSandbox/).
One of the following options must be specified:
--env=[CONTAINER|SANDBOX]
--container
--sandbox
The value specified for the --env= parameter is not case
sensitive, but must be either CONTAINER or SANDBOX. For example,
--env=ConTAiner, --env=SandBox, and --env=sandbox
are all valid, but --env=CONTAIN is not valid.
--container is equivalent to --env=CONTAINER
--sandbox is equivalent to --env=SANDBOX
NOTE: To run within the Sandbox, you will need sudo privileges
on the machine on which you are running. When commands are run
with sudo, you may be prompted for your password to validate
your sudo privileges.
Subject List File
-----------------
You must specify a file containing a list of subject information lines.
Each line in the subject file must contain the following information:
<subject-id>
Anything after a # on a line is considered a comment. To comment out a subject
information line, simply insert a # as the very first character on the line
Each subject information line will be parsed and the container or sandbox will
be used to run the specified processing for the specified subject.
Processing
----------
This script will run the actual Structural Preprocessing for the specified
subjects. It is not implemented to run the completion check for Structural
Preprocessing.
EOF
}
abort()
{
local error_msg
error_msg="${1}"
echo ""
usage
echo "--------------------------------------------------"
echo "ERROR: ${error_msg}"
echo "--------------------------------------------------"
echo ""
exit 1
}
get_options()
{
local arguments=($@)
# initialize global output variables
unset g_subject_list_file
g_study_dir="${DEFAULT_STUDY_DIR}"
g_gradient_coeffs_dir="${DEFAULT_GRADIENT_COEFFS_DIR}"
g_freesurfer_license_dir="${DEFAULT_FREESURFER_LICENSE_DIR}"
unset g_env
# parse arguments
local num_args=${#arguments[@]}
local argument
local index=0
while [ ${index} -lt ${num_args} ]; do
argument=${arguments[index]}
case ${argument} in
--help)
usage
exit 1
;;
--study-dir=*)
g_study_dir=${argument/*=/""}
index=$(( index + 1 ))
;;
--gradient-coeffs_dir=*)
g_gradient_coeffs_dir=${argument/*=/""}
index=$(( index + 1 ))
;;
--freesurfer-license-dir=*)
g_freesurfer_license_dir=${argument/*=/""}
index=$(( index + 1 ))
;;
--env=*)
g_env=${argument/*=/""}
g_env=$(echo ${g_run_type} | tr '[:lower:]' '[:upper:]')
index=$(( index + 1 ))
;;
--container)
g_run_type="CONTAINER"
index=$(( index + 1 ))
;;
--sandbox)
g_run_type="SANDBOX"
index=$(( index + 1 ))
;;
--subject-list=*)
g_subject_list_file=${argument/*=/""}
index=$(( index + 1 ))
;;
*)
echo "Unrecognized option: ${argument}"
exit 1
;;
esac
done
# check parameters
if [ -n "${g_study_dir}" ]; then
echo "INFO: study directory: ${g_study_dir}"
else
abort "--study-dir=<study-directory> must be specified"
fi
if [ -n "${g_gradient_coeffs_dir}" ]; then
echo "INFO: gradient coefficients directory: ${g_gradient_coeffs_dir}"
else
abort "--gradient-coeffs-dir=<gradient-coeffs-directory> must be specified"
fi
if [ -n "${g_freesurfer_license_dir}" ]; then
echo "INFO: FreeSurfer license directory: ${g_freesurfer_license_dir}"
else
abort "--freesurfer-license-dir=<freesurfer-license-directory> must be specified"
fi
if [ -z "${g_env}" ]; then
abort "run type (--env=[CONTAINER|SANDBOX], --container, or --sandbox) required"
fi
if [ "${g_env}" != "CONTAINER" -a "${g_env}" != "SANDBOX" ]; then
abort "environment must be CONTAINER or SANDBOX"
else
echo "INFO: Environment: ${g_env}"
fi
if [ -n "${g_subject_list_file}" ]; then
echo "INFO: running processing for subjects listed in file: ${g_subject_list_file}"
else
abort "--subject-list=<subject-list-filename> must be specified"
fi
}
main()
{
local line
local run_cmd
local subject_id
local where_study_is_on_my_system
local where_study_must_be_in_container
local where_gc_files_are_on_my_system
local where_gc_files_must_be_in_container
local where_license_file_is_on_my_system
local where_license_file_must_be_in_container
get_options "$@"
while read -r line; do
# remove comments - anything after a #
line=${line%%\#*}
# trim leading and trailing whitespace
line=$(echo ${line} | xargs)
if [ -z "${line}" ]; then
continue
fi
subject_id=${line}
echo ""
echo "-- Running processing for subject: ${subject_id} --"
echo ""
run_cmd=""
# Base Singularity command
if [ "${g_run_type}" = "CONTAINER" ]; then
run_cmd+="singularity run"
elif [ "${g_run_type}" = "SANDBOX" ]; then
run_cmd+="sudo singularity exec"
else
abort "Unrecognized run type: ${g_run_type}"
fi
# Bind your study directory
# Needs to show up as the /study directory in the Container/Sandbox
where_study_is_on_my_system="${g_study_dir}"
where_study_must_be_in_container="/study"
run_cmd+=" -B ${where_study_is_on_my_system}:${where_study_must_be_in_container}"
# Bind gradient coefficients files directory
# Needs to show up as the /export/HCP/gradient_coefficient_files directory in the Container/Sandbox
where_gc_files_are_on_my_system="${HOME}/projects/HCPpipelinesPrereqs/gradient_coefficients_files"
where_gc_files_must_be_in_container="/export/HCP/gradient_coefficient_files"
run_cmd+=" -B ${where_gc_files_are_on_my_system}:${where_gc_files_must_be_in_container}"
# Bind folder with FreeSurfer License
# Needs to show up as the /export/freesurfer_license directory in the Container/Sandbox
# Must contain a file named 'license.txt'
where_license_file_is_on_my_system="${HOME}/projects/HCPpipelinesPrereqs/FreeSurferLicense"
where_license_file_must_be_in_container="/export/freesurfer_license"
run_cmd+=" -B ${where_license_file_is_on_my_system}:${where_license_file_must_be_in_container}"
# Specify command or script to run
if [ "${g_env}" = "CONTAINER" ]; then
# application in the container to run
run_cmd+=" --app StructuralPreprocessing"
# container image file
run_cmd+=" HCPprocessPipelines.simg"
elif [ "${g_env}" = "SANDBOX" ]; then
# sandbox directory
run_cmd+=" HCPprocessPipelinesSandbox/"
# full path to script within sandbox to execute
run_cmd+=" /pipeline_tools/HCPpipelinesRunUtils/StructuralPreprocessing/StructuralPreprocessing.SINGULARITY_PROCESS"
else
abort "Unrecognized run type: ${g_run_type}"
fi
# Add command line parameters for command/script to run
run_cmd+=" --working-dir=/study" # Note: this path is from within the container
run_cmd+=" --subject=${subject_id}"
run_cmd+=" --classifier=3T"
run_cmd+=" --brainsize=150"
run_cmd+=" --first-t1w-directory-name=T1w_MPR1"
run_cmd+=" --first-t1w-file-name=${subject_id}_3T_T1w_MPR1.nii.gz"
run_cmd+=" --first-t2w-directory-name=T2w_SPC1"
run_cmd+=" --first-t2w-file-name=${subject_id}_3T_T2w_SPC1.nii.gz"
run_cmd+=" --t1template=MNI152_T1_0.7mm.nii.gz"
run_cmd+=" --t1templatebrain=MNI152_T1_0.7mm_brain.nii.gz"
run_cmd+=" --t1template2mm=MNI152_T1_2mm.nii.gz"
run_cmd+=" --t2template=MNI152_T2_0.7mm.nii.gz"
run_cmd+=" --t2templatebrain=MNI152_T2_0.7mm_brain.nii.gz"
run_cmd+=" --t2template2mm=MNI152_T2_2mm.nii.gz"
run_cmd+=" --templatemask=MNI152_T1_0.7mm_brain_mask.nii.gz"
run_cmd+=" --template2mmmask=MNI152_T1_2mm_brain_mask_dil.nii.gz"
run_cmd+=" --fnirtconfig=T1_2_MNI152_2mm.cnf"
run_cmd+=" --gdcoeffs=coeff_SC72C_Skyra.grad"
run_cmd+=" --topupconfig=b02b0.cnf"
run_cmd+=" --fieldmap-type=SiemensGradientEcho"
echo "run_cmd: ${run_cmd}"
time ${run_cmd}
done < "${g_subject_list_file}"
}
# Invoke the main function to get things started
main "$@"