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

Add all sessions conversion script for Lohani22 #37

Merged
merged 3 commits into from
Aug 15, 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
2 changes: 1 addition & 1 deletion make_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
- defaults
dependencies:
- python>=3.9
- python==3.9
- pip
- pip:
- -e . # This calls the setup and therefore requirements minimal
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def add_visual_stimulus(self, nwbfile: NWBFile, metadata: dict, stub_test: bool

n_frames = 100 if stub_test and len(start_times) > 100 else len(start_times)

for frame in range(n_frames):
for frame in range(n_frames-1):
intervals_table.add_row(
start_time=start_times[frame],
stop_time=stop_times[frame],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
"""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 .lohani_2022_convert_session import session_to_nwb

from parse import parse
from lohani_2022_convert_session import session_to_nwb

from nwbinspector import inspect_all
from nwbinspector.inspector_tools import save_report, format_messages

# Parameters for conversion
root_path = Path("/media/amtra/Samsung_T5/CN_data")
root_path = Path("F:")
data_dir_path = root_path / "Higley-CN-data-share"
output_dir_path = root_path / "Higley-conversion_nwb/"
stub_test = False
verbose = True

session_folder_format = "{date_string}_{subject_id}_{behavior_type}"

raw_imaging_dir_path = data_dir_path / "Lohani22 Meso Data"
for folder_path in raw_imaging_dir_path.iterdir():
if folder_path.is_dir():
session_id = folder_path.name
metadata = parse(session_folder_format, session_id)
if verbose:
print("-" * 80)
print(f"Converting session {session_id}")

session_ids = os.listdir(data_dir_path)
stub_test = True
for session_id in session_ids:
session_folder = data_dir_path / Path(session_id)
if os.path.isdir(session_folder):
subject_id = metadata["subject_id"]
parcellation_folder_path = (
data_dir_path
/ "Lohani22 Parcellated data"
/ f"{subject_id.replace('AM', '')}"
/ "imaging with 575 excitation"
/ session_id
)
session_to_nwb(
folder_path=session_folder,
folder_path=folder_path,
parcellation_folder_path=parcellation_folder_path,
output_dir_path=output_dir_path,
session_id=session_id,
stub_test=stub_test,
verbose=verbose,
)

report_path = output_dir_path / "inspector_result.txt"
if not report_path.exists():
results = list(inspect_all(path=output_dir_path))
save_report(
report_file_path=report_path,
formatted_messages=format_messages(
results,
levels=["importance", "file_path"],
),
)
10 changes: 7 additions & 3 deletions src/higley_lab_to_nwb/lohani_2022/lohani_2022_convert_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def session_to_nwb(
output_dir_path: Union[str, Path],
session_id: str,
stub_test: bool = False,
verbose: bool = True,
):
output_dir_path = Path(output_dir_path)
if stub_test:
Expand Down Expand Up @@ -210,10 +211,13 @@ def session_to_nwb(
ophys_metadata_path = Path(__file__).parent / "metadata" / "lohani_2022_ophys_metadata.yaml"
ophys_metadata = load_dict_from_file(ophys_metadata_path)

if verbose:
print("Start conversion")
converter = Lohani2022NWBConverter(
source_data=source_data,
excitation_type_channel_combination=excitation_type_channel_combination,
ophys_metadata=ophys_metadata,
verbose=verbose,
)

# Add datetime to conversion
Expand All @@ -237,17 +241,17 @@ def session_to_nwb(

if __name__ == "__main__":
# Parameters for conversion
root_path = Path("G:")
root_path = Path("F:")
data_dir_path = root_path / "Higley-CN-data-share"
output_dir_path = root_path / "Higley-conversion_nwb"
stub_test = True
date = "11232019"
animal_number = "05"
behavior = "airpuffs"
session_id = f"{date}_grabAM{animal_number}_{behavior}"
folder_path = data_dir_path / session_id
folder_path = data_dir_path / "Lohani22 Meso Data" / session_id
parcellation_folder_path = (
data_dir_path / "parcellation" / f"grab{animal_number}" / "imaging with 575 excitation" / session_id
data_dir_path / "Lohani22 Parcellated data" / f"grab{animal_number}" / "imaging with 575 excitation" / session_id
)
session_to_nwb(
folder_path=folder_path,
Expand Down
9 changes: 8 additions & 1 deletion src/higley_lab_to_nwb/lohani_2022/lohani_2022_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ NWBFile:
institution: Yale University School of Medicine
lab: Higley
experimenter:
- Moberly, Andrew # others
- Lohani, Sweyta
- Moberly, Andrew
- Benisty, Hadas
- Landa, Boris
- Jing, Miao
- Li, Yulong
- Higley, Michael
- Cardin, Jessica
surgery: All surgical implantation procedures were performed on adult mice (>P50D). Mice were anesthetized using 1-2% isoflurane and maintained at 37 °C for the duration of the surgery. The skin and fascia above the skull were removed from the nasal bone to the posterior of the intraparietal bone and laterally between the temporal muscles. The surface of the skull was thoroughly cleaned with saline, and the edges of the incision were secured to the skull with Vetbond. A custom titanium headpost was secured to the posterior of the nasal bone with trans-parent dental cement (Metabond, Parkell), and a thin layer of dental cement was applied to the entire dorsal surface of the skull. Next, alayer of cyanoacrylate (Maxi-Cure, Bob Smith Industries) was used to cover the skull and left to cure approximately 30 min at 22-24 °C room temperature to provide a smooth surface for transcranial imaging.
virus: Pups were injected bilaterally with 2 μl of AAV9-hsyn-ACh3.0 (1.8 x 1013 gc / ml) and 2 μl of AAV9-hsyn-NES-jRCaMP1b (2.5 x 1013 gc / ml; Addgene) per hemisphere.
Subject:
Expand Down
10 changes: 6 additions & 4 deletions src/higley_lab_to_nwb/lohani_2022/lohani_2022_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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
ndx-facemap-motionsvd @ git+https://github.com/catalystneuro/ndx-facemap-motionsvd.git@main
neo
ndx-facemap-motionsvd@git+https://github.com/catalystneuro/ndx-facemap-motionsvd.git@main
spikeinterface
ndx-events@git+https://github.com/rly/ndx-events.git@main
sonpy
opencv-python
28 changes: 0 additions & 28 deletions src/higley_lab_to_nwb/lohani_2022/lohani_2022nwbconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,6 @@ def get_metadata(self) -> DeepDict:

return metadata

def run_conversion( # until [Issue #908](https://github.com/catalystneuro/neuroconv/issues/908) is fixed
self,
nwbfile_path: str = None,
nwbfile: NWBFile = None,
metadata: Dict = None,
overwrite: bool = False,
conversion_options: Dict = None,
) -> None:
if metadata is None:
metadata = self.get_metadata()

self.validate_metadata(metadata=metadata)

self.validate_conversion_options(conversion_options=conversion_options)

self.temporally_align_data_interfaces()

with make_or_load_nwbfile(
nwbfile_path=nwbfile_path,
nwbfile=nwbfile,
metadata=metadata,
overwrite=overwrite,
verbose=self.verbose,
) as nwbfile_out:
self.add_to_nwbfile(nwbfile_out, metadata, conversion_options)

return
alessandratrapani marked this conversation as resolved.
Show resolved Hide resolved

def temporally_align_data_interfaces(self):
ttlsignal_interface = self.data_interface_objects["Spike2Signals"]

Expand Down