From 7440af276435886789fad5360e30976e334fbfab Mon Sep 17 00:00:00 2001 From: alessandratrapani Date: Tue, 8 Oct 2024 14:51:51 +0200 Subject: [PATCH 1/4] add minian data interface --- src/neuroconv/datainterfaces/__init__.py | 2 ++ .../datainterfaces/ophys/minian/__init__.py | 0 .../ophys/minian/miniandatainterface.py | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/neuroconv/datainterfaces/ophys/minian/__init__.py create mode 100644 src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py diff --git a/src/neuroconv/datainterfaces/__init__.py b/src/neuroconv/datainterfaces/__init__.py index bf5df908e..faf792583 100644 --- a/src/neuroconv/datainterfaces/__init__.py +++ b/src/neuroconv/datainterfaces/__init__.py @@ -81,6 +81,7 @@ from .ophys.micromanagertiff.micromanagertiffdatainterface import ( MicroManagerTiffImagingInterface, ) +from .ophys.minian.miniandatainterface import MinianSegmentationInterface from .ophys.miniscope.miniscopeimagingdatainterface import MiniscopeImagingInterface from .ophys.sbx.sbxdatainterface import SbxImagingInterface from .ophys.scanimage.scanimageimaginginterfaces import ( @@ -151,6 +152,7 @@ MicroManagerTiffImagingInterface, MiniscopeImagingInterface, TDTFiberPhotometryInterface, + MinianSegmentationInterface, # Behavior VideoInterface, AudioInterface, diff --git a/src/neuroconv/datainterfaces/ophys/minian/__init__.py b/src/neuroconv/datainterfaces/ophys/minian/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py b/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py new file mode 100644 index 000000000..c1152106b --- /dev/null +++ b/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py @@ -0,0 +1,30 @@ +from roiextractors.extraction_tools import PathType +from ..basesegmentationextractorinterface import BaseSegmentationExtractorInterface + + +class MinianSegmentationInterface(BaseSegmentationExtractorInterface): + """Data interface for MinianSegmentationExtractor.""" + + display_name = "Minian Segmentation" + associated_suffixes = (".zarr",) + info = "Interface for Minian segmentation data." + + + @classmethod + def get_source_schema(cls) -> dict: + source_metadata = super().get_source_schema() + source_metadata["properties"]["folder_path"]["description"] = "Path to .zarr output." + return source_metadata + + def __init__(self, folder_path: PathType, verbose: bool = True): + """ + + Parameters + ---------- + folder_path : PathType + Path to .zarr path. + verbose : bool, default True + Whether to print progress + """ + super().__init__(folder_path=folder_path) + self.verbose = verbose From f56651ac5c84f339505e5cc3c22516ccad4aad8d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:53:52 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../datainterfaces/ophys/minian/miniandatainterface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py b/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py index c1152106b..3f1f96210 100644 --- a/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py +++ b/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py @@ -1,4 +1,5 @@ from roiextractors.extraction_tools import PathType + from ..basesegmentationextractorinterface import BaseSegmentationExtractorInterface @@ -9,7 +10,6 @@ class MinianSegmentationInterface(BaseSegmentationExtractorInterface): associated_suffixes = (".zarr",) info = "Interface for Minian segmentation data." - @classmethod def get_source_schema(cls) -> dict: source_metadata = super().get_source_schema() From 44ff90d97004a63ae72ce8eb2b17adbb3e9844c2 Mon Sep 17 00:00:00 2001 From: alessandratrapani Date: Thu, 10 Oct 2024 11:01:51 +0200 Subject: [PATCH 3/4] add tests --- .../ophys/minian/miniandatainterface.py | 30 ++++++++++++ .../ophys/test_segmentation_interfaces.py | 47 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py b/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py index c1152106b..58e3db5fc 100644 --- a/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py +++ b/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py @@ -1,3 +1,7 @@ +from typing import Optional + +from pynwb import NWBFile + from roiextractors.extraction_tools import PathType from ..basesegmentationextractorinterface import BaseSegmentationExtractorInterface @@ -28,3 +32,29 @@ def __init__(self, folder_path: PathType, verbose: bool = True): """ super().__init__(folder_path=folder_path) self.verbose = verbose + + def add_to_nwbfile( + self, + nwbfile: NWBFile, + metadata: Optional[dict] = None, + stub_test: bool = False, + stub_frames: int = 100, + include_background_segmentation: bool = True, + include_roi_centroids: bool = True, + include_roi_acceptance: bool = False, + mask_type: Optional[str] = "image", # Literal["image", "pixel", "voxel"] + plane_segmentation_name: Optional[str] = None, + iterator_options: Optional[dict] = None, + ): + super().add_to_nwbfile( + nwbfile=nwbfile, + metadata=metadata, + stub_test=stub_test, + stub_frames=stub_frames, + include_background_segmentation=include_background_segmentation, + include_roi_centroids=include_roi_centroids, + include_roi_acceptance=include_roi_acceptance, + mask_type=mask_type, + plane_segmentation_name=plane_segmentation_name, + iterator_options=iterator_options, + ) \ No newline at end of file diff --git a/tests/test_on_data/ophys/test_segmentation_interfaces.py b/tests/test_on_data/ophys/test_segmentation_interfaces.py index b2c6428f1..db78c7bba 100644 --- a/tests/test_on_data/ophys/test_segmentation_interfaces.py +++ b/tests/test_on_data/ophys/test_segmentation_interfaces.py @@ -5,6 +5,7 @@ CnmfeSegmentationInterface, ExtractSegmentationInterface, Suite2pSegmentationInterface, + MinianSegmentationInterface, ) from neuroconv.tools.testing.data_interface_mixins import ( SegmentationExtractorInterfaceTestMixin, @@ -204,3 +205,49 @@ class TestSuite2pSegmentationInterfaceWithStubTest(SegmentationExtractorInterfac ) save_directory = OUTPUT_PATH conversion_options = dict(stub_test=True) + + +class TestMinianSegmentationInterface(SegmentationExtractorInterfaceTestMixin): + data_interface_cls = MinianSegmentationInterface + interface_kwargs = dict( + folder_path= OPHYS_DATA_PATH / "segmentation_datasets" / "minian" + ) + save_directory = OUTPUT_PATH + + @pytest.fixture( + params=[ + {"mask_type": "image", "include_background_segmentation": True}, + {"mask_type": "pixel", "include_background_segmentation": True}, + {"mask_type": "voxel", "include_background_segmentation": True}, + # {"mask_type": None, "include_background_segmentation": True}, # Uncomment when https://github.com/catalystneuro/neuroconv/issues/530 is resolved + {"include_roi_centroids": False, "include_background_segmentation": True}, + {"include_roi_acceptance": False, "include_background_segmentation": True}, + {"include_background_segmentation": False}, + ], + ids=[ + "mask_type_image", + "mask_type_pixel", + "mask_type_voxel", + "exclude_roi_centroids", + "exclude_roi_acceptance", + "exclude_background_segmentation", + ], + ) + def setup_interface(self, request): + + test_id = request.node.callspec.id + self.test_name = test_id + self.interface_kwargs = self.interface_kwargs + self.conversion_options = request.param + self.interface = self.data_interface_cls(**self.interface_kwargs) + + return self.interface, self.test_name + + +class TestMinianSegmentationInterfaceWithStubTest(SegmentationExtractorInterfaceTestMixin): + data_interface_cls = MinianSegmentationInterface + interface_kwargs = dict( + folder_path=OPHYS_DATA_PATH / "segmentation_datasets" / "minian", + ) + save_directory = OUTPUT_PATH + conversion_options = dict(stub_test=True) \ No newline at end of file From 3cf60e934a7fd6f110e71f1a04e5e4ca7a2d1f87 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 10 Oct 2024 09:02:44 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../datainterfaces/ophys/minian/miniandatainterface.py | 3 +-- tests/test_on_data/ophys/test_segmentation_interfaces.py | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py b/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py index 2045688b1..92e4620fa 100644 --- a/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py +++ b/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py @@ -1,7 +1,6 @@ from typing import Optional from pynwb import NWBFile - from roiextractors.extraction_tools import PathType from ..basesegmentationextractorinterface import BaseSegmentationExtractorInterface @@ -57,4 +56,4 @@ def add_to_nwbfile( mask_type=mask_type, plane_segmentation_name=plane_segmentation_name, iterator_options=iterator_options, - ) \ No newline at end of file + ) diff --git a/tests/test_on_data/ophys/test_segmentation_interfaces.py b/tests/test_on_data/ophys/test_segmentation_interfaces.py index db78c7bba..230415292 100644 --- a/tests/test_on_data/ophys/test_segmentation_interfaces.py +++ b/tests/test_on_data/ophys/test_segmentation_interfaces.py @@ -4,8 +4,8 @@ CaimanSegmentationInterface, CnmfeSegmentationInterface, ExtractSegmentationInterface, - Suite2pSegmentationInterface, MinianSegmentationInterface, + Suite2pSegmentationInterface, ) from neuroconv.tools.testing.data_interface_mixins import ( SegmentationExtractorInterfaceTestMixin, @@ -209,9 +209,7 @@ class TestSuite2pSegmentationInterfaceWithStubTest(SegmentationExtractorInterfac class TestMinianSegmentationInterface(SegmentationExtractorInterfaceTestMixin): data_interface_cls = MinianSegmentationInterface - interface_kwargs = dict( - folder_path= OPHYS_DATA_PATH / "segmentation_datasets" / "minian" - ) + interface_kwargs = dict(folder_path=OPHYS_DATA_PATH / "segmentation_datasets" / "minian") save_directory = OUTPUT_PATH @pytest.fixture( @@ -250,4 +248,4 @@ class TestMinianSegmentationInterfaceWithStubTest(SegmentationExtractorInterface folder_path=OPHYS_DATA_PATH / "segmentation_datasets" / "minian", ) save_directory = OUTPUT_PATH - conversion_options = dict(stub_test=True) \ No newline at end of file + conversion_options = dict(stub_test=True)