junifer 0.0.5.dev208__py3-none-any.whl → 0.0.5.dev240__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/datagrabber/__init__.py +2 -0
- junifer/datagrabber/base.py +10 -6
- junifer/datagrabber/hcp1200/hcp1200.py +1 -1
- junifer/datagrabber/multiple.py +42 -6
- junifer/datagrabber/pattern.py +33 -10
- junifer/datagrabber/pattern_validation_mixin.py +388 -0
- junifer/datagrabber/tests/test_multiple.py +161 -84
- junifer/datagrabber/tests/{test_datagrabber_utils.py → test_pattern_validation_mixin.py} +133 -108
- junifer/external/nilearn/__init__.py +2 -1
- junifer/external/nilearn/junifer_connectivity_measure.py +483 -0
- junifer/external/nilearn/tests/test_junifer_connectivity_measure.py +1089 -0
- junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py +25 -13
- junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +26 -22
- junifer/markers/functional_connectivity/edge_functional_connectivity_spheres.py +33 -27
- junifer/markers/functional_connectivity/functional_connectivity_base.py +42 -30
- junifer/markers/functional_connectivity/functional_connectivity_parcels.py +25 -19
- junifer/markers/functional_connectivity/functional_connectivity_spheres.py +31 -24
- junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py +3 -3
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_parcels.py +21 -4
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_spheres.py +22 -9
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +29 -8
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +30 -61
- junifer/utils/__init__.py +2 -1
- junifer/utils/helpers.py +30 -2
- junifer/utils/logging.py +18 -1
- junifer/utils/tests/test_logging.py +8 -0
- {junifer-0.0.5.dev208.dist-info → junifer-0.0.5.dev240.dist-info}/METADATA +1 -1
- {junifer-0.0.5.dev208.dist-info → junifer-0.0.5.dev240.dist-info}/RECORD +34 -32
- junifer/datagrabber/utils.py +0 -317
- {junifer-0.0.5.dev208.dist-info → junifer-0.0.5.dev240.dist-info}/AUTHORS.rst +0 -0
- {junifer-0.0.5.dev208.dist-info → junifer-0.0.5.dev240.dist-info}/LICENSE.md +0 -0
- {junifer-0.0.5.dev208.dist-info → junifer-0.0.5.dev240.dist-info}/WHEEL +0 -0
- {junifer-0.0.5.dev208.dist-info → junifer-0.0.5.dev240.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.5.dev208.dist-info → junifer-0.0.5.dev240.dist-info}/top_level.txt +0 -0
junifer/datagrabber/utils.py
DELETED
@@ -1,317 +0,0 @@
|
|
1
|
-
"""Provide utility functions for the datagrabber sub-package."""
|
2
|
-
|
3
|
-
# Authors: Federico Raimondo <f.raimondo@fz-juelich.de>
|
4
|
-
# Synchon Mandal <s.mandal@fz-juelich.de>
|
5
|
-
# License: AGPL
|
6
|
-
|
7
|
-
from typing import Dict, List
|
8
|
-
|
9
|
-
from ..utils import logger, raise_error
|
10
|
-
|
11
|
-
|
12
|
-
__all__ = ["validate_types", "validate_replacements", "validate_patterns"]
|
13
|
-
|
14
|
-
|
15
|
-
# Define schema for pattern-based datagrabber's patterns
|
16
|
-
PATTERNS_SCHEMA = {
|
17
|
-
"T1w": {
|
18
|
-
"mandatory": ["pattern", "space"],
|
19
|
-
"optional": {
|
20
|
-
"mask": {"mandatory": ["pattern", "space"], "optional": []},
|
21
|
-
},
|
22
|
-
},
|
23
|
-
"T2w": {
|
24
|
-
"mandatory": ["pattern", "space"],
|
25
|
-
"optional": {
|
26
|
-
"mask": {"mandatory": ["pattern", "space"], "optional": []},
|
27
|
-
},
|
28
|
-
},
|
29
|
-
"BOLD": {
|
30
|
-
"mandatory": ["pattern", "space"],
|
31
|
-
"optional": {
|
32
|
-
"mask": {"mandatory": ["pattern", "space"], "optional": []},
|
33
|
-
"confounds": {
|
34
|
-
"mandatory": ["pattern", "format"],
|
35
|
-
"optional": ["mappings"],
|
36
|
-
},
|
37
|
-
},
|
38
|
-
},
|
39
|
-
"Warp": {
|
40
|
-
"mandatory": ["pattern", "src", "dst"],
|
41
|
-
"optional": {},
|
42
|
-
},
|
43
|
-
"VBM_GM": {
|
44
|
-
"mandatory": ["pattern", "space"],
|
45
|
-
"optional": {},
|
46
|
-
},
|
47
|
-
"VBM_WM": {
|
48
|
-
"mandatory": ["pattern", "space"],
|
49
|
-
"optional": {},
|
50
|
-
},
|
51
|
-
"VBM_CSF": {
|
52
|
-
"mandatory": ["pattern", "space"],
|
53
|
-
"optional": {},
|
54
|
-
},
|
55
|
-
"DWI": {
|
56
|
-
"mandatory": ["pattern"],
|
57
|
-
"optional": {},
|
58
|
-
},
|
59
|
-
"FreeSurfer": {
|
60
|
-
"mandatory": ["pattern"],
|
61
|
-
"optional": {
|
62
|
-
"aseg": {"mandatory": ["pattern"], "optional": []},
|
63
|
-
"norm": {"mandatory": ["pattern"], "optional": []},
|
64
|
-
"lh_white": {"mandatory": ["pattern"], "optional": []},
|
65
|
-
"rh_white": {"mandatory": ["pattern"], "optional": []},
|
66
|
-
"lh_pial": {"mandatory": ["pattern"], "optional": []},
|
67
|
-
"rh_pial": {"mandatory": ["pattern"], "optional": []},
|
68
|
-
},
|
69
|
-
},
|
70
|
-
}
|
71
|
-
|
72
|
-
|
73
|
-
def validate_types(types: List[str]) -> None:
|
74
|
-
"""Validate the types.
|
75
|
-
|
76
|
-
Parameters
|
77
|
-
----------
|
78
|
-
types : list of str
|
79
|
-
The object to validate.
|
80
|
-
|
81
|
-
Raises
|
82
|
-
------
|
83
|
-
TypeError
|
84
|
-
If ``types`` is not a list or if the values are not string.
|
85
|
-
|
86
|
-
"""
|
87
|
-
if not isinstance(types, list):
|
88
|
-
raise_error(msg="`types` must be a list", klass=TypeError)
|
89
|
-
if any(not isinstance(x, str) for x in types):
|
90
|
-
raise_error(msg="`types` must be a list of strings", klass=TypeError)
|
91
|
-
|
92
|
-
|
93
|
-
def validate_replacements(
|
94
|
-
replacements: List[str], patterns: Dict[str, Dict[str, str]]
|
95
|
-
) -> None:
|
96
|
-
"""Validate the replacements.
|
97
|
-
|
98
|
-
Parameters
|
99
|
-
----------
|
100
|
-
replacements : list of str
|
101
|
-
The object to validate.
|
102
|
-
patterns : dict
|
103
|
-
The patterns to validate against.
|
104
|
-
|
105
|
-
Raises
|
106
|
-
------
|
107
|
-
TypeError
|
108
|
-
If ``replacements`` is not a list or if the values are not string.
|
109
|
-
ValueError
|
110
|
-
If a value in ``replacements`` is not part of a data type pattern or
|
111
|
-
if no data type patterns contain all values in ``replacements``.
|
112
|
-
|
113
|
-
"""
|
114
|
-
if not isinstance(replacements, list):
|
115
|
-
raise_error(msg="`replacements` must be a list.", klass=TypeError)
|
116
|
-
|
117
|
-
if any(not isinstance(x, str) for x in replacements):
|
118
|
-
raise_error(
|
119
|
-
msg="`replacements` must be a list of strings.", klass=TypeError
|
120
|
-
)
|
121
|
-
|
122
|
-
for x in replacements:
|
123
|
-
if all(
|
124
|
-
x not in y
|
125
|
-
for y in [
|
126
|
-
data_type_val["pattern"] for data_type_val in patterns.values()
|
127
|
-
]
|
128
|
-
):
|
129
|
-
raise_error(msg=f"Replacement: {x} is not part of any pattern.")
|
130
|
-
|
131
|
-
# Check that at least one pattern has all the replacements
|
132
|
-
at_least_one = False
|
133
|
-
for data_type_val in patterns.values():
|
134
|
-
if all(x in data_type_val["pattern"] for x in replacements):
|
135
|
-
at_least_one = True
|
136
|
-
if at_least_one is False:
|
137
|
-
raise_error(msg="At least one pattern must contain all replacements.")
|
138
|
-
|
139
|
-
|
140
|
-
def _validate_mandatory_keys(
|
141
|
-
keys: List[str], schema: List[str], data_type: str
|
142
|
-
) -> None:
|
143
|
-
"""Validate mandatory keys.
|
144
|
-
|
145
|
-
Parameters
|
146
|
-
----------
|
147
|
-
keys : list of str
|
148
|
-
The keys to validate.
|
149
|
-
schema : list of str
|
150
|
-
The schema to validate against.
|
151
|
-
data_type : str
|
152
|
-
The data type being validated.
|
153
|
-
|
154
|
-
Raises
|
155
|
-
------
|
156
|
-
KeyError
|
157
|
-
If any mandatory key is missing for a data type.
|
158
|
-
|
159
|
-
"""
|
160
|
-
for key in schema:
|
161
|
-
if key not in keys:
|
162
|
-
raise_error(
|
163
|
-
msg=f"Mandatory key: `{key}` missing for {data_type}",
|
164
|
-
klass=KeyError,
|
165
|
-
)
|
166
|
-
else:
|
167
|
-
logger.debug(f"Mandatory key: `{key}` found for {data_type}")
|
168
|
-
|
169
|
-
|
170
|
-
def _identify_stray_keys(
|
171
|
-
keys: List[str], schema: List[str], data_type: str
|
172
|
-
) -> None:
|
173
|
-
"""Identify stray keys.
|
174
|
-
|
175
|
-
Parameters
|
176
|
-
----------
|
177
|
-
keys : list of str
|
178
|
-
The keys to check.
|
179
|
-
schema : list of str
|
180
|
-
The schema to check against.
|
181
|
-
data_type : str
|
182
|
-
The data type being checked.
|
183
|
-
|
184
|
-
Raises
|
185
|
-
------
|
186
|
-
RuntimeError
|
187
|
-
If an unknown key is found for a data type.
|
188
|
-
|
189
|
-
"""
|
190
|
-
for key in keys:
|
191
|
-
if key not in schema:
|
192
|
-
raise_error(
|
193
|
-
msg=(
|
194
|
-
f"Key: {key} not accepted for {data_type} "
|
195
|
-
"pattern, remove it to proceed"
|
196
|
-
),
|
197
|
-
klass=RuntimeError,
|
198
|
-
)
|
199
|
-
|
200
|
-
|
201
|
-
def validate_patterns(
|
202
|
-
types: List[str], patterns: Dict[str, Dict[str, str]]
|
203
|
-
) -> None:
|
204
|
-
"""Validate the patterns.
|
205
|
-
|
206
|
-
Parameters
|
207
|
-
----------
|
208
|
-
types : list of str
|
209
|
-
The types list.
|
210
|
-
patterns : dict
|
211
|
-
The object to validate.
|
212
|
-
|
213
|
-
Raises
|
214
|
-
------
|
215
|
-
TypeError
|
216
|
-
If ``patterns`` is not a dictionary.
|
217
|
-
ValueError
|
218
|
-
If length of ``types`` and ``patterns`` are different or
|
219
|
-
if ``patterns`` is missing entries from ``types`` or
|
220
|
-
if unknown data type is found in ``patterns`` or
|
221
|
-
if data type pattern key contains '*' as value.
|
222
|
-
|
223
|
-
"""
|
224
|
-
# Validate the types
|
225
|
-
validate_types(types)
|
226
|
-
if not isinstance(patterns, dict):
|
227
|
-
raise_error(msg="`patterns` must be a dict.", klass=TypeError)
|
228
|
-
# Unequal length of objects
|
229
|
-
if len(types) > len(patterns):
|
230
|
-
raise_error(
|
231
|
-
msg="Length of `types` more than that of `patterns`.",
|
232
|
-
klass=ValueError,
|
233
|
-
)
|
234
|
-
# Missing type in patterns
|
235
|
-
if any(x not in patterns for x in types):
|
236
|
-
raise_error(
|
237
|
-
msg="`patterns` must contain all `types`", klass=ValueError
|
238
|
-
)
|
239
|
-
# Check against schema
|
240
|
-
for data_type_key, data_type_val in patterns.items():
|
241
|
-
# Check if valid data type is provided
|
242
|
-
if data_type_key not in PATTERNS_SCHEMA:
|
243
|
-
raise_error(
|
244
|
-
f"Unknown data type: {data_type_key}, "
|
245
|
-
f"should be one of: {list(PATTERNS_SCHEMA.keys())}"
|
246
|
-
)
|
247
|
-
# Check mandatory keys for data type
|
248
|
-
_validate_mandatory_keys(
|
249
|
-
keys=list(data_type_val),
|
250
|
-
schema=PATTERNS_SCHEMA[data_type_key]["mandatory"],
|
251
|
-
data_type=data_type_key,
|
252
|
-
)
|
253
|
-
# Check optional keys for data type
|
254
|
-
for optional_key, optional_val in PATTERNS_SCHEMA[data_type_key][
|
255
|
-
"optional"
|
256
|
-
].items():
|
257
|
-
if optional_key not in data_type_val:
|
258
|
-
logger.debug(
|
259
|
-
f"Optional key: `{optional_key}` missing for "
|
260
|
-
f"{data_type_key}"
|
261
|
-
)
|
262
|
-
else:
|
263
|
-
logger.debug(
|
264
|
-
f"Optional key: `{optional_key}` found for "
|
265
|
-
f"{data_type_key}"
|
266
|
-
)
|
267
|
-
# Set nested type name for easier access
|
268
|
-
nested_data_type = f"{data_type_key}.{optional_key}"
|
269
|
-
nested_mandatory_keys_schema = PATTERNS_SCHEMA[data_type_key][
|
270
|
-
"optional"
|
271
|
-
][optional_key]["mandatory"]
|
272
|
-
nested_optional_keys_schema = PATTERNS_SCHEMA[data_type_key][
|
273
|
-
"optional"
|
274
|
-
][optional_key]["optional"]
|
275
|
-
# Check mandatory keys for nested type
|
276
|
-
_validate_mandatory_keys(
|
277
|
-
keys=list(optional_val["mandatory"]),
|
278
|
-
schema=nested_mandatory_keys_schema,
|
279
|
-
data_type=nested_data_type,
|
280
|
-
)
|
281
|
-
# Check optional keys for nested type
|
282
|
-
for nested_optional_key in nested_optional_keys_schema:
|
283
|
-
if nested_optional_key not in optional_val["optional"]:
|
284
|
-
logger.debug(
|
285
|
-
f"Optional key: `{nested_optional_key}` missing "
|
286
|
-
f"for {nested_data_type}"
|
287
|
-
)
|
288
|
-
else:
|
289
|
-
logger.debug(
|
290
|
-
f"Optional key: `{nested_optional_key}` found for "
|
291
|
-
f"{nested_data_type}"
|
292
|
-
)
|
293
|
-
# Check stray key for nested data type
|
294
|
-
_identify_stray_keys(
|
295
|
-
keys=optional_val["mandatory"] + optional_val["optional"],
|
296
|
-
schema=nested_mandatory_keys_schema
|
297
|
-
+ nested_optional_keys_schema,
|
298
|
-
data_type=nested_data_type,
|
299
|
-
)
|
300
|
-
# Check stray key for data type
|
301
|
-
_identify_stray_keys(
|
302
|
-
keys=list(data_type_val.keys()),
|
303
|
-
schema=(
|
304
|
-
PATTERNS_SCHEMA[data_type_key]["mandatory"]
|
305
|
-
+ list(PATTERNS_SCHEMA[data_type_key]["optional"].keys())
|
306
|
-
),
|
307
|
-
data_type=data_type_key,
|
308
|
-
)
|
309
|
-
# Wildcard check in patterns
|
310
|
-
if "}*" in data_type_val["pattern"]:
|
311
|
-
raise_error(
|
312
|
-
msg=(
|
313
|
-
f"`{data_type_key}.pattern` must not contain `*` "
|
314
|
-
"following a replacement"
|
315
|
-
),
|
316
|
-
klass=ValueError,
|
317
|
-
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|