-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
390 lines (373 loc) · 11.8 KB
/
config.py
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import math
from os import set_inheritable
from src.executor import TaskConfig
from src.cli import VMEngine
from src.path import PathPlaceHolder, InputFile, InputDir, OutputFile, \
OutputDir
# This task is mostly used to copy singularity executable on compute node.
# @warning
# This won't work with dir in singularity/docker, as VM engine will be
# configured to map file, not dir (cf. decorators).
COPY_FILE = TaskConfig(
raw_executable='rsync',
singularity_image=None,
docker_image=None,
cmd='''
{0}
-avz --no-g --no-p
"{sourcePath}"
"{destPath}"
''',
decorators={
"sourcePath": InputFile,
"destPath": OutputFile
}
)
COPY_DIR = TaskConfig(
raw_executable='rsync',
singularity_image=None,
docker_image=None,
cmd='''
{0}
-avz --no-g --no-p
"{sourcePath}/"
"{destPath}/"
''',
decorators={
"sourcePath": InputDir,
"destPath": OutputDir
}
)
REMOVE_FILE = TaskConfig(
raw_executable='rm',
singularity_image=None,
docker_image=None,
cmd='''
{0}
"{filePath}"
''',
decorators={
"filePath": InputFile
}
)
REMOVE_DIR = TaskConfig(
raw_executable='rm',
singularity_image=None,
docker_image=None,
cmd='''
{0}
-r
"{dirPath}"
''',
decorators={
"dirPath": InputDir
}
)
ARCHIVE_DATASET = TaskConfig(
raw_executable='dar',
singularity_image=None, # @TODO !!! map to NONE
docker_image=None, # @TODO !!! map to NONE
cmd='''
{0} -R "{datasetDir}" -v -s 1024M -w -c "{archiveDir}/{archiveName}"
''',
decorators={
"datasetDir": InputDir,
"archiveDir": OutputDir
# @note archive name is just a prefix, thus not an OutputFile.
}
)
# @warning when outputDir is a local ssd, these can't be extracted to local
# node ssd on ComputeCanada@Beluga (mutualised 480GO ssd) when dataset ~>
# 300GO. Also, ssd space allocation is mutualised and not guaranteed.
EXTRACT_DATASET = TaskConfig(
raw_executable='dar',
singularity_image=None, # @TODO !!! map to NONE
docker_image=None, # @TODO !!! map to NONE
cmd='''
{0} -R "{outputDir}" -O -w -x "{archiveDir}/{archiveName}" -v -am
''',
decorators={
"outputDir": OutputDir,
"archiveDir": InputDir
# @note archive name is just a prefix, thus not an InputFile.
}
)
EXTRACT_DATASET_SUBJECT = TaskConfig(
raw_executable='dar',
singularity_image=None, # @TODO !!! map to NONE
docker_image=None, # @TODO !!! map to NONE
cmd='''
{0} -R "{outputDir}" -O -w -x "{archiveDir}/{archiveName}" -v -am -P "sub-*" -g "sub-{subjectId}"
''',
decorators={
"outputDir": OutputDir,
"archiveDir": InputDir
# @note archive name is just a prefix, thus not an InputFile.
}
)
EXTRACT_DATASET_SESSION = TaskConfig(
raw_executable='dar',
singularity_image=None, # @TODO !!! map to NONE
docker_image=None, # @TODO !!! map to NONE
# @TODO double check if multiple session extraction / file override doesn't cause trouble.
# @note --overwriting-policy=pP seems not required to do multiple extraction.
cmd='''
{0} -R "{outputDir}" -O -w
-x "{archiveDir}/{archiveName}" -v -am
-P "sub-*"
-g "sub-{subjectId}"
-P "sub-{subjectId}/ses-*"
-g "sub-{subjectId}/ses-{sessionId}"
''',
decorators={
"outputDir": OutputDir,
"archiveDir": InputDir
# @note archive name is just a prefix, thus not an InputFile.
}
)
LIST_ARCHIVE_SESSIONS = TaskConfig(
raw_executable='dar',
singularity_image=None, # @TODO !!! map to NONE
docker_image=None, # @TODO !!! map to NONE
# Will output with this format:
# 01 -- sub
# 01,01 -- sub,ses
# 01,01,/anat/sub-01_ses-01_run-01_T1w.nii.gz -- sub,ses,anat
# 01,02
# 02
# ...
# @note Double brakes are present `{{ }}` to prevent python interpolation,
# `\\`` and `\$` within `"` to prevent bash interpolation within 'HEREDOC'
# syntax.
# @note We truncate sub- / ses- prefixes to be consistant with pybids
# output.
# @note We store anat paths in order to be able to process anat sessions
# with smriprep on large longitudinal dataset.
cmd='''
{0} -l "{archiveDir}/{archiveName}" --list-format=normal
| awk "NR > 2 {{ print \$NF; }}"
| grep 'sub-'
| sed -E "s;^sub-([^/]+)(/ses-([^/]+))?(/anat/[^.]+_T1w.nii(.gz)?)?.*;\\1,\\3,\\4;g"
| sed -E "s/,+\$//g"
| sort | uniq
''',
decorators={
"datasetDir": InputDir,
# @note archive name is just a prefix, thus not an OutputFile.
}
)
BIDS_VALIDATOR = TaskConfig(
raw_executable='bids-validator',
singularity_image='../singularity-images/bids-validator-1.8.5.simg',
docker_image='bids/validator:v1.8.5',
cmd='''
{0} "{datasetDir}" --verbose
''',
# Map paths to vm volumes using argument decorators.
decorators={
"datasetDir": InputDir
}
)
MRIQC_SUBJECT = TaskConfig(
raw_executable='mriqc',
singularity_image='../singularity-images/mriqc-21.0.0rc2.simg',
docker_image='nipreps/mriqc:21.0.0rc2',
cmd='''
{0}
--no-sub
--nprocs {nproc}
--mem_gb {memGB}
-vvv
-w "{workDir}"
"{datasetDir}"
"{outputDir}"
participant
--participant_label "{subjectId}"
''',
# Map paths to vm volumes using argument decorators.
decorators={
"workDir": OutputDir,
"datasetDir": InputDir,
"outputDir": OutputDir,
"templateflowDataDir": InputDir,
"memGB": math.floor
}
)
MRIQC_GROUP = TaskConfig(
raw_executable='mriqc',
singularity_image='../singularity-images/mriqc-21.0.0rc2.simg',
docker_image='poldracklab/mriqc:21.0.0rc2',
cmd='''
{0}
--no-sub
--nprocs {nproc}
--mem_gb {memGB}
-vvv
-w "{workDir}"
"{datasetDir}"
"{outputDir}"
group
''',
# Map paths to vm volumes using argument decorators.
decorators={
"workDir": OutputDir,
"datasetDir": InputDir,
"outputDir": OutputDir,
"templateflowDataDir": InputDir,
"memGB": math.floor
}
)
# @warning 6000mb crashes on docker. (? was it ram ?)
# @note some additional output spaces seems required later on by fmriprep for
# intermediate processing (do they?).
# @warning potential templateflow compat issue.
# cf. https://neurostars.org/t/tips-for-getting-a-bare-metal-installation-of-fmriprep-1-4-1-working/4660/2
SMRIPREP_SUBJECT = TaskConfig(
raw_executable='smriprep',
singularity_image='../singularity-images/smriprep-0.8.1.simg',
docker_image='nipreps/smriprep:0.8.1',
cmd='''
{0}
--participant-label "{subjectId}"
--notrack
--output-spaces
MNI152NLin6Asym MNI152NLin2009cAsym OASIS30ANTs
--nprocs {nproc}
--mem-gb {memGB}
--fs-no-reconall
--skull-strip-mode "{skullStripMode}"
-vvv
--fs-license "{freesurferLicenseFile}"
-w "{workDir}"
"{datasetDir}"
"{outputDir}"
participant
--low-mem
''',
# Map paths to vm volumes using argument decorators.
decorators={
"datasetDir": InputDir,
"workDir": OutputDir,
"outputDir": OutputDir,
"templateflowDataDir": InputDir,
"freesurferLicenseFile": InputFile,
"memGB": math.floor
}
)
FMRIPREP_SUBJECT = TaskConfig(
raw_executable='fmriprep',
singularity_image='../singularity-images/fmriprep-20.2.6.simg',
docker_image='nipreps/fmriprep:20.2.6',
cmd='''
{0}
--notrack
--skip-bids-validation
--ignore slicetiming
--nprocs {nproc}
--mem-mb {memMB}
-vvv
--fs-no-reconall
--skull-strip-t1w "{skullStripT1w}"
--fs-license "{freesurferLicenseFile}"
-w "{workDir}"
"{datasetDir}"
"{outputDir}"
participant
--participant-label "{subjectId}"
--low-mem
''',
# Map paths to vm volumes using argument decorators.
decorators={
"datasetDir": InputDir,
"workDir": OutputDir,
"outputDir": OutputDir,
"templateflowDataDir": InputDir,
"freesurferLicenseFile": InputFile,
"memMB": math.floor
}
)
# Used to generate fmriprep bids file selection filter for session level
# granularity.
#
# @note we've removed the anat data from the filter, as fmriprep seems to
# reprocess the anatomical t1 even though we've used anat fast-track.
FMRIPREP_SESSION_FILTER = TaskConfig(
raw_executable='printf',
singularity_image=None, # @TODO !!! map to NONE
docker_image=None, # @TODO !!! map to NONE
cmd='''
{0} '%s' '{{
"fmap": {{
"datatype": "fmap"
}},
"bold": {{
"datatype": "func",
"suffix": "bold",
"session": "{sessionId}"
}},
"sbref": {{
"datatype": "func",
"suffix": "sbref",
"session": "{sessionId}"
}},
"flair": {{"datatype": "anat", "suffix": "FLAIR"}},
"t2w": {{"datatype": "anat", "suffix": "T2w"}},
"t1w": {{"datatype": "anat", "suffix": "T1w"}},
"roi": {{"datatype": "anat", "suffix": "roi"}}
}}' > "{bidsFilterFile}"
''',
# Map paths to vm volumes using argument decorators.
decorators={
"bidsFilterFile": OutputFile
}
)
# @note on some workers, some of the fmriprep processes (ie. mcflirt/fslsplit)
# hangs with 0% CPU and htop D flag (uninterruptible process). Might be due to
# memory overload, cf. https://github.com/nipreps/fmriprep/issues/1045, even
# though weird has we already inject 4GO per cpu, which is twice what
# fmriprep recommands (although no info about swap), and this is inner per-task
# processing,
# We thus use the --low-mem flag which swaps work files to disk - should work
# nice with ssds local processing. We've also reduced logging to minimun
# because it might be a bottleneck has it's recorded not on the local ssd but
# the network file system, even though mcflirt/fslsplit don't seem to pipe to
# this log.
FMRIPREP_SESSION = TaskConfig(
raw_executable='fmriprep',
singularity_image='../singularity-images/fmriprep-20.2.6.simg',
docker_image='nipreps/fmriprep:20.2.6',
cmd='''
{0}
--notrack
--skip-bids-validation
--output-spaces
MNI152NLin2009cAsym
--ignore slicetiming
--nprocs {nproc}
--mem-mb {memMB}
-vvv
--fs-no-reconall
--skull-strip-t1w "{skullStripT1w}"
--fs-license "{freesurferLicenseFile}"
--anat-derivatives "{anatsDerivativesDir}"
-w "{workDir}"
"{datasetDir}"
"{outputDir}"
participant
--participant-label "{subjectId}"
--bids-filter-file "{bidsFilterFile}"
--low-mem
''',
# Map paths to vm volumes using argument decorators.
decorators={
"datasetDir": InputDir,
"anatsDerivativesDir": InputDir,
"workDir": OutputDir,
"outputDir": OutputDir,
"templateflowDataDir": InputDir,
"freesurferLicenseFile": InputFile,
"bidsFilterFile": InputFile,
"memMB": math.floor,
"fasttrackFixDir": InputDir
}
)