-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMEA_analysis_exported.m
2797 lines (2243 loc) · 127 KB
/
MEA_analysis_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 MEA_analysis_exported < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
FileMenu matlab.ui.container.Menu
LoadsortedspikesMenu matlab.ui.container.Menu
LoaddatasetMenu matlab.ui.container.Menu
ExportdataMenu matlab.ui.container.Menu
ExportsubsetofspikesMenu matlab.ui.container.Menu
ExportanalysisfilesMenu matlab.ui.container.Menu
ExportfullrecordingMenu matlab.ui.container.Menu
ImportdataMenu matlab.ui.container.Menu
EditMenu matlab.ui.container.Menu
CopypanelcontentMenu matlab.ui.container.Menu
SettingsMenu matlab.ui.container.Menu
NoiseFileMenu matlab.ui.container.Menu
KernelMenu matlab.ui.container.Menu
MovieFrequencyMenu matlab.ui.container.Menu
ScriptFolderMenu matlab.ui.container.Menu
AssignenewMenu matlab.ui.container.Menu
ParallelprocessingMenu matlab.ui.container.Menu
OnMenu matlab.ui.container.Menu
OFFMenu matlab.ui.container.Menu
WindowsMenu matlab.ui.container.Menu
CloseallMenu matlab.ui.container.Menu
TabGroup matlab.ui.container.TabGroup
MainAnalysisTab matlab.ui.container.Tab
Mainpagegrid matlab.ui.container.GridLayout
UITable matlab.ui.control.Table
RunButton matlab.ui.control.Button
RefreshListButton matlab.ui.control.Button
ChangeFolderButton matlab.ui.control.Button
Stim_Axes matlab.ui.control.UIAxes
EditVariableButton matlab.ui.control.Button
RemoveselectedfileButton matlab.ui.control.Button
CreatenewstimulusfromzoomedButton matlab.ui.control.Button
DataListBox matlab.ui.control.ListBox
StimuliListBoxLabel matlab.ui.control.Label
StimuliListBox matlab.ui.control.ListBox
ScriptsListBoxLabel matlab.ui.control.Label
ScriptsListBox matlab.ui.control.ListBox
AllspikesPanel matlab.ui.container.Panel
QualitycheckPanel matlab.ui.container.Panel
DataLabel matlab.ui.control.Label
KernelsTab matlab.ui.container.Tab
UsequalityindexCheckBox matlab.ui.control.CheckBox
ShowButton matlab.ui.control.Button
Kernel_Axes matlab.ui.control.UIAxes
Kernel_Axes_2 matlab.ui.control.UIAxes
Kernel_Axes_4 matlab.ui.control.UIAxes
Kernel_Axes_3 matlab.ui.control.UIAxes
TimeSliderLabel matlab.ui.control.Label
TimeSlider matlab.ui.control.Slider
PlayButton matlab.ui.control.Button
StopButton matlab.ui.control.Button
QualityCriteriaPanel matlab.ui.container.Panel
ResetButton matlab.ui.control.Button
CalculateButton matlab.ui.control.Button
StdThresholdSliderLabel matlab.ui.control.Label
StdThresholdSlider matlab.ui.control.Slider
KernelsListBoxLabel matlab.ui.control.Label
KernelsListBox matlab.ui.control.ListBox
ShowtimekernelsCheckBox matlab.ui.control.CheckBox
NrneighboursSliderLabel matlab.ui.control.Label
NrneighboursSlider matlab.ui.control.Slider
LinkAxesButton matlab.ui.control.Button
RejectCellQIButton matlab.ui.control.Button
KernelsnewTab matlab.ui.container.Tab
Kernel_new_grid matlab.ui.container.GridLayout
RFIdentificationMethodPanel matlab.ui.container.Panel
STASDCheckBox matlab.ui.control.CheckBox
SelfCovarianceCheckBox matlab.ui.control.CheckBox
RFOptionsPanel matlab.ui.container.Panel
RFTypePanel matlab.ui.container.Panel
BoxCheckBox matlab.ui.control.CheckBox
AllsignificantpixelCheckBox matlab.ui.control.CheckBox
GaussianCheckBox matlab.ui.control.CheckBox
NumSDGaussSpinnerLabel matlab.ui.control.Label
NumSDGaussSpinner matlab.ui.control.Spinner
NumRingBoxesSpinnerLabel matlab.ui.control.Label
NumRingBoxesSpinner matlab.ui.control.Spinner
QualityControlThresholdPanel matlab.ui.container.Panel
STASDPanel matlab.ui.container.Panel
QCTypePanel matlab.ui.container.Panel
NumStdDevCheckBox matlab.ui.control.CheckBox
ConfIntCheckBox matlab.ui.control.CheckBox
SDThreshEditFieldLabel matlab.ui.control.Label
SDThreshEditField matlab.ui.control.EditField
CIUpperEditFieldLabel matlab.ui.control.Label
CIUpperEditField matlab.ui.control.EditField
SelfCovariancePanel matlab.ui.container.Panel
QCTypePanel_2 matlab.ui.container.Panel
NumStdDevCheckBox_2 matlab.ui.control.CheckBox
ConfIntCheckBox_2 matlab.ui.control.CheckBox
SDThreshEditField_2Label matlab.ui.control.Label
SDThreshEditField_2 matlab.ui.control.EditField
CILowerEditFieldLabel matlab.ui.control.Label
CILowerEditField matlab.ui.control.EditField
StimulusFrequencyEditFieldLabel matlab.ui.control.Label
StimulusFrequencyEditField matlab.ui.control.EditField
HzLabel matlab.ui.control.Label
FindRFsButton matlab.ui.control.Button
PlottingResultsPanel matlab.ui.container.Panel
PlotsinglecellButton matlab.ui.control.Button
CelltoplotSpinnerLabel matlab.ui.control.Label
CelltoplotSpinner matlab.ui.control.Spinner
STASDLabel matlab.ui.control.Label
SelfCovarianceLabel matlab.ui.control.Label
NumStdDevCheckBox_SC_plot matlab.ui.control.CheckBox
NumStdDevCheckBox_SS_plot matlab.ui.control.CheckBox
ConfIntCheckBox_SC_plot matlab.ui.control.CheckBox
ConfIntCheckBox_SS_plot matlab.ui.control.CheckBox
RFTypePanel_2 matlab.ui.container.Panel
BoxCheckBox_plot matlab.ui.control.CheckBox
AllsignificantpixelCheckBox_plot matlab.ui.control.CheckBox
GaussianCheckBox_plot matlab.ui.control.CheckBox
HeatmapButtonGroup matlab.ui.container.ButtonGroup
GrayButton matlab.ui.control.RadioButton
ColourButton matlab.ui.control.RadioButton
PlotstatisticsforallcellsButton matlab.ui.control.Button
GeneraloptionsPanel matlab.ui.container.Panel
NumSTEbinsSpinnerLabel matlab.ui.control.Label
NumSTEbinsSpinner matlab.ui.control.Spinner
PlotRFinformationCheckBox matlab.ui.control.CheckBox
PlotrasterplotPanel matlab.ui.container.Panel
CelltoplotSpinner_2Label matlab.ui.control.Label
CelltoplotSpinner_2 matlab.ui.control.Spinner
PlotsinglecellButton_2 matlab.ui.control.Button
CellRFoverviewPanel matlab.ui.container.Panel
RFcellsoverviewPanel matlab.ui.container.Panel
GratingsTab matlab.ui.container.Tab
GridLayout matlab.ui.container.GridLayout
PolarPlotsPanel matlab.ui.container.Panel
Panel2 matlab.ui.container.Panel
SignificancecriteriaPanel matlab.ui.container.Panel
RTestCheckBox matlab.ui.control.CheckBox
OTestCheckBox matlab.ui.control.CheckBox
RTestTimeWindowCheckBox matlab.ui.control.CheckBox
OTestTimeWindowCheckBox matlab.ui.control.CheckBox
ShowButton_2 matlab.ui.control.Button
GratingsListBox matlab.ui.control.ListBox
Grating_cells_qcPanel matlab.ui.container.Panel
Grating_qc_summaryPanel matlab.ui.container.Panel
Grating_frequencyPanel matlab.ui.container.Panel
FFFTab matlab.ui.container.Tab
GridLayout2 matlab.ui.container.GridLayout
PlotsPanel matlab.ui.container.Panel
CellListBoxLabel matlab.ui.control.Label
CellListBox matlab.ui.control.ListBox
QualityOverviewPanel matlab.ui.container.Panel
AlltracesoverviewPanel matlab.ui.container.Panel
QualityoverviewdetailedPanel matlab.ui.container.Panel
ClusteringTab matlab.ui.container.Tab
StatusLampLabel matlab.ui.control.Label
StatusLamp matlab.ui.control.Lamp
SelectedstimulusEditFieldLabel matlab.ui.control.Label
SelectedstimulusEditField matlab.ui.control.EditField
end
properties (Access = private)
%%This part declares variables which can be accessed globaly using the app.variable nomenclature
spike_info %Stores information about the main analysis file.
dataselection %Stores the index of the recording selected in the Listbox containing loaded files
nr_r %Keeps track of how many files have been loaded in total
working_path %Working path for the app
data_info = cell(1,3) %Cell with information shown in the first list box (Filename, cluster, spikes)
selected_stimuli %Index of the stimulu(i) selected in the stimulus list
scriptfolder %= "C:\Users\Marvin Seifert\Documents\MATLAB\App_functions" %Default script folder which gets loaded at startup
appfolder % = "C:\Users\Marvin Seifert\Documents\MATLAB\App" %Folder with the main scripts for the app
selected_script %Stores the name of the script selected in the scripts list box
to_function %Structure which contains all the information which is input to a respective script once "Run" is clicked
spiketimestamps %Stores loaded spiketimestamps once run is hit until selected stimulus or recording is changed
add_info %Stores additional information in a structure and is use as input into the analysis function
Kernel_info %Structure which saves data for the Kernel tab
stop_movie %Stores 1 or 0 if button pushed or not
settings_location %The location of the settings.mat file which is loaded at startup
out%return of the script run by the run_script function
stimulus_info %Stores information about the selected stimulus if existing
Grating_info %Saves data for the Gratings tab like Kernel_info does for Kernels
Tab_reload %True or false, if true the tabfunction runs when tabs are changed, if false, tabfunction does
%not run (Tabfunction shall only run if stimulus selected is changed)
FFF_figures %Stores handles of figures in the FFF tab
Cuda_status %Boolean, saves if CUDA driver/ device exists on the computer
all_cells_figures %Stores figures to be potted into the main tab
%Stim Ch
stim_ch%Data of the stim_ch which is displayed under the stimulus list
downsample_f%factor by which the stim_ch trace is downsampled to save memory space
xlineob_1%vertical line which indicates the begining of a stimulus in the stim trace
xlineob_2%vertical line which indicates the ending of a stimulus in the stim trace
test1
test2
test3
test4
%Data Manipulation
Data_Variable
%Axis Kernel Plot
k_ax1
k_ax2
k_ax3
k_ax4
end
methods (Access = private)
%This section contains different functions which can be used within the app (they are not accessable in normal Matlab)
function run_script(app)
%This function runs the script with the name defined in the
%variable (app.)selected_stimuli. It takes only one input which
%is app but relies on app.selected_stimuli to be present.
app.StatusLamp.Color = 'red'; %Change lamp to red
drawnow(); %Update GUI
%In case the script cant be found it returns an error message
try
% file = app.data_info{app.dataselection, 1};
selected_stimuli = app.selected_stimuli; %Chronologic number of the selected stimulus
catch ME %Error message returned to the Matlab Command Window
message = sprintf('Error running script. Select Recording and stimulus first');
uiwait(warndlg(message));
app.StatusLamp.Color = 'green';
return
end
try
%Try update the app.add_info structure which will be handed
%to the function called.
app.add_info.stim_begin = app.spike_info.stim_begin(selected_stimuli);%Only pick the times for the stimuli choosen
app.add_info.stim_end= app.spike_info.stim_end(selected_stimuli);
catch ME
message = sprintf('Error loading variable "stim_begin" and or "stim_end" \n%s', ME.message);
uiwait(warndlg(message));
app.StatusLamp.Color = 'green';
return
end
try
function_to_run = erase(app.selected_script,'.m'); %delets the file type description
%Now we create the call to the function as a string, this
%includes input arguments, next we will use eval to
%evaluate that string as if it was written as code
function_in = strcat(function_to_run,"(app.data_info{app.dataselection,1},app.add_info)");
app.add_info
app.add_info.out = eval(function_in);
% app.add_info.out %uncomment to see what the function
% called returns
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
app.StatusLamp.Color = 'green';
return
end
end
function Tabfunction(app, Tab)
%This function runs whenever a new tab is selected in the GUI. It
%is like a startup function for different tabs
if app.Tab_reload == true %Only run if tab shall be reloaded
if strcmp(Tab, 'Kernels') == 1
try
%Load the Data file for the selected stimulus
S = load(app.spike_info.Stimulus_info{app.add_info.stim_idx});
Data = S.Data;
clear S
%Check if a folder with the name "Kernel" exists
Kernel_idx = find([Data.Folder] == "Kernel");
Kernel_name_str = Data(Kernel_idx).Files;
Kernel_length = length(Kernel_name_str);
%Sort data based on cell indices
TF = zeros(1,Kernel_length);
for ii = 1:Kernel_length
log = isstrprop(Kernel_name_str{ii},'digit');
string_name = Kernel_name_str{ii};
TF(ii) = string(string_name(log));
end
[~, a_order] = sort(TF);
Kernel_name_str = Kernel_name_str(a_order);
%Update the Kernel ListBox
app.KernelsListBox.Items = Kernel_name_str;
catch ME
%Errors here mostly mean that no Kernels have been
%calculated
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
%This part updates the FFF tab
elseif strcmp(Tab, 'FFF') == 1
try %Since FFF are much more straightforward, we just list all indices of all cells in the file
File = load(app.data_info{app.dataselection,1},'-mat','all_clusters','cell_indices');
Cell_nr = File.all_clusters;
Cell_nr_str = File.cell_indices;
Cell_name_str = {1,Cell_nr};
for ii = 1:Cell_nr
Cell_name_str{1, ii} = strcat('Cell_',num2str(Cell_nr_str(ii)));
end
%update the Cell Listbox
app.CellListBox.Items = Cell_name_str;
catch ME
%For debugging
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
%Delet existing figures
try
delete(app.QualityOverviewPanel.Children);
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
try
delete(app.AlltracesoverviewPanel.Children);
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
try
delete(app.QualityoverviewdetailedPanel.Children);
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
%Try to load figures
try
dummy_figure = openfig(findfile_app(app.add_info.stim_idx,app.spike_info.savename,"overview_FFF.fig"),'invisible');
dummy_ax = findobj(dummy_figure,'Type','Axes');
app.FFF_figures.Overview = copyobj(dummy_ax, app.QualityOverviewPanel);
delete(dummy_figure)
1
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
try
dummy_figure = openfig(findfile_app(app.add_info.stim_idx,app.spike_info.savename,"all_traces_plot.fig"),'invisible');
dummy_ax = findobj(dummy_figure,'Type','Axes');
app.FFF_figures.Alltraces = copyobj(dummy_ax, app.AlltracesoverviewPanel);
delete(dummy_figure)
colormap(app.FFF_figures.Alltraces,flipud(gray));
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
try
dummy_figure = openfig(findfile_app(app.add_info.stim_idx,app.spike_info.savename,"detail_stats_FFF.fig"),'invisible');
dummy_ax = findobj(dummy_figure,'Type','Axes');
colormap (flipud(gray));
app.FFF_figures.QualityOV = copyobj(dummy_ax, app.QualityoverviewdetailedPanel);
delete(dummy_figure)
colormap(app.FFF_figures.QualityOV,flipud(gray));
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
%This part updates the Gartings Tab, equal to the FFF tab
elseif strcmp(Tab, 'Gratings') == 1
if length(app.add_info.stim_idx) > 1
warning("Multiple stimuli selected, this tab only works with one stimulus selected")
return
end
try
File = load(app.data_info{app.dataselection,1},'-mat','all_clusters','cell_indices');
Cell_nr = File.all_clusters;
Cell_nr_str = File.cell_indices;
Cell_name_str = {1,Cell_nr};
for ii = 1:Cell_nr
Cell_name_str{1, ii} = strcat('Cell_',num2str(Cell_nr_str(ii)));
end
app.GratingsListBox.Items = Cell_name_str;
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
try
%Try to load figures with the QC information
dummy_figure = openfig(findfile_app(app.add_info.stim_idx,app.spike_info.savename,"Grating_qc_figure.fig"),'invisible');
dummy_ax = findobj(dummy_figure,'Type','Axes');
copyobj(dummy_ax, app.Grating_cells_qcPanel);
delete(dummy_figure)
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
try
%Try to load figures with the QC information
dummy_figure = openfig(findfile_app(app.add_info.stim_idx,app.spike_info.savename,"grating_qc_summary.fig"),'invisible');
dummy_ax = findobj(dummy_figure,'Type','Axes');
copyobj(dummy_ax, app.Grating_qc_summaryPanel);
delete(dummy_figure)
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
try
%Try to load figures with the QC information
dummy_figure = openfig(findfile_app(app.add_info.stim_idx,app.spike_info.savename,"frequency_qc_summary.fig"),'invisible');
dummy_ax = findobj(dummy_figure,'Type','Axes');
copyobj(dummy_ax, app.Grating_frequencyPanel);
delete(dummy_figure)
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
elseif strcmp(Tab, 'Kernels new') == 1
try
app.add_info.settings.kernel_new.cells_overview_panel = app.RFcellsoverviewPanel;
app.selected_script = "plotoverview_kernel_new.m";
run_script(app)
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
end
end
app.Tab_reload = false;
end
function screen_position(app)
%This function sets the screen position of the app during
%startup
screenSize = get(groot,'ScreenSize');
screenWidth = screenSize(3);
screenHeight = screenSize(4);
left = screenWidth*0.1;
bottom = screenHeight*0.1;
width = screenWidth*0.8;
height = screenHeight*0.8;
drawnow;
app.UIFigure.Position = [left bottom width height];
end
function edit_Variable(btn,app,uit,name)
%This function saves a new value assigned to a variable in the
%varaible list box when edit variable and in "save" is clicked
%in the pop up window
new_Variable = uit.Data;
MF = matfile(app.data_info{app.dataselection,1},"Writable",true);
MF.(name) = new_Variable;
end
function savesettings(app) %Saves new settings to settings file after updated in the GUI
settings = app.add_info.settings;
save(app.settings_location,"settings",'-mat')
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
%%This function assignes values to variables declared earlier
%%and runs functions before the actual app is started
%Witch lamp to red
app.StatusLamp.Color = 'red';
drawnow() %Updates the gui
%
%Set the resolution of the app
screen_position(app)
% Define main path and relative paths from settings
[app.appfolder,~,~] = fileparts(mfilename('fullpath')); %Get the folder in which the app is running
app.settings_location = strcat(app.appfolder,'\Settings.mat'); %Sets the location of the file with the settings information
% Settings
%This loads the settings from the settings file or creates a
%new settings file when no existing file is found
try
S = load(app.settings_location,'-mat'); %Load the data from the file specified above
app.add_info.settings = S.settings;
app.scriptfolder = S.settings.location.scripts;
catch
disp('Could not find settings file, settings set to default')
path = uigetdir(app.appfolder,'Select main script folder');
if isequal(path,0)
disp('User selected Cancel')
else
disp(['User selected ', path])
app.add_info.settings.location.scripts = path;
app.scriptfolder = path;
addpath(genpath(app.appfolder)); %This adds the app folder to the matlab path
end
savesettings(app)
end
%General
app.dataselection = uint8(0);
app.UITable.ColumnName = ["Filename", "Clusters", "Spikes"]; %Set default column names for the datafile table
app.UITable.ColumnFormat = {'char', 'numeric', 'numeric'}; %Define the formate of the columns
app.UITable.ColumnEditable = true(1,3); %all columns editable
app.nr_r = uint8(1);
app.StimuliListBox.Multiselect = 'on'; %This enables multiselections in the stimulus list
app.StimuliListBox.Items = {};
app.Cuda_status = logical(gpuDeviceCount);
app.appfolder = pwd;
%addpath(app.scriptfolder); %Adds the scriptfolder to the matlab search path
addpath(app.appfolder); %Adds the folder with the main functions for the app
app.UITable.Enable = 'off';
%Set the script List
folder_content = dir(app.scriptfolder); %List all contents in the script folder
app.ScriptsListBox.Items = {folder_content(3:end).name}; %Adds the content into the list in the GUI
app.ScriptsListBox.Multiselect = 'off'; %Disables multiselection in the list
app.selected_script = string(app.ScriptsListBox.Value); %Save the name of the first script in the list at startup
%Tabs general
app.Tab_reload = true;
%Kernel Tab
app.Kernel_info.Cell = 0; %Sets Kernel count to zero
app.TimeSlider.Limits = [-100 100];
app.Kernel_info.kernel_time = 250;
app.stop_movie = 0;
app.Kernel_info.std_threshold = 2;
app.Kernel_info.neighbours = 1; %Determinds how many time series are shown
app.Kernel_info.time_kernels = 0; %Stores value if time kernels shall be plotted or not
app.Kernel_info.movie_frequency = 0.05;
app.ShowtimekernelsCheckBox.Enable = 'off';
%Stim_Ch
app.downsample_f = 10;
app.Stim_Axes
%Gratings tab
app.Grating_info.rtest = 0;
app.Grating_info.otest = 0;
app.PolarPlotsPanel.AutoResizeChildren = 'off';
app.Panel2.AutoResizeChildren = 'off';
app.Grating_info.rtest = 0;
app.Grating_info.otest = 0;%Stores inital parameters for Quality Criteria Tick Boxes in Gratings Tab
% app.test1 = subplot(1,4,1,'Parent',app.GratingsTab);
% app.test2 = subplot(1,4,2,'Parent',app.GratingsTab);
% app.test3 = subplot(1,4,3,'Parent',app.GratingsTab);
% app.test4 = subplot(1,4,4,'Parent',app.GratingsTab);
% plot(app.test1,[1 2 3 4 5])
% plot(app.test2,[9 8 7 6 5])
% plot(app.test3,[9 8 7 6 5])
% plot(app.test4,[9 8 7 6 5])
%
%FFF tab
app.PlotsPanel.AutoResizeChildren = 'off';
%Kernel_new tab
set(findall(app.STASDPanel, '-property', 'enable'), 'enable', 'off')
set(findall(app.SelfCovariancePanel, '-property', 'enable'), 'enable', 'off')
set(findall(app.GaussianCheckBox, '-property', 'enable'), 'enable', 'off')
app.CellRFoverviewPanel.AutoResizeChildren = 'off';
app.RFcellsoverviewPanel.AutoResizeChildren = 'off';
app.StatusLamp.Color = 'green';
drawnow() %Updates the gui
end
% Menu selected function: LoadsortedspikesMenu
function LoadsortedspikesMenuSelected(app, event)
%This function runs when "Load sorted spikes" in the menu is clicked
%It runs the function "Loadspikes_app" which is stored in the
%apps main folder. Once this function has run the Uitable is
%filled with the information about the cells and spikes that
%have been loaded
app.StatusLamp.Color = 'red';
drawnow();
app.Tab_reload = true; %If true tabs will return to default look
try
app.spike_info = Loadspikes_app; %The out file in loadspikes_app must contain all the information which is saved in the analysis mat file
%Write the essential information into the apps memory
app.working_path(app.nr_r) = string(app.spike_info.pathname);
app.data_info{app.nr_r, 1} = app.spike_info.savename;
app.data_info{app.nr_r, 2} = app.spike_info.all_clusters;
app.data_info{app.nr_r, 3} = app.spike_info.all_spikes;
%Update Table in the GUI (Table is switched off as long as
%no recording is selected
if app.nr_r == 1
app.UITable.Enable = 'on';
end
app.UITable.Data = app.data_info;
%Update number of recordings
app.nr_r = app.nr_r + 1;
catch ME %Error
message = sprintf('Error loading spiketimes\n%s', ME.message);
uiwait(warndlg(message));
end
app.StatusLamp.Color = 'green';
drawnow();
figure(app.UIFigure);
end
% Menu selected function: LoaddatasetMenu
function LoaddatasetMenuSelected(app, event)
%This function loads an existing dataset previously created and
%saved by the app. It than adds the information into the
%Uitable. It returns an error if the data cant be loaded, or essential information
%has not been saved into the savefile
app.StatusLamp.Color = 'red';
drawnow();
app.Tab_reload = true; %If true tabs will return to default look
try
[hdfname,pathname] = uigetfile('*.mat','Select .mat data file'); %Ask user to choose a file to load into the app
data_file=strcat(pathname,hdfname);
data = load(data_file,'-mat','pathname', 'savename', 'all_spikes', 'all_clusters'); %loads the file
%Check if file is already loaded
Idx = strfind(app.data_info{:,1}, data.savename);
if Idx == 1
error('File has already been loaded')
end
app.working_path(app.nr_r) = string(data.pathname); %updates the essential information in the app
app.data_info{app.nr_r, 1} = data.savename;
app.data_info{app.nr_r, 2} = data.all_clusters;
app.data_info{app.nr_r, 3} = data.all_spikes;
% app.savenames(app.nr_r) = data.savename;
% app.spike_nr(app.nr_r) = data.all_spikes;
% app.cluster_nr(app.nr_r) = data.all_clusters;
app.UITable.Data = app.data_info;
app.spike_info = load(data_file,'-mat');
if app.nr_r == 1
app.UITable.Enable = 'on'; %Update Table in the GUI (Table is switched off as long as
%no recording is selected
end
%Update number of recordings
app.nr_r = app.nr_r+1;
catch ME %Error handling
message = sprintf('Error loading file \n%s', ME.message);
uiwait(warndlg(message));
end
app.StatusLamp.Color = 'green';
drawnow();
figure(app.UIFigure);
end
% Cell selection callback: UITable
function UITableCellSelection(app, event)
%This is the callback function for selection of a dataset in
%the UItable
%%Update the GUI depending on the user selection in the table
indices = event.Indices;
app.dataselection = indices(1,1);
%update spike info, which contains all information about the
%selected recording
app.spike_info = load(app.data_info{app.dataselection,1},'-mat');
%Items = load(app.data_info{app.dataselection,1},'-mat','stim_list');%Load stim list from the file selected
app.StimuliListBox.Items = app.spike_info.stim_list; %Change stim list in the GUI
app.StimuliListBox.ItemsData = 1:numel(app.spike_info.stim_list); %This gives an index to every stimulus item in the list so that the stimulus can be picked later
%Change the contents of the variables window (depending on
%which file was selected)
listOfVariables = fieldnames(app.spike_info);
app.DataListBox.Items = listOfVariables;
%%Update the stimulus trace figure
%S = load(app.data_info{app.dataselection,1},'-mat','Ch'); %Load the stimulus channel from the mat file
if app.Cuda_status
app.stim_ch = gpuArray(app.spike_info.Ch.Ch01_02);%Load stimulus channel into gpu
xvalue = (0:app.downsample_f:numel(app.stim_ch));%create values for x-axis
app.stim_ch = downsample(app.stim_ch,app.downsample_f);%Trace is downsampled for performance reasons
%sampling_Freq = S.Ch.SamplingFrequency;
else
app.stim_ch = app.spike_info.Ch.Ch01_02;
Ch_length = length(app.stim_ch);
xvalue = (0:app.downsample_f:Ch_length);%create values for x-axis
ds_array = xvalue+1;
if length(ds_array)>Ch_length
ds_array = ds_array(1,1:Ch_length);
end
try
app.stim_ch = app.stim_ch(1,ds_array);
catch ME
ds_array = ds_array(1,1:end-1);
app.stim_ch = app.stim_ch(1,ds_array);
end
end
if size(xvalue,2) > size(app.stim_ch)
difference = size(xvalue,2) - size(app.stim_ch,2);
idx_begin = size(xvalue,2)-difference;
xvalue(:,idx_begin+1:end) = [];
end
plot(app.Stim_Axes,xvalue,app.stim_ch);%Plot the trace to the GUI
%Load figures into Main Tab
try
delete(app.AllspikesPanel.Children);
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
%Try to load figures
try
dummy_figure = openfig([app.spike_info.pathname,'hdf_figure.fig'],'invisible');
dummy_ax = findobj(dummy_figure,'Type','Axes');
app.all_cells_figures.allspikes = copyobj(dummy_ax, app.AllspikesPanel);
delete(dummy_figure)
1
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
try
delete(app.QualitycheckPanel.Children);
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
%Try to load figures
try
dummy_figure = openfig([app.spike_info.pathname,'freq_figure.fig'],'invisible');
dummy_ax = findobj(dummy_figure,'Type','Axes');
app.all_cells_figures.freq = copyobj(dummy_ax, app.QualitycheckPanel);
delete(dummy_figure)
1
catch ME
disp( getReport( ME, 'extended', 'hyperlinks', 'on' ) )
end
%app.dataselection
end
% Value changed function: StimuliListBox
function StimuliListBoxValueChanged(app, event)
%This is the callback function in case one or more stimuli are selected
%in the stimulus listbox
app.add_info.stim_idx = event.Value; %Get the index
app.SelectedstimulusEditField.Value = app.spike_info.stim_list{app.add_info.stim_idx};
app.Tab_reload = true; %Set tabs to default
%Loading the stimulus channel and the stim_begin and stim_end
%times for the selected stimuli
app.selected_stimuli = app.StimuliListBox.Value;
try
S = load(app.data_info{app.dataselection,1},'-mat','Stimulus_info');
app.stimulus_info = S.Stimulus_info(app.selected_stimuli);
clear S
catch ME %Error handling
%message = sprintf('Error loading file \n%s', ME.message);
%uiwait(warndlg(message));
end
s_s = app.selected_stimuli;
nr_select = numel(s_s);
%Update the stim channel figure
sampling_Freq = app.spike_info.Ch.SamplingFrequency;
%Display the stim_begin and stim_end times in the Stim_channel
%figure
try
%This erases existing lines
set(app.xlineob_1,'visible','off')
set(app.xlineob_2,'visible','off')
catch ME
end
%Create new lines
for ii = 1:nr_select
stim_begin = app.spike_info.stim_begin(s_s(ii))*sampling_Freq;
stim_end = app.spike_info.stim_end(s_s(ii))*sampling_Freq;
try
app.xlineob_1(ii) = xline(app.Stim_Axes,stim_begin,'g',{num2str(stim_begin)});
app.xlineob_2(ii) = xline(app.Stim_Axes,stim_end,'r',{num2str(stim_end)});
catch
try
app.xlineob_2(ii) = xline(app.Stim_Axes,stim_end,'r',{num2str(stim_end)});
catch
continue
end
continue
end
end
end
% Button pushed function: ChangeFolderButton
function ChangeFolderButtonPushed(app, event)
%This function sets a new folder for the scripts that can be
%run
app.scriptfolder = uigetdir;
folder_content = dir(app.scriptfolder); %List all contents in the script folder
app.ScriptsListBox.Items = {folder_content(3:end).name}; %Adds the content into the list in the GUI
end
% Button pushed function: RunButton
function RunButtonPushed(app, event)
%This runs the activated script and hands over the respective
%stimulus information
app.StatusLamp.Color = 'red';
app.selected_script = app.ScriptsListBox.Value;
app.selected_script
run_script(app)
app.StatusLamp.Color = 'green';
end
% Value changed function: ScriptsListBox
function ScriptsListBoxValueChanged(app, event)
app.selected_script = string(app.ScriptsListBox.Value); %Save the function name selected as string
end
% Button pushed function: RefreshListButton
function RefreshListButtonPushed(app, event)
folder_content = dir(app.scriptfolder); %List all contents in the script folder
app.ScriptsListBox.Items = {folder_content(3:end).name}; %Adds the content into the list in the GUI
end
% Button pushed function: ShowButton
function ShowButtonPushed(app, event)
%This function shows spatial kernels calculated before
cla(app.Kernel_Axes,'reset')
cla(app.Kernel_Axes_2,'reset')
cla(app.Kernel_Axes_3,'reset')
cla(app.Kernel_Axes_4,'reset')
app.StatusLamp.Color = 'red';
%app.Kernel_info
try
app.add_info.Kernel_info = app.Kernel_info;
app.selected_script = "Get_spatial_kernel_app.m";
run_script(app);
app.Kernel_info.Kernels = app.add_info.out;
%%Plot kernels
app.TimeSlider.Limits = [-app.Kernel_info.Kernels.bins/2 app.Kernel_info.Kernels.bins/2];
%Creates an imshow from the kernel file
imshow(app.Kernel_info.Kernels.uv_kernel_grey(:,:,app.Kernel_info.kernel_time),'parent',app.Kernel_Axes);
colormap(app.Kernel_Axes,Colormap.dense);
% app.Kernel_Axes.Position(3) = 250;
% app.Kernel_Axes.Position(4) = 250;
imshow(app.Kernel_info.Kernels.blue_kernel_grey(:,:,app.Kernel_info.kernel_time),'parent',app.Kernel_Axes_2);
colormap(app.Kernel_Axes_2,flipud(Colormap.ice));
% app.Kernel_Axes_2.Position(3) = 250;
% app.Kernel_Axes_2.Position(4) = 250;
imshow(app.Kernel_info.Kernels.green_kernel_grey(:,:,app.Kernel_info.kernel_time),'parent',app.Kernel_Axes_3);
colormap(app.Kernel_Axes_3,Colormap.algae);
% app.Kernel_Axes_3.Position(3) = 250;
% app.Kernel_Axes_3.Position(4) = 250;
imshow(app.Kernel_info.Kernels.red_kernel_grey(:,:,app.Kernel_info.kernel_time),'parent',app.Kernel_Axes_4);
colormap(app.Kernel_Axes_4,Colormap.amp);
% app.Kernel_Axes_4.Position(3) = 250;
% app.Kernel_Axes_4.Position(4) = 250;
%% Get the limits of the axes
app.k_ax1.xlim = app.Kernel_Axes.XLim;
app.k_ax1.ylim = app.Kernel_Axes.YLim;
app.k_ax2.xlim = app.Kernel_Axes_2.XLim;
app.k_ax2.ylim = app.Kernel_Axes_2.YLim;
app.k_ax3.xlim = app.Kernel_Axes_3.XLim;
app.k_ax3.ylim = app.Kernel_Axes_3.YLim;
app.k_ax4.xlim = app.Kernel_Axes_4.XLim;
app.k_ax4.ylim = app.Kernel_Axes_4.YLim;
catch ME
message = sprintf('Error loading Kernel \n%s', ME.message);
uiwait(warndlg(message));
end
%Check if time kernels shall be plotted
if app.Kernel_info.time_kernels == 1
try
app.add_info.Kernel_info = app.Kernel_info;
app.selected_script = "Plot_time_kernels.m";
run_script(app);
catch ME
message = sprintf('Couldnt plot spatial kernels \n%s', ME.message);
uiwait(warndlg(message));
end
app.Kernel_info.time_kernels = 0;
end
app.StatusLamp.Color = 'green';
end
% Value changed function: UsequalityindexCheckBox
function UsequalityindexCheckBoxValueChanged(app, event)
%This function erases all cells which have no passed the
%kernels quality criteria from the kernel list box
Box_tick = app.UsequalityindexCheckBox.Value;
if Box_tick == 0
app.Tab_reload = true;
Tabfunction(app,"Kernels")
app.ShowtimekernelsCheckBox.Value = 0;
app.ShowtimekernelsCheckBox.Enable = 'off';
else
app.ShowtimekernelsCheckBox.Enable = 'on';