junifer 0.0.4.dev781__py3-none-any.whl → 0.0.4.dev810__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/configs/juseless/datagrabbers/aomic_id1000_vbm.py +6 -1
- junifer/configs/juseless/datagrabbers/camcan_vbm.py +6 -1
- junifer/configs/juseless/datagrabbers/ixi_vbm.py +6 -1
- junifer/configs/juseless/datagrabbers/ucla.py +42 -24
- junifer/configs/juseless/datagrabbers/ukb_vbm.py +6 -1
- junifer/datagrabber/aomic/id1000.py +98 -91
- junifer/datagrabber/aomic/piop1.py +97 -73
- junifer/datagrabber/aomic/piop2.py +97 -73
- junifer/datagrabber/base.py +6 -4
- junifer/datagrabber/datalad_base.py +0 -2
- junifer/datagrabber/dmcc13_benchmark.py +87 -50
- junifer/datagrabber/hcp1200/hcp1200.py +21 -19
- junifer/datagrabber/pattern.py +124 -25
- junifer/datagrabber/pattern_datalad.py +111 -13
- junifer/datagrabber/tests/test_base.py +0 -6
- junifer/datagrabber/tests/test_datagrabber_utils.py +204 -76
- junifer/datagrabber/tests/test_datalad_base.py +0 -6
- junifer/datagrabber/tests/test_multiple.py +43 -10
- junifer/datagrabber/tests/test_pattern.py +125 -178
- junifer/datagrabber/tests/test_pattern_datalad.py +44 -25
- junifer/datagrabber/utils.py +141 -21
- junifer/datareader/default.py +6 -7
- {junifer-0.0.4.dev781.dist-info → junifer-0.0.4.dev810.dist-info}/METADATA +1 -1
- {junifer-0.0.4.dev781.dist-info → junifer-0.0.4.dev810.dist-info}/RECORD +30 -30
- {junifer-0.0.4.dev781.dist-info → junifer-0.0.4.dev810.dist-info}/AUTHORS.rst +0 -0
- {junifer-0.0.4.dev781.dist-info → junifer-0.0.4.dev810.dist-info}/LICENSE.md +0 -0
- {junifer-0.0.4.dev781.dist-info → junifer-0.0.4.dev810.dist-info}/WHEEL +0 -0
- {junifer-0.0.4.dev781.dist-info → junifer-0.0.4.dev810.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.4.dev781.dist-info → junifer-0.0.4.dev810.dist-info}/top_level.txt +0 -0
@@ -26,11 +26,21 @@ def test_MultipleDataGrabber() -> None:
|
|
26
26
|
rootdir = "example_bids_ses"
|
27
27
|
replacements = ["subject", "session"]
|
28
28
|
pattern1 = {
|
29
|
-
"T1w":
|
29
|
+
"T1w": {
|
30
|
+
"pattern": (
|
31
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
32
|
+
),
|
33
|
+
"space": "native",
|
34
|
+
},
|
30
35
|
}
|
31
36
|
pattern2 = {
|
32
|
-
"BOLD":
|
33
|
-
|
37
|
+
"BOLD": {
|
38
|
+
"pattern": (
|
39
|
+
"{subject}/{session}/func/"
|
40
|
+
"{subject}_{session}_task-rest_bold.nii.gz"
|
41
|
+
),
|
42
|
+
"space": "MNI152NLin6Asym",
|
43
|
+
},
|
34
44
|
}
|
35
45
|
dg1 = PatternDataladDataGrabber(
|
36
46
|
rootdir=rootdir,
|
@@ -84,11 +94,21 @@ def test_MultipleDataGrabber_no_intersection() -> None:
|
|
84
94
|
rootdir = "example_bids_ses"
|
85
95
|
replacements = ["subject", "session"]
|
86
96
|
pattern1 = {
|
87
|
-
"T1w":
|
97
|
+
"T1w": {
|
98
|
+
"pattern": (
|
99
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
100
|
+
),
|
101
|
+
"space": "native",
|
102
|
+
},
|
88
103
|
}
|
89
104
|
pattern2 = {
|
90
|
-
"BOLD":
|
91
|
-
|
105
|
+
"BOLD": {
|
106
|
+
"pattern": (
|
107
|
+
"{subject}/{session}/func/"
|
108
|
+
"{subject}_{session}_task-rest_bold.nii.gz"
|
109
|
+
),
|
110
|
+
"space": "MNI152NLin6Asym",
|
111
|
+
},
|
92
112
|
}
|
93
113
|
dg1 = PatternDataladDataGrabber(
|
94
114
|
rootdir=rootdir,
|
@@ -119,7 +139,12 @@ def test_MultipleDataGrabber_get_item() -> None:
|
|
119
139
|
rootdir = "example_bids_ses"
|
120
140
|
replacements = ["subject", "session"]
|
121
141
|
pattern1 = {
|
122
|
-
"T1w":
|
142
|
+
"T1w": {
|
143
|
+
"pattern": (
|
144
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
145
|
+
),
|
146
|
+
"space": "native",
|
147
|
+
},
|
123
148
|
}
|
124
149
|
dg1 = PatternDataladDataGrabber(
|
125
150
|
rootdir=rootdir,
|
@@ -142,10 +167,18 @@ def test_MultipleDataGrabber_validation() -> None:
|
|
142
167
|
replacement1 = ["subject", "session"]
|
143
168
|
replacement2 = ["subject"]
|
144
169
|
pattern1 = {
|
145
|
-
"T1w":
|
170
|
+
"T1w": {
|
171
|
+
"pattern": (
|
172
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
173
|
+
),
|
174
|
+
"space": "native",
|
175
|
+
},
|
146
176
|
}
|
147
177
|
pattern2 = {
|
148
|
-
"
|
178
|
+
"BOLD": {
|
179
|
+
"pattern": "{subject}/func/{subject}_task-rest_bold.nii.gz",
|
180
|
+
"space": "MNI152NLin6Asym",
|
181
|
+
},
|
149
182
|
}
|
150
183
|
dg1 = PatternDataladDataGrabber(
|
151
184
|
rootdir=rootdir,
|
@@ -158,7 +191,7 @@ def test_MultipleDataGrabber_validation() -> None:
|
|
158
191
|
dg2 = PatternDataladDataGrabber(
|
159
192
|
rootdir=rootdir,
|
160
193
|
uri=repo_uri2,
|
161
|
-
types=["
|
194
|
+
types=["BOLD"],
|
162
195
|
patterns=pattern2,
|
163
196
|
replacements=replacement2,
|
164
197
|
)
|
@@ -5,6 +5,7 @@
|
|
5
5
|
# Synchon Mandal <s.mandal@fz-juelich.de>
|
6
6
|
# License: AGPL
|
7
7
|
|
8
|
+
from itertools import product
|
8
9
|
from pathlib import Path
|
9
10
|
|
10
11
|
import pytest
|
@@ -21,144 +22,88 @@ def test_PatternDataGrabber_errors(tmp_path: Path) -> None:
|
|
21
22
|
The path to the test directory.
|
22
23
|
|
23
24
|
"""
|
24
|
-
|
25
|
-
with pytest.raises(TypeError, match=r"`types` must be a list"):
|
26
|
-
PatternDataGrabber(
|
27
|
-
datadir="/tmp",
|
28
|
-
types="wrong", # type: ignore
|
29
|
-
patterns={"wrong": "pattern"},
|
30
|
-
replacements="subject", # type: ignore
|
31
|
-
)
|
32
|
-
|
33
|
-
with pytest.raises(TypeError, match=r"`types` must be a list of strings"):
|
34
|
-
PatternDataGrabber(
|
35
|
-
datadir="/tmp", # type: ignore
|
36
|
-
types=[1, 2, 3], # type: ignore
|
37
|
-
patterns={"1": "pattern", "2": "pattern", "3": "pattern"},
|
38
|
-
replacements="subject", # type: ignore
|
39
|
-
)
|
40
|
-
|
41
|
-
with pytest.raises(
|
42
|
-
ValueError, match=r"`patterns` must contain all `types`"
|
43
|
-
):
|
44
|
-
PatternDataGrabber(
|
45
|
-
datadir="/tmp",
|
46
|
-
types=["func", "anat"],
|
47
|
-
patterns={"1": "pattern", "2": "pattern", "3": "pattern"},
|
48
|
-
replacements=1, # type: ignore
|
49
|
-
)
|
50
|
-
|
51
|
-
with pytest.raises(TypeError, match=r"`patterns` must be a dict"):
|
52
|
-
PatternDataGrabber(
|
53
|
-
datadir="/tmp",
|
54
|
-
types=["func", "anat"],
|
55
|
-
patterns="wrong", # type: ignore
|
56
|
-
replacements="subject", # type: ignore
|
57
|
-
)
|
58
|
-
|
59
|
-
with pytest.raises(
|
60
|
-
ValueError, match=r"Length of `types` more than that of `patterns`"
|
61
|
-
):
|
62
|
-
PatternDataGrabber(
|
63
|
-
datadir="/tmp",
|
64
|
-
types=["func", "anat"],
|
65
|
-
patterns={"wrong": "pattern"},
|
66
|
-
replacements="subject", # type: ignore
|
67
|
-
)
|
68
|
-
|
69
|
-
with pytest.raises(
|
70
|
-
ValueError, match=r"`patterns` must contain all `types`"
|
71
|
-
):
|
72
|
-
PatternDataGrabber(
|
73
|
-
datadir="/tmp",
|
74
|
-
types=["func", "anat"],
|
75
|
-
patterns={"wrong": "pattern", "func": "pattern"},
|
76
|
-
replacements="subject", # type: ignore
|
77
|
-
)
|
78
|
-
|
79
|
-
with pytest.raises(TypeError, match=r"must be a list of strings"):
|
80
|
-
PatternDataGrabber(
|
81
|
-
datadir="/tmp",
|
82
|
-
types=["func", "anat"],
|
83
|
-
patterns={"func": "func/test", "anat": "anat/test"},
|
84
|
-
replacements=1, # type: ignore
|
85
|
-
)
|
86
|
-
|
87
|
-
with pytest.raises(ValueError, match=r"not part of any pattern"):
|
88
|
-
PatternDataGrabber(
|
89
|
-
datadir="/tmp",
|
90
|
-
types=["func", "anat"],
|
91
|
-
patterns={
|
92
|
-
"func": "func/{subject}.nii",
|
93
|
-
"anat": "anat/{subject}.nii",
|
94
|
-
},
|
95
|
-
replacements=["subject", "wrong"],
|
96
|
-
)
|
97
|
-
|
98
25
|
tmpdir = tmp_path / "pattern_dg_test_errors"
|
99
26
|
|
100
|
-
|
27
|
+
datagrabber_no_access = PatternDataGrabber(
|
101
28
|
datadir=tmpdir,
|
102
|
-
types=["
|
29
|
+
types=["BOLD", "T1w"],
|
103
30
|
patterns={
|
104
|
-
"
|
105
|
-
|
31
|
+
"BOLD": {
|
32
|
+
"pattern": "func/{subject}_single.nii",
|
33
|
+
"space": "MNI152NLin6Asym",
|
34
|
+
},
|
35
|
+
"T1w": {
|
36
|
+
"pattern": "anat/{subject}_{session}_ses.nii",
|
37
|
+
"space": "MNI152NLin6Asym",
|
38
|
+
},
|
106
39
|
},
|
107
40
|
replacements=["subject", "session"],
|
108
41
|
)
|
109
42
|
|
110
43
|
with pytest.raises(ValueError, match="element keys must be"):
|
111
|
-
|
44
|
+
datagrabber_no_access[("sub001")]
|
112
45
|
|
113
46
|
# This should not work, file does not exists
|
114
|
-
with pytest.raises(
|
115
|
-
|
47
|
+
with pytest.raises(RuntimeError, match="Cannot access"):
|
48
|
+
datagrabber_no_access[("sub001", "ses001")]
|
116
49
|
|
50
|
+
# Create directories and files
|
117
51
|
(tmpdir / "func").mkdir(exist_ok=True, parents=True)
|
118
52
|
(tmpdir / "anat").mkdir(exist_ok=True, parents=True)
|
119
|
-
for t_subject in range(3):
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
(tmpdir / "anat" / f"{subject}_{session}_ses.nii").touch()
|
53
|
+
for t_subject, t_session in product(range(3), range(2)):
|
54
|
+
subject = f"sub{t_subject:03d}"
|
55
|
+
session = f"ses{t_session:03d}"
|
56
|
+
(tmpdir / "func" / f"{subject}_single.nii").touch()
|
57
|
+
if t_subject == 2:
|
58
|
+
(tmpdir / "func" / f"{subject}_extra.nii").touch()
|
59
|
+
(tmpdir / "anat" / f"{subject}_{session}_ses.nii").touch()
|
127
60
|
|
128
61
|
# This should work, file now exists
|
129
|
-
|
62
|
+
datagrabber_no_access[("sub001", "ses001")]
|
130
63
|
|
131
|
-
|
64
|
+
datagrabber_multi_access = PatternDataGrabber(
|
132
65
|
datadir=tmpdir,
|
133
|
-
types=["
|
66
|
+
types=["BOLD", "T1w"],
|
134
67
|
patterns={
|
135
|
-
"
|
136
|
-
|
68
|
+
"BOLD": {
|
69
|
+
"pattern": "func/{subject}_*.nii",
|
70
|
+
"space": "MNI152NLin6Asym",
|
71
|
+
},
|
72
|
+
"T1w": {
|
73
|
+
"pattern": "anat/{subject}_{session}_*.nii",
|
74
|
+
"space": "MNI152NLin6Asym",
|
75
|
+
},
|
137
76
|
},
|
138
77
|
replacements=["subject", "session"],
|
139
78
|
)
|
140
79
|
|
141
|
-
#
|
142
|
-
with pytest.raises(
|
143
|
-
|
80
|
+
# Access a subject with a missing session
|
81
|
+
with pytest.raises(RuntimeError, match="No file matches"):
|
82
|
+
datagrabber_multi_access[("sub001", "ses004")]
|
144
83
|
|
145
|
-
#
|
146
|
-
with pytest.raises(
|
147
|
-
|
84
|
+
# Access a subject with two matching files
|
85
|
+
with pytest.raises(RuntimeError, match="More than one"):
|
86
|
+
datagrabber_multi_access[("sub002", "ses001")]
|
148
87
|
|
149
|
-
#
|
150
|
-
|
88
|
+
# Access the right one
|
89
|
+
datagrabber_multi_access[("sub001", "ses001")]
|
151
90
|
|
152
|
-
|
91
|
+
datagrabber_fake_access = PatternDataGrabber(
|
153
92
|
datadir=tmpdir,
|
154
|
-
types=["
|
93
|
+
types=["BOLD", "T1w"],
|
155
94
|
patterns={
|
156
|
-
"
|
157
|
-
|
95
|
+
"BOLD": {
|
96
|
+
"pattern": "func/{subject}_single.nii",
|
97
|
+
"space": "MNI152NLin6Asym",
|
98
|
+
},
|
99
|
+
"T1w": {
|
100
|
+
"pattern": "anat2/{subject}_{session}_ses.nii",
|
101
|
+
"space": "MNI152NLin6Asym",
|
102
|
+
},
|
158
103
|
},
|
159
104
|
replacements=["subject", "session"],
|
160
105
|
)
|
161
|
-
assert len(
|
106
|
+
assert len(datagrabber_fake_access.get_elements()) == 0
|
162
107
|
|
163
108
|
|
164
109
|
def test_PatternDataGrabber(tmp_path: Path) -> None:
|
@@ -171,43 +116,59 @@ def test_PatternDataGrabber(tmp_path: Path) -> None:
|
|
171
116
|
|
172
117
|
"""
|
173
118
|
|
174
|
-
|
119
|
+
datagrabber_first = PatternDataGrabber(
|
175
120
|
datadir="/tmp/data",
|
176
|
-
types=["
|
177
|
-
patterns={
|
121
|
+
types=["BOLD", "T1w"],
|
122
|
+
patterns={
|
123
|
+
"BOLD": {
|
124
|
+
"pattern": "func/{subject}.nii",
|
125
|
+
"space": "MNI152NLin6Asym",
|
126
|
+
},
|
127
|
+
"T1w": {
|
128
|
+
"pattern": "anat/{subject}.nii",
|
129
|
+
"space": "native",
|
130
|
+
},
|
131
|
+
},
|
178
132
|
replacements="subject",
|
179
133
|
)
|
180
|
-
assert
|
181
|
-
assert
|
182
|
-
assert
|
134
|
+
assert datagrabber_first.datadir == Path("/tmp/data")
|
135
|
+
assert set(datagrabber_first.types) == {"T1w", "BOLD"}
|
136
|
+
assert datagrabber_first.replacements == ["subject"]
|
183
137
|
|
184
|
-
|
138
|
+
datagrabber_second = PatternDataGrabber(
|
185
139
|
datadir=Path("/tmp/data"),
|
186
|
-
types=["
|
140
|
+
types=["BOLD", "T1w"],
|
187
141
|
patterns={
|
188
|
-
"
|
189
|
-
|
142
|
+
"BOLD": {
|
143
|
+
"pattern": "func/{subject}.nii",
|
144
|
+
"space": "MNI152NLin6Asym",
|
145
|
+
},
|
146
|
+
"T1w": {
|
147
|
+
"pattern": "anat/{subject}_{session}.nii",
|
148
|
+
"space": "native",
|
149
|
+
},
|
190
150
|
},
|
191
151
|
replacements=["subject", "session"],
|
192
152
|
)
|
193
|
-
assert
|
194
|
-
assert
|
195
|
-
assert
|
153
|
+
assert datagrabber_second.datadir == Path("/tmp/data")
|
154
|
+
assert set(datagrabber_second.types) == {"T1w", "BOLD"}
|
155
|
+
assert datagrabber_second.replacements == ["subject", "session"]
|
196
156
|
|
157
|
+
# Create directories and files
|
197
158
|
tmpdir = tmp_path / "pattern_dg_test"
|
198
159
|
(tmpdir / "func").mkdir(exist_ok=True, parents=True)
|
199
160
|
(tmpdir / "anat").mkdir(exist_ok=True, parents=True)
|
200
161
|
(tmpdir / "vbm").mkdir(exist_ok=True, parents=True)
|
201
|
-
for t_subject in
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
162
|
+
for t_subject, t_session, t_task in product(
|
163
|
+
range(3), range(2), range(2, 4)
|
164
|
+
):
|
165
|
+
subject = f"sub{t_subject:03d}"
|
166
|
+
session = f"ses{t_session:03d}"
|
167
|
+
task = f"task{t_task:03d}"
|
168
|
+
if t_subject != 2:
|
169
|
+
(tmpdir / "func" / f"{subject}.nii").touch()
|
170
|
+
(tmpdir / "anat" / f"{subject}_{session}.nii").touch()
|
171
|
+
(tmpdir / "vbm" / f"{subject}_{task}_{session}.nii").touch()
|
211
172
|
|
212
173
|
expected_elements = [
|
213
174
|
("sub000", "ses000"),
|
@@ -218,16 +179,19 @@ def test_PatternDataGrabber(tmp_path: Path) -> None:
|
|
218
179
|
("sub002", "ses001"),
|
219
180
|
]
|
220
181
|
|
221
|
-
|
182
|
+
datagrabber_third = PatternDataGrabber(
|
222
183
|
datadir=tmpdir,
|
223
|
-
types=["
|
184
|
+
types=["T1w"],
|
224
185
|
patterns={
|
225
|
-
"
|
186
|
+
"T1w": {
|
187
|
+
"pattern": "anat/{subject}_{session}.nii",
|
188
|
+
"space": "native",
|
189
|
+
},
|
226
190
|
},
|
227
191
|
replacements=["subject", "session"],
|
228
192
|
)
|
229
193
|
|
230
|
-
elements =
|
194
|
+
elements = datagrabber_third.get_elements()
|
231
195
|
assert set(elements) == set(expected_elements)
|
232
196
|
|
233
197
|
expected_elements = [
|
@@ -241,26 +205,35 @@ def test_PatternDataGrabber(tmp_path: Path) -> None:
|
|
241
205
|
("sub001", "ses001", "task003"),
|
242
206
|
]
|
243
207
|
|
244
|
-
|
208
|
+
datagrabber_fourth = PatternDataGrabber(
|
245
209
|
datadir=tmpdir,
|
246
|
-
types=["
|
210
|
+
types=["T1w", "BOLD", "VBM_GM"],
|
247
211
|
patterns={
|
248
|
-
"
|
249
|
-
|
250
|
-
|
212
|
+
"BOLD": {
|
213
|
+
"pattern": "func/{subject}.nii",
|
214
|
+
"space": "MNI152NLin6Asym",
|
215
|
+
},
|
216
|
+
"T1w": {
|
217
|
+
"pattern": "anat/{subject}_{session}.nii",
|
218
|
+
"space": "native",
|
219
|
+
},
|
220
|
+
"VBM_GM": {
|
221
|
+
"pattern": "vbm/{subject}_{task}_{session}.nii",
|
222
|
+
"space": "MNI152NLin6Asym",
|
223
|
+
},
|
251
224
|
},
|
252
225
|
replacements=["subject", "session", "task"],
|
253
226
|
)
|
254
227
|
|
255
|
-
elements =
|
228
|
+
elements = datagrabber_fourth.get_elements()
|
256
229
|
assert set(elements) == set(expected_elements)
|
257
230
|
|
258
|
-
out1 =
|
259
|
-
out2 =
|
231
|
+
out1 = datagrabber_fourth[("sub000", "ses000", "task002")]
|
232
|
+
out2 = datagrabber_fourth[("sub000", "ses000", "task003")]
|
260
233
|
|
261
|
-
assert out1["
|
262
|
-
assert out1["
|
263
|
-
assert out1["
|
234
|
+
assert out1["BOLD"]["path"] == out2["BOLD"]["path"]
|
235
|
+
assert out1["T1w"]["path"] == out2["T1w"]["path"]
|
236
|
+
assert out1["VBM_GM"]["path"] != out2["VBM_GM"]["path"]
|
264
237
|
|
265
238
|
|
266
239
|
def test_PatternDataGrabber_confounds_format_error_on_init() -> None:
|
@@ -269,40 +242,14 @@ def test_PatternDataGrabber_confounds_format_error_on_init() -> None:
|
|
269
242
|
ValueError, match="Invalid value for `confounds_format`"
|
270
243
|
):
|
271
244
|
PatternDataGrabber(
|
272
|
-
types=["
|
273
|
-
patterns={
|
245
|
+
types=["BOLD"],
|
246
|
+
patterns={
|
247
|
+
"BOLD": {
|
248
|
+
"pattern": "func/{subject}.nii",
|
249
|
+
"space": "MNI152NLin6Asym",
|
250
|
+
},
|
251
|
+
},
|
274
252
|
replacements=["subject"],
|
275
253
|
datadir="/tmp",
|
276
254
|
confounds_format="foobar",
|
277
255
|
)
|
278
|
-
|
279
|
-
|
280
|
-
def test_PatternDataGrabber_confounds_format_error_on_fetch(
|
281
|
-
tmp_path: Path,
|
282
|
-
) -> None:
|
283
|
-
"""Test PatterDataGrabber confounds format error on fetching.
|
284
|
-
|
285
|
-
Parameters
|
286
|
-
----------
|
287
|
-
tmp_path : pathlib.Path
|
288
|
-
The path to the test directory.
|
289
|
-
|
290
|
-
"""
|
291
|
-
# Create test directory path
|
292
|
-
tmpdir = tmp_path / "pattern_dg_test"
|
293
|
-
# Create final test directory
|
294
|
-
(tmpdir / "func" / "confounds").mkdir(exist_ok=True, parents=True)
|
295
|
-
# Create test confound file
|
296
|
-
(tmpdir / "func" / "confounds" / "sub-001.nii").touch()
|
297
|
-
# Initialize datagrabber
|
298
|
-
datagrabber = PatternDataGrabber(
|
299
|
-
types=["BOLD_confounds"],
|
300
|
-
patterns={"BOLD_confounds": "func/confounds/{subject}.nii"},
|
301
|
-
replacements=["subject"],
|
302
|
-
datadir=tmpdir,
|
303
|
-
)
|
304
|
-
# Check error on fetch
|
305
|
-
with pytest.raises(
|
306
|
-
ValueError, match="As the DataGrabber used specifies 'BOLD_confounds'"
|
307
|
-
):
|
308
|
-
datagrabber.get_item(subject="sub-001")
|
@@ -43,8 +43,14 @@ def test_bids_PatternDataladDataGrabber() -> None:
|
|
43
43
|
types = ["T1w", "BOLD"]
|
44
44
|
# Define patterns
|
45
45
|
patterns = {
|
46
|
-
"T1w":
|
47
|
-
|
46
|
+
"T1w": {
|
47
|
+
"pattern": "{subject}/anat/{subject}_T1w.nii.gz",
|
48
|
+
"space": "MNI152NLin6Asym",
|
49
|
+
},
|
50
|
+
"BOLD": {
|
51
|
+
"pattern": "{subject}/func/{subject}_task-rest_bold.nii.gz",
|
52
|
+
"space": "MNI152NLin6Asym",
|
53
|
+
},
|
48
54
|
}
|
49
55
|
# Define replacements
|
50
56
|
replacements = ["subject"]
|
@@ -92,31 +98,28 @@ def test_bids_PatternDataladDataGrabber() -> None:
|
|
92
98
|
|
93
99
|
def test_bids_PatternDataladDataGrabber_datadir() -> None:
|
94
100
|
"""Test PatternDataladDataGrabber with a datadir set to a relative path."""
|
95
|
-
# Define types
|
96
|
-
types = ["T1w", "BOLD"]
|
97
101
|
# Define patterns
|
98
102
|
patterns = {
|
99
|
-
"T1w":
|
100
|
-
|
103
|
+
"T1w": {
|
104
|
+
"pattern": "{subject}/anat/{subject}_T*w.nii.gz",
|
105
|
+
"space": "MNI152NLin6Asym",
|
106
|
+
},
|
107
|
+
"BOLD": {
|
108
|
+
"pattern": "{subject}/func/{subject}_task-rest_*.nii.gz",
|
109
|
+
"space": "MNI152NLin6Asym",
|
110
|
+
},
|
101
111
|
}
|
102
|
-
# Define
|
103
|
-
replacements = ["subject"]
|
104
|
-
|
105
|
-
repo_uri = _testing_dataset["example_bids"]["uri"]
|
106
|
-
|
112
|
+
# Define datadir
|
107
113
|
datadir = "dataset" # use string and not absolute path
|
108
|
-
patterns = {
|
109
|
-
"T1w": "example_bids/{subject}/anat/{subject}_T*w.nii.gz",
|
110
|
-
"BOLD": "example_bids/{subject}/func/{subject}_task-rest_*.nii.gz",
|
111
|
-
}
|
112
114
|
with PatternDataladDataGrabber(
|
113
|
-
uri=
|
114
|
-
types=
|
115
|
+
uri=_testing_dataset["example_bids"]["uri"],
|
116
|
+
types=["T1w", "BOLD"],
|
115
117
|
patterns=patterns,
|
116
118
|
datadir=datadir,
|
117
|
-
|
119
|
+
rootdir="example_bids",
|
120
|
+
replacements=["subject"],
|
118
121
|
) as dg:
|
119
|
-
assert dg.datadir == Path(datadir)
|
122
|
+
assert dg.datadir == Path(datadir) / "example_bids"
|
120
123
|
for elem in dg:
|
121
124
|
t_sub = dg[elem]
|
122
125
|
assert "path" in t_sub["T1w"]
|
@@ -133,12 +136,23 @@ def test_bids_PatternDataladDataGrabber_session():
|
|
133
136
|
"""Test a subject and session-based BIDS PatternDataladDataGrabber."""
|
134
137
|
types = ["T1w", "BOLD"]
|
135
138
|
patterns = {
|
136
|
-
"T1w":
|
137
|
-
|
138
|
-
|
139
|
+
"T1w": {
|
140
|
+
"pattern": (
|
141
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
142
|
+
),
|
143
|
+
"space": "MNI152NLin6Asym",
|
144
|
+
},
|
145
|
+
"BOLD": {
|
146
|
+
"pattern": (
|
147
|
+
"{subject}/{session}/func/"
|
148
|
+
"{subject}_{session}_task-rest_bold.nii.gz"
|
149
|
+
),
|
150
|
+
"space": "MNI152NLin6Asym",
|
151
|
+
},
|
139
152
|
}
|
140
153
|
replacements = ["subject", "session"]
|
141
154
|
|
155
|
+
# Check error
|
142
156
|
with pytest.raises(ValueError, match=r"`uri` must be provided"):
|
143
157
|
PatternDataladDataGrabber(
|
144
158
|
datadir=None,
|
@@ -147,9 +161,9 @@ def test_bids_PatternDataladDataGrabber_session():
|
|
147
161
|
replacements=replacements,
|
148
162
|
)
|
149
163
|
|
164
|
+
# Set parameters
|
150
165
|
repo_uri = _testing_dataset["example_bids_ses"]["uri"]
|
151
166
|
rootdir = "example_bids_ses"
|
152
|
-
# repo_commit = _testing_dataset['example_bids_ses']['id']
|
153
167
|
|
154
168
|
# With T1W and bold, only 2 sessions are available
|
155
169
|
with PatternDataladDataGrabber(
|
@@ -159,7 +173,7 @@ def test_bids_PatternDataladDataGrabber_session():
|
|
159
173
|
patterns=patterns,
|
160
174
|
replacements=replacements,
|
161
175
|
) as dg:
|
162
|
-
subs = list(dg)
|
176
|
+
subs = list(dg.get_elements())
|
163
177
|
expected_subs = [
|
164
178
|
(f"sub-{i:02d}", f"ses-{j:02d}")
|
165
179
|
for j in range(1, 3)
|
@@ -170,7 +184,12 @@ def test_bids_PatternDataladDataGrabber_session():
|
|
170
184
|
# Test with a different T1w only, it should have 3 sessions
|
171
185
|
types = ["T1w"]
|
172
186
|
patterns = {
|
173
|
-
"T1w":
|
187
|
+
"T1w": {
|
188
|
+
"pattern": (
|
189
|
+
"{subject}/{session}/anat/{subject}_{session}_T1w.nii.gz"
|
190
|
+
),
|
191
|
+
"space": "MNI152NLin6Asym",
|
192
|
+
},
|
174
193
|
}
|
175
194
|
with PatternDataladDataGrabber(
|
176
195
|
rootdir=rootdir,
|