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

Expose flags to include or not data streams #14

Merged
merged 2 commits into from
Nov 11, 2024
Merged
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
67 changes: 45 additions & 22 deletions src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_miniscope_folder_path(folder_path: Union[str, Path]):
miniscope_name = general_metadata["miniscopes"][0]
return folder_path / miniscope_name.replace(" ", "_")
else:
print("No Miniscope data found at {}".format(folder_path))
print(f"No Miniscope data found at {folder_path}")
return None


Expand All @@ -35,8 +35,13 @@ def session_to_nwb(
time_str: str,
stub_test: bool = False,
verbose: bool = True,
include_imaging: bool = True,
include_freezing_behavior: bool = True,
include_sleep_classification: bool = True,
include_behavioral_video: bool = True,
include_eeg_emg_signals: bool = True,
):
print("Converting session {}".format(session_id))
print(f"Converting session {session_id}")
if verbose:
start = time.time()

Expand All @@ -56,70 +61,88 @@ def session_to_nwb(
experiment_dir_path = data_dir_path / "Ca_EEG_Experiment" / subject_id / (subject_id + "_Offline") / offline_day
else:
experiment_dir_path = data_dir_path / "Ca_EEG_Experiment" / subject_id / (subject_id + "_Sessions") / session_id
include_eeg_emg_signals = False
include_sleep_classification = False

# Add Imaging
folder_path = experiment_dir_path / date_str / time_str
miniscope_folder_path = get_miniscope_folder_path(folder_path)
if miniscope_folder_path is not None:
if miniscope_folder_path is not None and include_imaging:
source_data.update(dict(MiniscopeImaging=dict(folder_path=miniscope_folder_path)))
conversion_options.update(dict(MiniscopeImaging=dict(stub_test=stub_test)))
elif verbose and not include_imaging:
print(f"Miniscope data will not be included for session {session_id}")
elif verbose and miniscope_folder_path is None:
print(f"No Miniscope data found at {miniscope_folder_path}")

# Add Segmentation
minian_folder_path = data_dir_path / "Ca_EEG_Calcium" / subject_id / session_id / "minian"
if minian_folder_path.is_dir():
if minian_folder_path.is_dir() and include_imaging:
source_data.update(dict(MinianSegmentation=dict(folder_path=minian_folder_path)))
conversion_options.update(dict(MinianSegmentation=dict(stub_test=stub_test)))
elif verbose:
print("No Minian data found at {}".format(minian_folder_path))
elif verbose and not include_imaging:
print(f"Minian data will not be included for session {session_id}")
elif verbose and not minian_folder_path.is_dir():
print(f"No Minian data found at {minian_folder_path}")

# Add Motion Correction
motion_corrected_video = minian_folder_path / "minian_mc.mp4"
if motion_corrected_video.is_file():
if motion_corrected_video.is_file() and include_imaging:
source_data.update(
dict(MinianMotionCorrection=dict(folder_path=minian_folder_path, video_file_path=motion_corrected_video))
)
conversion_options.update(dict(MinianMotionCorrection=dict(stub_test=stub_test)))
elif verbose:
print("No motion corrected data found at {}".format(motion_corrected_video))
elif verbose and not include_imaging:
print(f"Minian Motion Correction data will not be included for session {session_id}")
elif verbose and not motion_corrected_video.is_file():
print(f"No motion corrected data found at {motion_corrected_video}")

# Add Behavioral Video
video_file_path = experiment_dir_path / (session_id + ".wmv")
if video_file_path.is_file():
if video_file_path.is_file() and include_behavioral_video:
source_data.update(dict(Video=dict(file_paths=[video_file_path])))
conversion_options.update(dict(Video=dict(stub_test=stub_test)))
elif verbose:
print("No behavioral video found at {}".format(video_file_path))
elif verbose and not include_behavioral_video:
print(f"The behavioral video will not be included for session {session_id}")
elif verbose and not video_file_path.is_file():
print(f"No behavioral video found at {video_file_path}")

# Add Freezing Analysis output
freezing_output_file_path = experiment_dir_path / (session_id + "_FreezingOutput.csv")
if freezing_output_file_path.is_file():
if freezing_output_file_path.is_file() and include_freezing_behavior:
source_data.update(
dict(FreezingBehavior=dict(file_path=freezing_output_file_path, video_sampling_frequency=30.0))
)
elif verbose:
print("No freezing output csv file found at {}".format(freezing_output_file_path))
elif verbose and not include_freezing_behavior:
print(f"The Freezing Analysis output will not be included for session {session_id}")
elif verbose and not freezing_output_file_path.is_file():
print(f"No freezing output csv file found at {freezing_output_file_path}")

# Add EEG, EMG, Temperature and Activity signals
# TODO discuss how to slice this data
datetime_obj = datetime.strptime(date_str, "%Y_%m_%d")
reformatted_date_str = datetime_obj.strftime("_%m%d%y")
edf_file_path = data_dir_path / "Ca_EEG_EDF" / (subject_id + "_EDF") / (subject_id + reformatted_date_str + ".edf")
if edf_file_path.is_file():
if edf_file_path.is_file() and include_eeg_emg_signals:
source_data.update(dict(EDFSignals=dict(file_path=edf_file_path)))
conversion_options.update(dict(EDFSignals=dict(stub_test=stub_test)))
elif verbose:
print("No .edf file found at {}".format(edf_file_path))
elif verbose and not include_eeg_emg_signals:
print(f"The EEG, EMG, Temperature and Activity signals will not be included for session {session_id}")
elif verbose and not edf_file_path.is_file():
print(f"No .edf file found at {edf_file_path}")

# Add Sleep Classification output
sleep_classification_file_path = (
data_dir_path / "Ca_EEG_Sleep" / subject_id / "AlignedSleep" / (session_id + "_AlignedSleep.csv")
)
if sleep_classification_file_path.is_file():
if sleep_classification_file_path.is_file() and include_sleep_classification:
source_data.update(
dict(SleepClassification=dict(file_path=sleep_classification_file_path, video_sampling_frequency=30.0))
)
elif verbose:
print("No sleep classification output csv file found at {}".format(sleep_classification_file_path))
elif verbose and not include_sleep_classification:
print(f"The Sleep Classification output will not be included for session {session_id}")
elif verbose and not sleep_classification_file_path.is_file():
print(f"No sleep classification output csv file found at {sleep_classification_file_path}")

converter = Zaki2024NWBConverter(source_data=source_data)

Expand Down Expand Up @@ -159,7 +182,7 @@ def session_to_nwb(
# Parameters for conversion
data_dir_path = Path("D:/")
subject_id = "Ca_EEG3-4"
task = "OfflineDay1Session1"
task = "NeutralExposure"
session_id = subject_id + "_" + task
output_dir_path = Path("D:/cai_lab_conversion_nwb/")
stub_test = True
Expand Down
Loading