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..92e4620fa --- /dev/null +++ b/src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py @@ -0,0 +1,59 @@ +from typing import Optional + +from pynwb import NWBFile +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 + + 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, + ) diff --git a/tests/test_on_data/ophys/test_segmentation_interfaces.py b/tests/test_on_data/ophys/test_segmentation_interfaces.py index b2c6428f1..230415292 100644 --- a/tests/test_on_data/ophys/test_segmentation_interfaces.py +++ b/tests/test_on_data/ophys/test_segmentation_interfaces.py @@ -4,6 +4,7 @@ CaimanSegmentationInterface, CnmfeSegmentationInterface, ExtractSegmentationInterface, + MinianSegmentationInterface, Suite2pSegmentationInterface, ) from neuroconv.tools.testing.data_interface_mixins import ( @@ -204,3 +205,47 @@ 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)