Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2p only conversion #22

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from typing import Union
from neuroconv.utils import load_dict_from_file, dict_deep_update
from higley_lab_to_nwb.benisty_2024 import Benisty2024NWBConverter
from higley_lab_to_nwb.lohani_2022.interfaces.lohani_2022_spike2signals_interface import get_streams
import os

import glob

def _get_sampling_frequency_and_image_size(folder_path: Union[str, Path]):
from roiextractors.extractors.tiffimagingextractors.scanimagetiff_utils import (
Expand All @@ -27,7 +28,6 @@ def _get_sampling_frequency_and_image_size(folder_path: Union[str, Path]):
image_size = [_num_rows, _num_columns]
return parsed_metadata["sampling_frequency"], image_size


def session_to_nwb(
folder_path: Union[str, Path], output_dir_path: Union[str, Path], session_id: str, stub_test: bool = False
):
Expand All @@ -42,6 +42,45 @@ def session_to_nwb(
source_data = dict()
conversion_options = dict()

search_pattern = "_".join(session_id.split("_")[:2])

# Add Analog signals from Spike2
file_path = glob.glob(os.path.join(folder_path, f"{search_pattern}*.smrx"))[0]
stream_ids, stream_names = get_streams(file_path=file_path)

# Define each smrx signal name
TTLsignals_name_map = {
stream_ids[stream_names == "galvo"][0]: "TTLSignal2PExcitation",
stream_ids[stream_names == "pupilcam"][0]: "TTLSignalPupilCamera",
}
behavioral_name_map = {
stream_ids[stream_names == "wheel"][0]: "WheelSignal",
}

source_data.update(
dict(
Spike2Signals=dict(
file_path=file_path,
ttl_stream_ids_to_names_map=TTLsignals_name_map,
behavioral_stream_ids_to_names_map=behavioral_name_map,
)
)
)
conversion_options.update(dict(Spike2Signals=dict(stub_test=stub_test)))

if "vis_stim" in session_id:
csv_file_path = glob.glob(os.path.join(folder_path, f"{search_pattern}*.csv"))[0]
source_data.update(
dict(
VisualStimulusInterface=dict(
spike2_file_path=file_path,
csv_file_path=csv_file_path,
stream_id=stream_ids[stream_names == "Vis"][0],
)
)
)
conversion_options.update(dict(VisualStimulusInterface=dict(stub_test=stub_test)))

# Add 2p Imaging
imaging_path = folder_path / "tiff"
source_data.update(dict(TwoPhotonImaging=dict(folder_path=str(imaging_path), file_pattern="*.tif")))
Expand Down Expand Up @@ -84,14 +123,28 @@ def session_to_nwb(
)
)

# Add Behavioral Video Recording
avi_files = glob.glob(os.path.join(folder_path, f"{search_pattern}*.avi"))
video_file_path = avi_files[0]
source_data.update(dict(Video=dict(file_paths=[video_file_path], verbose=False)))
conversion_options.update(dict(Video=dict(stub_test=stub_test)))

# Add Facemap outpt
# mat_files = glob.glob(os.path.join(folder_path, f"{search_pattern}*_proc.mat"))
# mat_file_path = mat_files[0]
# source_data.update(
# dict(
# FacemapInterface=dict(mat_file_path=str(mat_file_path), video_file_path=str(video_file_path), verbose=False)
# )
# )

# Add ophys metadata
ophys_metadata_path = Path(__file__).parent / "metadata" / "benisty_2024_ophys_metadata.yaml"
ophys_metadata_path = Path(__file__).parent / "metadata" / "benisty_2024_ophys_2p_only_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()
subject_id = session_id.split("_")[1]
metadata["Subject"].update(subject_id=subject_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Primary script to run to convert an entire session for of data using the NWBConverter."""

from pathlib import Path
from typing import Union
import os
from .benisty_2024_convert_session import session_to_nwb
from .benisty_2024_convert_2p_only_session import session_to_nwb



Expand Down
35 changes: 30 additions & 5 deletions src/higley_lab_to_nwb/benisty_2024/benisty_2024_nwbconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from neuroconv.utils import DeepDict

from neuroconv.datainterfaces import ScanImageMultiFileImagingInterface, Suite2pSegmentationInterface
from higley_lab_to_nwb.lohani_2022.interfaces import (
Lohani2022Spike2SignalsInterface,
Lohani2022VisualStimulusInterface,
)
from neuroconv.datainterfaces import VideoInterface, FacemapInterface

from .interfaces import Benisty2024CidanSegmentationInterface
from higley_lab_to_nwb.lohani_2022.interfaces import Lohani2022Spike2SignalsInterface
class Benisty2024NWBConverter(NWBConverter):
Expand All @@ -13,13 +19,16 @@ class Benisty2024NWBConverter(NWBConverter):
data_interface_classes = dict(
TwoPhotonImaging=ScanImageMultiFileImagingInterface,
Suite2pSegmentation=Suite2pSegmentationInterface,
CIDANSegmentation=Benisty2024CidanSegmentationInterface,
Spike2Signals=Lohani2022Spike2SignalsInterface,
CIDANSegmentation=Benisty2024CidanSegmentationInterface,
Video=VideoInterface,
FacemapInterface=FacemapInterface,
VisualStimulusInterface=Lohani2022VisualStimulusInterface,
)

def __init__(self, source_data: Dict[str, dict],ophys_metadata: Dict[str, dict], verbose: bool = True):
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
self.ophys_metadata = ophys_metadata

def get_metadata(self) -> DeepDict:
metadata = super().get_metadata()
Expand All @@ -38,7 +47,7 @@ def get_metadata(self) -> DeepDict:
metadata["Ophys"]["ImagingPlane"] = self.ophys_metadata["Ophys"]["ImagingPlane"]

return metadata

def temporally_align_data_interfaces(self):
ttlsignal_interface = self.data_interface_objects["Spike2Signals"]
# Synch imaging
Expand All @@ -54,4 +63,20 @@ def temporally_align_data_interfaces(self):
)
ttl_times = ttlsignal_interface.get_event_times_from_ttl(stream_id=stream_id)
imaging_interface.set_aligned_starting_time(ttl_times[0])
segmentation_interface.set_aligned_starting_time(ttl_times[0])
segmentation_interface.set_aligned_starting_time(ttl_times[0])

# Synch behaviour
video_interface = self.data_interface_objects["Video"]
# facemap_interface = self.data_interface_objects["FacemapInterface"]
video_interface._timestamps = video_interface.get_timestamps()
stream_id = next(
(
stream_id
for stream_id, stream_name in ttlsignal_interface.ttl_stream_ids_to_names_map.items()
if stream_name == "TTLSignalPupilCamera"
),
None,
)
ttl_times = ttlsignal_interface.get_event_times_from_ttl(stream_id=stream_id)
video_interface.set_aligned_starting_time(ttl_times[0])
# facemap_interface.set_aligned_starting_time(ttl_times[0])
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
nwb-conversion-tools==0.11.1 # Example of specific pinned dependecy
some-extra-package==1.11.3 # Example of another extra package that's necessary for the current conversion
roiextractors
neuroconv @ git+https://github.com/catalystneuro/neuroconv.git@facemap
neuroconv @ git+https://github.com/catalystneuro/neuroconv.git@facemap
ndx-facemap-motionsvd @ git+https://github.com/catalystneuro/ndx-facemap-motionsvd.git@main
46 changes: 0 additions & 46 deletions src/higley_lab_to_nwb/benisty_2024/utils/lohani_2022_utils.py

This file was deleted.