-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheventerapp_exported.m
4884 lines (4545 loc) · 227 KB
/
eventerapp_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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
classdef eventerapp_exported < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
Eventer matlab.ui.Figure
CreditsButton matlab.ui.control.Button
StorePanel matlab.ui.container.Panel
UnsavedLabel matlab.ui.control.Label
StoreCurrentWaveButton matlab.ui.control.Button
CurrentWaveStoredBox matlab.ui.control.CheckBox
RunDropDown matlab.ui.control.DropDown
RunButton matlab.ui.control.Button
RunningLamp matlab.ui.control.Lamp
PopupGraphButton matlab.ui.control.Button
StoreAllWavesButton matlab.ui.control.Button
WaveDropDown matlab.ui.control.DropDown
WaveDropDownLabel matlab.ui.control.Label
ParallelPanel matlab.ui.container.Panel
ParallelsettingsLabel matlab.ui.control.Label
ProfileLabel matlab.ui.control.Label
ProfileNameButton matlab.ui.control.Button
NoofworkersSpinner matlab.ui.control.Spinner
NoofworkersSpinnerLabel matlab.ui.control.Label
ParallelCheckBox matlab.ui.control.CheckBox
TabGroupEventer matlab.ui.container.TabGroup
PreviewTab matlab.ui.container.Tab
WavePreviewAxes matlab.ui.control.UIAxes
TemplateTab matlab.ui.container.Tab
SignoftheEventsSwitchLabel_2 matlab.ui.control.Label
SignoftheEventsSwitch_2 matlab.ui.control.Switch
msLabel matlab.ui.control.Label
TimeconstantsPanel matlab.ui.container.Panel
ApplyToAllButtonTemplate matlab.ui.control.Button
DecayLabel matlab.ui.control.Label
RiseLabel matlab.ui.control.Label
msLabel_2 matlab.ui.control.Label
TimeConstantsEditField1 matlab.ui.control.NumericEditField
TimeConstantsEditField2 matlab.ui.control.NumericEditField
FitparametersPanel matlab.ui.container.Panel
Button matlab.ui.control.Button
msLabel_5 matlab.ui.control.Label
msLabel_4 matlab.ui.control.Label
tau2EditField matlab.ui.control.NumericEditField
tau2EditFieldLabel matlab.ui.control.Label
tau1EditField matlab.ui.control.NumericEditField
tau1EditFieldLabel matlab.ui.control.Label
SelectLabel matlab.ui.control.Label
TemplateSelectButton matlab.ui.control.Button
TemplatePreviewAxes matlab.ui.control.UIAxes
ExcludeTab matlab.ui.container.Tab
cell_ten matlab.ui.control.NumericEditField
cell_nine matlab.ui.control.NumericEditField
cell_twelve matlab.ui.control.NumericEditField
cell_eleven matlab.ui.control.NumericEditField
cell_six matlab.ui.control.NumericEditField
cell_five matlab.ui.control.NumericEditField
cell_eight matlab.ui.control.NumericEditField
cell_seven matlab.ui.control.NumericEditField
cell_two matlab.ui.control.NumericEditField
cell_one matlab.ui.control.NumericEditField
cell_four matlab.ui.control.NumericEditField
cell_three matlab.ui.control.NumericEditField
EditField_9 matlab.ui.control.NumericEditField
EditField_8 matlab.ui.control.NumericEditField
EditField_7 matlab.ui.control.NumericEditField
EditField_6 matlab.ui.control.NumericEditField
EditField_5 matlab.ui.control.NumericEditField
EditField_4 matlab.ui.control.NumericEditField
EditField_3 matlab.ui.control.EditField
EditField_2 matlab.ui.control.EditField
EditField_1 matlab.ui.control.EditField
zone_one_x matlab.ui.control.Button
ApplyToAllButton_xexclusion matlab.ui.control.Button
ApplyToAllButton_ex_6 matlab.ui.control.Button
ApplyToAllButton_ex_5 matlab.ui.control.Button
ApplyToAllButton_ex_4 matlab.ui.control.Button
ApplyToAllButton_ex_3 matlab.ui.control.Button
zone_two_x matlab.ui.control.Button
ApplyToAllButton_ex_2 matlab.ui.control.Button
ApplyToAllButton_ex_1 matlab.ui.control.Button
ExtraExclusions matlab.ui.control.TextArea
zone_eleven_x matlab.ui.control.Button
exselect_6 matlab.ui.control.Button
exselect_5 matlab.ui.control.Button
exselect_4 matlab.ui.control.Button
exselect_3 matlab.ui.control.Button
exselect_2 matlab.ui.control.Button
exselect_1 matlab.ui.control.Button
zone_six_x matlab.ui.control.Button
zone_five_x matlab.ui.control.Button
zone_four_x matlab.ui.control.Button
zone_three_x matlab.ui.control.Button
DetectionTab matlab.ui.container.Tab
ThresholdAbsoluteEditField matlab.ui.control.NumericEditField
ThresholdabsoluteEditFieldLabel matlab.ui.control.Label
ModelfileEditField matlab.ui.control.EditField
ModelfileEditFieldLabel matlab.ui.control.Label
TrainingmodeCheckBox matlab.ui.control.CheckBox
LoadmodelButton matlab.ui.control.Button
ConfigurationDropDown matlab.ui.control.DropDown
ConfigurationDropDownLabel matlab.ui.control.Label
EventCriterionLabel matlab.ui.control.Label
CorrelationCoefficientSpinner matlab.ui.control.Spinner
CorrelationCoefficientLabel matlab.ui.control.Label
CriterionDropDown matlab.ui.control.DropDown
SignoftheEventsSwitch matlab.ui.control.Switch
SignoftheEventsSwitchLabel matlab.ui.control.Label
WavefilterPanel matlab.ui.container.Panel
HighpassPreFiltermethodDropDown matlab.ui.control.DropDown
HighpassfiltermethodDropDownLabel matlab.ui.control.Label
OnOffCheckBoxLPF matlab.ui.control.CheckBox
OnOffCheckBoxHPF matlab.ui.control.CheckBox
LowpassPreFilterCutOffSpinner matlab.ui.control.Spinner
LowpassFilterCutOffSpinnerLabel matlab.ui.control.Label
HighpassPreFilterCutOffSpinner matlab.ui.control.Spinner
HighpassFilterCutOffSpinnerLabel matlab.ui.control.Label
HzLabel_2 matlab.ui.control.Label
HzLabel matlab.ui.control.Label
ThresholdSpinner matlab.ui.control.Spinner
ThresholdSpinnerLabel matlab.ui.control.Label
stdevLabel matlab.ui.control.Label
AdvancedTab matlab.ui.container.Tab
DeconvolutedWaveSignalProcessingPanel_2 matlab.ui.container.Panel
LowpassFilterCutOffSpinnerLabel_2 matlab.ui.control.Label
LowpassFilterCutOffSpinner matlab.ui.control.Spinner
HzLabel_3 matlab.ui.control.Label
HighpassFilterCutOffSpinner matlab.ui.control.Spinner
HzLabel_4 matlab.ui.control.Label
HighpassFilterCutOffSpinner_2Label matlab.ui.control.Label
LevenbergMarquardtSettingsPanel matlab.ui.container.Panel
LambdaDisp matlab.ui.control.NumericEditField
LambdaSlider matlab.ui.control.Slider
LambdaSliderLabel matlab.ui.control.Label
ExmodeDropDown matlab.ui.control.DropDown
ExmodeDropDownLabel matlab.ui.control.Label
msLabel_3 matlab.ui.control.Label
BaselineTimeSpinner matlab.ui.control.Spinner
BaselineTimeSpinnerLabel matlab.ui.control.Label
NoofTausSpinner matlab.ui.control.Spinner
NoofTausSpinnerLabel matlab.ui.control.Label
EventsettingsPanel matlab.ui.container.Panel
OutputTab matlab.ui.container.Tab
outdirLabel matlab.ui.control.Label
SetOutputFolderButton matlab.ui.control.Button
RootdirectoryEditField matlab.ui.control.EditField
RootdirectoryEditFieldLabel matlab.ui.control.Label
sLabel_3 matlab.ui.control.Label
sLabel_2 matlab.ui.control.Label
MinWindowSpinner matlab.ui.control.Spinner
EventwindowLabel matlab.ui.control.Label
MaxWindowSpinner matlab.ui.control.Spinner
GNUZipCompressionCheckBox matlab.ui.control.CheckBox
wavesstackedLabel matlab.ui.control.Label
dpiLabel matlab.ui.control.Label
FigureFormatDropDown matlab.ui.control.DropDown
FigureFormatDropDownLabel matlab.ui.control.Label
WaveFormatDropDown matlab.ui.control.DropDown
WaveFormatDropDownLabel matlab.ui.control.Label
EnsembleAverageButtonGroup matlab.ui.container.ButtonGroup
MeanButton matlab.ui.control.RadioButton
MedianButton matlab.ui.control.RadioButton
SummaryTab matlab.ui.container.Tab
TabGroupSummary matlab.ui.container.TabGroup
AllTab matlab.ui.container.Tab
SummaryAll matlab.ui.control.TextArea
CurrentTab matlab.ui.container.Tab
SummaryCurrent matlab.ui.control.TextArea
FilePanel matlab.ui.container.Panel
sLabel matlab.ui.control.Label
SplitSpinner matlab.ui.control.Spinner
SplitSpinnerLabel matlab.ui.control.Label
ClosefiguresButton matlab.ui.control.Button
ApplypresetsButton matlab.ui.control.Button
PresetsButton matlab.ui.control.Button
FullPathNameBox matlab.ui.control.ListBox
CloseButton matlab.ui.control.Button
ChannelSpinner matlab.ui.control.Spinner
ChannelSpinnerLabel matlab.ui.control.Label
LoadButton matlab.ui.control.Button
end
properties (Access = private)
%defaults
timeconstant1_default = 0.45;
timeconstant2_default = 3;
sign_default = '-';
scalefactor_default = 4;
exclude_default = [];
rmin_default = 0.4;
hpf_default = 10;
lpf_default = 200;
phpf_default = 0;
plpf_default = Inf;
taus_default = 2;
base_line_default = 1;
exmode_default = '1';
lambda_default = 1;
config_default = 'VC';
average_default = 'median';
export_default = 'abf';
figure_default = 'fig';
gz_default = 0;
%file path
baseName;
FullFileName;
nFiles;
%preset path
presets_file='';
presets_path='';
presetsFile_flag = 0;
%model path
model_file=0;
model_path='';
%array
current_wave;
wave_number;
xdiff;
yunit;
xunit;
ref_array = [];
array = [];
fig_wave = [];
nWaves;
S;
%plotting variables
ch=1;
template_plot;
ex_plot;
lpe = struct;
preview_plot;
prevone;
prevtwo;
base_x = 0;
base_y = 0;
ex_1;
ex_2;
ex_3;
ex_4;
ex_5;
ex_6;
ex_7;
ex_8;
ex_9;
ex_10;
ex_11;
ex_12;
xexclusion=[0, 0];
%misc
saved = [];
h
file = [];
settings = {};
fullpathlist = {};
refpathlist = {};
path = '';
wavefileidx = [];
profile = 'local';
predlg = [];
prefield = struct;
split_excl = [0,0];
outdir = {''};
model = [];
confirmedUnits = {};
xSF = '';
ySF = '';
%train eventer
train_dlg
event_checkbox
event_spinner
event_time
train_btn
selectall_btn
event_plot
training_data
event_class
event_features
end
methods (Access = private)
function unstored(app)
if app.CurrentWaveStoredBox.Value == 1
if ( app.TimeConstantsEditField1.Value ~= app.settings{app.current_wave+1}.TC1*1000 ) || ...
( app.TimeConstantsEditField2.Value ~= app.settings{app.current_wave+1}.TC2*1000 ) || ...
( ~strcmp(app.SignoftheEventsSwitch.Value,app.settings{1}.s) ) || ...
( app.ThresholdSpinner.Value ~= app.settings{1}.threshold ) || ...
( ~strcmp(app.CriterionDropDown.Value,app.settings{1}.criterion) ) || ...
( app.CorrelationCoefficientSpinner.Value ~= app.settings{1}.rmin ) || ...
( app.MinWindowSpinner.Value ~= app.settings{1}.win(1) ) || ...
( app.MaxWindowSpinner.Value ~= app.settings{1}.win(2) ) || ...
( app.HighpassFilterCutOffSpinner.Value ~= app.settings{1}.hpf ) || ...
( app.LowpassFilterCutOffSpinner.Value ~= app.settings{1}.lpf ) || ...
( ~strcmp(app.HighpassPreFiltermethodDropDown.Value,app.settings{1}.phpf_type) ) || ...
( app.HighpassPreFilterCutOffSpinner.Value ~= app.settings{1}.phpf ) || ...
( app.LowpassPreFilterCutOffSpinner.Value ~= app.settings{1}.plpf ) || ...
( app.NoofTausSpinner.Value ~= app.settings{1}.taus ) || ...
( app.BaselineTimeSpinner.Value ~= app.settings{1}.baseline*1000 ) || ...
( app.LambdaDisp.Value ~= app.settings{1}.lambda ) || ...
( ~strcmp(app.ConfigurationDropDown.Value,app.settings{1}.config) ) || ...
( strcmp(app.settings{1}.average,'mean') && (app.MedianButton.Value == 1) ) || ...
( strcmp(app.settings{1}.average,'median') && (app.MedianButton.Value == 0) ) || ...
( ~strcmp(app.ExmodeDropDown.Value,app.settings{1}.exmode) ) || ...
( ~strcmp(app.WaveFormatDropDown.Value,app.settings{1}.export) ) || ...
( ~strcmp(app.FigureFormatDropDown.Value,app.settings{1}.format) ) || ...
( ~strcmp(app.outdirLabel.Text,app.settings{1}.outdir{1}) ) || ...
( app.GNUZipCompressionCheckBox.Value ~= app.settings{1}.gz ) || ...
( app.cell_one.Value ~= app.settings{app.current_wave+1}.cell_one ) || ...
( app.cell_two.Value ~= app.settings{app.current_wave+1}.cell_two ) || ...
( app.cell_three.Value ~= app.settings{app.current_wave+1}.cell_three ) || ...
( app.cell_four.Value ~= app.settings{app.current_wave+1}.cell_four ) || ...
( app.cell_five.Value ~= app.settings{app.current_wave+1}.cell_five ) || ...
( app.cell_six.Value ~= app.settings{app.current_wave+1}.cell_six ) || ...
( app.cell_seven.Value ~= app.settings{app.current_wave+1}.cell_seven ) || ...
( app.cell_eight.Value ~= app.settings{app.current_wave+1}.cell_eight ) || ...
( app.cell_nine.Value ~= app.settings{app.current_wave+1}.cell_nine ) || ...
( app.cell_ten.Value ~= app.settings{app.current_wave+1}.cell_ten ) || ...
( app.cell_eleven.Value ~= app.settings{app.current_wave+1}.cell_eleven ) || ...
( app.cell_twelve.Value ~= app.settings{app.current_wave+1}.cell_twelve ) || ...
( app.ThresholdAbsoluteEditField.Value ~= app.settings{1}.absthreshold ) || ...
( ~strcmp(app.ModelfileEditField.Value,app.settings{1}.model_source)) || ...
( ~strcmp(app.ExtraExclusions.Value{1},app.settings{app.current_wave+1}.xexclusion{1}) )
app.UnsavedLabel.Visible = 'on';
app.UnsavedLabel.Enable = 'on';
else
app.UnsavedLabel.Visible = 'off';
app.UnsavedLabel.Enable = 'off';
end
end
end
function PreFilterWaves(app)
filter_waitbar = waitbar(0,'Please wait while we apply filter settings to all the waves...');
n = size(app.ref_array,2);
for i=2:size(app.ref_array,2)
waitbar((i-1)/(n-1),filter_waitbar);
app.array(:,i) = filter1 (app.ref_array(:,i), app.array(:,1), app.HighpassPreFilterCutOffSpinner.Value, app.LowpassPreFilterCutOffSpinner.Value, app.HighpassPreFiltermethodDropDown.Value);
end
close(filter_waitbar);
end
function UpdateWavePreview(app)
app.fig_wave = [app.array(:,1),app.array(:,app.current_wave+1)];
app.ApplyExclusionZones;
fig_wave = reduce_data(app.fig_wave,app.WavePreviewAxes.Position(3));
app.preview_plot = plot(app.WavePreviewAxes,fig_wave(:,1),fig_wave(:,2),'Color',[0 0 0],'LineWidth',0.25);
disableDefaultInteractivity(app.WavePreviewAxes)
app.WavePreviewAxes.XLim = [min(app.fig_wave(:,1)) max(app.fig_wave(:,1))];
app.WavePreviewAxes.YLim = [min(app.fig_wave(:,2)) max(app.fig_wave(:,2))];
end
function ApplyExclusionZones(app)
app.ex_1 = dsearchn(app.array(:,1), app.cell_one.Value);
app.ex_2 = dsearchn(app.array(:,1), app.cell_two.Value);
app.ex_3 = dsearchn(app.array(:,1), app.cell_three.Value);
app.ex_4 = dsearchn(app.array(:,1), app.cell_four.Value);
app.ex_5 = dsearchn(app.array(:,1), app.cell_five.Value);
app.ex_6 = dsearchn(app.array(:,1), app.cell_six.Value);
app.ex_7 = dsearchn(app.array(:,1), app.cell_seven.Value);
app.ex_8 = dsearchn(app.array(:,1), app.cell_eight.Value);
app.ex_9 = dsearchn(app.array(:,1), app.cell_nine.Value);
app.ex_10 = dsearchn(app.array(:,1), app.cell_ten.Value);
app.ex_11 = dsearchn(app.array(:,1), app.cell_eleven.Value);
app.ex_12 = dsearchn(app.array(:,1), app.cell_twelve.Value);
app.fig_wave = [app.array(:,1),app.array(:,app.current_wave+1)];
app.fig_wave(app.ex_1:app.ex_2,2) = NaN;
app.fig_wave(app.ex_3:app.ex_4,2) = NaN;
app.fig_wave(app.ex_5:app.ex_6,2) = NaN;
app.fig_wave(app.ex_7:app.ex_8,2) = NaN;
app.fig_wave(app.ex_9:app.ex_10,2) = NaN;
app.fig_wave(app.ex_11:app.ex_12,2) = NaN;
app.create_xexclusion;
for i=1:size(app.xexclusion)
temp_ex1 = dsearchn(app.array(:,1), app.xexclusion(i,1));
temp_ex2 = dsearchn(app.array(:,1), app.xexclusion(i,2));
app.fig_wave(temp_ex1:temp_ex2,2) = NaN;
end
unstored(app);
end
function UpdatePopupGraph(app)
if ishandle(7)
figure(7);
app.fig_wave = [app.array(:,1),app.array(:,app.current_wave+1)];
app.ApplyExclusionZones;
app.ex_plot = reduce_plot(app.fig_wave(:,1),app.fig_wave(:,2),'Color',[0 0 0],'linewidth',1.25);
app.lpe = LinePlotExplorer(f,app.WavePreviewAxes.XLim(1),app.WavePreviewAxes.XLim(2));
app.lpe.AttachCallback('WindowKeyPressFcn', @(h,event)app.EventerWindowKeyPress(event));
figure(app.Eventer); % reset focus on eventer window
end
end
function create_xexclusion(app)
if isempty(app.FullPathNameBox.Value)
return
end
if isempty(app.ExtraExclusions.Value{1})
app.xexclusion = [0 0];
end
try
app.xexclusion = eval(cell2mat(app.ExtraExclusions.Value'));
app.ExtraExclusions.FontColor = [0 0 0];
catch
app.ExtraExclusions.FontColor = [1 0 0];
end
if size(app.xexclusion,2) ~= 2
app.ExtraExclusions.FontColor = [1 0 0];
return
end
end
function f = AddFile(app)
% Add a single file to file list
% Loading previous analysis from .evt file
if strcmpi(app.file.baseName(end-3:end),'.evt')
chdir(app.file.Path);
load(app.file.baseName,'-mat')
app.settings = saveddata;
% The following if statements and assignments are for backwards compatibility
if ~isfield(app.settings{1},'xexclusion')
for i=1:numel(app.settings)
app.settings{i}.xexclusion={'[0 0]'};
end
end
if ~isfield(app.settings{1},'split')
app.settings{1}.split = 0; % this was not an option on previous versions
else
app.SplitSpinner.Value = app.settings{1}.split;
end
if ~isfield(app.settings{1},'criterion')
app.settings{1}.criterion = 'Pearson'; % this was not an option on previous versions
else
app.CriterionDropDown.Value = app.settings{1}.criterion;
end
if ~isfield(app.settings{1},'absthreshold')
app.settings{1}.absthreshold = 0; % this was not an option on previous versions
else
app.ThresholdAbsoluteEditField.Value = app.settings{1}.absthreshold;
end
if ~isfield(app.settings{1},'outdir')
app.settings{1}.outdir = {''}; % this was not an option on previous versions
end
app.outdir = app.settings{1}.outdir;
if ~isempty(app.outdir{1})
cd ..
app.path = pwd;
chdir(app.outdir{1});
else
app.path = app.file.Path;
end
% If filepaths.txt exists pathlist is created from there
if ~exist('filepaths.txt')
f = errordlg('Filepaths file not found','Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
else
fid=fopen('filepaths.txt','r');
rootpath = fgetl(fid);
temp = fgetl(fid);
app.fullpathlist = cell(1);
count = 0;
while ischar(temp)
count = count + 1;
app.fullpathlist{1,count} = temp;
temp = fgetl(fid);
end
fclose(fid);
if ~strcmpi(rootpath,'.')
% If necessary, calculate relative path list (for backwards compatibility)
relpathlist = cell(size(app.fullpathlist));
filenamelist = cell(size(app.fullpathlist));
for j=1:numel(relpathlist)
[fullpath,fname,extn] = fileparts(app.fullpathlist{j});
relpathlist{j} = relativepath(fullpath,rootpath);
if strcmp(relpathlist{j},filesep)
relpathlist{j} = ['.' relpathlist{j}];
end
filenamelist{j} = [fname,extn];
app.fullpathlist{j} = fullfile(relpathlist{j},filenamelist{j});
%app.fullpathlist{j} = [relpathlist{j} filesep filenamelist{j}];
end
end
% Convert to absolute path list
for j=1:numel(app.fullpathlist)
chdir(app.path);
[relpath, fname, extn] = fileparts(parse_path(app,app.fullpathlist{j}));
if ~isempty(relpath)
chdir(relpath)
end
app.fullpathlist{j} = fullfile(pwd,[fname extn]);
end
app.FullPathNameBox.Items = app.fullpathlist;
chdir(app.path);
if ~isempty(app.outdir{1})
chdir(app.outdir{1});
end
% Check for eventer.output for summary read
if exist('./eventer.output/ALL_events/summary.txt','file')
cd eventer.output/ALL_events/
app.SummaryAll.Value = fileread('summary.txt');
end
app.refpathlist = cell(size(app.fullpathlist));
end
end
if isempty(app.refpathlist)
app.path = app.file.Path;
chdir(app.path);
end
if ~strcmpi(app.file.baseName(end-3:end),'.evt')
app.fullpathlist = [app.fullpathlist {strcat(app.file.Path,app.file.baseName)}];
app.refpathlist = [app.refpathlist cell(1)];
if numel(unique(app.fullpathlist)) ~= numel(app.fullpathlist)
errMsg = sprintf('The following file you selected is already loaded:\n%s ',app.fullpathlist{end});
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
end
app.FullPathNameBox.Items = app.fullpathlist;
end
% requires: nFiles, fullpathlist, array, settings, ref array
% check if fullpathlist exists
% if no fullpathlist from selection
% if yes, add selection to existing fullpathlist
app.nFiles = numel(app.fullpathlist);
c = cell(1);
% Systematically chdir and run ephysIO on newly added files
for i=1:app.nFiles
if strcmp(app.fullpathlist{i},app.refpathlist{i})
continue
if strcmpi(app.file.baseName(end-3:end),'.evt')
waitbar(i/numel(app.nFiles),app.h);
end
end
if i==1
chdir(fileparts(app.fullpathlist{i}));
lasterr('');
warning('');
try
app.S = ephysIO({app.fullpathlist{i},app.ChannelSpinner.Value}); % replaced 1 with app.ch
catch
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
[errMsg] = lasterr;
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
end
if any(strcmpi(app.fullpathlist{i}(end-3:end),{'.csv','.txt'}))
% Enter units for raw text files if they are not
% defined in a header
prompt = {'Enter the units for x (e.g. ms):','Enter the units for y (e.g. pA):'};
app.confirmedUnits = inputdlg(prompt,'Data units',1,{'s','A'});
if isempty(app.confirmedUnits)
f = uifigure('Visible','off'); % create invisible figure handle
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
app.S = {};
return
end
app.S.xunit = app.confirmedUnits{1};
app.S.yunit = app.confirmedUnits{2};
[app.S.array(:,1), app.S.xunit, app.xSF] = app.scale_units(app.S.array(:,1),app.S.xunit);
if ~strcmp(app.S.xunit,'s')
errMsg = 'Base units for time not recognised. Units must be s';
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
app.S = {};
return
end
if (app.S.xdiff == 0)
errMsg = 'The data must be sampled at even intervals.';
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
app.S = {};
return
end
app.S.xdiff = app.S.xdiff*app.xSF;
[app.S.array(:,2:end),app.S.yunit, app.ySF] = app.scale_units(app.S.array(:,2:end),app.S.yunit);
if ~any(strcmp(app.S.yunit,{'A','V','au',''}))
errMsg = 'Base units not recognised. If specified, units must be A, V or au.';
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
app.S = {};
return
end
elseif strcmpi(app.fullpathlist{i}(end-4:end),'.tdms')
% Allow user to scale data input from tdms files
prompt = 'Enter the factor to scale the data by:';
app.ySF = inputdlg(prompt,'Data scaling',1,{'1'});
if isempty(app.ySF)
f = uifigure('Visible','off'); % create invisible figure handle
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
app.S = {};
return
end
app.ySF = str2num(app.ySF{1});
if isempty(app.ySF)
errMsg = 'The scale factor must be numeric';
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
app.S = {};
return
else
if (app.ySF <= 0) || (~isreal(app.ySF))
errMsg = 'The scale factor must be a real, non-zero and positive number';
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
app.S = {};
end
end
app.S.array(:,2:end) = app.S.array(:,2:end) * app.ySF;
end
[warnMsg] = lastwarn;
if ~isempty(warnMsg)
f = errordlg(warnMsg,'Warning');
set(f,'WindowStyle','modal');
uiwait(f);
end
app.split_excl = [0 0];
if app.SplitSpinner.Value > 0
rectime = size(app.S.array,1)*(size(app.S.array,2)-1)*app.S.xdiff;
if app.SplitSpinner.Value < rectime
splitwaves(app);
app.nWaves = size(app.S.array,2)-1;
else
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
errMsg='Duration of each wave after splitting must be <= the total recording time.';
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
end
end
app.array = app.S.array;
app.nWaves = size(app.S.array,2)-1;
if ~strcmpi(app.file.baseName(end-3:end),'.evt')
app.settings = cell(app.nWaves+1,1);
end
app.xdiff = app.S.xdiff;
app.xunit = app.S.xunit;
app.yunit = app.S.yunit;
else
lasterr('');
warning('');
try
app.S = ephysIO({app.fullpathlist{i},app.ChannelSpinner.Value});%replaced 1 with app.ch
catch
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
[errMsg] = lasterr;
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
end
[warnMsg] = lastwarn;
if ~isempty(warnMsg)
f = errordlg(warnMsg,'Warning');
set(f,'WindowStyle','modal');
uiwait(f);
end
if any(strcmpi(app.fullpathlist{i}(end-3:end),{'.csv','.txt'}))
% Assume the same units as for the first file loaded
% if loading data from raw text files
app.S.xunit = app.xunit;
app.S.xdiff = app.xdiff;
app.S.yunit = app.yunit;
app.S.array(:,1) = app.S.array(:,1) * app.xSF;
app.S.array(2:end) = app.S.array(2:end) * app.ySF;
elseif strcmpi(app.fullpathlist{i}(end-4:end),'.tdms')
app.S.array(:,2:end) = app.S.array(:,2:end) * app.ySF;
end
app.split_excl = [0 0];
if app.SplitSpinner.Value > 0
rectime = size(app.S.array,1)*(size(app.S.array,2)-1)*app.S.xdiff;
if app.SplitSpinner.Value < rectime
splitwaves(app);
app.nWaves = app.nWaves + size(app.S.array,2)-1;
else
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
errMsg='Duration of each wave after splitting must be <= the total recording time.';
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
end
end
if abs(app.S.xdiff-app.xdiff) > eps('single')
try
error(sprintf('inconsistent sampling interval encountered at file:\n%s',app.fullpathlist{i}))
catch
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
[errMsg] = lasterr;
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
end
end
if size(app.array,1) ~= size(app.S.array,1)
try
error('Recording length is inconsistent at file:\n%s',app.fullpathlist{i});
catch
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
[errMsg] = lasterr;
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
end
end
if ~strcmp(app.S.xunit,app.xunit)
try
error(sprintf('xunits are inconsistent at file:\n&s',app.fullpathlist{i}))
catch
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
[errMsg] = lasterr;
f = errordlg(errMsg,'Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
end
end
warning('');
if ~strcmp(app.S.yunit,app.yunit)
warning(sprintf('yunits are inconsistent at file:\n&s',app.fullpathlist{i}))
[warnMsg] = lastwarn;
if ~isempty(warnMsg)
f = errordlg(warnMsg,'Warning');
set(f,'WindowStyle','modal');
uiwait(f);
end
end
app.array = cat(2,app.array, app.S.array(:,2:end));
if ~strcmpi(app.file.baseName(end-3:end),'.evt')
app.settings = cat(1,app.settings,cell(size(app.S.array,2)-1,1));
end
app.nWaves = size(app.array,2)-1;
end
app.wavefileidx = [app.wavefileidx; i*ones(size(app.S.array,2)-1,1)];
if strcmpi(app.file.baseName(end-3:end),'.evt')
waitbar(i/numel(app.nFiles),app.h);
end
end
app.settings{app.nWaves+1}.xexclusion{1} = sprintf('[%.6g %.6g]',app.split_excl(1),app.split_excl(2));
if size(app.settings,1)-1 == app.nWaves+1
% Code for compatibility of v1.1.4 with evt files from
% v1.1.3 and earlier where split is not exact multiple
% of the recording length
app.settings(app.nWaves+1) = []; % remove settings from incomplete wave
warning(sprintf('Note that the final wave is not full length and so was discarded'))
[warnMsg] = lastwarn;
f = errordlg(warnMsg,'Warning');
set(f,'WindowStyle','modal');
uiwait(f);
end
if app.nWaves ~= size(app.settings,1)-1
app.fullpathlist(end)=[];
app.refpathlist(end)=[];
app.FullPathNameBox.Items = app.fullpathlist;
f = errordlg('inconsistent dimensions between wave number and settings array','Error');
set(f,'WindowStyle','modal');
uiwait(f);
return
end
app.ref_array = app.array;
%wave numbers
items = cell(1, app.nWaves);
for i = 1:app.nWaves
wave_drop = int2str(i);
items{1,i} = wave_drop;
end
app.WaveDropDown.Items = items;
app.WaveDropDown.ItemsData = items;
%Rename waves
app.S.names = {'Time'};
for i = 1:app.nWaves
app.S.names{i+1} = ['YWave' pad(num2str(i),3,'left','0')];
end
%load first wave
if isempty(app.refpathlist{1})
app.WaveDropDown.Value = '1';
else
app.WaveDropDown.Value = num2str(app.nWaves);
end
app.WaveDropDownValueChanged;
if strcmp(app.S.yunit,'A')
app.ConfigurationDropDown.Value = 'VC';
elseif strcmp(app.S.yunit,'V')
app.ConfigurationDropDown.Value = 'CC';
else
app.ConfigurationDropDown.Value = 'dummy';
end
app.ConfigurationDropDownValueChanged;
app.WaveFormatDropDownValueChanged;
%% check store status of all waves
%allStoredFlag = 1;
%for i=1:app.nWaves
% if ~isfield(app.settings{i+1},'s')
% allStoredFlag = 0;
% end
%end
%if allStoredFlag > 0
% app.StoreAllWavesButton.Text = 'Unstore all waves';
%else
% app.StoreAllWavesButton.Text = 'Store all waves';
%end
% Store a reference list of current file paths
app.refpathlist = app.fullpathlist;
% Return value for f upon success file load
f = 1;
end
function LoadPresetsButtonPushed(app, event)
cwd = pwd;
if app.presets_file ~= 0
chdir(app.presets_path)
end
f = figure('Units','normalized','Position',[0.4,0.5,0.25,0.02],'NumberTitle', 'off', 'Name','Loading presets file open dialogue...','Toolbar','None','MenuBar','None');
drawnow;
f.Visible = 'off';
[app.presets_file, app.presets_path] = uigetfile(...
{'*.m','MATLAB script file (*.m)'},...
'Load file');
% delete dummy figure
delete(f);
chdir(cwd);
if app.presets_file ~= 0
app.presetsFile_flag = 1;
else
return
end
app.prefield.Value = fullfile(app.presets_path,app.presets_file);
end
function SavePresetsButtonPushed(app, event, filename)
format short g
if nargin > 2
chdir(app.path);
if ~isempty(app.outdir{1})
chdir(app.outdir{1});
pathname = pwd;
cd ..
else
pathname = pwd;
end
else
[filename, pathname] = uiputfile({'*.m','MATLAB script file (*.m)'},'Save as');
if filename == 0
return
end
end
fid=fopen(fullfile(pathname,filename),'w+t');
fprintf(fid,'app.TimeConstantsEditField1.Value = %g;\n',app.TimeConstantsEditField1.Value);
fprintf(fid,'app.TimeConstantsEditField2.Value = %g;\n',app.TimeConstantsEditField2.Value);
fprintf(fid,'app.ConfigurationDropDown.Value = ''%s'';\n',app.ConfigurationDropDown.Value);
fprintf(fid,'app.SignoftheEventsSwitch.Value = ''%s'';\n',app.SignoftheEventsSwitch.Value);
fprintf(fid,'app.ThresholdSpinner.Value = %g;\n',app.ThresholdSpinner.Value);
fprintf(fid,'app.CriterionDropDown.Value = ''%s'';\n',app.CriterionDropDown.Value);
fprintf(fid,'app.CorrelationCoefficientSpinner.Value = %g;\n',app.CorrelationCoefficientSpinner.Value);
fprintf(fid,'app.HighpassPreFiltermethodDropDown.Value = ''%s'';\n',app.HighpassPreFiltermethodDropDown.Value);
fprintf(fid,'app.HighpassPreFilterCutOffSpinner.Value = %g;\n',app.HighpassPreFilterCutOffSpinner.Value);
fprintf(fid,'app.LowpassPreFilterCutOffSpinner.Value = %g;\n',app.LowpassPreFilterCutOffSpinner.Value);
fprintf(fid,'app.ExtraExclusions.Value = {''%s''};\n',app.ExtraExclusions.Value{1});
fprintf(fid,'app.NoofTausSpinner.Value = %g;\n',app.NoofTausSpinner.Value);
fprintf(fid,'app.BaselineTimeSpinner.Value = %g;\n',app.BaselineTimeSpinner.Value);
fprintf(fid,'app.ExmodeDropDown.Value = ''%s'';\n',app.ExmodeDropDown.Value);
fprintf(fid,'app.LambdaDisp.Value = %g;\n',app.LambdaDisp.Value);
fprintf(fid,'app.HighpassFilterCutOffSpinner.Value = %g;\n',app.HighpassFilterCutOffSpinner.Value);
fprintf(fid,'app.LowpassFilterCutOffSpinner.Value = %g;\n',app.LowpassFilterCutOffSpinner.Value);
fprintf(fid,'app.MedianButton.Value = %g;\n',app.MedianButton.Value);
fprintf(fid,'app.MinWindowSpinner.Value = %g;\n',app.MinWindowSpinner.Value);
fprintf(fid,'app.MaxWindowSpinner.Value = %g;\n',app.MaxWindowSpinner.Value);
fprintf(fid,'app.WaveFormatDropDown.Value = ''%s'';\n',app.WaveFormatDropDown.Value);
fprintf(fid,'app.GNUZipCompressionCheckBox.Value = %g;\n',app.GNUZipCompressionCheckBox.Value);
fprintf(fid,'app.FigureFormatDropDown.Value = ''%s'';\n',app.FigureFormatDropDown.Value);
fprintf(fid,'app.SplitSpinner.Value = %g;\n',app.SplitSpinner.Value);
fprintf(fid,'app.ThresholdAbsoluteEditField.Value = %g;\n',app.ThresholdAbsoluteEditField.Value);
%fprintf(fid,'app.outdir = {''%s''};\n',app.outdir{1});
fclose(fid);
app.presets_path = pathname;
app.presets_file = filename;
app.LoadSavePresetsButtonPushed;
app.prefield.Value = fullfile(app.presets_path, app.presets_file);
app.presetsFile_flag = 1;
end
function SaveAnalysis(app)
saveflag = 0;
for i=1:app.nWaves
if isfield(app.settings{i+1},'s')
saveflag = 1;
end
end
if saveflag == 1
chdir(app.path);
if ~isempty(app.outdir{1})
if ~exist(['./',app.outdir{1}],'dir')
mkdir(app.outdir{1});
end
chdir(app.outdir{1});
end
if app.CurrentWaveStoredBox.Value == 1
if strcmpi(app.UnsavedLabel.Visible,'on')
app.StoreCurrentWaveButtonPushed;
end
end
relpathlist = cell(size(app.fullpathlist));
filenamelist = cell(size(app.fullpathlist));
for j=1:numel(relpathlist)
[fullpath,fname,extn] = fileparts(app.fullpathlist{j});
relpathlist{j} = relativepath(fullpath,app.path);
filenamelist{j} = [fname,extn];
end
fullpath = app.path;
saveddata = app.settings; % settings to saveddata here
save('analysis.evt','fullpath','relpathlist','saveddata','-mat','-v7.3');
% Save full file paths in readable filepaths.txt
fid=fopen('filepaths.txt','w+t');
fprintf(fid,'%s\n',fullpath);
for j=1:numel(relpathlist)
fprintf(fid,'%s\n',[relpathlist{j} filenamelist{j}]);
end
fclose(fid);
if ~isempty(app.outdir{1})
cd ..
end
end
end
function splitwaves(app)
% split waves function
temp = app.S.array(:,2:end);
temp = temp(:);
n = round(app.SplitSpinner.Value/app.S.xdiff);
l = floor(size(temp,1)/n);
app.S.array = NaN([n,l+1]);
app.S.array(:,1) = app.S.xdiff*[1:n]';
for i = 1:l
% floor
app.S.array(:,i+1) = temp((i-1)*n+1:i*n);
% ceil
%if i < l
% app.S.array(:,i+1) = temp((i-1)*n+1:i*n);
%else
% app.S.array(:,l+1) = temp(end);
% m = numel(temp((l-1)*n+1:end));
% app.S.array(1:m,l+1) = temp((l-1)*n+1:end);
% if size(app.S.array,1)-m ~= 0