junifer 0.0.5__py3-none-any.whl → 0.0.5.dev11__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/__init__.py +0 -17
- junifer/_version.py +2 -2
- junifer/api/__init__.py +1 -4
- junifer/api/cli.py +1 -91
- junifer/api/decorators.py +0 -9
- junifer/api/functions.py +10 -56
- junifer/api/parser.py +0 -3
- junifer/api/queue_context/__init__.py +1 -4
- junifer/api/res/afni/run_afni_docker.sh +1 -1
- junifer/api/res/ants/run_ants_docker.sh +1 -1
- junifer/api/res/fsl/run_fsl_docker.sh +1 -1
- junifer/api/tests/test_api_utils.py +2 -4
- junifer/api/tests/test_cli.py +0 -83
- junifer/api/tests/test_functions.py +2 -27
- junifer/configs/__init__.py +1 -1
- junifer/configs/juseless/__init__.py +1 -4
- junifer/configs/juseless/datagrabbers/__init__.py +1 -10
- junifer/configs/juseless/datagrabbers/aomic_id1000_vbm.py +0 -3
- junifer/configs/juseless/datagrabbers/camcan_vbm.py +0 -3
- junifer/configs/juseless/datagrabbers/ixi_vbm.py +0 -3
- junifer/configs/juseless/datagrabbers/tests/test_ucla.py +3 -1
- junifer/configs/juseless/datagrabbers/ucla.py +9 -12
- junifer/configs/juseless/datagrabbers/ukb_vbm.py +0 -3
- junifer/data/__init__.py +1 -21
- junifer/data/coordinates.py +19 -10
- junifer/data/masks.py +87 -58
- junifer/data/parcellations.py +3 -14
- junifer/data/template_spaces.py +1 -4
- junifer/data/tests/test_masks.py +37 -26
- junifer/data/utils.py +0 -3
- junifer/datagrabber/__init__.py +1 -18
- junifer/datagrabber/aomic/__init__.py +0 -3
- junifer/datagrabber/aomic/id1000.py +37 -70
- junifer/datagrabber/aomic/piop1.py +36 -69
- junifer/datagrabber/aomic/piop2.py +38 -71
- junifer/datagrabber/aomic/tests/test_id1000.py +99 -44
- junifer/datagrabber/aomic/tests/test_piop1.py +108 -65
- junifer/datagrabber/aomic/tests/test_piop2.py +102 -45
- junifer/datagrabber/base.py +6 -13
- junifer/datagrabber/datalad_base.py +1 -13
- junifer/datagrabber/dmcc13_benchmark.py +53 -36
- junifer/datagrabber/hcp1200/__init__.py +0 -3
- junifer/datagrabber/hcp1200/datalad_hcp1200.py +0 -3
- junifer/datagrabber/hcp1200/hcp1200.py +1 -4
- junifer/datagrabber/multiple.py +6 -45
- junifer/datagrabber/pattern.py +62 -170
- junifer/datagrabber/pattern_datalad.py +12 -25
- junifer/datagrabber/tests/test_datagrabber_utils.py +218 -0
- junifer/datagrabber/tests/test_datalad_base.py +4 -4
- junifer/datagrabber/tests/test_dmcc13_benchmark.py +19 -46
- junifer/datagrabber/tests/test_multiple.py +84 -161
- junifer/datagrabber/tests/test_pattern.py +0 -45
- junifer/datagrabber/tests/test_pattern_datalad.py +4 -4
- junifer/datagrabber/utils.py +230 -0
- junifer/datareader/__init__.py +1 -4
- junifer/datareader/default.py +43 -95
- junifer/external/__init__.py +1 -1
- junifer/external/nilearn/__init__.py +1 -5
- junifer/external/nilearn/junifer_nifti_spheres_masker.py +9 -23
- junifer/external/nilearn/tests/test_junifer_nifti_spheres_masker.py +1 -76
- junifer/markers/__init__.py +1 -23
- junifer/markers/base.py +28 -68
- junifer/markers/collection.py +2 -10
- junifer/markers/complexity/__init__.py +0 -10
- junifer/markers/complexity/complexity_base.py +43 -26
- junifer/markers/complexity/hurst_exponent.py +0 -3
- junifer/markers/complexity/multiscale_entropy_auc.py +0 -3
- junifer/markers/complexity/perm_entropy.py +0 -3
- junifer/markers/complexity/range_entropy.py +0 -3
- junifer/markers/complexity/range_entropy_auc.py +0 -3
- junifer/markers/complexity/sample_entropy.py +0 -3
- junifer/markers/complexity/tests/test_hurst_exponent.py +3 -11
- junifer/markers/complexity/tests/test_multiscale_entropy_auc.py +3 -11
- junifer/markers/complexity/tests/test_perm_entropy.py +3 -11
- junifer/markers/complexity/tests/test_range_entropy.py +3 -11
- junifer/markers/complexity/tests/test_range_entropy_auc.py +3 -11
- junifer/markers/complexity/tests/test_sample_entropy.py +3 -11
- junifer/markers/complexity/tests/test_weighted_perm_entropy.py +3 -11
- junifer/markers/complexity/weighted_perm_entropy.py +0 -3
- junifer/markers/ets_rss.py +42 -27
- junifer/markers/falff/__init__.py +0 -3
- junifer/markers/falff/_afni_falff.py +2 -5
- junifer/markers/falff/_junifer_falff.py +0 -3
- junifer/markers/falff/falff_base.py +46 -20
- junifer/markers/falff/falff_parcels.py +27 -56
- junifer/markers/falff/falff_spheres.py +29 -60
- junifer/markers/falff/tests/test_falff_parcels.py +23 -39
- junifer/markers/falff/tests/test_falff_spheres.py +23 -39
- junifer/markers/functional_connectivity/__init__.py +0 -9
- junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py +60 -63
- junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +32 -45
- junifer/markers/functional_connectivity/edge_functional_connectivity_spheres.py +36 -49
- junifer/markers/functional_connectivity/functional_connectivity_base.py +70 -71
- junifer/markers/functional_connectivity/functional_connectivity_parcels.py +25 -34
- junifer/markers/functional_connectivity/functional_connectivity_spheres.py +30 -40
- junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py +7 -11
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_parcels.py +7 -27
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_spheres.py +12 -28
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +11 -35
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +62 -36
- junifer/markers/parcel_aggregation.py +61 -47
- junifer/markers/reho/__init__.py +0 -3
- junifer/markers/reho/_afni_reho.py +2 -5
- junifer/markers/reho/_junifer_reho.py +1 -4
- junifer/markers/reho/reho_base.py +27 -8
- junifer/markers/reho/reho_parcels.py +17 -28
- junifer/markers/reho/reho_spheres.py +18 -27
- junifer/markers/reho/tests/test_reho_parcels.py +3 -8
- junifer/markers/reho/tests/test_reho_spheres.py +3 -8
- junifer/markers/sphere_aggregation.py +59 -43
- junifer/markers/temporal_snr/__init__.py +0 -3
- junifer/markers/temporal_snr/temporal_snr_base.py +32 -23
- junifer/markers/temporal_snr/temporal_snr_parcels.py +6 -9
- junifer/markers/temporal_snr/temporal_snr_spheres.py +6 -9
- junifer/markers/temporal_snr/tests/test_temporal_snr_parcels.py +3 -6
- junifer/markers/temporal_snr/tests/test_temporal_snr_spheres.py +3 -6
- junifer/markers/tests/test_collection.py +8 -9
- junifer/markers/tests/test_ets_rss.py +9 -15
- junifer/markers/tests/test_markers_base.py +18 -17
- junifer/markers/tests/test_parcel_aggregation.py +32 -93
- junifer/markers/tests/test_sphere_aggregation.py +19 -72
- junifer/onthefly/__init__.py +1 -4
- junifer/onthefly/read_transform.py +0 -3
- junifer/pipeline/__init__.py +1 -9
- junifer/pipeline/pipeline_step_mixin.py +4 -21
- junifer/pipeline/registry.py +0 -3
- junifer/pipeline/singleton.py +0 -3
- junifer/pipeline/tests/test_registry.py +1 -1
- junifer/pipeline/update_meta_mixin.py +0 -3
- junifer/pipeline/utils.py +1 -67
- junifer/pipeline/workdir_manager.py +0 -3
- junifer/preprocess/__init__.py +2 -10
- junifer/preprocess/ants/__init__.py +4 -0
- junifer/preprocess/ants/ants_apply_transforms_warper.py +185 -0
- junifer/preprocess/ants/tests/test_ants_apply_transforms_warper.py +56 -0
- junifer/preprocess/base.py +3 -6
- junifer/preprocess/bold_warper.py +265 -0
- junifer/preprocess/confounds/__init__.py +0 -3
- junifer/preprocess/confounds/fmriprep_confound_remover.py +60 -47
- junifer/preprocess/confounds/tests/test_fmriprep_confound_remover.py +113 -72
- junifer/preprocess/fsl/__init__.py +4 -0
- junifer/preprocess/fsl/apply_warper.py +179 -0
- junifer/preprocess/fsl/tests/test_apply_warper.py +45 -0
- junifer/preprocess/tests/test_bold_warper.py +159 -0
- junifer/preprocess/warping/__init__.py +0 -3
- junifer/preprocess/warping/_ants_warper.py +0 -3
- junifer/preprocess/warping/_fsl_warper.py +0 -3
- junifer/stats.py +1 -4
- junifer/storage/__init__.py +1 -9
- junifer/storage/base.py +1 -40
- junifer/storage/hdf5.py +9 -71
- junifer/storage/pandas_base.py +0 -3
- junifer/storage/sqlite.py +0 -3
- junifer/storage/tests/test_hdf5.py +10 -82
- junifer/storage/utils.py +0 -9
- junifer/testing/__init__.py +1 -4
- junifer/testing/datagrabbers.py +6 -13
- junifer/testing/tests/test_partlycloudytesting_datagrabber.py +7 -7
- junifer/testing/utils.py +0 -3
- junifer/utils/__init__.py +2 -13
- junifer/utils/fs.py +0 -3
- junifer/utils/helpers.py +1 -32
- junifer/utils/logging.py +4 -33
- junifer/utils/tests/test_logging.py +0 -8
- {junifer-0.0.5.dist-info → junifer-0.0.5.dev11.dist-info}/METADATA +16 -17
- junifer-0.0.5.dev11.dist-info/RECORD +259 -0
- {junifer-0.0.5.dist-info → junifer-0.0.5.dev11.dist-info}/WHEEL +1 -1
- junifer/api/res/freesurfer/mri_binarize +0 -3
- junifer/api/res/freesurfer/mri_mc +0 -3
- junifer/api/res/freesurfer/mri_pretess +0 -3
- junifer/api/res/freesurfer/mris_convert +0 -3
- junifer/api/res/freesurfer/run_freesurfer_docker.sh +0 -61
- junifer/data/masks/ukb/UKB_15K_GM_template.nii.gz +0 -0
- junifer/datagrabber/pattern_validation_mixin.py +0 -388
- junifer/datagrabber/tests/test_pattern_validation_mixin.py +0 -249
- junifer/external/BrainPrint/brainprint/__init__.py +0 -4
- junifer/external/BrainPrint/brainprint/_version.py +0 -3
- junifer/external/BrainPrint/brainprint/asymmetry.py +0 -91
- junifer/external/BrainPrint/brainprint/brainprint.py +0 -441
- junifer/external/BrainPrint/brainprint/surfaces.py +0 -258
- junifer/external/BrainPrint/brainprint/utils/__init__.py +0 -1
- junifer/external/BrainPrint/brainprint/utils/_config.py +0 -112
- junifer/external/BrainPrint/brainprint/utils/utils.py +0 -188
- junifer/external/nilearn/junifer_connectivity_measure.py +0 -483
- junifer/external/nilearn/tests/test_junifer_connectivity_measure.py +0 -1089
- junifer/markers/brainprint.py +0 -459
- junifer/markers/tests/test_brainprint.py +0 -58
- junifer/preprocess/smoothing/__init__.py +0 -9
- junifer/preprocess/smoothing/_afni_smoothing.py +0 -119
- junifer/preprocess/smoothing/_fsl_smoothing.py +0 -116
- junifer/preprocess/smoothing/_nilearn_smoothing.py +0 -69
- junifer/preprocess/smoothing/smoothing.py +0 -174
- junifer/preprocess/smoothing/tests/test_smoothing.py +0 -94
- junifer-0.0.5.dist-info/RECORD +0 -275
- {junifer-0.0.5.dist-info → junifer-0.0.5.dev11.dist-info}/AUTHORS.rst +0 -0
- {junifer-0.0.5.dist-info → junifer-0.0.5.dev11.dist-info}/LICENSE.md +0 -0
- {junifer-0.0.5.dist-info → junifer-0.0.5.dev11.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.5.dist-info → junifer-0.0.5.dev11.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,218 @@
|
|
1
|
+
"""Provide tests for utils."""
|
2
|
+
|
3
|
+
# Authors: Federico Raimondo <f.raimondo@fz-juelich.de>
|
4
|
+
# License: AGPL
|
5
|
+
|
6
|
+
from contextlib import nullcontext
|
7
|
+
from typing import ContextManager, Dict, List, Union
|
8
|
+
|
9
|
+
import pytest
|
10
|
+
|
11
|
+
from junifer.datagrabber.utils import (
|
12
|
+
validate_patterns,
|
13
|
+
validate_replacements,
|
14
|
+
validate_types,
|
15
|
+
)
|
16
|
+
|
17
|
+
|
18
|
+
@pytest.mark.parametrize(
|
19
|
+
"types, expect",
|
20
|
+
[
|
21
|
+
("wrong", pytest.raises(TypeError, match="must be a list")),
|
22
|
+
([1], pytest.raises(TypeError, match="must be a list of strings")),
|
23
|
+
(["T1w", "BOLD"], nullcontext()),
|
24
|
+
],
|
25
|
+
)
|
26
|
+
def test_validate_types(
|
27
|
+
types: Union[str, List[str], List[int]],
|
28
|
+
expect: ContextManager,
|
29
|
+
) -> None:
|
30
|
+
"""Test validation of types.
|
31
|
+
|
32
|
+
Parameters
|
33
|
+
----------
|
34
|
+
types : str, list of int or str
|
35
|
+
The parametrized data types to validate.
|
36
|
+
expect : typing.ContextManager
|
37
|
+
The parametrized ContextManager object.
|
38
|
+
|
39
|
+
"""
|
40
|
+
with expect:
|
41
|
+
validate_types(types) # type: ignore
|
42
|
+
|
43
|
+
|
44
|
+
@pytest.mark.parametrize(
|
45
|
+
"replacements, patterns, expect",
|
46
|
+
[
|
47
|
+
(
|
48
|
+
"wrong",
|
49
|
+
"also wrong",
|
50
|
+
pytest.raises(TypeError, match="must be a list"),
|
51
|
+
),
|
52
|
+
(
|
53
|
+
[1],
|
54
|
+
{
|
55
|
+
"T1w": {"pattern": "{subject}/anat/{subject}_T1w.nii.gz"},
|
56
|
+
"BOLD": {
|
57
|
+
"pattern": "{subject}/func/{subject}_task-rest_bold.nii.gz"
|
58
|
+
},
|
59
|
+
},
|
60
|
+
pytest.raises(TypeError, match="must be a list of strings"),
|
61
|
+
),
|
62
|
+
(
|
63
|
+
["session"],
|
64
|
+
{
|
65
|
+
"T1w": {"pattern": "{subject}/anat/{subject}_T1w.nii.gz"},
|
66
|
+
"BOLD": {
|
67
|
+
"pattern": "{subject}/func/{subject}_task-rest_bold.nii.gz"
|
68
|
+
},
|
69
|
+
},
|
70
|
+
pytest.raises(ValueError, match="is not part of"),
|
71
|
+
),
|
72
|
+
(
|
73
|
+
["subject", "session"],
|
74
|
+
{
|
75
|
+
"T1w": {"pattern": "{subject}/anat/_T1w.nii.gz"},
|
76
|
+
"BOLD": {"pattern": "{session}/func/_task-rest_bold.nii.gz"},
|
77
|
+
},
|
78
|
+
pytest.raises(ValueError, match="At least one pattern"),
|
79
|
+
),
|
80
|
+
(
|
81
|
+
["subject"],
|
82
|
+
{
|
83
|
+
"T1w": {"pattern": "{subject}/anat/{subject}_T1w.nii.gz"},
|
84
|
+
"BOLD": {
|
85
|
+
"pattern": "{subject}/func/{subject}_task-rest_bold.nii.gz"
|
86
|
+
},
|
87
|
+
},
|
88
|
+
nullcontext(),
|
89
|
+
),
|
90
|
+
],
|
91
|
+
)
|
92
|
+
def test_validate_replacements(
|
93
|
+
replacements: Union[str, List[str], List[int]],
|
94
|
+
patterns: Union[str, Dict[str, Dict[str, str]]],
|
95
|
+
expect: ContextManager,
|
96
|
+
) -> None:
|
97
|
+
"""Test validation of replacements.
|
98
|
+
|
99
|
+
Parameters
|
100
|
+
----------
|
101
|
+
replacements : str, list of str or int
|
102
|
+
The parametrized pattern replacements to validate.
|
103
|
+
patterns : str, dict
|
104
|
+
The parametrized patterns to validate against.
|
105
|
+
expect : typing.ContextManager
|
106
|
+
The parametrized ContextManager object.
|
107
|
+
|
108
|
+
"""
|
109
|
+
with expect:
|
110
|
+
validate_replacements(replacements=replacements, patterns=patterns) # type: ignore
|
111
|
+
|
112
|
+
|
113
|
+
@pytest.mark.parametrize(
|
114
|
+
"types, patterns, expect",
|
115
|
+
[
|
116
|
+
(
|
117
|
+
["T1w", "BOLD"],
|
118
|
+
"wrong",
|
119
|
+
pytest.raises(TypeError, match="must be a dict"),
|
120
|
+
),
|
121
|
+
(
|
122
|
+
["T1w", "BOLD"],
|
123
|
+
{
|
124
|
+
"T1w": {"pattern": "{subject}/anat/{subject}_T1w.nii.gz"},
|
125
|
+
},
|
126
|
+
pytest.raises(
|
127
|
+
ValueError,
|
128
|
+
match="Length of `types` more than that of `patterns`.",
|
129
|
+
),
|
130
|
+
),
|
131
|
+
(
|
132
|
+
["T1w", "BOLD"],
|
133
|
+
{
|
134
|
+
"T1w": {"pattern": "{subject}/anat/{subject}_T1w.nii.gz"},
|
135
|
+
"T2w": {"pattern": "{subject}/anat/{subject}_T2w.nii.gz"},
|
136
|
+
},
|
137
|
+
pytest.raises(ValueError, match="contain all"),
|
138
|
+
),
|
139
|
+
(
|
140
|
+
["T3w"],
|
141
|
+
{
|
142
|
+
"T3w": {"pattern": "{subject}/anat/{subject}_T3w.nii.gz"},
|
143
|
+
},
|
144
|
+
pytest.raises(ValueError, match="Unknown data type"),
|
145
|
+
),
|
146
|
+
(
|
147
|
+
["BOLD"],
|
148
|
+
{
|
149
|
+
"BOLD": {"patterns": "{subject}/func/{subject}_BOLD.nii.gz"},
|
150
|
+
},
|
151
|
+
pytest.raises(KeyError, match="Mandatory key"),
|
152
|
+
),
|
153
|
+
(
|
154
|
+
["BOLD_confounds"],
|
155
|
+
{
|
156
|
+
"BOLD_confounds": {
|
157
|
+
"pattern": "{subject}/func/{subject}_confounds.tsv",
|
158
|
+
"format": "fmriprep",
|
159
|
+
"space": "MNINLin6Asym",
|
160
|
+
},
|
161
|
+
},
|
162
|
+
pytest.raises(RuntimeError, match="not accepted"),
|
163
|
+
),
|
164
|
+
(
|
165
|
+
["T1w"],
|
166
|
+
{
|
167
|
+
"T1w": {
|
168
|
+
"pattern": "{subject}/anat/{subject}*.nii",
|
169
|
+
"space": "native",
|
170
|
+
},
|
171
|
+
},
|
172
|
+
pytest.raises(ValueError, match="following a replacement"),
|
173
|
+
),
|
174
|
+
(
|
175
|
+
["T1w", "T2w", "BOLD", "BOLD_confounds"],
|
176
|
+
{
|
177
|
+
"T1w": {
|
178
|
+
"pattern": "{subject}/anat/{subject}_T1w.nii.gz",
|
179
|
+
"space": "native",
|
180
|
+
},
|
181
|
+
"T2w": {
|
182
|
+
"pattern": "{subject}/anat/{subject}_T2w.nii.gz",
|
183
|
+
"space": "native",
|
184
|
+
},
|
185
|
+
"BOLD": {
|
186
|
+
"pattern": (
|
187
|
+
"{subject}/func/{subject}_task-rest_bold.nii.gz"
|
188
|
+
),
|
189
|
+
"space": "MNI152NLin6Asym",
|
190
|
+
},
|
191
|
+
"BOLD_confounds": {
|
192
|
+
"pattern": "{subject}/func/{subject}_confounds.tsv",
|
193
|
+
"format": "fmriprep",
|
194
|
+
},
|
195
|
+
},
|
196
|
+
nullcontext(),
|
197
|
+
),
|
198
|
+
],
|
199
|
+
)
|
200
|
+
def test_validate_patterns(
|
201
|
+
types: List[str],
|
202
|
+
patterns: Union[str, Dict[str, Dict[str, str]]],
|
203
|
+
expect: ContextManager,
|
204
|
+
) -> None:
|
205
|
+
"""Test validation of patterns.
|
206
|
+
|
207
|
+
Parameters
|
208
|
+
----------
|
209
|
+
types : list of str
|
210
|
+
The parametrized data types.
|
211
|
+
patterns : str, dict
|
212
|
+
The patterns to validate.
|
213
|
+
expect : typing.ContextManager
|
214
|
+
The parametrized ContextManager object.
|
215
|
+
|
216
|
+
"""
|
217
|
+
with expect:
|
218
|
+
validate_patterns(types=types, patterns=patterns) # type: ignore
|
@@ -15,13 +15,13 @@ from junifer.datagrabber import DataladDataGrabber
|
|
15
15
|
_testing_dataset = {
|
16
16
|
"example_bids": {
|
17
17
|
"uri": "https://gin.g-node.org/juaml/datalad-example-bids",
|
18
|
-
"commit": "
|
19
|
-
"id": "
|
18
|
+
"commit": "522dfb203afcd2cd55799bf347f9b211919a7338",
|
19
|
+
"id": "fec92475-d9c0-4409-92ba-f041b6a12c40",
|
20
20
|
},
|
21
21
|
"example_bids_ses": {
|
22
22
|
"uri": "https://gin.g-node.org/juaml/datalad-example-bids-ses",
|
23
|
-
"commit": "
|
24
|
-
"id": "
|
23
|
+
"commit": "3d08d55d1faad4f12ab64ac9497544a0d924d47a",
|
24
|
+
"id": "c83500d0-532f-45be-baf1-0dab703bdc2a",
|
25
25
|
},
|
26
26
|
}
|
27
27
|
|
@@ -93,10 +93,13 @@ def test_DMCC13Benchmark(
|
|
93
93
|
# Available data types
|
94
94
|
data_types = [
|
95
95
|
"BOLD",
|
96
|
+
"BOLD_confounds",
|
97
|
+
"BOLD_mask",
|
96
98
|
"VBM_CSF",
|
97
99
|
"VBM_GM",
|
98
100
|
"VBM_WM",
|
99
101
|
"T1w",
|
102
|
+
"T1w_mask",
|
100
103
|
]
|
101
104
|
# Add Warp if native T1w is accessed
|
102
105
|
if native_t1w:
|
@@ -108,6 +111,14 @@ def test_DMCC13Benchmark(
|
|
108
111
|
f"sub-01_{ses}_task-{task}_acq-mb4{phase}_run-{run}_"
|
109
112
|
"space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz"
|
110
113
|
),
|
114
|
+
(
|
115
|
+
f"sub-01_{ses}_task-{task}_acq-mb4{phase}_run-{run}_"
|
116
|
+
"desc-confounds_regressors.tsv"
|
117
|
+
),
|
118
|
+
(
|
119
|
+
f"sub-01_{ses}_task-{task}_acq-mb4{phase}_run-{run}_"
|
120
|
+
"space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz"
|
121
|
+
),
|
111
122
|
"sub-01_space-MNI152NLin2009cAsym_label-CSF_probseg.nii.gz",
|
112
123
|
"sub-01_space-MNI152NLin2009cAsym_label-GM_probseg.nii.gz",
|
113
124
|
"sub-01_space-MNI152NLin2009cAsym_label-WM_probseg.nii.gz",
|
@@ -116,12 +127,16 @@ def test_DMCC13Benchmark(
|
|
116
127
|
data_file_names.extend(
|
117
128
|
[
|
118
129
|
"sub-01_desc-preproc_T1w.nii.gz",
|
130
|
+
"sub-01_desc-brain_mask.nii.gz",
|
119
131
|
"sub-01_from-MNI152NLin2009cAsym_to-T1w_mode-image_xfm.h5",
|
120
132
|
]
|
121
133
|
)
|
122
134
|
else:
|
123
|
-
data_file_names.
|
124
|
-
|
135
|
+
data_file_names.extend(
|
136
|
+
[
|
137
|
+
"sub-01_space-MNI152NLin2009cAsym_desc-preproc_T1w.nii.gz",
|
138
|
+
"sub-01_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz",
|
139
|
+
]
|
125
140
|
)
|
126
141
|
|
127
142
|
for data_type, data_file_name in zip(data_types, data_file_names):
|
@@ -136,48 +151,6 @@ def test_DMCC13Benchmark(
|
|
136
151
|
# Assert metadata
|
137
152
|
assert "meta" in out[data_type]
|
138
153
|
|
139
|
-
# Check BOLD nested data types
|
140
|
-
for type_, file_name in zip(
|
141
|
-
("mask", "confounds"),
|
142
|
-
(
|
143
|
-
(
|
144
|
-
f"sub-01_{ses}_task-{task}_acq-mb4{phase}_run-{run}_"
|
145
|
-
"space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz"
|
146
|
-
),
|
147
|
-
(
|
148
|
-
f"sub-01_{ses}_task-{task}_acq-mb4{phase}_run-{run}_"
|
149
|
-
"desc-confounds_regressors.tsv"
|
150
|
-
),
|
151
|
-
),
|
152
|
-
):
|
153
|
-
# Assert data type
|
154
|
-
assert type_ in out["BOLD"]
|
155
|
-
# Assert data file path exists
|
156
|
-
assert out["BOLD"][type_]["path"].exists()
|
157
|
-
# Assert data file path is a file
|
158
|
-
assert out["BOLD"][type_]["path"].is_file()
|
159
|
-
# Assert data file name
|
160
|
-
assert out["BOLD"][type_]["path"].name == file_name
|
161
|
-
|
162
|
-
# Check T1w nested data types
|
163
|
-
# Assert data type
|
164
|
-
assert "mask" in out["T1w"]
|
165
|
-
# Assert data file path exists
|
166
|
-
assert out["T1w"]["mask"]["path"].exists()
|
167
|
-
# Assert data file path is a file
|
168
|
-
assert out["T1w"]["mask"]["path"].is_file()
|
169
|
-
# Assert data file name
|
170
|
-
if native_t1w:
|
171
|
-
assert (
|
172
|
-
out["T1w"]["mask"]["path"].name
|
173
|
-
== "sub-01_desc-brain_mask.nii.gz"
|
174
|
-
)
|
175
|
-
else:
|
176
|
-
assert (
|
177
|
-
out["T1w"]["mask"]["path"].name
|
178
|
-
== "sub-01_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz"
|
179
|
-
)
|
180
|
-
|
181
154
|
|
182
155
|
@pytest.mark.parametrize(
|
183
156
|
"types, native_t1w",
|
@@ -192,8 +165,8 @@ def test_DMCC13Benchmark(
|
|
192
165
|
("VBM_GM", False),
|
193
166
|
("VBM_WM", True),
|
194
167
|
("VBM_WM", False),
|
195
|
-
(["BOLD", "
|
196
|
-
(["BOLD", "
|
168
|
+
(["BOLD", "BOLD_confounds"], True),
|
169
|
+
(["BOLD", "BOLD_confounds"], False),
|
197
170
|
(["T1w", "VBM_CSF"], True),
|
198
171
|
(["T1w", "VBM_CSF"], False),
|
199
172
|
(["VBM_GM", "VBM_WM"], True),
|
@@ -25,26 +25,28 @@ def test_MultipleDataGrabber() -> None:
|
|
25
25
|
repo_uri = _testing_dataset["example_bids_ses"]["uri"]
|
26
26
|
rootdir = "example_bids_ses"
|
27
27
|
replacements = ["subject", "session"]
|
28
|
-
|
28
|
+
pattern1 = {
|
29
|
+
"T1w": {
|
30
|
+
"pattern": (
|
31
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
32
|
+
),
|
33
|
+
"space": "native",
|
34
|
+
},
|
35
|
+
}
|
36
|
+
pattern2 = {
|
37
|
+
"BOLD": {
|
38
|
+
"pattern": (
|
39
|
+
"{subject}/{session}/func/"
|
40
|
+
"{subject}_{session}_task-rest_bold.nii.gz"
|
41
|
+
),
|
42
|
+
"space": "MNI152NLin6Asym",
|
43
|
+
},
|
44
|
+
}
|
29
45
|
dg1 = PatternDataladDataGrabber(
|
30
46
|
rootdir=rootdir,
|
31
47
|
uri=repo_uri,
|
32
48
|
types=["T1w"],
|
33
|
-
patterns=
|
34
|
-
"T1w": {
|
35
|
-
"pattern": (
|
36
|
-
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
37
|
-
),
|
38
|
-
"space": "native",
|
39
|
-
"mask": {
|
40
|
-
"pattern": (
|
41
|
-
"{subject}/{session}/anat/{subject}_{session}_"
|
42
|
-
"brain_mask.nii.gz"
|
43
|
-
),
|
44
|
-
"space": "native",
|
45
|
-
},
|
46
|
-
},
|
47
|
-
},
|
49
|
+
patterns=pattern1,
|
48
50
|
replacements=replacements,
|
49
51
|
)
|
50
52
|
|
@@ -52,22 +54,7 @@ def test_MultipleDataGrabber() -> None:
|
|
52
54
|
rootdir=rootdir,
|
53
55
|
uri=repo_uri,
|
54
56
|
types=["BOLD"],
|
55
|
-
patterns=
|
56
|
-
"BOLD": {
|
57
|
-
"pattern": (
|
58
|
-
"{subject}/{session}/func/"
|
59
|
-
"{subject}_{session}_task-rest_bold.nii.gz"
|
60
|
-
),
|
61
|
-
"space": "MNI152NLin6Asym",
|
62
|
-
"mask": {
|
63
|
-
"pattern": (
|
64
|
-
"{subject}/{session}/func/"
|
65
|
-
"{subject}_{session}_task-rest_brain_mask.nii.gz"
|
66
|
-
),
|
67
|
-
"space": "MNI152NLin6Asym",
|
68
|
-
},
|
69
|
-
},
|
70
|
-
},
|
57
|
+
patterns=pattern2,
|
71
58
|
replacements=replacements,
|
72
59
|
)
|
73
60
|
|
@@ -86,17 +73,14 @@ def test_MultipleDataGrabber() -> None:
|
|
86
73
|
with dg:
|
87
74
|
subs = list(dg)
|
88
75
|
assert set(subs) == set(expected_subs)
|
89
|
-
|
76
|
+
|
90
77
|
elem = dg[("sub-01", "ses-01")]
|
91
|
-
# Check data types
|
92
78
|
assert "T1w" in elem
|
93
79
|
assert "BOLD" in elem
|
94
|
-
# Check meta
|
95
80
|
assert "meta" in elem["BOLD"]
|
96
81
|
meta = elem["BOLD"]["meta"]["datagrabber"]
|
97
82
|
assert "class" in meta
|
98
83
|
assert meta["class"] == "MultipleDataGrabber"
|
99
|
-
# Check datagrabbers
|
100
84
|
assert "datagrabbers" in meta
|
101
85
|
assert len(meta["datagrabbers"]) == 2
|
102
86
|
assert meta["datagrabbers"][0]["class"] == "PatternDataladDataGrabber"
|
@@ -105,37 +89,40 @@ def test_MultipleDataGrabber() -> None:
|
|
105
89
|
|
106
90
|
def test_MultipleDataGrabber_no_intersection() -> None:
|
107
91
|
"""Test MultipleDataGrabber without intersection (0 elements)."""
|
92
|
+
repo_uri1 = _testing_dataset["example_bids"]["uri"]
|
93
|
+
repo_uri2 = _testing_dataset["example_bids_ses"]["uri"]
|
108
94
|
rootdir = "example_bids_ses"
|
109
95
|
replacements = ["subject", "session"]
|
110
|
-
|
96
|
+
pattern1 = {
|
97
|
+
"T1w": {
|
98
|
+
"pattern": (
|
99
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
100
|
+
),
|
101
|
+
"space": "native",
|
102
|
+
},
|
103
|
+
}
|
104
|
+
pattern2 = {
|
105
|
+
"BOLD": {
|
106
|
+
"pattern": (
|
107
|
+
"{subject}/{session}/func/"
|
108
|
+
"{subject}_{session}_task-rest_bold.nii.gz"
|
109
|
+
),
|
110
|
+
"space": "MNI152NLin6Asym",
|
111
|
+
},
|
112
|
+
}
|
111
113
|
dg1 = PatternDataladDataGrabber(
|
112
114
|
rootdir=rootdir,
|
113
|
-
uri=
|
115
|
+
uri=repo_uri1,
|
114
116
|
types=["T1w"],
|
115
|
-
patterns=
|
116
|
-
"T1w": {
|
117
|
-
"pattern": (
|
118
|
-
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
119
|
-
),
|
120
|
-
"space": "native",
|
121
|
-
},
|
122
|
-
},
|
117
|
+
patterns=pattern1,
|
123
118
|
replacements=replacements,
|
124
119
|
)
|
125
120
|
|
126
121
|
dg2 = PatternDataladDataGrabber(
|
127
122
|
rootdir=rootdir,
|
128
|
-
uri=
|
123
|
+
uri=repo_uri2,
|
129
124
|
types=["BOLD"],
|
130
|
-
patterns=
|
131
|
-
"BOLD": {
|
132
|
-
"pattern": (
|
133
|
-
"{subject}/{session}/func/"
|
134
|
-
"{subject}_{session}_task-rest_bold.nii.gz"
|
135
|
-
),
|
136
|
-
"space": "MNI152NLin6Asym",
|
137
|
-
},
|
138
|
-
},
|
125
|
+
patterns=pattern2,
|
139
126
|
replacements=replacements,
|
140
127
|
)
|
141
128
|
|
@@ -148,19 +135,23 @@ def test_MultipleDataGrabber_no_intersection() -> None:
|
|
148
135
|
|
149
136
|
def test_MultipleDataGrabber_get_item() -> None:
|
150
137
|
"""Test MultipleDataGrabber get_item() error."""
|
138
|
+
repo_uri1 = _testing_dataset["example_bids"]["uri"]
|
139
|
+
rootdir = "example_bids_ses"
|
140
|
+
replacements = ["subject", "session"]
|
141
|
+
pattern1 = {
|
142
|
+
"T1w": {
|
143
|
+
"pattern": (
|
144
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
145
|
+
),
|
146
|
+
"space": "native",
|
147
|
+
},
|
148
|
+
}
|
151
149
|
dg1 = PatternDataladDataGrabber(
|
152
|
-
rootdir=
|
153
|
-
uri=
|
150
|
+
rootdir=rootdir,
|
151
|
+
uri=repo_uri1,
|
154
152
|
types=["T1w"],
|
155
|
-
patterns=
|
156
|
-
|
157
|
-
"pattern": (
|
158
|
-
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
159
|
-
),
|
160
|
-
"space": "native",
|
161
|
-
},
|
162
|
-
},
|
163
|
-
replacements=["subject", "session"],
|
153
|
+
patterns=pattern1,
|
154
|
+
replacements=replacements,
|
164
155
|
)
|
165
156
|
|
166
157
|
dg = MultipleDataGrabber([dg1])
|
@@ -170,111 +161,43 @@ def test_MultipleDataGrabber_get_item() -> None:
|
|
170
161
|
|
171
162
|
def test_MultipleDataGrabber_validation() -> None:
|
172
163
|
"""Test MultipleDataGrabber init validation."""
|
164
|
+
repo_uri1 = _testing_dataset["example_bids"]["uri"]
|
165
|
+
repo_uri2 = _testing_dataset["example_bids_ses"]["uri"]
|
173
166
|
rootdir = "example_bids_ses"
|
174
|
-
|
167
|
+
replacement1 = ["subject", "session"]
|
168
|
+
replacement2 = ["subject"]
|
169
|
+
pattern1 = {
|
170
|
+
"T1w": {
|
171
|
+
"pattern": (
|
172
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
173
|
+
),
|
174
|
+
"space": "native",
|
175
|
+
},
|
176
|
+
}
|
177
|
+
pattern2 = {
|
178
|
+
"BOLD": {
|
179
|
+
"pattern": "{subject}/func/{subject}_task-rest_bold.nii.gz",
|
180
|
+
"space": "MNI152NLin6Asym",
|
181
|
+
},
|
182
|
+
}
|
175
183
|
dg1 = PatternDataladDataGrabber(
|
176
184
|
rootdir=rootdir,
|
177
|
-
uri=
|
185
|
+
uri=repo_uri1,
|
178
186
|
types=["T1w"],
|
179
|
-
patterns=
|
180
|
-
|
181
|
-
"pattern": (
|
182
|
-
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
183
|
-
),
|
184
|
-
"space": "native",
|
185
|
-
},
|
186
|
-
},
|
187
|
-
replacements=["subject", "session"],
|
187
|
+
patterns=pattern1,
|
188
|
+
replacements=replacement1,
|
188
189
|
)
|
189
190
|
|
190
191
|
dg2 = PatternDataladDataGrabber(
|
191
192
|
rootdir=rootdir,
|
192
|
-
uri=
|
193
|
+
uri=repo_uri2,
|
193
194
|
types=["BOLD"],
|
194
|
-
patterns=
|
195
|
-
|
196
|
-
"pattern": "{subject}/func/{subject}_task-rest_bold.nii.gz",
|
197
|
-
"space": "MNI152NLin6Asym",
|
198
|
-
},
|
199
|
-
},
|
200
|
-
replacements=["subject"],
|
195
|
+
patterns=pattern2,
|
196
|
+
replacements=replacement2,
|
201
197
|
)
|
202
198
|
|
203
|
-
with pytest.raises(
|
199
|
+
with pytest.raises(ValueError, match="different element key"):
|
204
200
|
MultipleDataGrabber([dg1, dg2])
|
205
201
|
|
206
|
-
with pytest.raises(
|
202
|
+
with pytest.raises(ValueError, match="overlapping types"):
|
207
203
|
MultipleDataGrabber([dg1, dg1])
|
208
|
-
|
209
|
-
|
210
|
-
def test_MultipleDataGrabber_partial_pattern() -> None:
|
211
|
-
"""Test MultipleDataGrabber partial pattern."""
|
212
|
-
repo_uri = _testing_dataset["example_bids_ses"]["uri"]
|
213
|
-
rootdir = "example_bids_ses"
|
214
|
-
replacements = ["subject", "session"]
|
215
|
-
|
216
|
-
dg1 = PatternDataladDataGrabber(
|
217
|
-
rootdir=rootdir,
|
218
|
-
uri=repo_uri,
|
219
|
-
types=["BOLD"],
|
220
|
-
patterns={
|
221
|
-
"BOLD": {
|
222
|
-
"pattern": (
|
223
|
-
"{subject}/{session}/func/"
|
224
|
-
"{subject}_{session}_task-rest_bold.nii.gz"
|
225
|
-
),
|
226
|
-
"space": "MNI152NLin6Asym",
|
227
|
-
},
|
228
|
-
},
|
229
|
-
replacements=replacements,
|
230
|
-
)
|
231
|
-
|
232
|
-
dg2 = PatternDataladDataGrabber(
|
233
|
-
rootdir=rootdir,
|
234
|
-
uri=repo_uri,
|
235
|
-
types=["BOLD"],
|
236
|
-
patterns={
|
237
|
-
"BOLD": {
|
238
|
-
"confounds": {
|
239
|
-
"pattern": (
|
240
|
-
"{subject}/{session}/func/"
|
241
|
-
"{subject}_{session}_task-rest_"
|
242
|
-
"confounds_regressors.tsv"
|
243
|
-
),
|
244
|
-
"format": "fmriprep",
|
245
|
-
},
|
246
|
-
},
|
247
|
-
},
|
248
|
-
replacements=["subject", "session"],
|
249
|
-
partial_pattern_ok=True,
|
250
|
-
)
|
251
|
-
|
252
|
-
dg = MultipleDataGrabber([dg1, dg2])
|
253
|
-
|
254
|
-
types = dg.get_types()
|
255
|
-
assert "BOLD" in types
|
256
|
-
|
257
|
-
expected_subs = [
|
258
|
-
(f"sub-{i:02d}", f"ses-{j:02d}")
|
259
|
-
for j in range(1, 3)
|
260
|
-
for i in range(1, 10)
|
261
|
-
]
|
262
|
-
|
263
|
-
with dg:
|
264
|
-
subs = list(dg)
|
265
|
-
assert set(subs) == set(expected_subs)
|
266
|
-
# Fetch element
|
267
|
-
elem = dg[("sub-01", "ses-01")]
|
268
|
-
# Check data type and nested data type
|
269
|
-
assert "BOLD" in elem
|
270
|
-
assert "confounds" in elem["BOLD"]
|
271
|
-
# Check meta
|
272
|
-
assert "meta" in elem["BOLD"]
|
273
|
-
meta = elem["BOLD"]["meta"]["datagrabber"]
|
274
|
-
assert "class" in meta
|
275
|
-
assert meta["class"] == "MultipleDataGrabber"
|
276
|
-
# Check datagrabbers
|
277
|
-
assert "datagrabbers" in meta
|
278
|
-
assert len(meta["datagrabbers"]) == 2
|
279
|
-
assert meta["datagrabbers"][0]["class"] == "PatternDataladDataGrabber"
|
280
|
-
assert meta["datagrabbers"][1]["class"] == "PatternDataladDataGrabber"
|