From f97f47397029b192782048be53a9a3dbaf9651eb Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Wed, 15 May 2024 12:13:23 +0200 Subject: [PATCH 1/3] add suite2p interface and correct for right metadata --- .../benisty_2024_convert_session.py | 18 +++++++++------ .../benisty_2024/benisty_2024_nwbconverter.py | 23 ++++++++++++++++--- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py b/src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py index 3e63a4e..544b88a 100644 --- a/src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py +++ b/src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py @@ -32,11 +32,21 @@ def session_to_nwb( source_data.update(dict(TwoPhotonImagingGreenChannel=dict(folder_path=str(imaging_path), file_pattern=f"*.tif"))) conversion_options.update(dict(TwoPhotonImagingGreenChannel=dict(stub_test=stub_test))) + # Add Segmentation + suite2p_path = folder_path / "suite2p" + source_data.update(dict(SegmentationGreenChannel=dict(folder_path = suite2p_path))) + conversion_options.update(dict(SegmentationGreenChannel=dict(stub_test=stub_test))) + + # Add ophys metadata + ophys_metadata_path = Path(__file__).parent / "metadata" / "benisty_2024_ophys_metadata.yaml" + ophys_metadata = load_dict_from_file(ophys_metadata_path) + converter = Benisty2024NWBConverter( - source_data=source_data, + source_data=source_data,ophys_metadata=ophys_metadata ) # Add datetime to conversion + metadata = converter.get_metadata() subject_id = session_id.split("_")[1] metadata["Subject"].update(subject_id=subject_id) @@ -47,12 +57,6 @@ def session_to_nwb( editable_metadata = load_dict_from_file(editable_metadata_path) metadata = dict_deep_update(metadata, editable_metadata) - # Add ophys metadata - ophys_metadata_path = Path(__file__).parent / "metadata" / "benisty_2024_ophys_metadata.yaml" - ophys_metadata = load_dict_from_file(ophys_metadata_path) - metadata.pop("Ophys", None) - metadata = dict_deep_update(metadata, ophys_metadata) - # Run conversion converter.run_conversion( metadata=metadata, nwbfile_path=nwbfile_path, conversion_options=conversion_options, overwrite=True diff --git a/src/higley_lab_to_nwb/benisty_2024/benisty_2024_nwbconverter.py b/src/higley_lab_to_nwb/benisty_2024/benisty_2024_nwbconverter.py index 00cb585..7e85537 100644 --- a/src/higley_lab_to_nwb/benisty_2024/benisty_2024_nwbconverter.py +++ b/src/higley_lab_to_nwb/benisty_2024/benisty_2024_nwbconverter.py @@ -1,12 +1,29 @@ """Primary NWBConverter class for this dataset.""" - +from typing import Dict from neuroconv import NWBConverter -from neuroconv.datainterfaces import ScanImageMultiFileImagingInterface +from neuroconv.datainterfaces import ScanImageMultiFileImagingInterface, Suite2pSegmentationInterface +from neuroconv.utils import DeepDict class Benisty2024NWBConverter(NWBConverter): """Primary conversion class.""" data_interface_classes = dict( TwoPhotonImagingGreenChannel=ScanImageMultiFileImagingInterface, - ) \ No newline at end of file + SegmentationGreenChannel=Suite2pSegmentationInterface, + ) + def __init__(self, source_data: Dict[str, dict],ophys_metadata: Dict[str, dict], verbose: bool = True): + super().__init__(source_data, verbose) + self.ophys_metadata=ophys_metadata + + def get_metadata(self) -> DeepDict: + metadata = super().get_metadata() + segmentation_metadata = self.data_interface_objects["SegmentationGreenChannel"].get_metadata() + for segmentation_metadata_ind in range(len(segmentation_metadata["Ophys"]["ImageSegmentation"]["plane_segmentations"])): + metadata["Ophys"]["ImageSegmentation"]["plane_segmentations"][segmentation_metadata_ind]["imaging_plane"] = self.ophys_metadata["Ophys"]["ImagingPlane"][0]["name"] + + metadata["Ophys"]["Device"] = self.ophys_metadata["Ophys"]["Device"] + metadata["Ophys"]["TwoPhotonSeries"] = self.ophys_metadata["Ophys"]["TwoPhotonSeries"] + metadata["Ophys"]["ImagingPlane"] = self.ophys_metadata["Ophys"]["ImagingPlane"] + + return metadata \ No newline at end of file From 5c1ff42679215b1700c40636eaf2e8b4eab0cf40 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Thu, 16 May 2024 15:15:24 +0200 Subject: [PATCH 2/3] update metadata --- .../metadata/benisty_2024_ophys_metadata.yaml | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/higley_lab_to_nwb/benisty_2024/metadata/benisty_2024_ophys_metadata.yaml b/src/higley_lab_to_nwb/benisty_2024/metadata/benisty_2024_ophys_metadata.yaml index 5fe4fd7..f6832cf 100644 --- a/src/higley_lab_to_nwb/benisty_2024/metadata/benisty_2024_ophys_metadata.yaml +++ b/src/higley_lab_to_nwb/benisty_2024/metadata/benisty_2024_ophys_metadata.yaml @@ -1,4 +1,21 @@ Ophys: Device: - OnePhotonSeries: - ImagingPlane: \ No newline at end of file + - name: TwoPhotonMicroscope + description: MOM microscope (Sutter Instruments) coupled to a 16x, 0.8 NA objective (Nikon). Excitation was driven by a Titanium-Sapphire Laser (Mai-Tai eHP DeepSee, Spectra-Physics). + manufacturer: Sutter Instruments + TwoPhotonSeries: + - name: TwoPhotonSeriesGreenChannel + description: Imaging data from Green channel recorded with 2p microscope. Images were acquired at 512x512 resolution at 30 Hz using a galvo-resonant scan system controlled by ScanImage software (Vidrio). + imaging_plane: ImagingPlaneGreenChannel + unit: n.a. + ImagingPlane: + - name: ImagingPlaneGreenChannel + description: Imaging plane for the Green channel recorded with 2p microscope. + excitation_lambda: 920.0 # in nm + location: Whole Brain + device: TwoPhotonMicroscope + optical_channel: + - name: Green + description: Emitted light was collected through a 525/50 filter and a gallium arsenide phosphide photomultiplier tube (Hamamatsu). + emission_lambda: 525.0 + indicator: GCaMP6s \ No newline at end of file From 148de926938f80a344c7820c9691c856050a82d8 Mon Sep 17 00:00:00 2001 From: Alessandra Trapani Date: Thu, 16 May 2024 15:42:23 +0200 Subject: [PATCH 3/3] minor fixes --- .../benisty_2024_convert_session.py | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py b/src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py index c503af8..4403fd7 100644 --- a/src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py +++ b/src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py @@ -5,7 +5,6 @@ from neuroconv.utils import load_dict_from_file, dict_deep_update from higley_lab_to_nwb.benisty_2024 import Benisty2024NWBConverter import os -import glob def session_to_nwb( @@ -17,39 +16,30 @@ def session_to_nwb( output_dir_path = output_dir_path / "nwb_stub" output_dir_path.mkdir(parents=True, exist_ok=True) - nwbfile_path = output_dir_path / f"{session_id}_new.nwb" - - source_data = dict() - conversion_options = dict() - nwbfile_path = output_dir_path / f"{session_id}.nwb" source_data = dict() conversion_options = dict() # Add 2p Imaging - imaging_path = folder_path / "tiff" - source_data.update(dict(TwoPhotonImagingGreenChannel=dict(folder_path=str(imaging_path), file_pattern=f"*.tif"))) + imaging_path = folder_path / "tiff" + source_data.update(dict(TwoPhotonImagingGreenChannel=dict(folder_path=str(imaging_path), file_pattern="*.tif"))) conversion_options.update(dict(TwoPhotonImagingGreenChannel=dict(stub_test=stub_test))) # Add Segmentation suite2p_path = folder_path / "suite2p" - source_data.update(dict(SegmentationGreenChannel=dict(folder_path = suite2p_path))) + source_data.update(dict(SegmentationGreenChannel=dict(folder_path=suite2p_path))) conversion_options.update(dict(SegmentationGreenChannel=dict(stub_test=stub_test))) # Add ophys metadata ophys_metadata_path = Path(__file__).parent / "metadata" / "benisty_2024_ophys_metadata.yaml" ophys_metadata = load_dict_from_file(ophys_metadata_path) - converter = Benisty2024NWBConverter( - source_data=source_data,ophys_metadata=ophys_metadata - ) + converter = Benisty2024NWBConverter(source_data=source_data, ophys_metadata=ophys_metadata) # Add datetime to conversion metadata = converter.get_metadata() - date = read_session_start_time(folder_path=folder_path) - metadata["NWBFile"]["session_start_time"] = date subject_id = session_id.split("_")[1] metadata["Subject"].update(subject_id=subject_id) metadata["NWBFile"].update(session_id=session_id) @@ -73,7 +63,7 @@ def session_to_nwb( output_dir_path = root_path / "Higley-conversion_nwb/" stub_test = True session_ids = os.listdir(data_dir_path) - session_id = "11222019_grabAM06_vis_stim" + session_id = "04072021_am2psi_05_spont" folder_path = data_dir_path / Path(session_id) session_to_nwb( folder_path=folder_path,