From 8d5bb34c32980c13362c3da2c4c8138299baa389 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 3 Jan 2023 13:20:54 +0100 Subject: [PATCH 01/17] update: add abstract base class for functional connectivity markers --- .../functional_connectivity_base.py | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 junifer/markers/functional_connectivity/functional_connectivity_base.py diff --git a/junifer/markers/functional_connectivity/functional_connectivity_base.py b/junifer/markers/functional_connectivity/functional_connectivity_base.py new file mode 100644 index 000000000..94ffa2538 --- /dev/null +++ b/junifer/markers/functional_connectivity/functional_connectivity_base.py @@ -0,0 +1,149 @@ +"""Provide abstract base class for functional connectivity (FC).""" + +# Authors: Synchon Mandal +# License: AGPL + + +from abc import abstractmethod +from typing import Any, Dict, List, Optional + +from nilearn.connectome import ConnectivityMeasure +from sklearn.covariance import EmpiricalCovariance + +from ...utils import raise_error +from ..base import BaseMarker + + +class FunctionalConnectivityBase(BaseMarker): + """Abstract base class for functional connectivity markers. + + Parameters + ---------- + agg_method : str, optional + The method to perform aggregation using. Check valid options in + :func:`junifer.stats.get_aggfunc_by_name` (default "mean"). + agg_method_params : dict, optional + Parameters to pass to the aggregation function. Check valid options in + :func:`junifer.stats.get_aggfunc_by_name` (default None). + cor_method : str, optional + The method to perform correlation using. Check valid options in + :class:`nilearn.connectome.ConnectivityMeasure` + (default "covariance"). + cor_method_params : dict, optional + Parameters to pass to the correlation function. Check valid options in + :class:`nilearn.connectome.ConnectivityMeasure` (default None). + mask : str, optional + The name of the mask to apply to regions before extracting signals. + Check valid options by calling :func:`junifer.data.masks.list_masks` + (default None). + name : str, optional + The name of the marker. If None, will use the class name (default + None). + + """ + + _DEPENDENCIES = {"nilearn", "scikit-learn"} + + def __init__( + self, + agg_method: str = "mean", + agg_method_params: Optional[Dict] = None, + cor_method: str = "covariance", + cor_method_params: Optional[Dict] = None, + mask: Optional[str] = None, + name: Optional[str] = None, + ) -> None: + self.agg_method = agg_method + self.agg_method_params = agg_method_params + self.cor_method = cor_method + self.cor_method_params = cor_method_params or {} + + # default to nilearn behavior + self.cor_method_params["empirical"] = self.cor_method_params.get( + "empirical", False + ) + self.mask = mask + super().__init__(on="BOLD", name=name) + + @abstractmethod + def aggregate(self, input: Dict[str, Any]) -> Dict[str, Any]: + """Perform aggregation.""" + raise_error( + msg="Concrete classes need to implement aggregate().", + klass=NotImplementedError, + ) + + def get_valid_inputs(self) -> List[str]: + """Get valid data types for input. + + Returns + ------- + list of str + The list of data types that can be used as input for this marker. + """ + return ["BOLD"] + + def get_output_type(self, input_type: str) -> str: + """Get output type. + + Parameters + ---------- + input_type : str + The data type input to the marker. + + Returns + ------- + str + The storage type output by the marker. + + """ + return "matrix" + + def compute( + self, + input: Dict[str, Any], + extra_input: Optional[Dict] = None, + ) -> Dict: + """Compute. + + Parameters + ---------- + input : dict + A single input from the pipeline data object in which to compute + the marker. + extra_input : dict, optional + The other fields in the pipeline data object. Useful for accessing + other data kind that needs to be used in the computation. For + example, the functional connectivity markers can make use of the + confounds if available (default None). + + Returns + ------- + dict + The computed result as dictionary. The following keys will be + included in the dictionary: + + * ``data`` : functional connectivity matrix as a ``numpy.ndarray``. + * ``row_names`` : row names as a list + * ``col_names`` : column names as a list + * ``matrix_kind`` : the kind of matrix (tril, triu or full) + + """ + # Perform necessary aggregation + aggregation = self.aggregate(input) + # Compute correlation + if self.cor_method_params["empirical"]: + connectivity = ConnectivityMeasure( + cov_estimator=EmpiricalCovariance(), + kind=self.cor_method, + ) + else: + connectivity = ConnectivityMeasure(kind=self.cor_method) + # Create dictionary for output + out = {} + out["data"] = connectivity.fit_transform([aggregation["data"]])[0] + # Create column names + out["row_names"] = aggregation["columns"] + out["col_names"] = aggregation["columns"] + out["matrix_kind"] = "tril" + return out -- 2.52.0 From 9e9165e355ab1ad13bac9efdd63a76607f8b1b4a Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 3 Jan 2023 13:21:59 +0100 Subject: [PATCH 02/17] update: add test for abstract base class of functional connectivity markers --- .../tests/test_functional_connectivity_base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 junifer/markers/functional_connectivity/tests/test_functional_connectivity_base.py diff --git a/junifer/markers/functional_connectivity/tests/test_functional_connectivity_base.py b/junifer/markers/functional_connectivity/tests/test_functional_connectivity_base.py new file mode 100644 index 000000000..01eec0703 --- /dev/null +++ b/junifer/markers/functional_connectivity/tests/test_functional_connectivity_base.py @@ -0,0 +1,16 @@ +"""Provide tests for base functional connectivity marker.""" + +# Authors: Synchon Mandal +# License: AGPL + +import pytest + +from junifer.markers.functional_connectivity.functional_connectivity_base import ( + FunctionalConnectivityBase, +) + + +def test_base_functional_connectivity_marker_abstractness() -> None: + """Test FunctionalConnectivityBase is an abstract base class.""" + with pytest.raises(TypeError, match="abstract"): + FunctionalConnectivityBase() -- 2.52.0 From 1f16dc79c648c3a660d974c27206953522013477 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 3 Jan 2023 13:27:01 +0100 Subject: [PATCH 03/17] refactor: prune and move FunctionalConnectivityParcels --- .../functional_connectivity_parcels.py | 77 +++++++++ .../functional_connectivity_parcels.py | 153 ------------------ 2 files changed, 77 insertions(+), 153 deletions(-) create mode 100644 junifer/markers/functional_connectivity/functional_connectivity_parcels.py delete mode 100644 junifer/markers/functional_connectivity_parcels.py diff --git a/junifer/markers/functional_connectivity/functional_connectivity_parcels.py b/junifer/markers/functional_connectivity/functional_connectivity_parcels.py new file mode 100644 index 000000000..ef0147eaa --- /dev/null +++ b/junifer/markers/functional_connectivity/functional_connectivity_parcels.py @@ -0,0 +1,77 @@ +"""Provide class for functional connectivity using parcels.""" + +# Authors: Amir Omidvarnia +# Kaustubh R. Patil +# Synchon Mandal +# License: AGPL + +from typing import Any, Dict, List, Optional, Union + +from ...api.decorators import register_marker +from ..parcel_aggregation import ParcelAggregation +from .functional_connectivity_base import FunctionalConnectivityBase + + +@register_marker +class FunctionalConnectivityParcels(FunctionalConnectivityBase): + """Class for functional connectivity using parcellations. + + Parameters + ---------- + parcellation : str or list of str + The name(s) of the parcellation(s). Check valid options by calling + :func:`junifer.data.parcellations.list_parcellations`. + agg_method : str, optional + The method to perform aggregation using. Check valid options in + :func:`junifer.stats.get_aggfunc_by_name` (default "mean"). + agg_method_params : dict, optional + Parameters to pass to the aggregation function. Check valid options in + :func:`junifer.stats.get_aggfunc_by_name` (default None). + cor_method : str, optional + The method to perform correlation using. Check valid options in + :class:`nilearn.connectome.ConnectivityMeasure` + (default "covariance"). + cor_method_params : dict, optional + Parameters to pass to the correlation function. Check valid options in + :class:`nilearn.connectome.ConnectivityMeasure` (default None). + mask : str, optional + The name of the mask to apply to regions before extracting signals. + Check valid options by calling :func:`junifer.data.masks.list_masks` + (default None). + name : str, optional + The name of the marker. If None, will use the class name (default + None). + + """ + + def __init__( + self, + parcellation: Union[str, List[str]], + agg_method: str = "mean", + agg_method_params: Optional[Dict] = None, + cor_method: str = "covariance", + cor_method_params: Optional[Dict] = None, + mask: Optional[str] = None, + name: Optional[str] = None, + ) -> None: + self.parcellation = parcellation + super().__init__( + agg_method=agg_method, + agg_method_params=agg_method_params, + cor_method=cor_method, + cor_method_params=cor_method_params, + mask=mask, + name=name, + ) + + def aggregate(self, input: Dict[str, Any]) -> Dict: + """Perform parcel aggregation.""" + parcel_aggregation = ParcelAggregation( + parcellation=self.parcellation, + method=self.agg_method, + method_params=self.agg_method_params, + mask=self.mask, + on="BOLD", + ) + # Return the 2D timeseries after parcel aggregation + return parcel_aggregation.compute(input) diff --git a/junifer/markers/functional_connectivity_parcels.py b/junifer/markers/functional_connectivity_parcels.py deleted file mode 100644 index 649038e6d..000000000 --- a/junifer/markers/functional_connectivity_parcels.py +++ /dev/null @@ -1,153 +0,0 @@ -"""Provide class for functional connectivity.""" - -# Authors: Amir Omidvarnia -# Kaustubh R. Patil -# License: AGPL - -from typing import Any, Dict, List, Optional, Union - -from nilearn.connectome import ConnectivityMeasure -from sklearn.covariance import EmpiricalCovariance - -from ..api.decorators import register_marker -from .base import BaseMarker -from .parcel_aggregation import ParcelAggregation - - -@register_marker -class FunctionalConnectivityParcels(BaseMarker): - """Class for functional connectivity. - - Parameters - ---------- - parcellation : str or list of str - The name(s) of the parcellation(s). Check valid options by calling - :func:`junifer.data.parcellations.list_parcellations`. - agg_method : str, optional - The method to perform aggregation using. Check valid options in - :func:`junifer.stats.get_aggfunc_by_name` (default "mean"). - agg_method_params : dict, optional - Parameters to pass to the aggregation function. Check valid options in - :func:`junifer.stats.get_aggfunc_by_name` (default None). - cor_method : str, optional - The method to perform correlation using. Check valid options in - :class:`nilearn.connectome.ConnectivityMeasure` - (default "covariance"). - cor_method_params : dict, optional - Parameters to pass to the correlation function. Check valid options in - :class:`nilearn.connectome.ConnectivityMeasure` (default None). - mask : str, optional - The name of the mask to apply to regions before extracting signals. - Check valid options by calling :func:`junifer.data.masks.list_masks` - (default None). - name : str, optional - The name of the marker. If None, will use the class name (default - None). - """ - - _DEPENDENCIES = {"nilearn", "scikit-learn"} - - def __init__( - self, - parcellation: Union[str, List[str]], - agg_method: str = "mean", - agg_method_params: Optional[Dict] = None, - cor_method: str = "covariance", - cor_method_params: Optional[Dict] = None, - mask: Optional[str] = None, - name: Optional[str] = None, - ) -> None: - self.parcellation = parcellation - self.agg_method = agg_method - self.agg_method_params = agg_method_params - self.cor_method = cor_method - self.cor_method_params = cor_method_params or {} - - # default to nilearn behavior - self.cor_method_params["empirical"] = self.cor_method_params.get( - "empirical", False - ) - self.mask = mask - - super().__init__(name=name) - - def get_valid_inputs(self) -> List[str]: - """Get valid data types for input. - - Returns - ------- - list of str - The list of data types that can be used as input for this marker. - """ - return ["BOLD"] - - def get_output_type(self, input_type: str) -> str: - """Get output type. - - Parameters - ---------- - input_type : str - The data type input to the marker. - - Returns - ------- - str - The storage type output by the marker. - - """ - return "matrix" - - def compute( - self, - input: Dict[str, Any], - extra_input: Optional[Dict] = None, - ) -> Dict: - """Compute. - - Parameters - ---------- - input : dict - A single input from the pipeline data object in which to compute - the marker. - extra_input : dict, optional - The other fields in the pipeline data object. Useful for accessing - other data kind that needs to be used in the computation. For - example, the functional connectivity markers can make use of the - confounds if available (default None). - - Returns - ------- - dict - The computed result as dictionary. The following data will be - included in the dictionary: - - * ``data`` : functional connectivity matrix as a numpy.ndarray. - * ``row_names`` : row names as a list - * ``col_names`` : column names as a list - * ``matrix_kind`` : the kind of matrix (tril, triu or full) - - """ - pa = ParcelAggregation( - parcellation=self.parcellation, - method=self.agg_method, - method_params=self.agg_method_params, - mask=self.mask, - on="BOLD", - ) - # get the 2D timeseries after parcel aggregation - ts = pa.compute(input) - - if self.cor_method_params["empirical"]: - cm = ConnectivityMeasure( - cov_estimator=EmpiricalCovariance(), # type: ignore - kind=self.cor_method, - ) - else: - cm = ConnectivityMeasure(kind=self.cor_method) - out = {} - out["data"] = cm.fit_transform([ts["data"]])[0] - # create column names - out["row_names"] = ts["columns"] - out["col_names"] = ts["columns"] - out["matrix_kind"] = "tril" - return out -- 2.52.0 From f11767293540ee0d72af67708672dbd5758f461c Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 3 Jan 2023 13:29:20 +0100 Subject: [PATCH 04/17] update: move tests for FunctionalConnectivityParcels --- .../tests/test_functional_connectivity_parcels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename junifer/markers/{ => functional_connectivity}/tests/test_functional_connectivity_parcels.py (98%) diff --git a/junifer/markers/tests/test_functional_connectivity_parcels.py b/junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py similarity index 98% rename from junifer/markers/tests/test_functional_connectivity_parcels.py rename to junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py index 5b5758970..aa438d8a5 100644 --- a/junifer/markers/tests/test_functional_connectivity_parcels.py +++ b/junifer/markers/functional_connectivity/tests/test_functional_connectivity_parcels.py @@ -11,7 +11,7 @@ from nilearn.connectome import ConnectivityMeasure from nilearn.maskers import NiftiLabelsMasker from numpy.testing import assert_array_almost_equal, assert_array_equal -from junifer.markers.functional_connectivity_parcels import ( +from junifer.markers.functional_connectivity import ( FunctionalConnectivityParcels, ) from junifer.markers.parcel_aggregation import ParcelAggregation -- 2.52.0 From 525dd097a885d81698efa5f29a73453eec448eb9 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 3 Jan 2023 13:39:06 +0100 Subject: [PATCH 05/17] refactor: prune and move FunctionalConnectivitySpheres --- .../functional_connectivity_spheres.py | 87 +++++++++ .../functional_connectivity_spheres.py | 165 ------------------ 2 files changed, 87 insertions(+), 165 deletions(-) create mode 100644 junifer/markers/functional_connectivity/functional_connectivity_spheres.py delete mode 100644 junifer/markers/functional_connectivity_spheres.py diff --git a/junifer/markers/functional_connectivity/functional_connectivity_spheres.py b/junifer/markers/functional_connectivity/functional_connectivity_spheres.py new file mode 100644 index 000000000..9155df655 --- /dev/null +++ b/junifer/markers/functional_connectivity/functional_connectivity_spheres.py @@ -0,0 +1,87 @@ +"""Provide class for functional connectivity using spheres.""" + +# Authors: Amir Omidvarnia +# Kaustubh R. Patil +# Synchon Mandal +# License: AGPL + +from typing import Any, Dict, Optional + +from ...api.decorators import register_marker +from ..sphere_aggregation import SphereAggregation +from ..utils import raise_error +from .functional_connectivity_base import FunctionalConnectivityBase + + +@register_marker +class FunctionalConnectivitySpheres(FunctionalConnectivityBase): + """Class for functional connectivity using coordinates (spheres). + + Parameters + ---------- + coords : str + The name of the coordinates list to use. See + :func:`junifer.data.coordinates.list_coordinates` for options. + radius : float, optional + The radius of the sphere in mm. If None, the signal will be extracted + from a single voxel. See :class:`nilearn.maskers.NiftiSpheresMasker` + for more information (default None). + agg_method : str, optional + The aggregation method to use. + See :func:`junifer.stats.get_aggfunc_by_name` for more information + (default None). + agg_method_params : dict, optional + The parameters to pass to the aggregation method (default None). + cor_method : str, optional + The method to perform correlation using. Check valid options in + :class:`nilearn.connectome.ConnectivityMeasure` (default "covariance"). + cor_method_params : dict, optional + Parameters to pass to the correlation function. Check valid options in + :class:`nilearn.connectome.ConnectivityMeasure` (default None). + mask : str, optional + The name of the mask to apply to regions before extracting signals. + Check valid options by calling :func:`junifer.data.masks.list_masks` + (default None). + name : str, optional + The name of the marker. By default, it will use + KIND_FunctionalConnectivitySpheres where KIND is the kind of data it + was applied to (default None). + + """ + + def __init__( + self, + coords: str, + radius: Optional[float] = None, + agg_method: str = "mean", + agg_method_params: Optional[Dict] = None, + cor_method: str = "covariance", + cor_method_params: Optional[Dict] = None, + mask: Optional[str] = None, + name: Optional[str] = None, + ) -> None: + self.coords = coords + self.radius = radius + if radius is None or radius <= 0: + raise_error(f"radius should be > 0: provided {radius}") + super().__init__( + agg_method=agg_method, + agg_method_params=agg_method_params, + cor_method=cor_method, + cor_method_params=cor_method_params, + mask=mask, + name=name, + ) + + def aggregate(self, input: Dict[str, Any]) -> Dict: + """Perform sphere aggregation.""" + sphere_aggregation = SphereAggregation( + coords=self.coords, + radius=self.radius, + method=self.agg_method, + method_params=self.agg_method_params, + mask=self.mask, + on="BOLD", + ) + # Return the 2D timeseries after sphere aggregation + return sphere_aggregation.compute(input) diff --git a/junifer/markers/functional_connectivity_spheres.py b/junifer/markers/functional_connectivity_spheres.py deleted file mode 100644 index 97b485e7b..000000000 --- a/junifer/markers/functional_connectivity_spheres.py +++ /dev/null @@ -1,165 +0,0 @@ -"""Provide base class for functional connectivity using spheres.""" - -# Authors: Amir Omidvarnia -# Kaustubh R. Patil -# License: AGPL - -from typing import Any, Dict, List, Optional - -from nilearn.connectome import ConnectivityMeasure -from sklearn.covariance import EmpiricalCovariance - -from ..api.decorators import register_marker -from ..utils import raise_error -from .base import BaseMarker -from .sphere_aggregation import SphereAggregation - - -@register_marker -class FunctionalConnectivitySpheres(BaseMarker): - """Class for functional connectivity using coordinates (spheres). - - Parameters - ---------- - coords : str - The name of the coordinates list to use. See - :func:`junifer.data.coordinates.list_coordinates` for options. - radius : float, optional - The radius of the sphere in mm. If None, the signal will be extracted - from a single voxel. See :class:`nilearn.maskers.NiftiSpheresMasker` - for more information (default None). - agg_method : str, optional - The aggregation method to use. - See :func:`junifer.stats.get_aggfunc_by_name` for more information - (default None). - agg_method_params : dict, optional - The parameters to pass to the aggregation method (default None). - cor_method : str, optional - The method to perform correlation using. Check valid options in - :class:`nilearn.connectome.ConnectivityMeasure` (default "covariance"). - cor_method_params : dict, optional - Parameters to pass to the correlation function. Check valid options in - :class:`nilearn.connectome.ConnectivityMeasure` (default None). - mask : str, optional - The name of the mask to apply to regions before extracting signals. - Check valid options by calling :func:`junifer.data.masks.list_masks` - (default None). - name : str, optional - The name of the marker. By default, it will use - KIND_FunctionalConnectivitySpheres where KIND is the kind of data it - was applied to (default None). - - """ - - _DEPENDENCIES = {"nilearn", "scikit-learn"} - - def __init__( - self, - coords: str, - radius: Optional[float] = None, - agg_method: str = "mean", - agg_method_params: Optional[Dict] = None, - cor_method: str = "covariance", - cor_method_params: Optional[Dict] = None, - mask: Optional[str] = None, - name: Optional[str] = None, - ) -> None: - self.coords = coords - self.radius = radius - if radius is None or radius <= 0: - raise_error(f"radius should be > 0: provided {radius}") - self.agg_method = agg_method - self.agg_method_params = agg_method_params - self.cor_method = cor_method - self.cor_method_params = cor_method_params or {} - - # default to nilearn behavior - self.cor_method_params["empirical"] = self.cor_method_params.get( - "empirical", False - ) - - self.mask = mask - - super().__init__(name=name) - - def get_valid_inputs(self) -> List[str]: - """Get valid data types for input. - - Returns - ------- - list of str - The list of data types that can be used as input for this marker. - """ - return ["BOLD"] - - def get_output_type(self, input_type: str) -> str: - """Get output type. - - Parameters - ---------- - input_type : str - The data type input to the marker. - - Returns - ------- - str - The storage type output by the marker. - - """ - return "matrix" - - def compute( - self, - input: Dict[str, Any], - extra_input: Optional[Dict] = None, - ) -> Dict: - """Compute. - - Parameters - ---------- - input : dict - A single input from the pipeline data object in which to compute - the marker. - extra_input : dict, optional - The other fields in the pipeline data object. Useful for accessing - other data kind that needs to be used in the computation. For - example, the functional connectivity markers can make use of the - confounds if available (default None). - - Returns - ------- - dict - The computed result as dictionary. The following keys will be - included in the dictionary: - - * ``data`` : functional connectivity matrix as a numpy.ndarray. - * ``row_names`` : row names as a list - * ``col_names`` : column names as a list - * ``matrix_kind`` : the kind of matrix (tril, triu or full) - - """ - sa = SphereAggregation( - coords=self.coords, - radius=self.radius, - method=self.agg_method, - method_params=self.agg_method_params, - mask=self.mask, - on="BOLD", - ) - - ts = sa.compute(input) - - if self.cor_method_params["empirical"]: - cm = ConnectivityMeasure( - cov_estimator=EmpiricalCovariance(), # type: ignore - kind=self.cor_method, - ) - else: - cm = ConnectivityMeasure(kind=self.cor_method) - out = {} - out["data"] = cm.fit_transform([ts["data"]])[0] - # create column names - out["row_names"] = ts["columns"] - out["col_names"] = ts["columns"] - out["matrix_kind"] = "tril" - return out -- 2.52.0 From 490827bfc1bc3f77cab1122920d0d0cdc9575592 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 3 Jan 2023 13:39:40 +0100 Subject: [PATCH 06/17] update: move tests for FunctionalConnectivitySpheres --- .../tests/test_functional_connectivity_spheres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename junifer/markers/{ => functional_connectivity}/tests/test_functional_connectivity_spheres.py (98%) diff --git a/junifer/markers/tests/test_functional_connectivity_spheres.py b/junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py similarity index 98% rename from junifer/markers/tests/test_functional_connectivity_spheres.py rename to junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py index 819d4a6ad..ddc4c842b 100644 --- a/junifer/markers/tests/test_functional_connectivity_spheres.py +++ b/junifer/markers/functional_connectivity/tests/test_functional_connectivity_spheres.py @@ -13,7 +13,7 @@ from nilearn.connectome import ConnectivityMeasure from numpy.testing import assert_array_almost_equal from sklearn.covariance import EmpiricalCovariance -from junifer.markers.functional_connectivity_spheres import ( +from junifer.markers.functional_connectivity import ( FunctionalConnectivitySpheres, ) from junifer.markers.sphere_aggregation import SphereAggregation -- 2.52.0 From be55e85753d8a2f7191448b5d87b317103d5709d Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 3 Jan 2023 13:40:03 +0100 Subject: [PATCH 07/17] update: add imports for markers.functional_connectivity --- junifer/markers/functional_connectivity/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 junifer/markers/functional_connectivity/__init__.py diff --git a/junifer/markers/functional_connectivity/__init__.py b/junifer/markers/functional_connectivity/__init__.py new file mode 100644 index 000000000..a1733ee9d --- /dev/null +++ b/junifer/markers/functional_connectivity/__init__.py @@ -0,0 +1,7 @@ +"""Provide imports for functional connectivity sub-package.""" + +# Authors: Synchon Mandal +# License: AGPL + +from .functional_connectivity_parcels import FunctionalConnectivityParcels +from .functional_connectivity_spheres import FunctionalConnectivitySpheres -- 2.52.0 From 8fd43de26b9f5d74dbff883d2b6e15160a11dc8a Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 3 Jan 2023 13:48:00 +0100 Subject: [PATCH 08/17] update: correct imports for junifer.markers --- junifer/markers/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/junifer/markers/__init__.py b/junifer/markers/__init__.py index bc069e3db..542a26333 100644 --- a/junifer/markers/__init__.py +++ b/junifer/markers/__init__.py @@ -2,16 +2,19 @@ # Authors: Federico Raimondo # Leonard Sasse +# Synchon Mandal # License: AGPL from .base import BaseMarker from .collection import MarkerCollection from .crossparcellation_functional_connectivity import CrossParcellationFC from .ets_rss import RSSETSMarker -from .functional_connectivity_parcels import FunctionalConnectivityParcels -from .functional_connectivity_spheres import FunctionalConnectivitySpheres from .parcel_aggregation import ParcelAggregation from .sphere_aggregation import SphereAggregation +from .functional_connectivity import ( + FunctionalConnectivityParcels, + FunctionalConnectivitySpheres, +) from .reho import ReHoParcels, ReHoSpheres from .falff import ( AmplitudeLowFrequencyFluctuationParcels, -- 2.52.0 From 1808bd42ca8283ba989037e72240bf3ce7c8e223 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Tue, 3 Jan 2023 15:03:48 +0100 Subject: [PATCH 09/17] chore: fix lint for FunctionalConnectivityBase tests --- .../tests/test_functional_connectivity_base.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/junifer/markers/functional_connectivity/tests/test_functional_connectivity_base.py b/junifer/markers/functional_connectivity/tests/test_functional_connectivity_base.py index 01eec0703..634267fad 100644 --- a/junifer/markers/functional_connectivity/tests/test_functional_connectivity_base.py +++ b/junifer/markers/functional_connectivity/tests/test_functional_connectivity_base.py @@ -5,12 +5,11 @@ import pytest -from junifer.markers.functional_connectivity.functional_connectivity_base import ( - FunctionalConnectivityBase, -) +# done to keep line length 79 +import junifer.markers.functional_connectivity as fc def test_base_functional_connectivity_marker_abstractness() -> None: """Test FunctionalConnectivityBase is an abstract base class.""" with pytest.raises(TypeError, match="abstract"): - FunctionalConnectivityBase() + fc.functional_connectivity_base.FunctionalConnectivityBase() -- 2.52.0 From 7d68e21bd7e4817a6f6ad3c03fec71a24083924e Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Mon, 9 Jan 2023 17:02:18 +0100 Subject: [PATCH 10/17] refactor: move CrossParcellationFC to markers.functional_connectivity --- ...crossparcellation_functional_connectivity.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) rename junifer/markers/{ => functional_connectivity}/crossparcellation_functional_connectivity.py (91%) diff --git a/junifer/markers/crossparcellation_functional_connectivity.py b/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py similarity index 91% rename from junifer/markers/crossparcellation_functional_connectivity.py rename to junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py index e57e9180e..6a6aafba7 100644 --- a/junifer/markers/crossparcellation_functional_connectivity.py +++ b/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py @@ -8,12 +8,11 @@ from typing import Any, Dict, List, Optional import pandas as pd -from ..api.decorators import register_marker -from ..utils import logger -from ..utils.logging import raise_error -from .base import BaseMarker -from .parcel_aggregation import ParcelAggregation -from .utils import _correlate_dataframes +from ...api.decorators import register_marker +from ...utils import logger, raise_error +from ..base import BaseMarker +from ..parcel_aggregation import ParcelAggregation +from ..utils import _correlate_dataframes @register_marker @@ -115,10 +114,10 @@ class CrossParcellationFC(BaseMarker): to the user or stored in the storage by calling the store method with this as a parameter. The dictionary has the following keys: - * data : the correlation values between the two parcellations as + * ``data`` : the correlation values between the two parcellations as a numpy.ndarray - * col_names : the ROIs for first parcellation as a list - * row_names : the ROIs for second parcellation as a list + * ``col_names`` : the ROIs for first parcellation as a list + * ``row_names`` : the ROIs for second parcellation as a list """ logger.debug( -- 2.52.0 From c6f0ed4c7038c761d97c2d20ab71f20d7ca29a21 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Mon, 9 Jan 2023 17:03:14 +0100 Subject: [PATCH 11/17] update: move tests for CrossParcellationFC --- .../tests/test_crossparcellation_functional_connectivity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename junifer/markers/{ => functional_connectivity}/tests/test_crossparcellation_functional_connectivity.py (97%) diff --git a/junifer/markers/tests/test_crossparcellation_functional_connectivity.py b/junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py similarity index 97% rename from junifer/markers/tests/test_crossparcellation_functional_connectivity.py rename to junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py index 485a4900a..6a3317235 100644 --- a/junifer/markers/tests/test_crossparcellation_functional_connectivity.py +++ b/junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py @@ -9,7 +9,7 @@ from pathlib import Path import pytest from nilearn import image -from junifer.markers.crossparcellation_functional_connectivity import ( +from junifer.markers.functional_connectivity import ( CrossParcellationFC, ) from junifer.storage import SQLiteFeatureStorage -- 2.52.0 From 6be1b8bf86487dcae52005501eb9643f2871f273 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Mon, 9 Jan 2023 17:03:45 +0100 Subject: [PATCH 12/17] update: add CrossParcellationFC to markers.functional_connectivity imports --- junifer/markers/functional_connectivity/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/junifer/markers/functional_connectivity/__init__.py b/junifer/markers/functional_connectivity/__init__.py index a1733ee9d..8763a661d 100644 --- a/junifer/markers/functional_connectivity/__init__.py +++ b/junifer/markers/functional_connectivity/__init__.py @@ -5,3 +5,4 @@ from .functional_connectivity_parcels import FunctionalConnectivityParcels from .functional_connectivity_spheres import FunctionalConnectivitySpheres +from .crossparcellation_functional_connectivity import CrossParcellationFC -- 2.52.0 From 8774ca4fc0a92035f2ad342376bae686bd13bfe7 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Mon, 9 Jan 2023 17:04:38 +0100 Subject: [PATCH 13/17] update: add CrossParcellationFC import to markers.__init__ --- junifer/markers/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/junifer/markers/__init__.py b/junifer/markers/__init__.py index 542a26333..f5a4e2be6 100644 --- a/junifer/markers/__init__.py +++ b/junifer/markers/__init__.py @@ -14,6 +14,7 @@ from .sphere_aggregation import SphereAggregation from .functional_connectivity import ( FunctionalConnectivityParcels, FunctionalConnectivitySpheres, + CrossParcellationFC, ) from .reho import ReHoParcels, ReHoSpheres from .falff import ( -- 2.52.0 From 4ab877eba88debe3d23c26e2e8e327ebbc23fb44 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Mon, 9 Jan 2023 17:08:05 +0100 Subject: [PATCH 14/17] chore: update latest.inc --- docs/changes/latest.inc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changes/latest.inc b/docs/changes/latest.inc index d7d5c9a64..8d4365755 100644 --- a/docs/changes/latest.inc +++ b/docs/changes/latest.inc @@ -29,6 +29,9 @@ Enhancements - Add support for ``Dosenbach`` coordinates (:gh:`168` by `Synchon Mandal`_). +- Organize functional connectivity markers in ``junifer.markers.functional_connectivity`` + (:gh:`107` by `Synchon Mandal`_). + Bugs ~~~~ -- 2.52.0 From 8b36b7af2880369c3d9c5591c5364e46cfbd0c24 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Mon, 9 Jan 2023 17:24:19 +0100 Subject: [PATCH 15/17] fix: remove unnecesary import from markers.__init__ --- junifer/markers/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/junifer/markers/__init__.py b/junifer/markers/__init__.py index f5a4e2be6..de37c5a26 100644 --- a/junifer/markers/__init__.py +++ b/junifer/markers/__init__.py @@ -7,7 +7,6 @@ from .base import BaseMarker from .collection import MarkerCollection -from .crossparcellation_functional_connectivity import CrossParcellationFC from .ets_rss import RSSETSMarker from .parcel_aggregation import ParcelAggregation from .sphere_aggregation import SphereAggregation -- 2.52.0 From 4d5993b057dc3ef6fc2a20e23e952d1d6e34b4f2 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Mon, 9 Jan 2023 17:25:32 +0100 Subject: [PATCH 16/17] fix: issues with docs build indentation --- docs/changes/latest.inc | 2 +- junifer/markers/falff/falff_parcels.py | 1 + .../crossparcellation_functional_connectivity.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/changes/latest.inc b/docs/changes/latest.inc index 8d4365755..0fa9aa7d2 100644 --- a/docs/changes/latest.inc +++ b/docs/changes/latest.inc @@ -30,7 +30,7 @@ Enhancements - Add support for ``Dosenbach`` coordinates (:gh:`168` by `Synchon Mandal`_). - Organize functional connectivity markers in ``junifer.markers.functional_connectivity`` - (:gh:`107` by `Synchon Mandal`_). + (:gh:`107` by `Synchon Mandal`_). Bugs ~~~~ diff --git a/junifer/markers/falff/falff_parcels.py b/junifer/markers/falff/falff_parcels.py index 0dd3080b8..4015540f8 100644 --- a/junifer/markers/falff/falff_parcels.py +++ b/junifer/markers/falff/falff_parcels.py @@ -110,6 +110,7 @@ class AmplitudeLowFrequencyFluctuationParcels( * ``data`` : the actual computed values as a numpy.ndarray * ``columns`` : the column labels for the computed values as a list + """ pa = ParcelAggregation( parcellation=self.parcellation, diff --git a/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py b/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py index 6a6aafba7..1f1ca429c 100644 --- a/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py +++ b/junifer/markers/functional_connectivity/crossparcellation_functional_connectivity.py @@ -114,8 +114,8 @@ class CrossParcellationFC(BaseMarker): to the user or stored in the storage by calling the store method with this as a parameter. The dictionary has the following keys: - * ``data`` : the correlation values between the two parcellations as - a numpy.ndarray + * ``data`` : the correlation values between the two parcellations + as a numpy.ndarray * ``col_names`` : the ROIs for first parcellation as a list * ``row_names`` : the ROIs for second parcellation as a list -- 2.52.0 From 08bfd36a711d47a252ad4bb680be0e8bf44ce3ef Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Mon, 9 Jan 2023 17:26:14 +0100 Subject: [PATCH 17/17] chore: isort code base --- .../tests/test_crossparcellation_functional_connectivity.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py b/junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py index 6a3317235..608897482 100644 --- a/junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py +++ b/junifer/markers/functional_connectivity/tests/test_crossparcellation_functional_connectivity.py @@ -9,9 +9,7 @@ from pathlib import Path import pytest from nilearn import image -from junifer.markers.functional_connectivity import ( - CrossParcellationFC, -) +from junifer.markers.functional_connectivity import CrossParcellationFC from junifer.storage import SQLiteFeatureStorage from junifer.testing.datagrabbers import SPMAuditoryTestingDatagrabber -- 2.52.0