junifer 0.0.3.dev186__py3-none-any.whl → 0.0.4__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 +14 -2
- junifer/api/cli.py +162 -17
- junifer/api/functions.py +87 -419
- junifer/api/parser.py +24 -0
- junifer/api/queue_context/__init__.py +8 -0
- junifer/api/queue_context/gnu_parallel_local_adapter.py +258 -0
- junifer/api/queue_context/htcondor_adapter.py +365 -0
- junifer/api/queue_context/queue_context_adapter.py +60 -0
- junifer/api/queue_context/tests/test_gnu_parallel_local_adapter.py +192 -0
- junifer/api/queue_context/tests/test_htcondor_adapter.py +257 -0
- junifer/api/res/afni/run_afni_docker.sh +6 -6
- junifer/api/res/ants/ResampleImage +3 -0
- junifer/api/res/ants/antsApplyTransforms +3 -0
- junifer/api/res/ants/antsApplyTransformsToPoints +3 -0
- junifer/api/res/ants/run_ants_docker.sh +39 -0
- junifer/api/res/fsl/applywarp +3 -0
- junifer/api/res/fsl/flirt +3 -0
- junifer/api/res/fsl/img2imgcoord +3 -0
- junifer/api/res/fsl/run_fsl_docker.sh +39 -0
- junifer/api/res/fsl/std2imgcoord +3 -0
- junifer/api/res/run_conda.sh +4 -4
- junifer/api/res/run_venv.sh +22 -0
- junifer/api/tests/data/partly_cloudy_agg_mean_tian.yml +16 -0
- junifer/api/tests/test_api_utils.py +21 -3
- junifer/api/tests/test_cli.py +232 -9
- junifer/api/tests/test_functions.py +211 -439
- junifer/api/tests/test_parser.py +1 -1
- 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/tests/test_ucla.py +8 -8
- junifer/configs/juseless/datagrabbers/ucla.py +44 -26
- junifer/configs/juseless/datagrabbers/ukb_vbm.py +6 -1
- junifer/data/VOIs/meta/AutobiographicalMemory_VOIs.txt +23 -0
- junifer/data/VOIs/meta/Power2013_MNI_VOIs.tsv +264 -0
- junifer/data/__init__.py +4 -0
- junifer/data/coordinates.py +298 -31
- junifer/data/masks.py +360 -28
- junifer/data/parcellations.py +621 -188
- junifer/data/template_spaces.py +190 -0
- junifer/data/tests/test_coordinates.py +34 -3
- junifer/data/tests/test_data_utils.py +1 -0
- junifer/data/tests/test_masks.py +202 -86
- junifer/data/tests/test_parcellations.py +266 -55
- junifer/data/tests/test_template_spaces.py +104 -0
- junifer/data/utils.py +4 -2
- junifer/datagrabber/__init__.py +1 -0
- junifer/datagrabber/aomic/id1000.py +111 -70
- junifer/datagrabber/aomic/piop1.py +116 -53
- junifer/datagrabber/aomic/piop2.py +116 -53
- junifer/datagrabber/aomic/tests/test_id1000.py +27 -27
- junifer/datagrabber/aomic/tests/test_piop1.py +27 -27
- junifer/datagrabber/aomic/tests/test_piop2.py +27 -27
- junifer/datagrabber/base.py +62 -10
- junifer/datagrabber/datalad_base.py +0 -2
- junifer/datagrabber/dmcc13_benchmark.py +372 -0
- junifer/datagrabber/hcp1200/datalad_hcp1200.py +5 -0
- junifer/datagrabber/hcp1200/hcp1200.py +30 -13
- junifer/datagrabber/pattern.py +133 -27
- junifer/datagrabber/pattern_datalad.py +111 -13
- junifer/datagrabber/tests/test_base.py +57 -6
- junifer/datagrabber/tests/test_datagrabber_utils.py +204 -76
- junifer/datagrabber/tests/test_datalad_base.py +0 -6
- junifer/datagrabber/tests/test_dmcc13_benchmark.py +256 -0
- 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 +151 -16
- junifer/datareader/default.py +36 -10
- junifer/external/nilearn/junifer_nifti_spheres_masker.py +6 -0
- junifer/markers/base.py +25 -16
- junifer/markers/collection.py +35 -16
- junifer/markers/complexity/__init__.py +27 -0
- junifer/markers/complexity/complexity_base.py +149 -0
- junifer/markers/complexity/hurst_exponent.py +136 -0
- junifer/markers/complexity/multiscale_entropy_auc.py +140 -0
- junifer/markers/complexity/perm_entropy.py +132 -0
- junifer/markers/complexity/range_entropy.py +136 -0
- junifer/markers/complexity/range_entropy_auc.py +145 -0
- junifer/markers/complexity/sample_entropy.py +134 -0
- junifer/markers/complexity/tests/test_complexity_base.py +19 -0
- junifer/markers/complexity/tests/test_hurst_exponent.py +69 -0
- junifer/markers/complexity/tests/test_multiscale_entropy_auc.py +68 -0
- junifer/markers/complexity/tests/test_perm_entropy.py +68 -0
- junifer/markers/complexity/tests/test_range_entropy.py +69 -0
- junifer/markers/complexity/tests/test_range_entropy_auc.py +69 -0
- junifer/markers/complexity/tests/test_sample_entropy.py +68 -0
- junifer/markers/complexity/tests/test_weighted_perm_entropy.py +68 -0
- junifer/markers/complexity/weighted_perm_entropy.py +133 -0
- junifer/markers/falff/_afni_falff.py +153 -0
- junifer/markers/falff/_junifer_falff.py +142 -0
- junifer/markers/falff/falff_base.py +91 -84
- junifer/markers/falff/falff_parcels.py +61 -45
- junifer/markers/falff/falff_spheres.py +64 -48
- junifer/markers/falff/tests/test_falff_parcels.py +89 -121
- junifer/markers/falff/tests/test_falff_spheres.py +92 -127
- junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py +1 -0
- junifer/markers/functional_connectivity/edge_functional_connectivity_parcels.py +1 -0
- junifer/markers/functional_connectivity/functional_connectivity_base.py +1 -0
- junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py +46 -44
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_parcels.py +34 -39
- junifer/markers/functional_connectivity/tests/test_edge_functional_connectivity_spheres.py +40 -52
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py +62 -70
- junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py +99 -85
- junifer/markers/parcel_aggregation.py +60 -38
- junifer/markers/reho/_afni_reho.py +192 -0
- junifer/markers/reho/_junifer_reho.py +281 -0
- junifer/markers/reho/reho_base.py +69 -34
- junifer/markers/reho/reho_parcels.py +26 -16
- junifer/markers/reho/reho_spheres.py +23 -9
- junifer/markers/reho/tests/test_reho_parcels.py +93 -92
- junifer/markers/reho/tests/test_reho_spheres.py +88 -86
- junifer/markers/sphere_aggregation.py +54 -9
- junifer/markers/temporal_snr/temporal_snr_base.py +1 -0
- junifer/markers/temporal_snr/tests/test_temporal_snr_parcels.py +38 -37
- junifer/markers/temporal_snr/tests/test_temporal_snr_spheres.py +34 -38
- junifer/markers/tests/test_collection.py +43 -42
- junifer/markers/tests/test_ets_rss.py +29 -37
- junifer/markers/tests/test_parcel_aggregation.py +587 -468
- junifer/markers/tests/test_sphere_aggregation.py +209 -157
- junifer/markers/utils.py +2 -40
- junifer/onthefly/read_transform.py +13 -6
- junifer/pipeline/__init__.py +1 -0
- junifer/pipeline/pipeline_step_mixin.py +105 -41
- junifer/pipeline/registry.py +17 -0
- junifer/pipeline/singleton.py +45 -0
- junifer/pipeline/tests/test_pipeline_step_mixin.py +139 -51
- junifer/pipeline/tests/test_update_meta_mixin.py +1 -0
- junifer/pipeline/tests/test_workdir_manager.py +104 -0
- junifer/pipeline/update_meta_mixin.py +8 -2
- junifer/pipeline/utils.py +154 -15
- junifer/pipeline/workdir_manager.py +246 -0
- junifer/preprocess/__init__.py +3 -0
- 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 +96 -69
- junifer/preprocess/bold_warper.py +265 -0
- junifer/preprocess/confounds/fmriprep_confound_remover.py +91 -134
- junifer/preprocess/confounds/tests/test_fmriprep_confound_remover.py +106 -111
- 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/tests/test_preprocess_base.py +6 -6
- junifer/preprocess/warping/__init__.py +6 -0
- junifer/preprocess/warping/_ants_warper.py +167 -0
- junifer/preprocess/warping/_fsl_warper.py +109 -0
- junifer/preprocess/warping/space_warper.py +213 -0
- junifer/preprocess/warping/tests/test_space_warper.py +198 -0
- junifer/stats.py +18 -4
- junifer/storage/base.py +9 -1
- junifer/storage/hdf5.py +8 -3
- junifer/storage/pandas_base.py +2 -1
- junifer/storage/sqlite.py +1 -0
- junifer/storage/tests/test_hdf5.py +2 -1
- junifer/storage/tests/test_sqlite.py +8 -8
- junifer/storage/tests/test_utils.py +6 -6
- junifer/storage/utils.py +1 -0
- junifer/testing/datagrabbers.py +11 -7
- junifer/testing/utils.py +1 -0
- junifer/tests/test_stats.py +2 -0
- junifer/utils/__init__.py +1 -0
- junifer/utils/helpers.py +53 -0
- junifer/utils/logging.py +14 -3
- junifer/utils/tests/test_helpers.py +35 -0
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/METADATA +59 -28
- junifer-0.0.4.dist-info/RECORD +257 -0
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/WHEEL +1 -1
- junifer/markers/falff/falff_estimator.py +0 -334
- junifer/markers/falff/tests/test_falff_estimator.py +0 -238
- junifer/markers/reho/reho_estimator.py +0 -515
- junifer/markers/reho/tests/test_reho_estimator.py +0 -260
- junifer-0.0.3.dev186.dist-info/RECORD +0 -199
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/AUTHORS.rst +0 -0
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/LICENSE.md +0 -0
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/entry_points.txt +0 -0
- {junifer-0.0.3.dev186.dist-info → junifer-0.0.4.dist-info}/top_level.txt +0 -0
@@ -6,10 +6,10 @@
|
|
6
6
|
|
7
7
|
from pathlib import Path
|
8
8
|
|
9
|
-
from
|
10
|
-
|
9
|
+
from junifer.datareader import DefaultDataReader
|
11
10
|
from junifer.markers.functional_connectivity import EdgeCentricFCParcels
|
12
11
|
from junifer.storage import SQLiteFeatureStorage
|
12
|
+
from junifer.testing.datagrabbers import PartlyCloudyTestingDataGrabber
|
13
13
|
|
14
14
|
|
15
15
|
def test_EdgeCentricFCParcels(tmp_path: Path) -> None:
|
@@ -21,40 +21,35 @@ def test_EdgeCentricFCParcels(tmp_path: Path) -> None:
|
|
21
21
|
The path to the test directory.
|
22
22
|
|
23
23
|
"""
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
features = storage.list_features()
|
58
|
-
assert any(
|
59
|
-
x["name"] == "BOLD_EdgeCentricFCParcels" for x in features.values()
|
60
|
-
)
|
24
|
+
with PartlyCloudyTestingDataGrabber() as dg:
|
25
|
+
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
26
|
+
marker = EdgeCentricFCParcels(
|
27
|
+
parcellation="TianxS1x3TxMNInonlinear2009cAsym",
|
28
|
+
cor_method_params={"empirical": True},
|
29
|
+
)
|
30
|
+
# Check correct output
|
31
|
+
assert marker.get_output_type("BOLD") == "matrix"
|
32
|
+
|
33
|
+
# Fit-transform the data
|
34
|
+
edge_fc = marker.fit_transform(element_data)
|
35
|
+
edge_fc_bold = edge_fc["BOLD"]
|
36
|
+
|
37
|
+
# For 16 ROIs we should get (16 * (16 -1) / 2) edges in the ETS
|
38
|
+
n_edges = int(16 * (16 - 1) / 2)
|
39
|
+
assert "data" in edge_fc_bold
|
40
|
+
assert "row_names" in edge_fc_bold
|
41
|
+
assert "col_names" in edge_fc_bold
|
42
|
+
assert edge_fc_bold["data"].shape[0] == n_edges
|
43
|
+
assert edge_fc_bold["data"].shape[1] == n_edges
|
44
|
+
assert len(set(edge_fc_bold["row_names"])) == n_edges
|
45
|
+
assert len(set(edge_fc_bold["col_names"])) == n_edges
|
46
|
+
|
47
|
+
# Store
|
48
|
+
storage = SQLiteFeatureStorage(
|
49
|
+
uri=tmp_path / "test_edge_fc_parcels.sqlite", upsert="ignore"
|
50
|
+
)
|
51
|
+
marker.fit_transform(input=element_data, storage=storage)
|
52
|
+
features = storage.list_features()
|
53
|
+
assert any(
|
54
|
+
x["name"] == "BOLD_EdgeCentricFCParcels" for x in features.values()
|
55
|
+
)
|
@@ -6,10 +6,10 @@
|
|
6
6
|
|
7
7
|
from pathlib import Path
|
8
8
|
|
9
|
-
from
|
10
|
-
|
9
|
+
from junifer.datareader import DefaultDataReader
|
11
10
|
from junifer.markers.functional_connectivity import EdgeCentricFCSpheres
|
12
11
|
from junifer.storage import SQLiteFeatureStorage
|
12
|
+
from junifer.testing.datagrabbers import SPMAuditoryTestingDataGrabber
|
13
13
|
|
14
14
|
|
15
15
|
def test_EdgeCentricFCSpheres(tmp_path: Path) -> None:
|
@@ -21,53 +21,41 @@ def test_EdgeCentricFCSpheres(tmp_path: Path) -> None:
|
|
21
21
|
The path to the test directory.
|
22
22
|
|
23
23
|
"""
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
uri = tmp_path / "test_fc_parcellation.sqlite"
|
64
|
-
# Single storage, must be the uri
|
65
|
-
storage = SQLiteFeatureStorage(uri=uri, upsert="ignore")
|
66
|
-
meta = {"element": {"subject": "test"}, "dependencies": {"numpy"}}
|
67
|
-
input = {"BOLD": {"data": fmri_img, "meta": meta}}
|
68
|
-
all_out = efc.fit_transform(input, storage=storage)
|
69
|
-
|
70
|
-
features = storage.list_features()
|
71
|
-
assert any(
|
72
|
-
x["name"] == "BOLD_EdgeCentricFCSpheres" for x in features.values()
|
73
|
-
)
|
24
|
+
with SPMAuditoryTestingDataGrabber() as dg:
|
25
|
+
element_data = DefaultDataReader().fit_transform(dg["sub001"])
|
26
|
+
marker = EdgeCentricFCSpheres(
|
27
|
+
coords="DMNBuckner", radius=5.0, cor_method="correlation"
|
28
|
+
)
|
29
|
+
# Check correct output
|
30
|
+
assert marker.get_output_type("BOLD") == "matrix"
|
31
|
+
|
32
|
+
# Fit-transform the data
|
33
|
+
edge_fc = marker.fit_transform(element_data)
|
34
|
+
edge_fc_bold = edge_fc["BOLD"]
|
35
|
+
|
36
|
+
# There are six DMNBuckner coordinates, so
|
37
|
+
# for 6 ROIs we should get (6 * (6 -1) / 2) edges in the ETS
|
38
|
+
n_edges = int(6 * (6 - 1) / 2)
|
39
|
+
assert "data" in edge_fc_bold
|
40
|
+
assert "row_names" in edge_fc_bold
|
41
|
+
assert "col_names" in edge_fc_bold
|
42
|
+
assert edge_fc_bold["data"].shape == (n_edges, n_edges)
|
43
|
+
assert len(set(edge_fc_bold["row_names"])) == n_edges
|
44
|
+
assert len(set(edge_fc_bold["col_names"])) == n_edges
|
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
|
+
)
|
53
|
+
# Store
|
54
|
+
storage = SQLiteFeatureStorage(
|
55
|
+
uri=tmp_path / "test_edge_fc_spheres.sqlite", upsert="ignore"
|
56
|
+
)
|
57
|
+
marker.fit_transform(input=element_data, storage=storage)
|
58
|
+
features = storage.list_features()
|
59
|
+
assert any(
|
60
|
+
x["name"] == "BOLD_EdgeCentricFCSpheres" for x in features.values()
|
61
|
+
)
|
@@ -2,20 +2,22 @@
|
|
2
2
|
|
3
3
|
# Authors: Amir Omidvarnia <a.omidvarnia@fz-juelich.de>
|
4
4
|
# Kaustubh R. Patil <k.patil@fz-juelich.de>
|
5
|
+
# Synchon Mandal <s.mandal@fz-juelich.de>
|
5
6
|
# License: AGPL
|
6
7
|
|
7
8
|
from pathlib import Path
|
8
9
|
|
9
|
-
from nilearn import datasets, image
|
10
10
|
from nilearn.connectome import ConnectivityMeasure
|
11
11
|
from nilearn.maskers import NiftiLabelsMasker
|
12
|
-
from numpy.testing import assert_array_almost_equal
|
12
|
+
from numpy.testing import assert_array_almost_equal
|
13
13
|
|
14
|
+
from junifer.data import get_parcellation
|
15
|
+
from junifer.datareader import DefaultDataReader
|
14
16
|
from junifer.markers.functional_connectivity import (
|
15
17
|
FunctionalConnectivityParcels,
|
16
18
|
)
|
17
|
-
from junifer.markers.parcel_aggregation import ParcelAggregation
|
18
19
|
from junifer.storage import SQLiteFeatureStorage
|
20
|
+
from junifer.testing.datagrabbers import PartlyCloudyTestingDataGrabber
|
19
21
|
|
20
22
|
|
21
23
|
def test_FunctionalConnectivityParcels(tmp_path: Path) -> None:
|
@@ -27,70 +29,60 @@ def test_FunctionalConnectivityParcels(tmp_path: Path) -> None:
|
|
27
29
|
The path to the test directory.
|
28
30
|
|
29
31
|
"""
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
storage = SQLiteFeatureStorage(uri=uri, upsert="ignore")
|
88
|
-
meta = {"element": {"subject": "test"}, "dependencies": {"numpy"}}
|
89
|
-
input = {"BOLD": {"data": fmri_img, "meta": meta}}
|
90
|
-
all_out = fc.fit_transform(input, storage=storage)
|
91
|
-
|
92
|
-
features = storage.list_features()
|
93
|
-
assert any(
|
94
|
-
x["name"] == "BOLD_FunctionalConnectivityParcels"
|
95
|
-
for x in features.values()
|
96
|
-
)
|
32
|
+
with PartlyCloudyTestingDataGrabber() as dg:
|
33
|
+
element_data = DefaultDataReader().fit_transform(dg["sub-01"])
|
34
|
+
marker = FunctionalConnectivityParcels(
|
35
|
+
parcellation="TianxS1x3TxMNInonlinear2009cAsym"
|
36
|
+
)
|
37
|
+
# Check correct output
|
38
|
+
assert marker.get_output_type("BOLD") == "matrix"
|
39
|
+
|
40
|
+
# Fit-transform the data
|
41
|
+
fc = marker.fit_transform(element_data)
|
42
|
+
fc_bold = fc["BOLD"]
|
43
|
+
|
44
|
+
assert "data" in fc_bold
|
45
|
+
assert "row_names" in fc_bold
|
46
|
+
assert "col_names" in fc_bold
|
47
|
+
assert fc_bold["data"].shape == (16, 16)
|
48
|
+
assert len(set(fc_bold["row_names"])) == 16
|
49
|
+
assert len(set(fc_bold["col_names"])) == 16
|
50
|
+
|
51
|
+
# Compare with nilearn
|
52
|
+
# Load testing parcellation for the target data
|
53
|
+
testing_parcellation, _ = get_parcellation(
|
54
|
+
parcellation=["TianxS1x3TxMNInonlinear2009cAsym"],
|
55
|
+
target_data=element_data["BOLD"],
|
56
|
+
)
|
57
|
+
# Extract timeseries
|
58
|
+
nifti_labels_masker = NiftiLabelsMasker(
|
59
|
+
labels_img=testing_parcellation, standardize=False
|
60
|
+
)
|
61
|
+
extracted_timeseries = nifti_labels_masker.fit_transform(
|
62
|
+
element_data["BOLD"]["data"]
|
63
|
+
)
|
64
|
+
# Compute the connectivity measure
|
65
|
+
connectivity_measure = ConnectivityMeasure(
|
66
|
+
kind="covariance"
|
67
|
+
).fit_transform([extracted_timeseries])[0]
|
68
|
+
|
69
|
+
# Check that FC are almost equal
|
70
|
+
assert_array_almost_equal(
|
71
|
+
connectivity_measure, fc_bold["data"], decimal=3
|
72
|
+
)
|
73
|
+
|
74
|
+
# Check empirical correlation method parameters
|
75
|
+
marker = FunctionalConnectivityParcels(
|
76
|
+
parcellation="TianxS1x3TxMNInonlinear2009cAsym",
|
77
|
+
cor_method_params={"empirical": True},
|
78
|
+
)
|
79
|
+
# Store
|
80
|
+
storage = SQLiteFeatureStorage(
|
81
|
+
uri=tmp_path / "test_fc_parcels.sqlite", upsert="ignore"
|
82
|
+
)
|
83
|
+
marker.fit_transform(input=element_data, storage=storage)
|
84
|
+
features = storage.list_features()
|
85
|
+
assert any(
|
86
|
+
x["name"] == "BOLD_FunctionalConnectivityParcels"
|
87
|
+
for x in features.values()
|
88
|
+
)
|
@@ -3,21 +3,24 @@
|
|
3
3
|
# Authors: Amir Omidvarnia <a.omidvarnia@fz-juelich.de>
|
4
4
|
# Kaustubh R. Patil <k.patil@fz-juelich.de>
|
5
5
|
# Federico Raimondo <f.raimondo@fz-juelich.de>
|
6
|
+
# Synchon Mandal <s.mandal@fz-juelich.de>
|
6
7
|
# License: AGPL
|
7
8
|
|
8
9
|
from pathlib import Path
|
9
10
|
|
10
11
|
import pytest
|
11
|
-
from nilearn import datasets, image
|
12
12
|
from nilearn.connectome import ConnectivityMeasure
|
13
|
+
from nilearn.maskers import NiftiSpheresMasker
|
13
14
|
from numpy.testing import assert_array_almost_equal
|
14
15
|
from sklearn.covariance import EmpiricalCovariance
|
15
16
|
|
17
|
+
from junifer.data import get_coordinates
|
18
|
+
from junifer.datareader import DefaultDataReader
|
16
19
|
from junifer.markers.functional_connectivity import (
|
17
20
|
FunctionalConnectivitySpheres,
|
18
21
|
)
|
19
|
-
from junifer.markers.sphere_aggregation import SphereAggregation
|
20
22
|
from junifer.storage import SQLiteFeatureStorage
|
23
|
+
from junifer.testing.datagrabbers import SPMAuditoryTestingDataGrabber
|
21
24
|
|
22
25
|
|
23
26
|
def test_FunctionalConnectivitySpheres(tmp_path: Path) -> None:
|
@@ -29,54 +32,57 @@ def test_FunctionalConnectivitySpheres(tmp_path: Path) -> None:
|
|
29
32
|
The path to the test directory.
|
30
33
|
|
31
34
|
"""
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
35
|
+
with SPMAuditoryTestingDataGrabber() as dg:
|
36
|
+
element_data = DefaultDataReader().fit_transform(dg["sub001"])
|
37
|
+
marker = FunctionalConnectivitySpheres(
|
38
|
+
coords="DMNBuckner", radius=5.0, cor_method="correlation"
|
39
|
+
)
|
40
|
+
# Check correct output
|
41
|
+
assert marker.get_output_type("BOLD") == "matrix"
|
42
|
+
|
43
|
+
# Fit-transform the data
|
44
|
+
fc = marker.fit_transform(element_data)
|
45
|
+
fc_bold = fc["BOLD"]
|
46
|
+
|
47
|
+
assert "data" in fc_bold
|
48
|
+
assert "row_names" in fc_bold
|
49
|
+
assert "col_names" in fc_bold
|
50
|
+
assert fc_bold["data"].shape == (6, 6)
|
51
|
+
assert len(set(fc_bold["row_names"])) == 6
|
52
|
+
assert len(set(fc_bold["col_names"])) == 6
|
53
|
+
|
54
|
+
# Compare with nilearn
|
55
|
+
# Load testing coordinates for the target data
|
56
|
+
testing_coords, _ = get_coordinates(
|
57
|
+
coords="DMNBuckner", target_data=element_data["BOLD"]
|
58
|
+
)
|
59
|
+
# Extract timeseries
|
60
|
+
nifti_spheres_masker = NiftiSpheresMasker(
|
61
|
+
seeds=testing_coords, radius=5.0
|
62
|
+
)
|
63
|
+
extracted_timeseries = nifti_spheres_masker.fit_transform(
|
64
|
+
element_data["BOLD"]["data"]
|
65
|
+
)
|
66
|
+
# Compute the connectivity measure
|
67
|
+
connectivity_measure = ConnectivityMeasure(
|
68
|
+
kind="correlation"
|
69
|
+
).fit_transform([extracted_timeseries])[0]
|
70
|
+
|
71
|
+
# Check that FC are almost equal
|
72
|
+
assert_array_almost_equal(
|
73
|
+
connectivity_measure, fc_bold["data"], decimal=3
|
74
|
+
)
|
75
|
+
|
76
|
+
# Store
|
77
|
+
storage = SQLiteFeatureStorage(
|
78
|
+
uri=tmp_path / "test_fc_spheres.sqlite", upsert="ignore"
|
79
|
+
)
|
80
|
+
marker.fit_transform(input=element_data, storage=storage)
|
81
|
+
features = storage.list_features()
|
82
|
+
assert any(
|
83
|
+
x["name"] == "BOLD_FunctionalConnectivitySpheres"
|
84
|
+
for x in features.values()
|
85
|
+
)
|
80
86
|
|
81
87
|
|
82
88
|
def test_FunctionalConnectivitySpheres_empirical(tmp_path: Path) -> None:
|
@@ -88,41 +94,49 @@ def test_FunctionalConnectivitySpheres_empirical(tmp_path: Path) -> None:
|
|
88
94
|
The path to the test directory.
|
89
95
|
|
90
96
|
"""
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
97
|
+
with SPMAuditoryTestingDataGrabber() as dg:
|
98
|
+
element_data = DefaultDataReader().fit_transform(dg["sub001"])
|
99
|
+
marker = FunctionalConnectivitySpheres(
|
100
|
+
coords="DMNBuckner",
|
101
|
+
radius=5.0,
|
102
|
+
cor_method="correlation",
|
103
|
+
cor_method_params={"empirical": True},
|
104
|
+
)
|
105
|
+
# Check correct output
|
106
|
+
assert marker.get_output_type("BOLD") == "matrix"
|
107
|
+
|
108
|
+
# Fit-transform the data
|
109
|
+
fc = marker.fit_transform(element_data)
|
110
|
+
fc_bold = fc["BOLD"]
|
111
|
+
|
112
|
+
assert "data" in fc_bold
|
113
|
+
assert "row_names" in fc_bold
|
114
|
+
assert "col_names" in fc_bold
|
115
|
+
assert fc_bold["data"].shape == (6, 6)
|
116
|
+
assert len(set(fc_bold["row_names"])) == 6
|
117
|
+
assert len(set(fc_bold["col_names"])) == 6
|
118
|
+
|
119
|
+
# Compare with nilearn
|
120
|
+
# Load testing coordinates for the target data
|
121
|
+
testing_coords, _ = get_coordinates(
|
122
|
+
coords="DMNBuckner", target_data=element_data["BOLD"]
|
123
|
+
)
|
124
|
+
# Extract timeseries
|
125
|
+
nifti_spheres_masker = NiftiSpheresMasker(
|
126
|
+
seeds=testing_coords, radius=5.0
|
127
|
+
)
|
128
|
+
extracted_timeseries = nifti_spheres_masker.fit_transform(
|
129
|
+
element_data["BOLD"]["data"]
|
130
|
+
)
|
131
|
+
# Compute the connectivity measure
|
132
|
+
connectivity_measure = ConnectivityMeasure(
|
133
|
+
cov_estimator=EmpiricalCovariance(), kind="correlation" # type: ignore
|
134
|
+
).fit_transform([extracted_timeseries])[0]
|
135
|
+
|
136
|
+
# Check that FC are almost equal
|
137
|
+
assert_array_almost_equal(
|
138
|
+
connectivity_measure, fc_bold["data"], decimal=3
|
139
|
+
)
|
126
140
|
|
127
141
|
|
128
142
|
def test_FunctionalConnectivitySpheres_error() -> None:
|