Skip to content

Commit

Permalink
Merge pull request #16 from catalystneuro/optogenetics
Browse files Browse the repository at this point in the history
OptogeneticInterface
  • Loading branch information
pauladkisson authored Apr 23, 2024
2 parents e51272b + 6026df0 commit ebb02e4
Show file tree
Hide file tree
Showing 8 changed files with 848 additions and 51 deletions.
1 change: 1 addition & 0 deletions src/lerner_lab_to_nwb/seiler_2024/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .seiler_2024behaviorinterface import Seiler2024BehaviorInterface
from .seiler_2024fiberphotometryinterface import Seiler2024FiberPhotometryInterface
from .seiler_2024optogeneticinterface import Seiler2024OptogeneticInterface
from .seiler_2024nwbconverter import Seiler2024NWBConverter
305 changes: 276 additions & 29 deletions src/lerner_lab_to_nwb/seiler_2024/seiler_2024_convert_dataset.py

Large diffs are not rendered by default.

273 changes: 261 additions & 12 deletions src/lerner_lab_to_nwb/seiler_2024/seiler_2024_convert_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def session_to_nwb(
session_conditions: dict,
start_variable: str,
experiment_type: Literal["FP", "Opto"],
experimental_group: Literal["DPR", "PR", "PS", "RR20"],
experimental_group: Literal["DPR", "PR", "PS", "RR20", "DMS-Inhibitory", "DMS-Excitatory", "DLS-Excitatory"],
optogenetic_treatment: Optional[Literal["ChR2", "EYFP", "ChR2Scrambled", "NpHR", "NpHRScrambled"]] = None,
fiber_photometry_folder_path: Optional[Union[str, Path]] = None,
stub_test: bool = False,
verbose: bool = True,
Expand All @@ -44,8 +45,10 @@ def session_to_nwb(
The name of the variable that starts the session (ex. 'Start Date').
experiment_type : Literal["FP", "Opto"]
The type of experiment.
experimental_group : Literal["DPR", "PR", "PS", "RR20"]
experimental_group : Literal["DPR", "PR", "PS", "RR20", "DMS-Inhibitory", "DMS-Excitatory", "DLS-Excitatory"]
The experimental group.
optogenetic_treatment : Optional[Literal["ChR2", "EYFP", "ChR2Scrambled", "NpHR", "NpHRScrambled"]], optional
The optogenetic treatment, by default None for FP sessions.
stub_test : bool, optional
Whether to run a stub test, by default False
verbose : bool, optional
Expand All @@ -58,9 +61,6 @@ 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"{experiment_type}_{experimental_group}_{subject_id}_{start_datetime.isoformat()}.nwb"
)
source_data = {}
conversion_options = {}

Expand Down Expand Up @@ -90,6 +90,22 @@ def session_to_nwb(
)
conversion_options.update(dict(FiberPhotometry={}))

# Add Optogenetics
if experiment_type == "Opto":
source_data.update(
dict(
Optogenetic={
"file_path": str(behavior_file_path),
"session_conditions": session_conditions,
"start_variable": start_variable,
"experimental_group": experimental_group,
"optogenetic_treatment": optogenetic_treatment,
"verbose": verbose,
}
)
)
conversion_options.update(dict(Optogenetic={}))

converter = Seiler2024NWBConverter(source_data=source_data, verbose=verbose)
metadata = converter.get_metadata()

Expand All @@ -98,6 +114,19 @@ def session_to_nwb(
editable_metadata = load_dict_from_file(editable_metadata_path)
metadata = dict_deep_update(metadata, editable_metadata)

start_datetime = metadata["NWBFile"]["session_start_time"]
if experiment_type == "FP":
nwbfile_path = (
output_dir_path / f"{experiment_type}_{experimental_group}_{subject_id}_{start_datetime.isoformat()}.nwb"
)
elif experiment_type == "Opto":
nwbfile_path = (
output_dir_path
/ f"{experiment_type}_{experimental_group}_{optogenetic_treatment}_{subject_id}_{start_datetime.isoformat()}.nwb"
)
else:
raise ValueError(f"Invalid experiment type: {experiment_type}")

# Run conversion
converter.run_conversion(metadata=metadata, nwbfile_path=nwbfile_path, conversion_options=conversion_options)

Expand Down Expand Up @@ -349,18 +378,237 @@ def session_to_nwb(
# stub_test=stub_test,
# )

# Behavior session from csv file
experiment_type = "FP"
experimental_group = "DPR"
subject_id = "87.239"
start_datetime = datetime(2019, 3, 19, 0, 0, 0)
# # Behavior session from csv file
# experiment_type = "FP"
# experimental_group = "DPR"
# subject_id = "87.239"
# start_datetime = datetime(2019, 3, 19, 0, 0, 0)
# session_conditions = {}
# start_variable = ""
# behavior_file_path = (
# data_dir_path
# / f"{experiment_type} Experiments"
# / "Behavior"
# / f"{experimental_group}"
# / f"{subject_id}"
# / f"{subject_id}_{start_datetime.strftime('%m-%d-%y')}.csv"
# )
# session_to_nwb(
# data_dir_path=data_dir_path,
# output_dir_path=output_dir_path,
# behavior_file_path=behavior_file_path,
# subject_id=subject_id,
# session_conditions=session_conditions,
# start_variable=start_variable,
# start_datetime=start_datetime,
# experiment_type=experiment_type,
# experimental_group=experimental_group,
# stub_test=stub_test,
# )

# Example DMS-Inhibitory Opto session
experiment_type = "Opto"
experimental_group = "DMS-Inhibitory"
optogenetic_treatment = "NpHR"
subject_id = "112.415"
start_datetime = datetime(2020, 10, 21, 13, 8, 39)
session_conditions = {
"Start Date": start_datetime.strftime("%m/%d/%y"),
"Start Time": start_datetime.strftime("%H:%M:%S"),
}
start_variable = "Start Date"
behavior_file_path = (
data_dir_path
/ f"{experiment_type} Experiments"
/ f"{experimental_group.replace('-', ' ')}"
/ f"Group 1"
/ f"Halo"
/ f"{subject_id}"
)
session_to_nwb(
data_dir_path=data_dir_path,
output_dir_path=output_dir_path,
behavior_file_path=behavior_file_path,
subject_id=subject_id,
session_conditions=session_conditions,
start_variable=start_variable,
start_datetime=start_datetime,
experiment_type=experiment_type,
experimental_group=experimental_group,
optogenetic_treatment=optogenetic_treatment,
stub_test=stub_test,
)

# Example DMS-Excitatory Opto session
experiment_type = "Opto"
experimental_group = "DMS-Excitatory"
optogenetic_treatment = "ChR2"
subject_id = "119.416"
start_datetime = datetime(2020, 10, 20, 13, 0, 57)
session_conditions = {
"Start Date": start_datetime.strftime("%m/%d/%y"),
"Start Time": start_datetime.strftime("%H:%M:%S"),
}
start_variable = "Start Date"
behavior_file_path = (
data_dir_path
/ f"{experiment_type} Experiments"
/ f"{experimental_group.replace('-', ' ')}"
/ f"{optogenetic_treatment}"
/ f"{subject_id}"
)
session_to_nwb(
data_dir_path=data_dir_path,
output_dir_path=output_dir_path,
behavior_file_path=behavior_file_path,
subject_id=subject_id,
session_conditions=session_conditions,
start_variable=start_variable,
start_datetime=start_datetime,
experiment_type=experiment_type,
experimental_group=experimental_group,
optogenetic_treatment=optogenetic_treatment,
stub_test=stub_test,
)

# Example DLS-Excitatory Opto session
experiment_type = "Opto"
experimental_group = "DLS-Excitatory"
optogenetic_treatment = "ChR2"
subject_id = "079.402"
start_datetime = datetime(2020, 6, 26, 13, 19, 27)
session_conditions = {
"Start Date": start_datetime.strftime("%m/%d/%y"),
"Start Time": start_datetime.strftime("%H:%M:%S"),
}
start_variable = "Start Date"
behavior_file_path = (
data_dir_path
/ f"{experiment_type} Experiments"
/ f"{experimental_group.replace('-', ' ')}"
/ f"{optogenetic_treatment}"
/ f"{subject_id}"
)
session_to_nwb(
data_dir_path=data_dir_path,
output_dir_path=output_dir_path,
behavior_file_path=behavior_file_path,
subject_id=subject_id,
session_conditions=session_conditions,
start_variable=start_variable,
start_datetime=start_datetime,
experiment_type=experiment_type,
experimental_group=experimental_group,
optogenetic_treatment=optogenetic_treatment,
stub_test=stub_test,
)

# Opto session with both left and right rewards
experiment_type = "Opto"
experimental_group = "DMS-Excitatory"
optogenetic_treatment = "ChR2"
subject_id = "281.402"
start_datetime = datetime(2020, 9, 23, 12, 36, 30)
session_conditions = {
"Start Date": start_datetime.strftime("%m/%d/%y"),
"Start Time": start_datetime.strftime("%H:%M:%S"),
}
start_variable = "Start Date"
behavior_file_path = (
data_dir_path
/ f"{experiment_type} Experiments"
/ f"{experimental_group.replace('-', ' ')}"
/ f"{optogenetic_treatment}"
/ "2020-09-23_12h36m_Subject 281.402"
)
session_to_nwb(
data_dir_path=data_dir_path,
output_dir_path=output_dir_path,
behavior_file_path=behavior_file_path,
subject_id=subject_id,
session_conditions=session_conditions,
start_variable=start_variable,
start_datetime=start_datetime,
experiment_type=experiment_type,
experimental_group=experimental_group,
optogenetic_treatment=optogenetic_treatment,
stub_test=stub_test,
)

# Opto session from csv file
experiment_type = "Opto"
experimental_group = "DLS-Excitatory"
optogenetic_treatment = "ChR2"
subject_id = "290.407"
start_datetime = datetime(2020, 9, 23, 0, 0, 0)
session_conditions = {}
start_variable = ""
behavior_file_path = (
data_dir_path
/ f"{experiment_type} Experiments"
/ f"{experimental_group.replace('-', ' ')}"
/ f"{optogenetic_treatment}"
/ f"{subject_id}"
/ f"{subject_id}_{start_datetime.strftime('%m-%d-%y')}.csv"
)
session_to_nwb(
data_dir_path=data_dir_path,
output_dir_path=output_dir_path,
behavior_file_path=behavior_file_path,
subject_id=subject_id,
session_conditions=session_conditions,
start_variable=start_variable,
start_datetime=start_datetime,
experiment_type=experiment_type,
experimental_group=experimental_group,
optogenetic_treatment=optogenetic_treatment,
stub_test=stub_test,
)

# Opto session from csv file with scrambled optogenetic stimulation
experiment_type = "Opto"
experimental_group = "DLS-Excitatory"
optogenetic_treatment = "ChR2Scrambled"
subject_id = "276.405"
start_datetime = datetime(2020, 10, 1, 0, 0, 0)
session_conditions = {}
start_variable = ""
behavior_file_path = (
data_dir_path
/ f"{experiment_type} Experiments"
/ f"{experimental_group.replace('-', ' ')}"
/ "Scrambled"
/ f"{subject_id.replace('.', '_')}"
/ f"{subject_id}_{start_datetime.strftime('%m-%d-%y')}.csv"
)
session_to_nwb(
data_dir_path=data_dir_path,
output_dir_path=output_dir_path,
behavior_file_path=behavior_file_path,
subject_id=subject_id,
session_conditions=session_conditions,
start_variable=start_variable,
start_datetime=start_datetime,
experiment_type=experiment_type,
experimental_group=experimental_group,
optogenetic_treatment=optogenetic_treatment,
stub_test=stub_test,
)

# Could not convert DLS-Excitatory/299.405/09/11/20 00:00:00
# Opto session with mixed dtype
experiment_type = "Opto"
experimental_group = "DLS-Excitatory"
optogenetic_treatment = "ChR2"
subject_id = "299.405"
start_datetime = datetime(2020, 9, 11, 0, 0, 0)
session_conditions = {}
start_variable = ""
behavior_file_path = (
data_dir_path
/ f"{experiment_type} Experiments"
/ "Behavior"
/ f"{experimental_group}"
/ f"{experimental_group.replace('-', ' ')}"
/ f"{optogenetic_treatment}"
/ f"{subject_id}"
/ f"{subject_id}_{start_datetime.strftime('%m-%d-%y')}.csv"
)
Expand All @@ -374,5 +622,6 @@ def session_to_nwb(
start_datetime=start_datetime,
experiment_type=experiment_type,
experimental_group=experimental_group,
optogenetic_treatment=optogenetic_treatment,
stub_test=stub_test,
)
49 changes: 49 additions & 0 deletions src/lerner_lab_to_nwb/seiler_2024/seiler_2024_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ Behavior:
D: right_reward_times
E: duration_of_port_entry
G: port_entry_times
RI 60 LEFT_STIM:
A: left_nose_poke_times
B: left_reward_times
C: right_nose_poke_times
D: right_reward_times
E: duration_of_port_entry
G: port_entry_times
RI 30 LEFT_STIM:
A: left_nose_poke_times
B: left_reward_times
C: right_nose_poke_times
D: right_reward_times
E: duration_of_port_entry
G: port_entry_times
RI30 Left Scrambled:
A: left_nose_poke_times
B: left_reward_times
Expand Down Expand Up @@ -223,3 +237,38 @@ Behavior:
E: duration_of_port_entry
G: port_entry_times
H: footshock_times

Optogenetics:
experimental_group_to_metadata:
DMS-Excitatory:
injection_location: medial SNc (AP -3.1, ML 0.8, DV -4.7)
stimulation_location: DMS (AP 0.8, ML 1.5, DV -2.8)
excitation_lambda: 460.0 # nm
ogen_site_description: Mice for DMS excitatory optogenetics experiments received 1 ml of AAV5-EF1a-DIO-hChR2(H134R)-EYFP (3.3e13 GC/mL, Addgene, lot v17652) or the control fluorophore-only virus AAV5-EF1a-DIO-EYFP (3.5e12 virus molecules/mL, UNC Vector Core, lot AV4310K) in medial (AP -3.1, ML 0.8, DV -4.7) and a single fiber optic implant (Prizmatix; 250mm core, 0.66 NA) over ipsilateral DMS (AP 0.8, ML 1.5, DV -2.8). Hemispheres were counterbalanced between mice.
ogen_series_description: During operant training (beginning with FR1), each rewarded nosepoke was paired with a train of blue light (460nm, 1 s, 20 Hz, 15 mW) generated by an LED light source and pulse generator (Prizmatix). A subset of mice ("ChR2 Scrambled") received the same train of light but paired with random nosepokes on a separate RI60 schedule.
duration: 1.0 # seconds
frequency: 20.0 # Hz
pulse_width: 0.01 # TODO: ask Lerner lab for pulse width
power: 0.015 # W

DLS-Excitatory:
injection_location: lateral SNc (AP -3.1, ML 1.3, DV -4.2)
stimulation_location: DLS (AP -0.1, ML 2.8, DV -3.5)
excitation_lambda: 460.0 # nm
ogen_site_description: Mice for DLS excitatory optogenetics experiments received 1 ml of AAV5-EF1a-DIO-hChR2(H134R)-EYFP (3.3e13 GC/mL, Addgene, lot v17652) or the control fluorophore-only virus AAV5-EF1a-DIO-EYFP (3.5e12 virus molecules/mL, UNC Vector Core, lot AV4310K) in lateral SNc (AP -3.1, ML 1.3, DV -4.2) and a single fiber optic implant (Prizmatix; 250mm core, 0.66 NA) over ipsilateral DLS (AP -0.1, ML 2.8, DV -3.5). Hemispheres were counterbalanced between mice.
ogen_series_description: During operant training (beginning with FR1), each rewarded nosepoke was paired with a train of blue light (460nm, 1 s, 20 Hz, 15 mW) generated by an LED light source and pulse generator (Prizmatix). A subset of mice ("ChR2 Scrambled") received the same train of light but paired with random nosepokes on a separate RI60 schedule.
duration: 1.0 # seconds
frequency: 20.0 # Hz
pulse_width: 0.01 # TODO: ask Lerner lab for pulse width
power: 0.015 # W

DMS-Inhibitory:
injection_location: bilateral medial SNc (AP -3.1, ML ± 0.8, DV -4.7)
stimulation_location: bilateral DMS (AP 0.8, ML ± 1.5, DV -2.8)
excitation_lambda: 625.0 # nm
ogen_site_description: Mice for DMS inhibitory optogenetics experiments received 1 ml per side of AAV5-EF1a-DIO-eNpHR3.0-EYFP (1.1e13 GC/mL, Addgene, lot v32533) or the control fluorophore-only virus AAV5-EF1a-DIO-EYFP (3.5e12 virus molecules/mL, UNC Vector Core, lot AV4310K) in bilateral medial SNc (AP -3.1, ML 0.8, DV -4.7) and bilateral fiber optic implants (Prizmatix; 500mm core, 0.66 NA) in DMS (AP 0.8, ML ± 1.5, DV -2.8).
ogen_series_description: There were two groups of inhibitory optogenetics animals. Group 1 received inhibitory stimulation during operant training beginning with FR1, Since a subset of animals in this group were unable to learn the operant task, we also ran another group (Group 2) that received inhibitory stimulation during operant training beginning with RI30. These groups are combined for analysis of behaviors occurring after RI training has begun. For both groups, each rewarded nosepoke was paired with a continuous pulse of orange/red light (625nm, 1 s, 15 mW) generated by an LED light source and pulse generator (Prizmatix). A subset of mice ("NpHR Scrambled") received the same continuous pulse of light but paired with random nosepokes on a separate RI60 schedule.
duration: 1.0 # seconds
frequency: 1.0 # Hz
pulse_width: 1.0 # seconds
power: 0.015 # W
Loading

0 comments on commit ebb02e4

Please sign in to comment.