Optogenetics

This tutorial will demonstrate how to write optogenetics data.

Creating an NWBFile object

When creating a NWB file, the first step is to create the NWBFile object using NwbFile.
nwb = NwbFile( ...
'session_description', 'mouse in open exploration',...
'identifier', char(java.util.UUID.randomUUID), ...
'session_start_time', datetime(2018, 4, 25, 2, 30, 3, 'TimeZone', 'local'), ...
'general_experimenter', 'Last, First M.', ... % optional
'general_session_id', 'session_1234', ... % optional
'general_institution', 'University of My Institution', ... % optional
'general_related_publications', 'DOI:10.1016/j.neuron.2016.12.011'); % optional
nwb
nwb =
NwbFile with properties: nwb_version: '2.9.0' file_create_date: [] identifier: 'af38b64a-0c6d-48d7-b068-88de1a94d771' session_description: 'mouse in open exploration' session_start_time: {[2018-04-25T02:30:03.000000+02:00]} timestamps_reference_time: [] acquisition: [0×1 types.untyped.Set] analysis: [0×1 types.untyped.Set] general: [0×1 types.untyped.Set] general_data_collection: '' general_devices: [0×1 types.untyped.Set] general_devices_models: [0×1 types.untyped.Set] general_experiment_description: '' general_experimenter: 'Last, First M.' general_extracellular_ephys: [0×1 types.untyped.Set] general_extracellular_ephys_electrodes: [] general_institution: 'University of My Institution' general_intracellular_ephys: [0×1 types.untyped.Set] general_intracellular_ephys_experimental_conditions: [] general_intracellular_ephys_filtering: '' general_intracellular_ephys_intracellular_recordings: [] general_intracellular_ephys_repetitions: [] general_intracellular_ephys_sequential_recordings: [] general_intracellular_ephys_simultaneous_recordings: [] general_intracellular_ephys_sweep_table: [] general_keywords: '' general_lab: '' general_notes: '' general_optogenetics: [0×1 types.untyped.Set] general_optophysiology: [0×1 types.untyped.Set] general_pharmacology: '' general_protocol: '' general_related_publications: 'DOI:10.1016/j.neuron.2016.12.011' general_session_id: 'session_1234' general_slices: '' general_source_script: '' general_source_script_file_name: '' general_stimulus: '' general_subject: [] general_surgery: '' general_virus: '' general_was_generated_by: '' intervals: [0×1 types.untyped.Set] intervals_epochs: [] intervals_invalid_times: [] intervals_trials: [] processing: [0×1 types.untyped.Set] scratch: [0×1 types.untyped.Set] stimulus_presentation: [0×1 types.untyped.Set] stimulus_templates: [0×1 types.untyped.Set] units: []

Subject Information

It is recommended to store information about the experimental subject in the file. Create a Subject object to store metadata about the subject, then assign it to nwb.general_subject.
subject = types.core.Subject( ...
'subject_id', '001', ...
'age', 'P90D', ...
'description', 'mouse 1', ...
'species', 'Mus musculus', ...
'sex', 'M' ...
);
nwb.general_subject = subject;

Adding optogenetic data

The ogen module contains two data types that you will need to write optogenetics data, OptogeneticStimulusSite, which contains metadata about the stimulus site, and OptogeneticSeries, which contains the values of the time series.
First, you need to create a Device object linked to the NWBFile:
device = types.core.Device();
nwb.general_devices.set('Device', device);
Now, you can create and add an OptogeneticStimulusSite.
ogen_stim_site = types.core.OptogeneticStimulusSite( ...
'device', types.untyped.SoftLink(device), ...
'description', 'This is an example optogenetic site.', ...
'excitation_lambda', 600.0, ...
'location', 'VISrl');
 
nwb.general_optogenetics.set('OptogeneticStimulusSite', ogen_stim_site);
With the OptogeneticStimulusSite added, you can now create and add a OptogeneticSeries. Here, we will generate some random data and specify the timing using rate. If you have samples at irregular intervals, you should use timestamps instead.
ogen_series = types.core.OptogeneticSeries( ...
'data', randn(20, 1), ...
'site', types.untyped.SoftLink(ogen_stim_site), ...
'starting_time', 0.0, ...
'starting_time_rate', 30.0); % Hz
nwb.stimulus_presentation.set('OptogeneticSeries', ogen_series);
 
nwb
nwb =
NwbFile with properties: nwb_version: '2.9.0' file_create_date: [] identifier: 'af38b64a-0c6d-48d7-b068-88de1a94d771' session_description: 'mouse in open exploration' session_start_time: {[2018-04-25T02:30:03.000000+02:00]} timestamps_reference_time: [] acquisition: [0×1 types.untyped.Set] analysis: [0×1 types.untyped.Set] general: [0×1 types.untyped.Set] general_data_collection: '' general_devices: [1×1 types.untyped.Set] general_devices_models: [0×1 types.untyped.Set] general_experiment_description: '' general_experimenter: 'Last, First M.' general_extracellular_ephys: [0×1 types.untyped.Set] general_extracellular_ephys_electrodes: [] general_institution: 'University of My Institution' general_intracellular_ephys: [0×1 types.untyped.Set] general_intracellular_ephys_experimental_conditions: [] general_intracellular_ephys_filtering: '' general_intracellular_ephys_intracellular_recordings: [] general_intracellular_ephys_repetitions: [] general_intracellular_ephys_sequential_recordings: [] general_intracellular_ephys_simultaneous_recordings: [] general_intracellular_ephys_sweep_table: [] general_keywords: '' general_lab: '' general_notes: '' general_optogenetics: [1×1 types.untyped.Set] general_optophysiology: [0×1 types.untyped.Set] general_pharmacology: '' general_protocol: '' general_related_publications: 'DOI:10.1016/j.neuron.2016.12.011' general_session_id: 'session_1234' general_slices: '' general_source_script: '' general_source_script_file_name: '' general_stimulus: '' general_subject: [1×1 types.core.Subject] general_surgery: '' general_virus: '' general_was_generated_by: '' intervals: [0×1 types.untyped.Set] intervals_epochs: [] intervals_invalid_times: [] intervals_trials: [] processing: [0×1 types.untyped.Set] scratch: [0×1 types.untyped.Set] stimulus_presentation: [1×1 types.untyped.Set] stimulus_templates: [0×1 types.untyped.Set] units: []
Now you can write the NWB file.
nwbExport(nwb, 'ogen_tutorial.nwb');