junifer 0.0.6.dev227__py3-none-any.whl → 0.0.6.dev248__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- junifer/_version.py +2 -2
- junifer/data/coordinates/_ants_coordinates_warper.py +4 -6
- junifer/data/coordinates/_coordinates.py +28 -15
- junifer/data/coordinates/_fsl_coordinates_warper.py +4 -6
- junifer/data/masks/_ants_mask_warper.py +16 -9
- junifer/data/masks/_fsl_mask_warper.py +4 -6
- junifer/data/masks/_masks.py +21 -25
- junifer/data/parcellations/_ants_parcellation_warper.py +16 -9
- junifer/data/parcellations/_fsl_parcellation_warper.py +4 -6
- junifer/data/parcellations/_parcellations.py +20 -24
- junifer/data/utils.py +67 -3
- junifer/datagrabber/aomic/id1000.py +22 -9
- junifer/datagrabber/aomic/piop1.py +22 -9
- junifer/datagrabber/aomic/piop2.py +22 -9
- junifer/datagrabber/base.py +6 -1
- junifer/datagrabber/datalad_base.py +15 -8
- junifer/datagrabber/dmcc13_benchmark.py +23 -10
- junifer/datagrabber/hcp1200/hcp1200.py +18 -7
- junifer/datagrabber/pattern.py +65 -35
- junifer/datagrabber/pattern_validation_mixin.py +197 -87
- junifer/datagrabber/tests/test_dmcc13_benchmark.py +26 -9
- junifer/pipeline/pipeline_step_mixin.py +8 -4
- junifer/pipeline/update_meta_mixin.py +21 -17
- junifer/preprocess/warping/_ants_warper.py +23 -2
- junifer/preprocess/warping/_fsl_warper.py +19 -3
- junifer/preprocess/warping/space_warper.py +31 -4
- {junifer-0.0.6.dev227.dist-info → junifer-0.0.6.dev248.dist-info}/METADATA +1 -1
- {junifer-0.0.6.dev227.dist-info → junifer-0.0.6.dev248.dist-info}/RECORD +33 -33
- {junifer-0.0.6.dev227.dist-info → junifer-0.0.6.dev248.dist-info}/WHEEL +1 -1
- {junifer-0.0.6.dev227.dist-info → junifer-0.0.6.dev248.dist-info}/AUTHORS.rst +0 -0
- {junifer-0.0.6.dev227.dist-info → junifer-0.0.6.dev248.dist-info}/LICENSE.md +0 -0
- {junifer-0.0.6.dev227.dist-info → junifer-0.0.6.dev248.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.6.dev227.dist-info → junifer-0.0.6.dev248.dist-info}/top_level.txt +0 -0
@@ -3,7 +3,7 @@
|
|
3
3
|
# Authors: Synchon Mandal <s.mandal@fz-juelich.de>
|
4
4
|
# License: AGPL
|
5
5
|
|
6
|
-
from typing import Dict, List
|
6
|
+
from typing import Dict, List, Union
|
7
7
|
|
8
8
|
from ..utils import logger, raise_error, warn_with_log
|
9
9
|
|
@@ -36,7 +36,7 @@ PATTERNS_SCHEMA = {
|
|
36
36
|
},
|
37
37
|
},
|
38
38
|
"Warp": {
|
39
|
-
"mandatory": ["pattern", "src", "dst"],
|
39
|
+
"mandatory": ["pattern", "src", "dst", "warper"],
|
40
40
|
"optional": {},
|
41
41
|
},
|
42
42
|
"VBM_GM": {
|
@@ -96,7 +96,7 @@ class PatternValidationMixin:
|
|
96
96
|
def _validate_replacements(
|
97
97
|
self,
|
98
98
|
replacements: List[str],
|
99
|
-
patterns: Dict[str, Dict[str, str]],
|
99
|
+
patterns: Dict[str, Union[Dict[str, str], List[Dict[str, str]]]],
|
100
100
|
partial_pattern_ok: bool,
|
101
101
|
) -> None:
|
102
102
|
"""Validate the replacements.
|
@@ -132,39 +132,51 @@ class PatternValidationMixin:
|
|
132
132
|
|
133
133
|
if any(not isinstance(x, str) for x in replacements):
|
134
134
|
raise_error(
|
135
|
-
msg="`replacements` must be a list of strings
|
135
|
+
msg="`replacements` must be a list of strings",
|
136
136
|
klass=TypeError,
|
137
137
|
)
|
138
138
|
|
139
|
+
# Make a list of all patterns recursively
|
140
|
+
all_patterns = []
|
141
|
+
for dtype_val in patterns.values():
|
142
|
+
# Conditional for list dtype vals like Warp
|
143
|
+
if isinstance(dtype_val, list):
|
144
|
+
for entry in dtype_val:
|
145
|
+
all_patterns.append(entry.get("pattern", ""))
|
146
|
+
else:
|
147
|
+
all_patterns.append(dtype_val.get("pattern", ""))
|
148
|
+
# Check for stray replacements
|
139
149
|
for x in replacements:
|
140
|
-
if all(
|
141
|
-
x not in y
|
142
|
-
for y in [
|
143
|
-
data_type_val.get("pattern", "")
|
144
|
-
for data_type_val in patterns.values()
|
145
|
-
]
|
146
|
-
):
|
150
|
+
if all(x not in y for y in all_patterns):
|
147
151
|
if partial_pattern_ok:
|
148
152
|
warn_with_log(
|
149
153
|
f"Replacement: `{x}` is not part of any pattern, "
|
150
154
|
"things might not work as expected if you are unsure "
|
151
|
-
"of what you are doing"
|
155
|
+
"of what you are doing."
|
152
156
|
)
|
153
157
|
else:
|
154
158
|
raise_error(
|
155
|
-
msg=f"Replacement: {x} is not part of any pattern
|
159
|
+
msg=f"Replacement: `{x}` is not part of any pattern"
|
156
160
|
)
|
157
161
|
|
158
162
|
# Check that at least one pattern has all the replacements
|
159
163
|
at_least_one = False
|
160
|
-
for
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
164
|
+
for dtype_val in patterns.values():
|
165
|
+
# Conditional for list dtype vals like Warp
|
166
|
+
if isinstance(dtype_val, list):
|
167
|
+
for entry in dtype_val:
|
168
|
+
if all(
|
169
|
+
x in entry.get("pattern", "") for x in replacements
|
170
|
+
):
|
171
|
+
at_least_one = True
|
172
|
+
else:
|
173
|
+
if all(
|
174
|
+
x in dtype_val.get("pattern", "") for x in replacements
|
175
|
+
):
|
176
|
+
at_least_one = True
|
165
177
|
if not at_least_one and not partial_pattern_ok:
|
166
178
|
raise_error(
|
167
|
-
msg="At least one pattern must contain all replacements
|
179
|
+
msg="At least one pattern must contain all replacements"
|
168
180
|
)
|
169
181
|
|
170
182
|
def _validate_mandatory_keys(
|
@@ -207,7 +219,7 @@ class PatternValidationMixin:
|
|
207
219
|
warn_with_log(
|
208
220
|
f"Mandatory key: `{key}` not found for {data_type}, "
|
209
221
|
"things might not work as expected if you are unsure "
|
210
|
-
"of what you are doing"
|
222
|
+
"of what you are doing."
|
211
223
|
)
|
212
224
|
else:
|
213
225
|
raise_error(
|
@@ -215,7 +227,7 @@ class PatternValidationMixin:
|
|
215
227
|
klass=KeyError,
|
216
228
|
)
|
217
229
|
else:
|
218
|
-
logger.debug(f"Mandatory key: `{key}` found for {data_type}")
|
230
|
+
logger.debug(f"Mandatory key: `{key}` found for {data_type}.")
|
219
231
|
|
220
232
|
def _identify_stray_keys(
|
221
233
|
self, keys: List[str], schema: List[str], data_type: str
|
@@ -251,7 +263,7 @@ class PatternValidationMixin:
|
|
251
263
|
self,
|
252
264
|
types: List[str],
|
253
265
|
replacements: List[str],
|
254
|
-
patterns: Dict[str, Dict[str, str]],
|
266
|
+
patterns: Dict[str, Union[Dict[str, str], List[Dict[str, str]]]],
|
255
267
|
partial_pattern_ok: bool = False,
|
256
268
|
) -> None:
|
257
269
|
"""Validate the patterns.
|
@@ -298,87 +310,185 @@ class PatternValidationMixin:
|
|
298
310
|
msg="`patterns` must contain all `types`", klass=ValueError
|
299
311
|
)
|
300
312
|
# Check against schema
|
301
|
-
for
|
313
|
+
for dtype_key, dtype_val in patterns.items():
|
302
314
|
# Check if valid data type is provided
|
303
|
-
if
|
315
|
+
if dtype_key not in PATTERNS_SCHEMA:
|
304
316
|
raise_error(
|
305
|
-
f"Unknown data type: {
|
317
|
+
f"Unknown data type: {dtype_key}, "
|
306
318
|
f"should be one of: {list(PATTERNS_SCHEMA.keys())}"
|
307
319
|
)
|
308
|
-
#
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
data_type=data_type_key,
|
313
|
-
partial_pattern_ok=partial_pattern_ok,
|
314
|
-
)
|
315
|
-
# Check optional keys for data type
|
316
|
-
for optional_key, optional_val in PATTERNS_SCHEMA[data_type_key][
|
317
|
-
"optional"
|
318
|
-
].items():
|
319
|
-
if optional_key not in data_type_val:
|
320
|
-
logger.debug(
|
321
|
-
f"Optional key: `{optional_key}` missing for "
|
322
|
-
f"{data_type_key}"
|
323
|
-
)
|
324
|
-
else:
|
325
|
-
logger.debug(
|
326
|
-
f"Optional key: `{optional_key}` found for "
|
327
|
-
f"{data_type_key}"
|
328
|
-
)
|
329
|
-
# Set nested type name for easier access
|
330
|
-
nested_data_type = f"{data_type_key}.{optional_key}"
|
331
|
-
nested_mandatory_keys_schema = PATTERNS_SCHEMA[
|
332
|
-
data_type_key
|
333
|
-
]["optional"][optional_key]["mandatory"]
|
334
|
-
nested_optional_keys_schema = PATTERNS_SCHEMA[
|
335
|
-
data_type_key
|
336
|
-
]["optional"][optional_key]["optional"]
|
337
|
-
# Check mandatory keys for nested type
|
320
|
+
# Conditional for list dtype vals like Warp
|
321
|
+
if isinstance(dtype_val, list):
|
322
|
+
for idx, entry in enumerate(dtype_val):
|
323
|
+
# Check mandatory keys for data type
|
338
324
|
self._validate_mandatory_keys(
|
339
|
-
keys=list(
|
340
|
-
schema=
|
341
|
-
data_type=
|
325
|
+
keys=list(entry),
|
326
|
+
schema=PATTERNS_SCHEMA[dtype_key]["mandatory"],
|
327
|
+
data_type=f"{dtype_key}.{idx}",
|
342
328
|
partial_pattern_ok=partial_pattern_ok,
|
343
329
|
)
|
344
|
-
# Check optional keys for
|
345
|
-
for
|
346
|
-
|
330
|
+
# Check optional keys for data type
|
331
|
+
for optional_key, optional_val in PATTERNS_SCHEMA[
|
332
|
+
dtype_key
|
333
|
+
]["optional"].items():
|
334
|
+
if optional_key not in entry:
|
347
335
|
logger.debug(
|
348
|
-
f"Optional key: `{
|
349
|
-
f"
|
336
|
+
f"Optional key: `{optional_key}` missing for "
|
337
|
+
f"{dtype_key}.{idx}"
|
350
338
|
)
|
351
339
|
else:
|
352
340
|
logger.debug(
|
353
|
-
f"Optional key: `{
|
354
|
-
f"
|
341
|
+
f"Optional key: `{optional_key}` found for "
|
342
|
+
f"{dtype_key}.{idx}"
|
343
|
+
)
|
344
|
+
# Set nested type name for easier access
|
345
|
+
nested_dtype = f"{dtype_key}.{idx}.{optional_key}"
|
346
|
+
nested_mandatory_keys_schema = PATTERNS_SCHEMA[
|
347
|
+
dtype_key
|
348
|
+
]["optional"][optional_key]["mandatory"]
|
349
|
+
nested_optional_keys_schema = PATTERNS_SCHEMA[
|
350
|
+
dtype_key
|
351
|
+
]["optional"][optional_key]["optional"]
|
352
|
+
# Check mandatory keys for nested type
|
353
|
+
self._validate_mandatory_keys(
|
354
|
+
keys=list(optional_val["mandatory"]),
|
355
|
+
schema=nested_mandatory_keys_schema,
|
356
|
+
data_type=nested_dtype,
|
357
|
+
partial_pattern_ok=partial_pattern_ok,
|
358
|
+
)
|
359
|
+
# Check optional keys for nested type
|
360
|
+
for (
|
361
|
+
nested_optional_key
|
362
|
+
) in nested_optional_keys_schema:
|
363
|
+
if (
|
364
|
+
nested_optional_key
|
365
|
+
not in optional_val["optional"]
|
366
|
+
):
|
367
|
+
logger.debug(
|
368
|
+
f"Optional key: "
|
369
|
+
f"`{nested_optional_key}` missing for "
|
370
|
+
f"{nested_dtype}"
|
371
|
+
)
|
372
|
+
else:
|
373
|
+
logger.debug(
|
374
|
+
f"Optional key: "
|
375
|
+
f"`{nested_optional_key}` found for "
|
376
|
+
f"{nested_dtype}"
|
377
|
+
)
|
378
|
+
# Check stray key for nested data type
|
379
|
+
self._identify_stray_keys(
|
380
|
+
keys=(
|
381
|
+
optional_val["mandatory"]
|
382
|
+
+ optional_val["optional"]
|
383
|
+
),
|
384
|
+
schema=(
|
385
|
+
nested_mandatory_keys_schema
|
386
|
+
+ nested_optional_keys_schema
|
387
|
+
),
|
388
|
+
data_type=nested_dtype,
|
355
389
|
)
|
356
|
-
# Check stray key for
|
390
|
+
# Check stray key for data type
|
357
391
|
self._identify_stray_keys(
|
358
|
-
keys=
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
392
|
+
keys=list(entry.keys()),
|
393
|
+
schema=(
|
394
|
+
PATTERNS_SCHEMA[dtype_key]["mandatory"]
|
395
|
+
+ list(
|
396
|
+
PATTERNS_SCHEMA[dtype_key]["optional"].keys()
|
397
|
+
)
|
398
|
+
),
|
399
|
+
data_type=dtype_key,
|
363
400
|
)
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
401
|
+
# Wildcard check in patterns
|
402
|
+
if "}*" in entry.get("pattern", ""):
|
403
|
+
raise_error(
|
404
|
+
msg=(
|
405
|
+
f"`{dtype_key}.pattern` must not contain `*` "
|
406
|
+
"following a replacement"
|
407
|
+
),
|
408
|
+
klass=ValueError,
|
409
|
+
)
|
410
|
+
else:
|
411
|
+
# Check mandatory keys for data type
|
412
|
+
self._validate_mandatory_keys(
|
413
|
+
keys=list(dtype_val),
|
414
|
+
schema=PATTERNS_SCHEMA[dtype_key]["mandatory"],
|
415
|
+
data_type=dtype_key,
|
416
|
+
partial_pattern_ok=partial_pattern_ok,
|
417
|
+
)
|
418
|
+
# Check optional keys for data type
|
419
|
+
for optional_key, optional_val in PATTERNS_SCHEMA[dtype_key][
|
420
|
+
"optional"
|
421
|
+
].items():
|
422
|
+
if optional_key not in dtype_val:
|
423
|
+
logger.debug(
|
424
|
+
f"Optional key: `{optional_key}` missing for "
|
425
|
+
f"{dtype_key}."
|
426
|
+
)
|
427
|
+
else:
|
428
|
+
logger.debug(
|
429
|
+
f"Optional key: `{optional_key}` found for "
|
430
|
+
f"{dtype_key}."
|
431
|
+
)
|
432
|
+
# Set nested type name for easier access
|
433
|
+
nested_dtype = f"{dtype_key}.{optional_key}"
|
434
|
+
nested_mandatory_keys_schema = PATTERNS_SCHEMA[
|
435
|
+
dtype_key
|
436
|
+
]["optional"][optional_key]["mandatory"]
|
437
|
+
nested_optional_keys_schema = PATTERNS_SCHEMA[
|
438
|
+
dtype_key
|
439
|
+
]["optional"][optional_key]["optional"]
|
440
|
+
# Check mandatory keys for nested type
|
441
|
+
self._validate_mandatory_keys(
|
442
|
+
keys=list(optional_val["mandatory"]),
|
443
|
+
schema=nested_mandatory_keys_schema,
|
444
|
+
data_type=nested_dtype,
|
445
|
+
partial_pattern_ok=partial_pattern_ok,
|
446
|
+
)
|
447
|
+
# Check optional keys for nested type
|
448
|
+
for nested_optional_key in nested_optional_keys_schema:
|
449
|
+
if (
|
450
|
+
nested_optional_key
|
451
|
+
not in optional_val["optional"]
|
452
|
+
):
|
453
|
+
logger.debug(
|
454
|
+
f"Optional key: `{nested_optional_key}` "
|
455
|
+
f"missing for {nested_dtype}"
|
456
|
+
)
|
457
|
+
else:
|
458
|
+
logger.debug(
|
459
|
+
f"Optional key: `{nested_optional_key}` "
|
460
|
+
f"found for {nested_dtype}"
|
461
|
+
)
|
462
|
+
# Check stray key for nested data type
|
463
|
+
self._identify_stray_keys(
|
464
|
+
keys=(
|
465
|
+
optional_val["mandatory"]
|
466
|
+
+ optional_val["optional"]
|
467
|
+
),
|
468
|
+
schema=(
|
469
|
+
nested_mandatory_keys_schema
|
470
|
+
+ nested_optional_keys_schema
|
471
|
+
),
|
472
|
+
data_type=nested_dtype,
|
473
|
+
)
|
474
|
+
# Check stray key for data type
|
475
|
+
self._identify_stray_keys(
|
476
|
+
keys=list(dtype_val.keys()),
|
477
|
+
schema=(
|
478
|
+
PATTERNS_SCHEMA[dtype_key]["mandatory"]
|
479
|
+
+ list(PATTERNS_SCHEMA[dtype_key]["optional"].keys())
|
379
480
|
),
|
380
|
-
|
481
|
+
data_type=dtype_key,
|
381
482
|
)
|
483
|
+
# Wildcard check in patterns
|
484
|
+
if "}*" in dtype_val.get("pattern", ""):
|
485
|
+
raise_error(
|
486
|
+
msg=(
|
487
|
+
f"`{dtype_key}.pattern` must not contain `*` "
|
488
|
+
"following a replacement"
|
489
|
+
),
|
490
|
+
klass=ValueError,
|
491
|
+
)
|
382
492
|
|
383
493
|
# Validate replacements
|
384
494
|
self._validate_replacements(
|
@@ -116,7 +116,12 @@ def test_DMCC13Benchmark(
|
|
116
116
|
data_file_names.extend(
|
117
117
|
[
|
118
118
|
"sub-01_desc-preproc_T1w.nii.gz",
|
119
|
-
|
119
|
+
[
|
120
|
+
"sub-01_from-MNI152NLin2009cAsym_to-T1w"
|
121
|
+
"_mode-image_xfm.h5",
|
122
|
+
"sub-01_from-T1w_to-MNI152NLin2009cAsym"
|
123
|
+
"_mode-image_xfm.h5",
|
124
|
+
],
|
120
125
|
]
|
121
126
|
)
|
122
127
|
else:
|
@@ -127,14 +132,26 @@ def test_DMCC13Benchmark(
|
|
127
132
|
for data_type, data_file_name in zip(data_types, data_file_names):
|
128
133
|
# Assert data type
|
129
134
|
assert data_type in out
|
130
|
-
#
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
135
|
+
# Conditional for Warp
|
136
|
+
if data_type == "Warp":
|
137
|
+
for idx, fname in enumerate(data_file_name):
|
138
|
+
# Assert data file path exists
|
139
|
+
assert out[data_type][idx]["path"].exists()
|
140
|
+
# Assert data file path is a file
|
141
|
+
assert out[data_type][idx]["path"].is_file()
|
142
|
+
# Assert data file name
|
143
|
+
assert out[data_type][idx]["path"].name == fname
|
144
|
+
# Assert metadata
|
145
|
+
assert "meta" in out[data_type][idx]
|
146
|
+
else:
|
147
|
+
# Assert data file path exists
|
148
|
+
assert out[data_type]["path"].exists()
|
149
|
+
# Assert data file path is a file
|
150
|
+
assert out[data_type]["path"].is_file()
|
151
|
+
# Assert data file name
|
152
|
+
assert out[data_type]["path"].name == data_file_name
|
153
|
+
# Assert metadata
|
154
|
+
assert "meta" in out[data_type]
|
138
155
|
|
139
156
|
# Check BOLD nested data types
|
140
157
|
for type_, file_name in zip(
|
@@ -196,10 +196,14 @@ class PipelineStepMixin:
|
|
196
196
|
for dependency in obj._CONDITIONAL_DEPENDENCIES:
|
197
197
|
if dependency["using"] == obj.using:
|
198
198
|
depends_on = dependency["depends_on"]
|
199
|
-
#
|
200
|
-
|
201
|
-
|
202
|
-
|
199
|
+
# Conditional to make `using="auto"` work
|
200
|
+
if not isinstance(depends_on, list):
|
201
|
+
depends_on = [depends_on]
|
202
|
+
for entry in depends_on:
|
203
|
+
# Check dependencies
|
204
|
+
_check_dependencies(entry)
|
205
|
+
# Check external dependencies
|
206
|
+
_check_ext_dependencies(entry)
|
203
207
|
|
204
208
|
# Check dependencies
|
205
209
|
_check_dependencies(self)
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# Synchon Mandal <s.mandal@fz-juelich.de>
|
5
5
|
# License: AGPL
|
6
6
|
|
7
|
-
from typing import Dict
|
7
|
+
from typing import Dict, List, Union
|
8
8
|
|
9
9
|
|
10
10
|
__all__ = ["UpdateMetaMixin"]
|
@@ -15,14 +15,14 @@ class UpdateMetaMixin:
|
|
15
15
|
|
16
16
|
def update_meta(
|
17
17
|
self,
|
18
|
-
input: Dict,
|
18
|
+
input: Union[Dict, List[Dict]],
|
19
19
|
step_name: str,
|
20
20
|
) -> None:
|
21
21
|
"""Update metadata.
|
22
22
|
|
23
23
|
Parameters
|
24
24
|
----------
|
25
|
-
input : dict
|
25
|
+
input : dict or list of dict
|
26
26
|
The data object to update.
|
27
27
|
step_name : str
|
28
28
|
The name of the pipeline step.
|
@@ -36,17 +36,21 @@ class UpdateMetaMixin:
|
|
36
36
|
for k, v in vars(self).items():
|
37
37
|
if not k.startswith("_"):
|
38
38
|
t_meta[k] = v
|
39
|
-
#
|
40
|
-
if
|
41
|
-
input
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
39
|
+
# Conditional for list dtype vals like Warp
|
40
|
+
if not isinstance(input, list):
|
41
|
+
input = [input]
|
42
|
+
for entry in input:
|
43
|
+
# Add "meta" to the step's entry's local context dict
|
44
|
+
if "meta" not in entry:
|
45
|
+
entry["meta"] = {}
|
46
|
+
# Add step name
|
47
|
+
entry["meta"][step_name] = t_meta
|
48
|
+
# Add step dependencies
|
49
|
+
if "dependencies" not in entry["meta"]:
|
50
|
+
entry["meta"]["dependencies"] = set()
|
51
|
+
# Update step dependencies
|
52
|
+
dependencies = getattr(self, "_DEPENDENCIES", set())
|
53
|
+
if dependencies is not None:
|
54
|
+
if not isinstance(dependencies, (set, list)):
|
55
|
+
dependencies = {dependencies}
|
56
|
+
entry["meta"]["dependencies"].update(dependencies)
|
@@ -15,7 +15,7 @@ import numpy as np
|
|
15
15
|
from ...data import get_template, get_xfm
|
16
16
|
from ...pipeline import WorkDirManager
|
17
17
|
from ...typing import Dependencies, ExternalDependencies
|
18
|
-
from ...utils import logger, run_ext_cmd
|
18
|
+
from ...utils import logger, raise_error, run_ext_cmd
|
19
19
|
|
20
20
|
|
21
21
|
__all__ = ["ANTsWarper"]
|
@@ -63,6 +63,11 @@ class ANTsWarper:
|
|
63
63
|
values and new ``reference_path`` key whose value points to the
|
64
64
|
reference file used for warping.
|
65
65
|
|
66
|
+
Raises
|
67
|
+
------
|
68
|
+
RuntimeError
|
69
|
+
If warp file path could not be found in ``extra_input``.
|
70
|
+
|
66
71
|
"""
|
67
72
|
# Create element-specific tempdir for storing post-warping assets
|
68
73
|
element_tempdir = WorkDirManager().get_element_tempdir(
|
@@ -77,6 +82,17 @@ class ANTsWarper:
|
|
77
82
|
# resolution
|
78
83
|
resolution = np.min(input["data"].header.get_zooms()[:3])
|
79
84
|
|
85
|
+
# Get warp file path
|
86
|
+
warp_file_path = None
|
87
|
+
for entry in extra_input["Warp"]:
|
88
|
+
if entry["dst"] == "native":
|
89
|
+
warp_file_path = entry["path"]
|
90
|
+
if warp_file_path is None:
|
91
|
+
raise_error(
|
92
|
+
klass=RuntimeError,
|
93
|
+
msg="Could not find correct warp file path",
|
94
|
+
)
|
95
|
+
|
80
96
|
# Create a tempfile for resampled reference output
|
81
97
|
resample_image_out_path = (
|
82
98
|
element_tempdir / "resampled_reference.nii.gz"
|
@@ -105,7 +121,7 @@ class ANTsWarper:
|
|
105
121
|
f"-i {input['path'].resolve()}",
|
106
122
|
# use resampled reference
|
107
123
|
f"-r {resample_image_out_path.resolve()}",
|
108
|
-
f"-t {
|
124
|
+
f"-t {warp_file_path.resolve()}",
|
109
125
|
f"-o {apply_transforms_out_path.resolve()}",
|
110
126
|
]
|
111
127
|
# Call antsApplyTransforms
|
@@ -115,6 +131,8 @@ class ANTsWarper:
|
|
115
131
|
input["data"] = nib.load(apply_transforms_out_path)
|
116
132
|
# Save resampled reference path
|
117
133
|
input["reference_path"] = resample_image_out_path
|
134
|
+
# Keep pre-warp space for further operations
|
135
|
+
input["prewarp_space"] = input["space"]
|
118
136
|
# Use reference input's space as warped input's space
|
119
137
|
input["space"] = extra_input["T1w"]["space"]
|
120
138
|
|
@@ -163,6 +181,9 @@ class ANTsWarper:
|
|
163
181
|
|
164
182
|
# Modify target data
|
165
183
|
input["data"] = nib.load(warped_output_path)
|
184
|
+
# Keep pre-warp space for further operations
|
185
|
+
input["prewarp_space"] = input["space"]
|
186
|
+
# Update warped input's space
|
166
187
|
input["space"] = reference
|
167
188
|
|
168
189
|
return input
|
@@ -14,7 +14,7 @@ import numpy as np
|
|
14
14
|
|
15
15
|
from ...pipeline import WorkDirManager
|
16
16
|
from ...typing import Dependencies, ExternalDependencies
|
17
|
-
from ...utils import logger, run_ext_cmd
|
17
|
+
from ...utils import logger, raise_error, run_ext_cmd
|
18
18
|
|
19
19
|
|
20
20
|
__all__ = ["FSLWarper"]
|
@@ -59,6 +59,11 @@ class FSLWarper:
|
|
59
59
|
values and new ``reference_path`` key whose value points to the
|
60
60
|
reference file used for warping.
|
61
61
|
|
62
|
+
Raises
|
63
|
+
------
|
64
|
+
RuntimeError
|
65
|
+
If warp file path could not be found in ``extra_input``.
|
66
|
+
|
62
67
|
"""
|
63
68
|
logger.debug("Using FSL for space warping")
|
64
69
|
|
@@ -66,6 +71,16 @@ class FSLWarper:
|
|
66
71
|
# resolution
|
67
72
|
resolution = np.min(input["data"].header.get_zooms()[:3])
|
68
73
|
|
74
|
+
# Get warp file path
|
75
|
+
warp_file_path = None
|
76
|
+
for entry in extra_input["Warp"]:
|
77
|
+
if entry["dst"] == "native":
|
78
|
+
warp_file_path = entry["path"]
|
79
|
+
if warp_file_path is None:
|
80
|
+
raise_error(
|
81
|
+
klass=RuntimeError, msg="Could not find correct warp file path"
|
82
|
+
)
|
83
|
+
|
69
84
|
# Create element-specific tempdir for storing post-warping assets
|
70
85
|
element_tempdir = WorkDirManager().get_element_tempdir(
|
71
86
|
prefix="fsl_warper"
|
@@ -93,7 +108,7 @@ class FSLWarper:
|
|
93
108
|
"--interp=spline",
|
94
109
|
f"-i {input['path'].resolve()}",
|
95
110
|
f"-r {flirt_out_path.resolve()}", # use resampled reference
|
96
|
-
f"-w {
|
111
|
+
f"-w {warp_file_path.resolve()}",
|
97
112
|
f"-o {applywarp_out_path.resolve()}",
|
98
113
|
]
|
99
114
|
# Call applywarp
|
@@ -103,7 +118,8 @@ class FSLWarper:
|
|
103
118
|
input["data"] = nib.load(applywarp_out_path)
|
104
119
|
# Save resampled reference path
|
105
120
|
input["reference_path"] = flirt_out_path
|
106
|
-
|
121
|
+
# Keep pre-warp space for further operations
|
122
|
+
input["prewarp_space"] = input["space"]
|
107
123
|
# Use reference input's space as warped input's space
|
108
124
|
input["space"] = extra_input["T1w"]["space"]
|
109
125
|
|