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
@@ -7,74 +7,60 @@
|
|
7
7
|
from abc import abstractmethod
|
8
8
|
from typing import Any, ClassVar, Dict, List, Optional, Set, Union
|
9
9
|
|
10
|
-
from
|
10
|
+
from nilearn.connectome import ConnectivityMeasure
|
11
|
+
from sklearn.covariance import EmpiricalCovariance
|
11
12
|
|
12
|
-
from ...external.nilearn import JuniferConnectivityMeasure
|
13
13
|
from ...utils import raise_error
|
14
14
|
from ..base import BaseMarker
|
15
15
|
|
16
16
|
|
17
|
-
__all__ = ["FunctionalConnectivityBase"]
|
18
|
-
|
19
|
-
|
20
17
|
class FunctionalConnectivityBase(BaseMarker):
|
21
18
|
"""Abstract base class for functional connectivity markers.
|
22
19
|
|
23
20
|
Parameters
|
24
21
|
----------
|
25
22
|
agg_method : str, optional
|
26
|
-
The method to perform aggregation using.
|
27
|
-
|
28
|
-
(default "mean").
|
23
|
+
The method to perform aggregation using. Check valid options in
|
24
|
+
:func:`.get_aggfunc_by_name` (default "mean").
|
29
25
|
agg_method_params : dict, optional
|
30
|
-
Parameters to pass to the aggregation function.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
If None, ``{"empirical": True}`` will be used, which would mean
|
40
|
-
:class:`sklearn.covariance.EmpiricalCovariance` is used to compute
|
41
|
-
covariance. If usage of :class:`sklearn.covariance.LedoitWolf` is
|
42
|
-
desired, ``{"empirical": False}`` should be passed
|
43
|
-
(default None).
|
26
|
+
Parameters to pass to the aggregation function. Check valid options in
|
27
|
+
:func:`.get_aggfunc_by_name` (default None).
|
28
|
+
cor_method : str, optional
|
29
|
+
The method to perform correlation using. Check valid options in
|
30
|
+
:class:`nilearn.connectome.ConnectivityMeasure`
|
31
|
+
(default "covariance").
|
32
|
+
cor_method_params : dict, optional
|
33
|
+
Parameters to pass to the correlation function. Check valid options in
|
34
|
+
:class:`nilearn.connectome.ConnectivityMeasure` (default None).
|
44
35
|
masks : str, dict or list of dict or str, optional
|
45
36
|
The specification of the masks to apply to regions before extracting
|
46
37
|
signals. Check :ref:`Using Masks <using_masks>` for more details.
|
47
38
|
If None, will not apply any mask (default None).
|
48
39
|
name : str, optional
|
49
|
-
The name of the marker. If None, will use
|
50
|
-
|
40
|
+
The name of the marker. If None, will use the class name (default
|
41
|
+
None).
|
51
42
|
|
52
43
|
"""
|
53
44
|
|
54
45
|
_DEPENDENCIES: ClassVar[Set[str]] = {"nilearn", "scikit-learn"}
|
55
46
|
|
56
|
-
_MARKER_INOUT_MAPPINGS: ClassVar[Dict[str, Dict[str, str]]] = {
|
57
|
-
"BOLD": {
|
58
|
-
"functional_connectivity": "matrix",
|
59
|
-
},
|
60
|
-
}
|
61
|
-
|
62
47
|
def __init__(
|
63
48
|
self,
|
64
49
|
agg_method: str = "mean",
|
65
50
|
agg_method_params: Optional[Dict] = None,
|
66
|
-
|
67
|
-
|
51
|
+
cor_method: str = "covariance",
|
52
|
+
cor_method_params: Optional[Dict] = None,
|
68
53
|
masks: Union[str, Dict, List[Union[Dict, str]], None] = None,
|
69
54
|
name: Optional[str] = None,
|
70
55
|
) -> None:
|
71
56
|
self.agg_method = agg_method
|
72
57
|
self.agg_method_params = agg_method_params
|
73
|
-
self.
|
74
|
-
self.
|
75
|
-
|
76
|
-
|
77
|
-
|
58
|
+
self.cor_method = cor_method
|
59
|
+
self.cor_method_params = cor_method_params or {}
|
60
|
+
|
61
|
+
# default to nilearn behavior
|
62
|
+
self.cor_method_params["empirical"] = self.cor_method_params.get(
|
63
|
+
"empirical", False
|
78
64
|
)
|
79
65
|
self.masks = masks
|
80
66
|
super().__init__(on="BOLD", name=name)
|
@@ -91,6 +77,33 @@ class FunctionalConnectivityBase(BaseMarker):
|
|
91
77
|
klass=NotImplementedError,
|
92
78
|
)
|
93
79
|
|
80
|
+
def get_valid_inputs(self) -> List[str]:
|
81
|
+
"""Get valid data types for input.
|
82
|
+
|
83
|
+
Returns
|
84
|
+
-------
|
85
|
+
list of str
|
86
|
+
The list of data types that can be used as input for this marker.
|
87
|
+
|
88
|
+
"""
|
89
|
+
return ["BOLD"]
|
90
|
+
|
91
|
+
def get_output_type(self, input_type: str) -> str:
|
92
|
+
"""Get output type.
|
93
|
+
|
94
|
+
Parameters
|
95
|
+
----------
|
96
|
+
input_type : str
|
97
|
+
The data type input to the marker.
|
98
|
+
|
99
|
+
Returns
|
100
|
+
-------
|
101
|
+
str
|
102
|
+
The storage type output by the marker.
|
103
|
+
|
104
|
+
"""
|
105
|
+
return "matrix"
|
106
|
+
|
94
107
|
def compute(
|
95
108
|
self,
|
96
109
|
input: Dict[str, Any],
|
@@ -112,44 +125,30 @@ class FunctionalConnectivityBase(BaseMarker):
|
|
112
125
|
Returns
|
113
126
|
-------
|
114
127
|
dict
|
115
|
-
The computed result as dictionary.
|
116
|
-
|
117
|
-
with this as a parameter. The dictionary has the following keys:
|
118
|
-
|
119
|
-
* ``functional_connectivity`` : dictionary with the following keys:
|
128
|
+
The computed result as dictionary. The following keys will be
|
129
|
+
included in the dictionary:
|
120
130
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
131
|
+
* ``data`` : functional connectivity matrix as a ``numpy.ndarray``.
|
132
|
+
* ``row_names`` : row names as a list
|
133
|
+
* ``col_names`` : column names as a list
|
134
|
+
* ``matrix_kind`` : the kind of matrix (tril, triu or full)
|
125
135
|
|
126
136
|
"""
|
127
137
|
# Perform necessary aggregation
|
128
138
|
aggregation = self.aggregate(input, extra_input=extra_input)
|
129
|
-
# Set covariance estimator
|
130
|
-
if self.conn_method_params["empirical"]:
|
131
|
-
cov_estimator = EmpiricalCovariance(store_precision=False)
|
132
|
-
else:
|
133
|
-
cov_estimator = LedoitWolf(store_precision=False)
|
134
139
|
# Compute correlation
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
},
|
143
|
-
)
|
140
|
+
if self.cor_method_params["empirical"]:
|
141
|
+
connectivity = ConnectivityMeasure(
|
142
|
+
cov_estimator=EmpiricalCovariance(), # type: ignore
|
143
|
+
kind=self.cor_method,
|
144
|
+
)
|
145
|
+
else:
|
146
|
+
connectivity = ConnectivityMeasure(kind=self.cor_method)
|
144
147
|
# Create dictionary for output
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
"col_names": aggregation["aggregation"]["col_names"],
|
153
|
-
"matrix_kind": "tril",
|
154
|
-
},
|
155
|
-
}
|
148
|
+
out = {}
|
149
|
+
out["data"] = connectivity.fit_transform([aggregation["data"]])[0]
|
150
|
+
# Create column names
|
151
|
+
out["row_names"] = aggregation["col_names"]
|
152
|
+
out["col_names"] = aggregation["col_names"]
|
153
|
+
out["matrix_kind"] = "tril"
|
154
|
+
return out
|
@@ -12,9 +12,6 @@ from ..parcel_aggregation import ParcelAggregation
|
|
12
12
|
from .functional_connectivity_base import FunctionalConnectivityBase
|
13
13
|
|
14
14
|
|
15
|
-
__all__ = ["FunctionalConnectivityParcels"]
|
16
|
-
|
17
|
-
|
18
15
|
@register_marker
|
19
16
|
class FunctionalConnectivityParcels(FunctionalConnectivityBase):
|
20
17
|
"""Class for functional connectivity using parcellations.
|
@@ -22,34 +19,28 @@ class FunctionalConnectivityParcels(FunctionalConnectivityBase):
|
|
22
19
|
Parameters
|
23
20
|
----------
|
24
21
|
parcellation : str or list of str
|
25
|
-
The name(s) of the parcellation(s)
|
26
|
-
|
22
|
+
The name(s) of the parcellation(s). Check valid options by calling
|
23
|
+
:func:`.list_parcellations`.
|
27
24
|
agg_method : str, optional
|
28
|
-
The method to perform aggregation using.
|
29
|
-
|
30
|
-
(default "mean").
|
25
|
+
The method to perform aggregation using. Check valid options in
|
26
|
+
:func:`.get_aggfunc_by_name` (default "mean").
|
31
27
|
agg_method_params : dict, optional
|
32
|
-
Parameters to pass to the aggregation function.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
If None, ``{"empirical": True}`` will be used, which would mean
|
42
|
-
:class:`sklearn.covariance.EmpiricalCovariance` is used to compute
|
43
|
-
covariance. If usage of :class:`sklearn.covariance.LedoitWolf` is
|
44
|
-
desired, ``{"empirical": False}`` should be passed
|
45
|
-
(default None).
|
28
|
+
Parameters to pass to the aggregation function. Check valid options in
|
29
|
+
:func:`.get_aggfunc_by_name` (default None).
|
30
|
+
cor_method : str, optional
|
31
|
+
The method to perform correlation using. Check valid options in
|
32
|
+
:class:`nilearn.connectome.ConnectivityMeasure`
|
33
|
+
(default "covariance").
|
34
|
+
cor_method_params : dict, optional
|
35
|
+
Parameters to pass to the correlation function. Check valid options in
|
36
|
+
:class:`nilearn.connectome.ConnectivityMeasure` (default None).
|
46
37
|
masks : str, dict or list of dict or str, optional
|
47
38
|
The specification of the masks to apply to regions before extracting
|
48
39
|
signals. Check :ref:`Using Masks <using_masks>` for more details.
|
49
40
|
If None, will not apply any mask (default None).
|
50
41
|
name : str, optional
|
51
|
-
The name of the marker. If None, will use
|
52
|
-
|
42
|
+
The name of the marker. If None, will use the class name (default
|
43
|
+
None).
|
53
44
|
|
54
45
|
"""
|
55
46
|
|
@@ -58,8 +49,8 @@ class FunctionalConnectivityParcels(FunctionalConnectivityBase):
|
|
58
49
|
parcellation: Union[str, List[str]],
|
59
50
|
agg_method: str = "mean",
|
60
51
|
agg_method_params: Optional[Dict] = None,
|
61
|
-
|
62
|
-
|
52
|
+
cor_method: str = "covariance",
|
53
|
+
cor_method_params: Optional[Dict] = None,
|
63
54
|
masks: Union[str, Dict, List[Union[Dict, str]], None] = None,
|
64
55
|
name: Optional[str] = None,
|
65
56
|
) -> None:
|
@@ -67,8 +58,8 @@ class FunctionalConnectivityParcels(FunctionalConnectivityBase):
|
|
67
58
|
super().__init__(
|
68
59
|
agg_method=agg_method,
|
69
60
|
agg_method_params=agg_method_params,
|
70
|
-
|
71
|
-
|
61
|
+
cor_method=cor_method,
|
62
|
+
cor_method_params=cor_method_params,
|
72
63
|
masks=masks,
|
73
64
|
name=name,
|
74
65
|
)
|
@@ -96,16 +87,16 @@ class FunctionalConnectivityParcels(FunctionalConnectivityBase):
|
|
96
87
|
to the user or stored in the storage by calling the store method
|
97
88
|
with this as a parameter. The dictionary has the following keys:
|
98
89
|
|
99
|
-
* ``
|
100
|
-
|
101
|
-
- ``data`` : ROI values as ``numpy.ndarray``
|
102
|
-
- ``col_names`` : ROI labels as list of str
|
90
|
+
* ``data`` : the actual computed values as a numpy.ndarray
|
91
|
+
* ``col_names`` : the column labels for the computed values as list
|
103
92
|
|
104
93
|
"""
|
105
|
-
|
94
|
+
parcel_aggregation = ParcelAggregation(
|
106
95
|
parcellation=self.parcellation,
|
107
96
|
method=self.agg_method,
|
108
97
|
method_params=self.agg_method_params,
|
109
98
|
masks=self.masks,
|
110
99
|
on="BOLD",
|
111
|
-
)
|
100
|
+
)
|
101
|
+
# Return the 2D timeseries after parcel aggregation
|
102
|
+
return parcel_aggregation.compute(input, extra_input=extra_input)
|
@@ -13,9 +13,6 @@ from ..utils import raise_error
|
|
13
13
|
from .functional_connectivity_base import FunctionalConnectivityBase
|
14
14
|
|
15
15
|
|
16
|
-
__all__ = ["FunctionalConnectivitySpheres"]
|
17
|
-
|
18
|
-
|
19
16
|
@register_marker
|
20
17
|
class FunctionalConnectivitySpheres(FunctionalConnectivityBase):
|
21
18
|
"""Class for functional connectivity using coordinates (spheres).
|
@@ -23,42 +20,35 @@ class FunctionalConnectivitySpheres(FunctionalConnectivityBase):
|
|
23
20
|
Parameters
|
24
21
|
----------
|
25
22
|
coords : str
|
26
|
-
The name of the coordinates list to use.
|
27
|
-
|
28
|
-
radius :
|
29
|
-
The radius of the sphere
|
30
|
-
|
31
|
-
|
32
|
-
(default None).
|
23
|
+
The name of the coordinates list to use. See
|
24
|
+
:func:`.list_coordinates` for options.
|
25
|
+
radius : float, optional
|
26
|
+
The radius of the sphere in mm. If None, the signal will be extracted
|
27
|
+
from a single voxel. See :class:`nilearn.maskers.NiftiSpheresMasker`
|
28
|
+
for more information (default None).
|
33
29
|
allow_overlap : bool, optional
|
34
30
|
Whether to allow overlapping spheres. If False, an error is raised if
|
35
|
-
the spheres overlap (default False).
|
31
|
+
the spheres overlap (default is False).
|
36
32
|
agg_method : str, optional
|
37
|
-
The method to
|
38
|
-
See :func:`.get_aggfunc_by_name` for
|
39
|
-
(default "mean").
|
40
|
-
agg_method_params : dict, optional
|
41
|
-
Parameters to pass to the aggregation function.
|
42
|
-
See :func:`.get_aggfunc_by_name` for options
|
43
|
-
(default None).
|
44
|
-
conn_method : str, optional
|
45
|
-
The method to perform connectivity measure using.
|
46
|
-
See :class:`.JuniferConnectivityMeasure` for options
|
47
|
-
(default "correlation").
|
48
|
-
conn_method_params : dict, optional
|
49
|
-
Parameters to pass to :class:`.JuniferConnectivityMeasure`.
|
50
|
-
If None, ``{"empirical": True}`` will be used, which would mean
|
51
|
-
:class:`sklearn.covariance.EmpiricalCovariance` is used to compute
|
52
|
-
covariance. If usage of :class:`sklearn.covariance.LedoitWolf` is
|
53
|
-
desired, ``{"empirical": False}`` should be passed
|
33
|
+
The aggregation method to use.
|
34
|
+
See :func:`.get_aggfunc_by_name` for more information
|
54
35
|
(default None).
|
36
|
+
agg_method_params : dict, optional
|
37
|
+
The parameters to pass to the aggregation method (default None).
|
38
|
+
cor_method : str, optional
|
39
|
+
The method to perform correlation using. Check valid options in
|
40
|
+
:class:`nilearn.connectome.ConnectivityMeasure` (default "covariance").
|
41
|
+
cor_method_params : dict, optional
|
42
|
+
Parameters to pass to the correlation function. Check valid options in
|
43
|
+
:class:`nilearn.connectome.ConnectivityMeasure` (default None).
|
55
44
|
masks : str, dict or list of dict or str, optional
|
56
45
|
The specification of the masks to apply to regions before extracting
|
57
46
|
signals. Check :ref:`Using Masks <using_masks>` for more details.
|
58
47
|
If None, will not apply any mask (default None).
|
59
48
|
name : str, optional
|
60
|
-
The name of the marker.
|
61
|
-
|
49
|
+
The name of the marker. By default, it will use
|
50
|
+
KIND_FunctionalConnectivitySpheres where KIND is the kind of data it
|
51
|
+
was applied to (default None).
|
62
52
|
|
63
53
|
"""
|
64
54
|
|
@@ -69,8 +59,8 @@ class FunctionalConnectivitySpheres(FunctionalConnectivityBase):
|
|
69
59
|
allow_overlap: bool = False,
|
70
60
|
agg_method: str = "mean",
|
71
61
|
agg_method_params: Optional[Dict] = None,
|
72
|
-
|
73
|
-
|
62
|
+
cor_method: str = "covariance",
|
63
|
+
cor_method_params: Optional[Dict] = None,
|
74
64
|
masks: Union[str, Dict, List[Union[Dict, str]], None] = None,
|
75
65
|
name: Optional[str] = None,
|
76
66
|
) -> None:
|
@@ -82,8 +72,8 @@ class FunctionalConnectivitySpheres(FunctionalConnectivityBase):
|
|
82
72
|
super().__init__(
|
83
73
|
agg_method=agg_method,
|
84
74
|
agg_method_params=agg_method_params,
|
85
|
-
|
86
|
-
|
75
|
+
cor_method=cor_method,
|
76
|
+
cor_method_params=cor_method_params,
|
87
77
|
masks=masks,
|
88
78
|
name=name,
|
89
79
|
)
|
@@ -111,13 +101,11 @@ class FunctionalConnectivitySpheres(FunctionalConnectivityBase):
|
|
111
101
|
to the user or stored in the storage by calling the store method
|
112
102
|
with this as a parameter. The dictionary has the following keys:
|
113
103
|
|
114
|
-
* ``
|
115
|
-
|
116
|
-
- ``data`` : ROI values as ``numpy.ndarray``
|
117
|
-
- ``col_names`` : ROI labels as list of str
|
104
|
+
* ``data`` : the actual computed values as a numpy.ndarray
|
105
|
+
* ``col_names`` : the column labels for the computed values as list
|
118
106
|
|
119
107
|
"""
|
120
|
-
|
108
|
+
sphere_aggregation = SphereAggregation(
|
121
109
|
coords=self.coords,
|
122
110
|
radius=self.radius,
|
123
111
|
allow_overlap=self.allow_overlap,
|
@@ -125,4 +113,6 @@ class FunctionalConnectivitySpheres(FunctionalConnectivityBase):
|
|
125
113
|
method_params=self.agg_method_params,
|
126
114
|
masks=self.masks,
|
127
115
|
on="BOLD",
|
128
|
-
)
|
116
|
+
)
|
117
|
+
# Return the 2D timeseries after sphere aggregation
|
118
|
+
return sphere_aggregation.compute(input, extra_input=extra_input)
|
junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py
CHANGED
@@ -27,17 +27,16 @@ def test_init() -> None:
|
|
27
27
|
CrossParcellationFC(
|
28
28
|
parcellation_one="a",
|
29
29
|
parcellation_two="a",
|
30
|
-
|
30
|
+
correlation_method="pearson",
|
31
31
|
)
|
32
32
|
|
33
33
|
|
34
34
|
def test_get_output_type() -> None:
|
35
35
|
"""Test CrossParcellationFC get_output_type()."""
|
36
|
-
|
36
|
+
crossparcellation = CrossParcellationFC(
|
37
37
|
parcellation_one=parcellation_one, parcellation_two=parcellation_two
|
38
|
-
).get_output_type(
|
39
|
-
input_type="BOLD", output_feature="functional_connectivity"
|
40
38
|
)
|
39
|
+
assert "matrix" == crossparcellation.get_output_type("BOLD")
|
41
40
|
|
42
41
|
|
43
42
|
@pytest.mark.skipif(
|
@@ -58,11 +57,9 @@ def test_compute(tmp_path: Path) -> None:
|
|
58
57
|
crossparcellation = CrossParcellationFC(
|
59
58
|
parcellation_one=parcellation_one,
|
60
59
|
parcellation_two=parcellation_two,
|
61
|
-
|
60
|
+
correlation_method="spearman",
|
62
61
|
)
|
63
|
-
out = crossparcellation.compute(element_data["BOLD"])
|
64
|
-
"functional_connectivity"
|
65
|
-
]
|
62
|
+
out = crossparcellation.compute(element_data["BOLD"])
|
66
63
|
assert out["data"].shape == (200, 100)
|
67
64
|
assert len(out["col_names"]) == 100
|
68
65
|
assert len(out["row_names"]) == 200
|
@@ -86,7 +83,7 @@ def test_store(tmp_path: Path) -> None:
|
|
86
83
|
crossparcellation = CrossParcellationFC(
|
87
84
|
parcellation_one=parcellation_one,
|
88
85
|
parcellation_two=parcellation_two,
|
89
|
-
|
86
|
+
correlation_method="spearman",
|
90
87
|
)
|
91
88
|
storage = SQLiteFeatureStorage(
|
92
89
|
uri=tmp_path / "test_crossparcellation.sqlite", upsert="ignore"
|
@@ -95,6 +92,5 @@ def test_store(tmp_path: Path) -> None:
|
|
95
92
|
crossparcellation.fit_transform(input=element_data, storage=storage)
|
96
93
|
features = storage.list_features()
|
97
94
|
assert any(
|
98
|
-
x["name"] == "
|
99
|
-
for x in features.values()
|
95
|
+
x["name"] == "BOLD_CrossParcellationFC" for x in features.values()
|
100
96
|
)
|
@@ -5,9 +5,6 @@
|
|
5
5
|
# License: AGPL
|
6
6
|
|
7
7
|
from pathlib import Path
|
8
|
-
from typing import Dict
|
9
|
-
|
10
|
-
import pytest
|
11
8
|
|
12
9
|
from junifer.datareader import DefaultDataReader
|
13
10
|
from junifer.markers.functional_connectivity import EdgeCentricFCParcels
|
@@ -15,51 +12,35 @@ from junifer.storage import SQLiteFeatureStorage
|
|
15
12
|
from junifer.testing.datagrabbers import PartlyCloudyTestingDataGrabber
|
16
13
|
|
17
14
|
|
18
|
-
|
19
|
-
"conn_method_params",
|
20
|
-
[
|
21
|
-
{"empirical": False},
|
22
|
-
{"empirical": True},
|
23
|
-
],
|
24
|
-
)
|
25
|
-
def test_EdgeCentricFCParcels(
|
26
|
-
tmp_path: Path,
|
27
|
-
conn_method_params: Dict[str, bool],
|
28
|
-
) -> None:
|
15
|
+
def test_EdgeCentricFCParcels(tmp_path: Path) -> None:
|
29
16
|
"""Test EdgeCentricFCParcels.
|
30
17
|
|
31
18
|
Parameters
|
32
19
|
----------
|
33
20
|
tmp_path : pathlib.Path
|
34
21
|
The path to the test directory.
|
35
|
-
conn_method_params : dict
|
36
|
-
The parametrized parameters to connectivity measure method.
|
37
22
|
|
38
23
|
"""
|
39
24
|
with PartlyCloudyTestingDataGrabber() as dg:
|
40
|
-
# Get element data
|
41
25
|
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
42
|
-
# Setup marker
|
43
26
|
marker = EdgeCentricFCParcels(
|
44
27
|
parcellation="TianxS1x3TxMNInonlinear2009cAsym",
|
45
|
-
|
46
|
-
conn_method_params=conn_method_params,
|
28
|
+
cor_method_params={"empirical": True},
|
47
29
|
)
|
48
30
|
# Check correct output
|
49
|
-
assert "
|
50
|
-
input_type="BOLD", output_feature="functional_connectivity"
|
51
|
-
)
|
31
|
+
assert marker.get_output_type("BOLD") == "matrix"
|
52
32
|
|
53
33
|
# Fit-transform the data
|
54
34
|
edge_fc = marker.fit_transform(element_data)
|
55
|
-
edge_fc_bold = edge_fc["BOLD"]
|
35
|
+
edge_fc_bold = edge_fc["BOLD"]
|
56
36
|
|
57
37
|
# For 16 ROIs we should get (16 * (16 -1) / 2) edges in the ETS
|
58
38
|
n_edges = int(16 * (16 - 1) / 2)
|
59
39
|
assert "data" in edge_fc_bold
|
60
40
|
assert "row_names" in edge_fc_bold
|
61
41
|
assert "col_names" in edge_fc_bold
|
62
|
-
assert edge_fc_bold["data"].shape ==
|
42
|
+
assert edge_fc_bold["data"].shape[0] == n_edges
|
43
|
+
assert edge_fc_bold["data"].shape[1] == n_edges
|
63
44
|
assert len(set(edge_fc_bold["row_names"])) == n_edges
|
64
45
|
assert len(set(edge_fc_bold["col_names"])) == n_edges
|
65
46
|
|
@@ -70,6 +51,5 @@ def test_EdgeCentricFCParcels(
|
|
70
51
|
marker.fit_transform(input=element_data, storage=storage)
|
71
52
|
features = storage.list_features()
|
72
53
|
assert any(
|
73
|
-
x["name"] == "
|
74
|
-
for x in features.values()
|
54
|
+
x["name"] == "BOLD_EdgeCentricFCParcels" for x in features.values()
|
75
55
|
)
|
@@ -5,9 +5,6 @@
|
|
5
5
|
# License: AGPL
|
6
6
|
|
7
7
|
from pathlib import Path
|
8
|
-
from typing import Dict
|
9
|
-
|
10
|
-
import pytest
|
11
8
|
|
12
9
|
from junifer.datareader import DefaultDataReader
|
13
10
|
from junifer.markers.functional_connectivity import EdgeCentricFCSpheres
|
@@ -15,45 +12,26 @@ from junifer.storage import SQLiteFeatureStorage
|
|
15
12
|
from junifer.testing.datagrabbers import SPMAuditoryTestingDataGrabber
|
16
13
|
|
17
14
|
|
18
|
-
|
19
|
-
"conn_method_params",
|
20
|
-
[
|
21
|
-
{"empirical": False},
|
22
|
-
{"empirical": True},
|
23
|
-
],
|
24
|
-
)
|
25
|
-
def test_EdgeCentricFCSpheres(
|
26
|
-
tmp_path: Path,
|
27
|
-
conn_method_params: Dict[str, bool],
|
28
|
-
) -> None:
|
15
|
+
def test_EdgeCentricFCSpheres(tmp_path: Path) -> None:
|
29
16
|
"""Test EdgeCentricFCSpheres.
|
30
17
|
|
31
18
|
Parameters
|
32
19
|
----------
|
33
20
|
tmp_path : pathlib.Path
|
34
21
|
The path to the test directory.
|
35
|
-
conn_method_params : dict
|
36
|
-
The parametrized parameters to connectivity measure method.
|
37
22
|
|
38
23
|
"""
|
39
24
|
with SPMAuditoryTestingDataGrabber() as dg:
|
40
|
-
# Get element data
|
41
25
|
element_data = DefaultDataReader().fit_transform(dg["sub001"])
|
42
|
-
# Setup marker
|
43
26
|
marker = EdgeCentricFCSpheres(
|
44
|
-
coords="DMNBuckner",
|
45
|
-
radius=5.0,
|
46
|
-
conn_method="correlation",
|
47
|
-
conn_method_params=conn_method_params,
|
27
|
+
coords="DMNBuckner", radius=5.0, cor_method="correlation"
|
48
28
|
)
|
49
29
|
# Check correct output
|
50
|
-
assert "
|
51
|
-
input_type="BOLD", output_feature="functional_connectivity"
|
52
|
-
)
|
30
|
+
assert marker.get_output_type("BOLD") == "matrix"
|
53
31
|
|
54
32
|
# Fit-transform the data
|
55
33
|
edge_fc = marker.fit_transform(element_data)
|
56
|
-
edge_fc_bold = edge_fc["BOLD"]
|
34
|
+
edge_fc_bold = edge_fc["BOLD"]
|
57
35
|
|
58
36
|
# There are six DMNBuckner coordinates, so
|
59
37
|
# for 6 ROIs we should get (6 * (6 -1) / 2) edges in the ETS
|
@@ -65,6 +43,13 @@ def test_EdgeCentricFCSpheres(
|
|
65
43
|
assert len(set(edge_fc_bold["row_names"])) == n_edges
|
66
44
|
assert len(set(edge_fc_bold["col_names"])) == n_edges
|
67
45
|
|
46
|
+
# Check empirical correlation method parameters
|
47
|
+
marker = EdgeCentricFCSpheres(
|
48
|
+
coords="DMNBuckner",
|
49
|
+
radius=5.0,
|
50
|
+
cor_method="correlation",
|
51
|
+
cor_method_params={"empirical": True},
|
52
|
+
)
|
68
53
|
# Store
|
69
54
|
storage = SQLiteFeatureStorage(
|
70
55
|
uri=tmp_path / "test_edge_fc_spheres.sqlite", upsert="ignore"
|
@@ -72,6 +57,5 @@ def test_EdgeCentricFCSpheres(
|
|
72
57
|
marker.fit_transform(input=element_data, storage=storage)
|
73
58
|
features = storage.list_features()
|
74
59
|
assert any(
|
75
|
-
x["name"] == "
|
76
|
-
for x in features.values()
|
60
|
+
x["name"] == "BOLD_EdgeCentricFCSpheres" for x in features.values()
|
77
61
|
)
|