-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathThresholdReviewer_exported.m
471 lines (398 loc) · 18.2 KB
/
ThresholdReviewer_exported.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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
classdef ThresholdReviewer_exported < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Panel matlab.ui.container.Panel
GridLayout2 matlab.ui.container.GridLayout
GridLayout4 matlab.ui.container.GridLayout
SaveButton matlab.ui.control.Button
RippleCheckBox matlab.ui.control.CheckBox
SharpwaveCheckBox matlab.ui.control.CheckBox
GridLayout8 matlab.ui.container.GridLayout
RSpinner matlab.ui.control.Spinner
RThresholdLabel matlab.ui.control.Label
GridLayout7 matlab.ui.container.GridLayout
SWSpinner matlab.ui.control.Spinner
SWThresholdLabel matlab.ui.control.Label
GridLayout matlab.ui.container.GridLayout
GridLayout3 matlab.ui.container.GridLayout
EventsSlider matlab.ui.control.Slider
NextButton matlab.ui.control.Button
LastButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
x;
bel;
pyr;
len;
animal;
filt_bel;
filt_pyr;
fn = 600;
detections;
r_threshold;
sw_threshold;
window = 3601;
detections_num;
true_positive_ripples = [];
true_positive_sharpwaves = [];
end
methods (Access = private)
function update(app)
half_wind = fix(app.window/2);
% Get event number
det_num = app.EventsSlider.Value;
% start
det_s = (app.detections.Peak(det_num) - half_wind);
% end
det_e = (app.detections.Peak(det_num) + half_wind);
% Update saved or unsaved state
if ismember(det_num, app.true_positive_ripples)
app.RippleCheckBox.Value = 1;
else
app.RippleCheckBox.Value = 0;
end
if ismember(det_num, app.true_positive_sharpwaves)
app.SharpwaveCheckBox.Value = 1;
else
app.SharpwaveCheckBox.Value = 0;
end
bel_sig = app.bel;
space = max(bel_sig(det_s:det_e)) - min(bel_sig(det_s:det_e));
pyr_sig = app.pyr + space;
space = max(pyr_sig(det_s:det_e)) - min(bel_sig(det_s:det_e));
filt_bel_sig = app.filt_bel + space;
sw_thres = app.sw_threshold + space;
space = max(filt_bel_sig(det_s:det_e)) - min(bel_sig(det_s:det_e));
filt_pyr_sig = 5.*app.filt_pyr + space;
r_thes = 5*app.r_threshold + space;
y_max = max(filt_pyr_sig(det_s:det_e)) + 250;
y_min = min(bel_sig(det_s:det_e)) - 250;
title(app.UIAxes, strcat("Event ", int2str(det_num)))
cla(app.UIAxes)
plot(app.UIAxes, app.x, filt_pyr_sig, 'Color', 'blue')
hold(app.UIAxes,'on')
plot(app.UIAxes, app.x, filt_bel_sig, 'Color', 'black')
hold(app.UIAxes,'on')
plot(app.UIAxes, app.x, pyr_sig, 'Color', 'blue')
hold(app.UIAxes,'on')
plot(app.UIAxes, app.x, bel_sig, 'Color', 'black')
hold(app.UIAxes,'on')
yline(app.UIAxes, r_thes)
hold(app.UIAxes,'on')
yline(app.UIAxes, sw_thres)
app.UIAxes.YLim = [y_min y_max];
app.UIAxes.XLim = [det_s/app.fn, det_e/app.fn];
hold(app.UIAxes,'on')
txt = app.detections.Type(det_num);
text(app.UIAxes, det_e-1, y_max+250, txt)
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
[file,path] = uigetfile('',...
'Select below and pyramidal signals', ...
'MultiSelect', 'on');
if length(file) == 2
app.bel = importdata(fullfile(path, file{1}));
app.pyr = importdata(fullfile(path, file{2}));
app.len = min([length(app.bel) length(app.pyr)]);
app.bel = app.bel(1:app.len);
app.pyr = app.pyr(1:app.len);
app.x = (1:app.len)/app.fn;
[c,d] = butter(3, [1/300 20/300]);
[e,f] = butter(3, [90/300 200/300]);
app.filt_bel = filtfilt(c,d, app.bel);
app.filt_pyr = filtfilt(e,f, app.pyr);
app.sw_threshold = mean(app.filt_bel) - 5 * std(app.filt_bel);
app.r_threshold = mean(app.filt_pyr) + 5 * std(app.filt_pyr);
app.SWSpinner.Value = app.sw_threshold;
app.RSpinner.Value = app.r_threshold;
[file,path] = uigetfile('','Select detections');
if file ~= 0
app.animal = strcat('_rat_', file(8:end-4));
filename = fullfile(path,file);
variable = 'grouped_oscil_table';
S = load(filename, variable);
app.detections = S.(variable);
app.detections_num = height(app.detections);
app.EventsSlider.Limits = [1 app.detections_num];
app.SharpwaveCheckBox.Enable = 'on';
app.RippleCheckBox.Enable = 'on';
app.EventsSlider.Enable = 'on';
app.SaveButton.Enable = 'on';
app.NextButton.Enable = 'on';
app.LastButton.Enable = 'on';
app.SWSpinner.Enable = 'on';
app.RSpinner.Enable = 'on';
app.update()
else
delete(app);
end
else
delete(app);
end
end
% Button pushed function: NextButton
function NextButtonPushed(app, event)
if app.EventsSlider.Value < app.detections_num
app.EventsSlider.Value = app.EventsSlider.Value + 1;
app.update()
end
end
% Button pushed function: LastButton
function LastButtonPushed(app, event)
if app.EventsSlider.Value > 1
app.EventsSlider.Value = app.EventsSlider.Value - 1;
app.update()
end
end
% Value changed function: EventsSlider
function EventsSliderValueChanged(app, event)
value = round(app.EventsSlider.Value);
app.EventsSlider.Value = value;
app.update()
end
% Value changed function: RippleCheckBox
function RippleCheckBoxValueChanged(app, event)
value = app.RippleCheckBox.Value;
if value
app.true_positive_ripples = [app.true_positive_ripples app.EventsSlider.Value];
else
app.true_positive_ripples(app.true_positive_ripples == app.EventsSlider.Value) = [];
end
app.update()
end
% Value changed function: SharpwaveCheckBox
function SharpwaveCheckBoxValueChanged(app, event)
value = app.SharpwaveCheckBox.Value;
if value
app.true_positive_sharpwaves = [app.true_positive_sharpwaves app.EventsSlider.Value];
else
app.true_positive_sharpwaves(app.true_positive_sharpwaves == app.EventsSlider.Value) = [];
end
app.update()
end
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
%ripples = app.true_positive_ripples;
%sharpwaves = app.true_positive_sharpwaves;
vars = {'app.true_positive_ripples', ...
'app.true_positive_sharpwaves'};
file = strcat('threshold_review_', ...
erase(date,'-'), app.rat);
uisave(vars, file);
end
% Value changed function: RSpinner
function RSpinnerValueChanged(app, event)
value = app.RSpinner.Value;
app.r_threshold = value;
app.update()
end
% Value changed function: SWSpinner
function SWSpinnerValueChanged(app, event)
value = app.SWSpinner.Value;
app.sw_threshold = value;
app.update()
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create GridLayout
app.GridLayout = uigridlayout(app.UIFigure);
app.GridLayout.ColumnWidth = {'1x'};
app.GridLayout.RowHeight = {'3x', '1x'};
% Create UIAxes
app.UIAxes = uiaxes(app.GridLayout);
title(app.UIAxes, 'Event')
zlabel(app.UIAxes, 'Z')
app.UIAxes.Layout.Row = 1;
app.UIAxes.Layout.Column = 1;
% Create Panel
app.Panel = uipanel(app.GridLayout);
app.Panel.Layout.Row = 2;
app.Panel.Layout.Column = 1;
% Create GridLayout2
app.GridLayout2 = uigridlayout(app.Panel);
app.GridLayout2.ColumnWidth = {'1x'};
app.GridLayout2.RowHeight = {'1.5x', '1x'};
% Create GridLayout3
app.GridLayout3 = uigridlayout(app.GridLayout2);
app.GridLayout3.ColumnWidth = {'1x', '8x', '1x'};
app.GridLayout3.RowHeight = {'1x'};
app.GridLayout3.Padding = [0 0 0 0];
app.GridLayout3.Layout.Row = 2;
app.GridLayout3.Layout.Column = 1;
% Create LastButton
app.LastButton = uibutton(app.GridLayout3, 'push');
app.LastButton.ButtonPushedFcn = createCallbackFcn(app, @LastButtonPushed, true);
app.LastButton.Enable = 'off';
app.LastButton.Layout.Row = 1;
app.LastButton.Layout.Column = 1;
app.LastButton.Text = 'Last';
% Create NextButton
app.NextButton = uibutton(app.GridLayout3, 'push');
app.NextButton.ButtonPushedFcn = createCallbackFcn(app, @NextButtonPushed, true);
app.NextButton.Enable = 'off';
app.NextButton.Layout.Row = 1;
app.NextButton.Layout.Column = 3;
app.NextButton.Text = 'Next';
% Create EventsSlider
app.EventsSlider = uislider(app.GridLayout3);
app.EventsSlider.Limits = [1 100];
app.EventsSlider.ValueChangedFcn = createCallbackFcn(app, @EventsSliderValueChanged, true);
app.EventsSlider.Enable = 'off';
app.EventsSlider.Layout.Row = 1;
app.EventsSlider.Layout.Column = 2;
app.EventsSlider.Value = 1;
% Create GridLayout4
app.GridLayout4 = uigridlayout(app.GridLayout2);
app.GridLayout4.ColumnWidth = {'1x', '1x', '1x', '1x', '1x'};
app.GridLayout4.RowHeight = {'1x'};
app.GridLayout4.Padding = [0 0 0 0];
app.GridLayout4.Layout.Row = 1;
app.GridLayout4.Layout.Column = 1;
% Create GridLayout7
app.GridLayout7 = uigridlayout(app.GridLayout4);
app.GridLayout7.ColumnWidth = {'1x'};
app.GridLayout7.Padding = [0 0 0 0];
app.GridLayout7.Layout.Row = 1;
app.GridLayout7.Layout.Column = 5;
% Create SWThresholdLabel
app.SWThresholdLabel = uilabel(app.GridLayout7);
app.SWThresholdLabel.HorizontalAlignment = 'center';
app.SWThresholdLabel.FontWeight = 'bold';
app.SWThresholdLabel.Layout.Row = 2;
app.SWThresholdLabel.Layout.Column = 1;
app.SWThresholdLabel.Text = 'SW Threshold';
% Create SWSpinner
app.SWSpinner = uispinner(app.GridLayout7);
app.SWSpinner.ValueChangedFcn = createCallbackFcn(app, @SWSpinnerValueChanged, true);
app.SWSpinner.Enable = 'off';
app.SWSpinner.Layout.Row = 1;
app.SWSpinner.Layout.Column = 1;
% Create GridLayout8
app.GridLayout8 = uigridlayout(app.GridLayout4);
app.GridLayout8.ColumnWidth = {'1x'};
app.GridLayout8.Padding = [0 0 0 0];
app.GridLayout8.Layout.Row = 1;
app.GridLayout8.Layout.Column = 4;
% Create RThresholdLabel
app.RThresholdLabel = uilabel(app.GridLayout8);
app.RThresholdLabel.HorizontalAlignment = 'center';
app.RThresholdLabel.FontWeight = 'bold';
app.RThresholdLabel.Layout.Row = 2;
app.RThresholdLabel.Layout.Column = 1;
app.RThresholdLabel.Text = 'R Threshold';
% Create RSpinner
app.RSpinner = uispinner(app.GridLayout8);
app.RSpinner.ValueChangedFcn = createCallbackFcn(app, @RSpinnerValueChanged, true);
app.RSpinner.Enable = 'off';
app.RSpinner.Layout.Row = 1;
app.RSpinner.Layout.Column = 1;
% Create SharpwaveCheckBox
app.SharpwaveCheckBox = uicheckbox(app.GridLayout4);
app.SharpwaveCheckBox.ValueChangedFcn = createCallbackFcn(app, @SharpwaveCheckBoxValueChanged, true);
app.SharpwaveCheckBox.Enable = 'off';
app.SharpwaveCheckBox.Text = 'TP SW';
app.SharpwaveCheckBox.FontWeight = 'bold';
app.SharpwaveCheckBox.Layout.Row = 1;
app.SharpwaveCheckBox.Layout.Column = 1;
% Create RippleCheckBox
app.RippleCheckBox = uicheckbox(app.GridLayout4);
app.RippleCheckBox.ValueChangedFcn = createCallbackFcn(app, @RippleCheckBoxValueChanged, true);
app.RippleCheckBox.Enable = 'off';
app.RippleCheckBox.Text = 'TP R';
app.RippleCheckBox.FontWeight = 'bold';
app.RippleCheckBox.Layout.Row = 1;
app.RippleCheckBox.Layout.Column = 2;
% Create SaveButton
app.SaveButton = uibutton(app.GridLayout4, 'push');
app.SaveButton.ButtonPushedFcn = createCallbackFcn(app, @SaveButtonPushed, true);
app.SaveButton.WordWrap = 'on';
app.SaveButton.Enable = 'off';
app.SaveButton.Layout.Row = 1;
app.SaveButton.Layout.Column = 3;
app.SaveButton.Text = 'Save thresholds review';
% Create SaveButton
app.SaveButton = uibutton(app.GridLayout4, 'push');
app.SaveButton.ButtonPushedFcn = createCallbackFcn(app, @SaveButtonPushed, true);
app.SaveButton.WordWrap = 'on';
app.SaveButton.Enable = 'off';
app.SaveButton.Layout.Row = 1;
app.SaveButton.Layout.Column = 3;
app.SaveButton.Text = 'Save thresholds review';
% Create SaveButton
app.SaveButton = uibutton(app.GridLayout4, 'push');
app.SaveButton.ButtonPushedFcn = createCallbackFcn(app, @SaveButtonPushed, true);
app.SaveButton.WordWrap = 'on';
app.SaveButton.Enable = 'off';
app.SaveButton.Layout.Row = 1;
app.SaveButton.Layout.Column = 3;
app.SaveButton.Text = 'Save thresholds review';
% Create RippleCheckBox
app.RippleCheckBox = uicheckbox(app.GridLayout4);
app.RippleCheckBox.ValueChangedFcn = createCallbackFcn(app, @RippleCheckBoxValueChanged, true);
app.RippleCheckBox.Enable = 'off';
app.RippleCheckBox.Text = 'TP R';
app.RippleCheckBox.FontWeight = 'bold';
app.RippleCheckBox.Layout.Row = 1;
app.RippleCheckBox.Layout.Column = 2;
% Create RippleCheckBox
app.RippleCheckBox = uicheckbox(app.GridLayout4);
app.RippleCheckBox.ValueChangedFcn = createCallbackFcn(app, @RippleCheckBoxValueChanged, true);
app.RippleCheckBox.Enable = 'off';
app.RippleCheckBox.Text = 'TP R';
app.RippleCheckBox.FontWeight = 'bold';
app.RippleCheckBox.Layout.Row = 1;
app.RippleCheckBox.Layout.Column = 2;
% Create SharpwaveCheckBox
app.SharpwaveCheckBox = uicheckbox(app.GridLayout4);
app.SharpwaveCheckBox.ValueChangedFcn = createCallbackFcn(app, @SharpwaveCheckBoxValueChanged, true);
app.SharpwaveCheckBox.Enable = 'off';
app.SharpwaveCheckBox.Text = 'TP SW';
app.SharpwaveCheckBox.FontWeight = 'bold';
app.SharpwaveCheckBox.Layout.Row = 1;
app.SharpwaveCheckBox.Layout.Column = 1;
% Create SharpwaveCheckBox
app.SharpwaveCheckBox = uicheckbox(app.GridLayout4);
app.SharpwaveCheckBox.ValueChangedFcn = createCallbackFcn(app, @SharpwaveCheckBoxValueChanged, true);
app.SharpwaveCheckBox.Enable = 'off';
app.SharpwaveCheckBox.Text = 'TP SW';
app.SharpwaveCheckBox.FontWeight = 'bold';
app.SharpwaveCheckBox.Layout.Row = 1;
app.SharpwaveCheckBox.Layout.Column = 1;
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = ThresholdReviewer_exported
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end