/
ABISweep.m
457 lines (433 loc) · 15.4 KB
/
ABISweep.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
% ABISweep.m
% A class representing a sweep in an Allen Brain Institute NWB file.
% Generic sweep approach: if a sweep doesn't have the attribute in either
% the acquisition or stimulus sections, it returns either a NaN or an empty
% string. Apparent truth: if, for a specific sweep number an attribute
% appears in both acquisition and stimulus/presentation sections, its
% value is the same in both; so here we report the value from the first
% place in which we find the attribute.
%% Sweep children discovered so far in the nwb files
% ----------------------------------|
% aibs_stimulus_amplitude_mv
% aibs_stimulus_amplitude_pa
% aibs_stimulus_description
% aibs_stimulus_interval
% aibs_stimulus_name
% bias_current
% bridge_balance
% capacitance_compensation
% capacitance_fast
% capacitance_slow
% data
% electrode
% gain
% initial_access_resistance
% num_samples
% resistance_comp_bandwidth
% resistance_comp_correction
% resistance_comp_prediction
% seal
% starting_time
% whole_cell_capacitance_comp
% whole_cell_series_resistance_comp
% ----------------------------------|
%%
classdef ABISweep < handle
properties
filepath;
sweepnum
sweepstr;
acqsweeploc;
anasweeploc;
stimsweeploc;
% The pdf says sampling rate is 200 KHz
SAMPLING_RATE = 200000.0;
SAMPLING_PERIOD = 1/200000.0;
% If we are viewing this sweep as from an experiment, then this is
% true
fromExperiment;
end
methods
%% Basic
% expnum ignored unless fromExperiment is true
function obj = ABISweep(filepath, sweepnum, fromExperiment, expNum)
obj.filepath = filepath;
if ~islogical(fromExperiment)
error(['ABISweep constructor: fromExperiment must be logical value']);
end
obj.fromExperiment = fromExperiment;
expStr = ['Experiment_' num2str(expNum)];
obj.sweepnum = sweepnum;
obj.sweepstr = ['Sweep_' num2str(sweepnum)];
if obj.fromExperiment
obj.acqsweeploc = ['/epochs/' expStr '/response/timeseries'];
obj.anasweeploc = ['/analysis/spike_times' '/' obj.sweepstr];
obj.stimsweeploc = ['/epochs/' expStr '/stimulus/timeseries'];
else
obj.acqsweeploc = ['/acquisition/timeseries' '/' obj.sweepstr];
obj.anasweeploc = ['/analysis/spike_times' '/' obj.sweepstr];
obj.stimsweeploc = ['/stimulus/presentation' '/' obj.sweepstr];
end
end
function num = GetSweepnum(obj)
num = obj.sweepnum;
end
function str = GetSweepStr(obj)
str = obj.sweepstr;
end
function rate = GetSamplingRate(obj)
rate = obj.SAMPLING_RATE;
end
function period = GetSamplingPeriod(obj)
period = obj.SAMPLING_PERIOD;
end
%% Features
% GetAIBSStimulusInfo
% With no spec for the file format, we are looking for everything
% we have seen so far and not panicking if we don't find it
function [amp_mv, amp_pa, des, int, name] = GetAIBSStimulusInfo(obj)
%
try
amp_mv = h5read(obj.filepath, ...
[obj.acqsweeploc '/aibs_stimulus_amplitude_mv']);
catch
try
amp_mv = h5read(obj.filepath, ...
[obj.stimsweeploc '/aibs_stimulus_amplitude_mv']); %#ok<*NASGU>
catch
amp_mv = NaN;
end
end
%
try
amp_pa = h5read(obj.filepath, ...
[obj.acqsweeploc '/aibs_stimulus_amplitude_pa']);
catch
try
amp_pa = h5read(obj.filepath, ...
[obj.stimsweeploc '/aibs_stimulus_amplitude_pa']);
catch
amp_pa = NaN;
end
end
%
try
descell = h5read(obj.filepath, ...
[obj.acqsweeploc '/aibs_stimulus_description']);
des = descell{1};
catch
try
descell = h5read(obj.filepath, ...
[obj.stimsweeploc '/aibs_stimulus_description']);
des = descell{1};
catch
des = '';
end
end
%
try
int = h5read(obj.filepath, ...
[obj.acqsweeploc '/aibs_stimulus_interval']);
catch
try
int = h5read(obj.filepath, ...
[obj.stimsweeploc '/aibs_stimulus_interval']);
catch
int = NaN;
end
end
%
try
namecell = h5read(obj.filepath, ...
[obj.acqsweeploc '/aibs_stimulus_name']);
name = namecell{1};
catch
try
namecell = h5read(obj.filepath, ...
[obj.stimsweeploc '/aibs_stimulus_name']);
name = namecell{1};
catch
name = '';
end
end
end
% GetCapacitances
function [capfast, capslow, whcellcapcomp] = GetCapacitances(obj)
try
capfast = h5read(obj.filepath, ...
[obj.acqsweeploc '/capacitance_fast']);
catch
try
capfast = h5read(obj.filepath, ...
[obj.stimsweeploc '/capacitance_fast']);
catch
capfast = NaN;
end
end
%
try
capslow = h5read(obj.filepath, ...
[obj.acqsweeploc '/capacitance_slow']);
catch
try
capslow = h5read(obj.filepath, ...
[obj.stimsweeploc '/capacitance_slow']);
catch
capslow = NaN;
end
end
%
try
whcellcapcomp = h5read(obj.filepath, ...
[obj.acqsweeploc '/whole_cell_capacitance_comp']);
catch
try
whcellcapcomp = h5read(obj.filepath, ...
[obj.stimsweeploc '/whole_cell_capacitance_comp']);
catch
whcellcapcomp = NaN;
end
end
end
% GetResistances
function [initAccess, compBW, compCorr, ...
compPred, whCellSeriesComp] = GetResistances(obj)
try
initAccess = h5read(obj.filepath, ...
[obj.acqsweeploc '/initial_access_resistance']);
catch
try
initAccess = h5read(obj.filepath, ...
[obj.stimsweeploc '/initial_access_resistance']);
catch
initAccess = NaN;
end
end
%
try
compBW = h5read(obj.filepath, ...
[obj.acqsweeploc '/resistance_comp_bandwidth']);
catch
try
compBW = h5read(obj.filepath, ...
[obj.stimsweeploc '/resistance_comp_bandwidth']);
catch
compBW = NaN;
end
end
%
try
compCorr = h5read(obj.filepath, ...
[obj.acqsweeploc '/resistance_comp_correction']);
catch
try
compCorr = h5read(obj.filepath, ...
[obj.stimsweeploc '/resistance_comp_correction']);
catch
compCorr = NaN;
end
end
%
try
compPred = h5read(obj.filepath, ...
[obj.acqsweeploc '/resistance_comp_prediction']);
catch
try
compPred = h5read(obj.filepath, ...
[obj.stimsweeploc '/resistance_comp_prediction']);
catch
compPred = NaN;
end
end
%
try
whCellSeriesComp = h5read(obj.filepath, ...
[obj.acqsweeploc '/whole_cell_series_resistance_comp']);
catch
try
whCellSeriesComp = h5read(obj.filepath, ...
[obj.stimsweeploc '/whole_cell_series_resistance_comp']);
catch
whCellSeriesComp = NaN;
end
end
end
% GetElectronic
function [bias_current, bridge_balance, capacitance_compensation] = ...
GetElectronic(obj)
try
bias_current = h5read(obj.filepath, ...
[obj.acqsweeploc '/bias_current']);
catch
try
bias_current = h5read(obj.filepath, ...
[obj.stimsweeploc '/bias_current']);
catch
bias_current = NaN;
end
end
%
try
bridge_balance = h5read(obj.filepath, ...
[obj.acqsweeploc '/bridge_balance']);
catch
try
bridge_balance = h5read(obj.filepath, ...
[obj.stimsweeploc '/bridge_balance']);
catch
bridge_balance = NaN;
end
end
%
try
capacitance_compensation = h5read(obj.filepath, ...
[obj.acqsweeploc '/capacitance_compensation']);
catch
try
capacitance_compensation = h5read(obj.filepath, ...
[obj.stimsweeploc '/capacitance_compensation']);
catch
capacitance_compensation = NaN;
end
end
end
% GetBasicInfo
function [electrode, gain, num_samples, seal, starting_time] = ...
GetBasicInfo(obj)
try
electrode = h5read(obj.filepath, ...
[obj.acqsweeploc '/electrode']);
catch
try
electrode = h5read(obj.filepath, ...
[obj.stimsweeploc '/electrode']);
catch
electrode = '';
end
end
%
try
gain = h5read(obj.filepath, [obj.acqsweeploc '/gain']);
catch
try
gain = h5read(obj.filepath, [obj.stimsweeploc '/gain']);
catch
gain = NaN;
end
end
%
try
num_samples = h5read(obj.filepath, ...
[obj.acqsweeploc '/num_samples']);
catch
try
num_samples = h5read(obj.filepath, ...
[obj.stimsweeploc '/num_samples']);
catch
num_samples = NaN;
end
end
%
try
seal = h5read(obj.filepath, [obj.acqsweeploc '/seal']);
catch
try
seal = h5read(obj.filepath, [obj.stimsweeploc '/seal']);
catch
seal = NaN;
end
end
%
try
starting_time = h5read(obj.filepath, ...
[obj.acqsweeploc '/starting_time']);
catch
try
starting_time = h5read(obj.filepath, ...
[obj.stimsweeploc '/starting_time']);
catch
starting_time = '';
end
end
end
%% Data
% GetTimeBase
% If tfUseStartTime is true, use the sweep's start time to start
% the time base. If tfUseStartTime is false, use 0.0 to start the
% time base. Using 0.0 will match the spike times seen in the
% analysis group
function timeBase = GetTimeBase(obj,tfUseStartTime)
if ~islogical(tfUseStartTime)
error('GetTimeBase: tfUseStartTime must be logical');
end
[~,~,numSamples,~,startTime] = obj.GetBasicInfo();
samplingPeriod = obj.GetSamplingPeriod();
if ~tfUseStartTime
startTime = 0.0;
end
timeBase = double(startTime):samplingPeriod:(double(startTime)+(double(numSamples)-1)*samplingPeriod);
if length(timeBase) ~= numSamples
error('TimeBase error');
end
end
% GetAcquisitionData
function [data, conversion, resolution, units] =...
GetAcquisitionData(obj)
data = h5read(obj.filepath, [obj.acqsweeploc '/data']);
try
conversion = ...
num2str(h5readatt(obj.filepath, ...
[obj.acqsweeploc '/data'], 'conversion'));
catch
conversion = '';
end
try
resolution = ...
num2str(h5readatt(obj.filepath, ...
[obj.acqsweeploc '/data'], 'resolution'));
catch
resolution = '';
end
try
unitscell = ...
h5readatt(obj.filepath, [obj.acqsweeploc '/data'], 'units');
units = unitscell{1};
catch
units = '';
end
end
% GetStimulusData
function [data, conversion, resolution, units] = GetStimulusData(obj)
data = h5read(obj.filepath, [obj.stimsweeploc '/data']);
try
conversion = ...
num2str(h5readatt(obj.filepath, ...
[obj.stimsweeploc '/data'], 'conversion'));
catch
conversion = '';
end
try
resolution = ...
num2str(h5readatt(obj.filepath, ...
[obj.stimsweeploc '/data'], 'resolution'));
catch
resolution = '';
end
try
unitscell = ...
h5readatt(obj.filepath, [obj.stimsweeploc '/data'], 'units');
units = unitscell{1};
catch
units = '';
end
end
% GetAnalysisSpikeTimes
function times = GetAnalysisSpikeTimes(obj)
try
times = h5read(obj.filepath, obj.anasweeploc);
catch
times = [];
end
end
end
end