Skip to content

Commit

Permalink
Merge pull request #17 from catalystneuro/add_suite2p
Browse files Browse the repository at this point in the history
Add suite2p interface
  • Loading branch information
alessandratrapani authored May 16, 2024
2 parents d0f7ff5 + 148de92 commit a5a1502
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 20 deletions.
31 changes: 17 additions & 14 deletions src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -17,21 +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"
nwbfile_path = output_dir_path / f"{session_id}.nwb"

source_data = dict()
conversion_options = dict()

search_pattern = "_".join(session_id.split("_")[:2])
# Add 2p Imaging
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)))

converter = Benisty2024NWBConverter(
source_data=source_data,
)
# 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, 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)
Expand All @@ -41,11 +49,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 = dict_deep_update(metadata, ophys_metadata)

# Run conversion
converter.run_conversion(
metadata=metadata, nwbfile_path=nwbfile_path, conversion_options=conversion_options, overwrite=True
Expand All @@ -60,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,
Expand Down
25 changes: 21 additions & 4 deletions src/higley_lab_to_nwb/benisty_2024/benisty_2024_nwbconverter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
"""Primary NWBConverter class for this dataset."""

from typing import Dict, List
from typing import Dict
from neuroconv import NWBConverter


from neuroconv.datainterfaces import ScanImageMultiFileImagingInterface, Suite2pSegmentationInterface
from neuroconv.utils import DeepDict

class Benisty2024NWBConverter(NWBConverter):
"""Primary conversion class."""

data_interface_classes = dict(
)
TwoPhotonImagingGreenChannel=ScanImageMultiFileImagingInterface,
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
Ophys:
Device:
OnePhotonSeries:
ImagingPlane:
- 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

0 comments on commit a5a1502

Please sign in to comment.