-
Notifications
You must be signed in to change notification settings - Fork 0
/
archiveMTUtah_moveBlank.m
139 lines (117 loc) · 6.13 KB
/
archiveMTUtah_moveBlank.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
pathRoot = '~/Documents/data/Published/'; % pathRoot for data
mapRoot = '~/Documents/data/mapFiles/'; % pathRoot for array maps
% include list of papers to reference in related pubs
paperList
metadat.experimenter = 'Elizabeth Zavitz, Hsin-Hao Yu, Marcello Rosa & Nicholas Price';
metadat.institution = 'Monash University';
metadat.describe = 'Acute Marmoset MT recording with Utah Array';
metadat.protocol = 'moveBlank';
metadat.case = {'CJ143', 'CJ144', 'CJ146', 'CJ156'};
metadat.age = {'P2Y', 'P2Y4M', 'P2Y1M', 'P2Y1M'};
metadat.file = {'049', '075', '036', '026'};
metadat.weight = {'393g', '385g', '288g', '340g'};
metadat.sex = {'M', 'F', 'M', 'M'};
metadat.arraySN = {'1017-011524', '1017-000172', '1017-011497', '1017-011524'};
metadat.arrayFile={'8983-10 SN 1017-011524_Fixed', ... %file name for map file
'SN 1017-000172_modified', ... %fixed/modified refers to patient
'SN 1017-011497_Modified', ... %cable correction.
'8983-10 SN 1017-011524_Fixed'};
metadat.start = {datetime(2013, 9, 4, 23, 23, 0),... % when the recording started
datetime(2013, 10, 23, 21, 48, 0),...
datetime(2014, 5, 21, 16, 18, 0),...
datetime(2015, 5, 6, 3, 34, 0)};
% loop through cases here
for iCase = 1:length(metadat.case)
clear nwb;
% ------ Load data to export
fileload = sprintf('%s%s%s%s_datafile%s_MATSORT.mat', ...
pathRoot, metadat.protocol, filesep, metadat.case{iCase}, metadat.file{iCase});
load(fileload);
% ------ General metadata
caseID = sprintf('Monash-%s-file%s-%s', ...
metadat.case{iCase}, metadat.file{iCase}, metadat.protocol);
nwb = NwbFile( ...
'session_description', metadat.describe,...
'session_start_time',metadat.start{iCase}, ...
'identifier', caseID, ...
'general_experimenter', metadat.experimenter, ...
'general_institution', metadat.institution, ...
'general_surgery', ['See: ' papers.BourneRosa], ...
'general_related_publications', ...
{papers.jNeuro2016, papers.cerCor2019, papers.jNphys2019});
subject = types.core.Subject( ...
'subject_id', metadat.case{iCase}, ...
'age', metadat.age{iCase}, ...
'description', 'Healthy young adult common marmoset, bred at the Australian National Primate Facility', ...
'species', 'Callithrix Jacchus', ...
'sex', metadat.sex{iCase}, ...
'weight', metadat.weight{iCase});
% ------ Stimulus Information
nTrials = length(onsetInds);
startTimes = onsetInds(1,:)/1000; % in seconds, not ms
stopTimes = startTimes + 0.5;
trials = types.core.TimeIntervals( ...
'colnames', {'start_time', 'stop_time', 'direction', 'speed',}, ...
'description', 'trial data and properties', ...
'id', types.hdmf_common.ElementIdentifiers('data', 0:nTrials-1), ...
'start_time', types.hdmf_common.VectorData('data', startTimes, ...
'description','start time of trial'), ...
'stop_time', types.hdmf_common.VectorData('data', stopTimes, ...
'description','end of each trial'), ...
'direction', types.hdmf_common.VectorData('data', onsetInds(2,:), ...
'description', 'direction (deg) of stimulus motion'), ...
'speed', types.hdmf_common.VectorData('data', onsetInds(3,:), ...
'description', 'speed (deg/s) of dot motion'));
nwb.general_subject = subject;
nwb.intervals_trials = trials;
% ------ Array Information (Device)
device_name = 'UtahArray';
deviceString = sprintf('Utah array SN: %s + Patient Cable', metadat.arraySN{iCase});
device = types.core.Device(...
'description', deviceString, ...
'manufacturer', 'Blackrock Microsystems');
nwb.general_devices.set(device_name, device);
device_link = types.untyped.SoftLink(['/general/devices/' device_name]);
% ------ Array Information (Group - this makes sense for >1 array)
group_name = 'UtahArray-Group';
nwb.general_extracellular_ephys.set(group_name, ...
types.core.ElectrodeGroup( ...
'description', 'Utah Array', ...
'location', 'MT+', ...
'device', device_link));
group_object_view = types.untyped.ObjectView( ...
['/general/extracellular_ephys/' group_name]);
% ------ Build table structure for electrodes
mapFile = [mapRoot metadat.arrayFile{iCase} '.cmp'];
% variables in the electrode table and their default values
variables = {'x', 'y', 'z', 'imp', 'location', 'filtering', 'group', 'label'};
values = {NaN, NaN, NaN, NaN, 'MT+', '750Hz', NaN, NaN};
tbl = getElectrodeTableFromMapFile(mapFile, group_object_view, variables, values);
electrode_table = util.table2nwb(tbl, 'all electrodes');
nwb.general_extracellular_ephys_electrodes = electrode_table;
% ------ SPIKE TIMES
% get spike times for multiunits and single units.
[spikes, allCh, unitTypes] = getSpikeTimesFromTrainStruct(spikeTrains);
% convert to 1D vector with index
[spike_times_vector, spike_times_index] = util.create_indexed_column( ...
spikes, '/units/spike_times');
electrodes_object_view = types.untyped.ObjectView( ...
'/general/extracellular_ephys/electrodes');
% which electrode was each unit recorded from?
electrode_table_region = types.hdmf_common.DynamicTableRegion( ...
'table', electrodes_object_view, ...
'description', 'Electrodes', ...
'data', allCh');
% compile electrode and spiking information into "units"
nwb.units = types.core.Units( ...
'colnames', {'spike_times'}, ...
'description', 'units table', ...
'id', types.hdmf_common.ElementIdentifiers( ...
'data', int64(0:length(spikes) - 1)), ...
'spike_times', spike_times_vector, ...
'spike_times_index', spike_times_index, ...
'electrodes', electrode_table_region, ...
'unit_class', types.hdmf_common.VectorData('data', unitTypes, ...
'description', 'sort group 0=MUA, 1=SU'));
nwbExport(nwb, [pathRoot caseID '.nwb']);
end