diff --git a/src/cai_lab_to_nwb/zaki_2024/__init__.py b/src/cai_lab_to_nwb/zaki_2024/__init__.py index ffd480e..6d8ace2 100644 --- a/src/cai_lab_to_nwb/zaki_2024/__init__.py +++ b/src/cai_lab_to_nwb/zaki_2024/__init__.py @@ -1 +1,3 @@ from .implant_interface import ImplantInterface +from .behaviorinterface import FreezingBehaviorInterface +from .sleepinterface import SleepBehaviorInterface \ No newline at end of file diff --git a/src/cai_lab_to_nwb/zaki_2024/metadata.yaml b/src/cai_lab_to_nwb/zaki_2024/metadata.yaml index c0cd6b0..09519c8 100644 --- a/src/cai_lab_to_nwb/zaki_2024/metadata.yaml +++ b/src/cai_lab_to_nwb/zaki_2024/metadata.yaml @@ -1,4 +1,15 @@ NWBFile: + keywords: + - hippocampus + - memory integration + - memory-linking + - ensemble + - reactivation + - co-firing + - offline periods + - sleep + - stress + - PTSD related_publications: https://doi.org/### or link to APA or MLA citation of the publication session_description: @@ -7,8 +18,24 @@ NWBFile: lab: Cai experimenter: - Cai, Denise + - Morales-Rodriguez, Denisse + - Bacon, Madeline E. + - Ko, BumJin + - Francisco, Taylor R. + - LaBanca, Alexa R. + - Sompolpong, Patlapa + - Dong, Zhe + - Lamsifer, Sophia + - Chen, Hung-Tu + - Carrillo Segura, Simón + - Christenson Wick, Zoé + - Silva, Alcino J. + - Rajan, Kanaka + - van der Meer, Matthijs + - Fenton, André + - Shuman, Tristan - Zaki, Yosif Subject: - species: Rattus norvegicus + species: Mus musculus age: TBD # in ISO 8601, such as "P1W2D" sex: TBD # One of M, F, U, or O diff --git a/src/cai_lab_to_nwb/zaki_2024/sleepinterface.py b/src/cai_lab_to_nwb/zaki_2024/sleepinterface.py new file mode 100644 index 0000000..696f94a --- /dev/null +++ b/src/cai_lab_to_nwb/zaki_2024/sleepinterface.py @@ -0,0 +1,77 @@ +"""Primary class for converting experiment-specific behavior.""" + +from pynwb.file import NWBFile + +from neuroconv.basedatainterface import BaseDataInterface +from neuroconv.utils import DeepDict +from pydantic import FilePath +from typing import Optional +from pynwb.epoch import TimeIntervals + + +class SleepBehaviorInterface(BaseDataInterface): + """Adds intervals of freezing behavior interface.""" + + keywords = ["behavior"] + + def __init__(self, file_path: FilePath, video_sampling_frequency: float, verbose: bool = False): + # This should load the data lazily and prepare variables you need + + self.file_path = file_path + self.verbose = verbose + self.video_sampling_frequency = video_sampling_frequency + + def get_metadata(self) -> DeepDict: + # Automatically retrieve as much metadata as possible from the source files available + metadata = super().get_metadata() + + return metadata + + def add_to_nwbfile(self, nwbfile: NWBFile, metadata: Optional[dict] = None): + + import pandas as pd + from ndx_events import LabeledEvents + + sleep_behavior_df = pd.read_csv(self.file_path) + + import numpy as np + + # Note this will have the first row as None + shifted_sleep_state = sleep_behavior_df['SleepState'].shift() + start_indices = np.where(sleep_behavior_df['SleepState'] != shifted_sleep_state)[0] + stop_indices = [i - 1 for i in start_indices[1:]] + stop_indices.append(len(sleep_behavior_df) - 1) + stop_indices = np.array(stop_indices) + + start_frames = sleep_behavior_df['Frame'][start_indices].values + start_times = start_frames / self.video_sampling_frequency + stop_frames = sleep_behavior_df['Frame'][stop_indices].values + stop_times = stop_frames / self.video_sampling_frequency + slep_state = sleep_behavior_df['SleepState'][start_indices].values + + + description = ( + "Sleep states classified with custom algorithm using the data " + "from the HD-X02 sensor (EEG, EMG, temperature, etc.)." + ) + + sleep_intervals = TimeIntervals(name="SleepIntervals", description=description) + column_description = """ + Sleep State Classification, it can be one of the following: + - 'quiet wake': The animal is awake and alert but at rest, without engaging in any voluntary movement or significant cognitive activity + - 'rem': Sleep stage characterized by Rapid Eye Movements (REM) beneath closed eyelids. + - 'sws': Slow-Wave Sleep (SWS) is a stage of non-REM (NREM) sleep characterized by slow, high-amplitude brain waves + - 'wake': State of full consciousness when the animal is alert, responsive to the environment, and capable of voluntary movement + """ + sleep_intervals.add_column(name="sleep_state", description=column_description) + + for start_time, stop_time, state in zip(start_times, stop_times, slep_state): + sleep_intervals.add_interval(start_time=start_time, stop_time=stop_time, sleep_state=state) + + if "sleep" not in nwbfile.processing: + sleep_module = nwbfile.create_processing_module(name="sleep", description="Sleep data") + else: + sleep_module = nwbfile.processing["sleep"] + + sleep_module.add(sleep_intervals) + diff --git a/src/cai_lab_to_nwb/zaki_2024/zaki_2024_notes.md b/src/cai_lab_to_nwb/zaki_2024/zaki_2024_notes.md index ea623ec..5b07a02 100644 --- a/src/cai_lab_to_nwb/zaki_2024/zaki_2024_notes.md +++ b/src/cai_lab_to_nwb/zaki_2024/zaki_2024_notes.md @@ -14,10 +14,6 @@ https://med-associates.com/product-category/software-all/software-software/ ## Questions and To-do: * Why sometimes the exposure has more than one attempt? Can you describe more about this? -* Inside the behavior tracking in the raw data for offline data there is a pose.csv, what is it? I see a lot of references to deep lab cut, was that attempted? (Yes, v4 of miniscope has that possibility but they are not using it. Ignore it) -* What are the pickle files in the EDF folder? (they can be ignored) -* How comes that pyedflib is not able to read the EDF files? (this is probably the proprietary format that they used) -* What is `headOrientation.csv` inside a miniscope folder? (this is another feature of miniscope that they are not using in Zaki conversion. Maybe it would be good to get data with this features for future conversions) * Where is the information of the context? that is, they say that they distinguish them by oddor and other features of the context, where is this. * In the Miniscope data, there are folders with `failed_to_fix` and `bad_frames`. Can you tell me more about those things? * What are the raw files like `Ca_EEG2-1_Recall3.raw`? @@ -25,11 +21,13 @@ https://med-associates.com/product-category/software-all/software-software/ * According to Alessandra notes, the behavior videos are synch to the miniscope data. I remember a pulse, can you confirm this? Basically, how to synch the miniscope data with the video? Usually they are part of the same system in miniscope, was it the case here? * What happens in day two? Are offline days 1 and 2 (which is actually three) different? * Is the freezing output on the segmentation folder the same that the one in the corresponding imaging folder? It seems that they are for some files, confirm this. -* The aligned sleep data has a column called frame but the corresponding ophys data is many videos? Again, how are they aligned? is the frame aggregated? In this case they are aligned to an idealized clock. +* For the sleep data, the labels in the paper are : NREM, REM, WAKE (Extended Figure 9 F) but in the data we only found labels: + `sleep_states = ['quiet wake', 'rem', 'sws', 'wake']` + +Relationship? What version of miniscope they used? do they know how it changes the configuration, the data? THEY ARE USING V4. -DAQ: @@ -76,6 +74,12 @@ This is the surgery performed on the experiments that we are converting the data > For calcium imaging experiments with EEG/EMG implants, mice underwent three serial procedures spaced ~two weeks apart. During the first surgery, mice had 300nL of AAV1-Syn-GCaMP6f injected into dorsal CA1 as described above, but had the incision sutured after the surgery. Two weeks later during a second surgery, mice had their overlying cortex aspirated and a GRIN lens implanted above the injection site, as above. During this surgery, a wireless telemetry probe (HD-X02, Data Science International) was also implanted with EEG and EMG wires. Two EMG wires were implanted into the left trapezius muscle. One EEG wire was implanted between skull and dura mater above dorsal hippocampus on the contralateral hemisphere to the GRIN lens (left hemisphere; AP -2mm, ML -1.5mm), and a reference EEG wire was implanted between skull and dura on the right hemisphere overlying prefrontal cortex (AP + 1.75mm, ML -0.5mm). Cyanoacrylate and dental cement fixed the GRIN lens, anchor screw, and EEG wires in place. The telemetry probes were implanted during the second surgery rather than the first to minimize the time that the mice needed to live with the implant (because the mice sometimes reject the implant after long periods). During the third procedure, the mice were returned to implant the baseplate, as described above. +### Subject + + +Adult C57BL/6J wild-type mice from Jackson Laboratories were used in all experiments except for inhibitory tagging experiments (Extended Figures 5,6). In those experiments, Gad2-cre mice from Jackson Laboratories (or bred in-house from Jackson Laboratories) were used. Mice ordered from Jackson arrived group-housed in cages of 4 mice/cage and were singly housed for the experiment. For behavioral experiments where mice did not undergo surgery, mice were ordered to arrive at 12 weeks of age and underwent behavioral testing 1-2 weeks from then. For experiments where mice underwent surgery, mice were ordered to arrive at 8-9 weeks of age and underwent behavioral testing about 4-6 weeks after the arrival date. For experiments where mice underwent PSAM virus injections, mice were included in the experiment if there was expression of GFP+ cell bodies in both the dorsal and ventral hippocampus. All experimental procedures were approved by the Icahn School of Medicine at Mount Sinai’s IACUC. + + ## File structure @@ -580,11 +584,19 @@ These files are full day recordings. Their filename contains a timestamps with a └── summary_files ``` -## EEG and MEG +## EDF (EEG and MEG) The EDF format specification: https://doi.org/10.1016/S1388-2457(03)00123-8 +The pickle files related to the edf data can be ignored. + +* How comes that pyedflib is not able to read the EDF files? The EDFs are produce with the HD-X02 device and is unclear to the authors. + + +### Device: +HD-X02, Data Science International. The sheet is [here](https://www.datasci.com/docs/default-source/implantable-telemetry/hd-x02_s02.pdf) + ### Exploration with MNE @@ -713,8 +725,6 @@ info["chs"] ``` -### Device: -HD-X02, Data Science International. The sheet is [here](https://www.datasci.com/docs/default-source/implantable-telemetry/hd-x02_s02.pdf) ## Miniscope @@ -745,6 +755,10 @@ Other changes AMU: Inertia Motion +`pose.csv` files are related to deep lab cut estimation of the pose of the animal. This is a feature on the latest version of minian that is currently not used in this conversion. + +* What is `headOrientation.csv` inside a miniscope folder? this is another feature of miniscope that they are not using in Zaki conversion. + This is the metadata file in the same directory that the minian videos: ```json @@ -857,8 +871,10 @@ The data looks like this: The possible sleep states are: * wake * quite wake -* sws +* sws (slow wave sleep) +* rem +* The aligned sleep data has a column called frame but the corresponding ophys data is many videos? Again, how are they aligned? is the frame aggregated? In this case they are aligned to an idealized clock. They interpolated from the video timestamps that used the perfect sampling rate. Check this with the authors when we are working with synchronization. ## Some synch information