-
Notifications
You must be signed in to change notification settings - Fork 59
/
NeuroScope2.m
7635 lines (6789 loc) · 396 KB
/
NeuroScope2.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
function NeuroScope2(varargin)
% % % % % % % % % % % % % % % % % % % % % % % % %
% NeuroScope2 is a visualizer for electrophysiological recordings. It was inspired by the original Neuroscope (http://neurosuite.sourceforge.net/)
% and made to mimic its features, but built upon Matlab and the data structure of CellExplorer, making it much easier to hack/customize,
% and faster than the original NeuroScope. NeuroScope2 is part of CellExplorer - https://CellExplorer.org/
% Learn more at: https://cellexplorer.org/interface/neuroscope2/
%
% Major features:
% - Multiple plotting styles and colors, electrode groups, channel tags, highlight, filter and hide channels
% - Live trace analysis: filters, spike and event detection, single channel spectrogram, RMS-noise-plot, CSD and spike waveforms
% - Plot multiple data streams together (ephys + analog + digital signals)
% - Plot CellExplorer/Buzcode structures: spikes, cell metrics, events, timeseries, states, behavior, trials
%
% Example calls:
% NeuroScope2
% NeuroScope2('basepath',basepath)
% NeuroScope2('session',session)
%
% By Peter Petersen
% % % % % % % % % % % % % % % % % % % % % % % % %
% Shortcuts to built-in functions
% initUI, initData, initInputs, initTraces,
% ClickPlot, performTestSuite
% plotData, plot_ephys, plotSpikeData, plotSpectrogram, plotTemporalStates, plotEventData, plotTimeseriesData, streamData
% plotAnalog, plotDigital, plotBehavior, plotTrials, plotRMSnoiseInset, plotSpikesPCAspace
% showEvents, showBehavior
% Global variables
UI = []; % Struct with UI elements and settings
UI.t0 = 0; % Timestamp of the start of the current window (in seconds)
data = []; % Contains all external data loaded like data.session, data.spikes, data.events, data.states, data.behavior
ephys = []; % Struct with ephys data for current shown time interval, e.g. ephys.raw (raw unprocessed data), ephys.traces (processed data)
ephys.traces = [];
ephys.sr = [];
UI.selectedUnits = [];
UI.selectedUnitsColors = [];
spikes_raster = []; % Spike raster (used for highlighting, to minimize computations)
epoch_plotElements.t0 = [];
epoch_plotElements.events = [];
raster = [];
sliderMovedManually = false;
deviceWriter = [];
polygon1.handle = gobjects(0);
if isdeployed % Check for if NeuroScope2 is running as a deployed app (compiled .exe or .app for windows and mac respectively)
if ~isempty(varargin) % If a file name is provided it will load it.
[basepath,basename,ext] = fileparts(varargin{1});
if isequal(basepath,0)
UI.priority = ext;
return
end
else % Otherwise a file load dialog will be shown
[file1,basepath] = uigetfile('*.mat;*.dat;*.lfp;*.xml','Please select a file with the basename in it from the basepath');
if ~isequal(file1,0)
temp1 = strsplit(file1,'.');
basename = temp1{1};
UI.priority = temp1{2};
else
return
end
end
else
% Handling inputs if run from Matlab
p = inputParser;
addParameter(p,'basepath',pwd,@ischar);
addParameter(p,'basename',[],@ischar);
addParameter(p,'session',[],@isstruct);
addParameter(p,'spikes',[],@ischar);
addParameter(p,'events',[],@ischar);
addParameter(p,'states',[],@ischar);
addParameter(p,'behavior',[],@ischar);
addParameter(p,'cellinfo',[],@ischar);
addParameter(p,'channeltag',[],@ischar);
addParameter(p,'performTestSuite',false,@islogical);
parse(p,varargin{:})
parameters = p.Results;
basepath = p.Results.basepath;
basename = p.Results.basename;
if isempty(basename)
basename = basenameFromBasepath(basepath);
end
if ~isempty(parameters.session)
basename = parameters.session.general.name;
basepath = parameters.session.general.basePath;
end
end
int_gt_0 = @(n,sr) (isempty(n)) || (n <= 0 ) || (n >= sr/2) || isnan(n);
% % % % % % % % % % % % % % % % % % % % % %
% Initialization
% % % % % % % % % % % % % % % % % % % % % %
initUI
initData(basepath,basename);
initInputs
initTraces
if UI.settings.audioPlay
initAudioDeviceWriter
end
% Maximazing figure to full screen
if ~verLessThan('matlab', '9.4')
set(UI.fig,'WindowState','maximize'), set(UI.fig,'visible','on')
else
warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame')
set(UI.fig,'visible','on')
drawnow nocallbacks; frame_h = get(UI.fig,'JavaFrame'); set(frame_h,'Maximized',1); drawnow nocallbacks;
end
% Perform test suite by input parameter
if exist('parameters','var') && parameters.performTestSuite
UI.settings.allow_dialogs = false;
performTestSuite
UI.t0 = -1;
end
% % % % % % % % % % % % % % % % % % % % % %
% Main while loop of the interface
% % % % % % % % % % % % % % % % % % % % % %
while UI.t0 >= 0
% breaking if figure has been closed
if ~ishandle(UI.fig)
break
else
if ~UI.settings.stickySelection
UI.selectedChannels = [];
UI.selectedChannelsColors = [];
UI.selectedUnits = [];
UI.selectedUnitsColors = [];
end
% Plotting data
plotData;
if UI.t0 == UI.t_total-UI.settings.windowDuration
UI.streamingText = text(UI.plot_axis1,UI.settings.windowDuration/2,1,'End of file','FontWeight', 'Bold','VerticalAlignment', 'top','HorizontalAlignment','center','color',UI.settings.primaryColor,'HitTest','off');
end
% Updating epoch axes
if ishandle(epoch_plotElements.t0)
delete(epoch_plotElements.t0)
end
epoch_plotElements.t0 = line(UI.epochAxes,[UI.t0,UI.t0],[0,1],'color','k', 'HitTest','off','linewidth',1);
% Update UI text and slider
UI.elements.lower.time.String = num2str(UI.t0);
setTimeText(UI.t0)
sliderMovedManually = false;
UI.elements.lower.slider.Value = min([UI.t0/(UI.t_total-UI.settings.windowDuration)*100,100]);
if UI.settings.debug
drawnow
end
UI.elements.lower.performance.String = [' Processing: ' num2str(toc(UI.timerInterface),3) ' seconds (', num2str(numel(ephys.traces)*2/1024/1024,3) ' MB ephys data)'];
uiwait(UI.fig);
% Tracking viewed timestamps in file (the history can be used by pressing the backspace key)
UI.settings.stream = false;
UI.t0 = max([0,min([UI.t0,UI.t_total-UI.settings.windowDuration])]);
if UI.track && UI.t0_track(end) ~= UI.t0
UI.t0_track = [UI.t0_track,UI.t0];
end
UI.track = true;
end
UI.timerInterface = tic;
end
% % % % % % % % % % % % % % % % % % % % % %
% Closing
% % % % % % % % % % % % % % % % % % % % % %
% Closing all file readers
fclose('all');
% Closing main figure if open
if ishandle(UI.fig)
close(UI.fig);
end
% Using google analytics for anonymous tracking of usage
trackGoogleAnalytics('NeuroScope2',1);
% Saving session metadata
if UI.settings.saveMetadata
session = data.session;
session.neuroScope2.t0 = UI.t0;
session.neuroScope2.colors = UI.colors;
for i_setting = 1:length(UI.settings.to_save)
session.neuroScope2.(UI.settings.to_save{i_setting}) = UI.settings.(UI.settings.to_save{i_setting});
end
try
saveStruct(session,'session','commandDisp',false);
catch
warning('Could not save session struct to basepath when closing NeuroScope2')
end
end
% % % % % % % % % % % % % % % % % % % % % %
% Embedded functions
% % % % % % % % % % % % % % % % % % % % % %
function initUI % Initialize the UI (settings, parameters, figure, menu, panels, axis)
% % % % % % % % % % % % % % % % % % % % % %
% System settings
% % % % % % % % % % % % % % % % % % % % % %
UI.forceNewData = true; % Reload raw data on display
UI.timerInterface = tic;
UI.timers.slider = tic;
UI.iLine = 1;
UI.colorLine = lines(256);
UI.freeText = '';
UI.selectedChannels = [];
UI.selectedChannelsColors = [];
UI.legend = {};
UI.settings.saveMetadata = true; % Save metadata on exit
UI.settings.fileRead = 'bof';
UI.settings.channelList = [];
UI.settings.brainRegionsToHide = [];
UI.settings.channelTags.hide = [];
UI.settings.channelTags.filter = [];
UI.settings.channelTags.highlight = [];
UI.settings.normalClick = true;
UI.settings.addEventonClick = 0;
UI.settings.columns = 1;
UI.settings.allow_dialogs = true;
% Spikes settings
UI.settings.showSpikes = false;
UI.settings.showKilosort = false;
UI.settings.showKlusta = false;
UI.settings.showSpykingcircus = false;
UI.settings.reverseSpikeSorting = 'ascend'; % 'ascend' or 'descend'
% Cell metrics
UI.settings.useMetrics = false;
% Event settings
UI.settings.showEvents = false;
UI.settings.eventData = [];
% Timeseries settings
UI.settings.showTimeseries = false;
UI.settings.timeseriesData = [];
% States settings
UI.settings.showStates = false;
UI.settings.statesData = [];
% Behavior settings
UI.settings.showBehavior = false;
UI.settings.behaviorData = [];
% Intan settings
UI.settings.intan_showAnalog = false;
UI.settings.intan_showAux = false;
UI.settings.intan_showDigital = false;
% Cell metrics
UI.params.cellTypes = [];
UI.params.cell_class_count = [];
UI.groupData1.groupsList = {'groups','tags','groundTruthClassification'};
UI.tableData.Column1 = 'putativeCellType';
UI.tableData.Column2 = 'firingRate';
UI.params.subsetTable = [];
UI.params.subsetFilter = [];
UI.params.subsetCellType = [];
UI.params.subsetGroups = [];
UI.params.sortingMetric = 'putativeCellType';
UI.params.groupMetric = 'putativeCellType';
% Audio
preferences.audioPlay = false; % Can be true or false
UI.settings.playAudioFirst = false; % Must be false
UI.settings.deviceWriterActive = false; % Must be false
% % % % % % % % % % % % % % % % % % % % % %
% User preferences/settings
% % % % % % % % % % % % % % % % % % % % % %
UI.settings = preferences_NeuroScope2(UI.settings);
% % % % % % % % % % % % % % % % % % % % % %
% Creating figure
% % % % % % % % % % % % % % % % % % % % % %
UI.fig = figure('Name','NeuroScope2','NumberTitle','off','renderer','opengl','KeyPressFcn', @keyPress,'KeyReleaseFcn',@keyRelease,'DefaultAxesLooseInset',[.01,.01,.01,.01],'visible','off','pos',[0,0,1600,800],'DefaultTextInterpreter', 'none', 'DefaultLegendInterpreter', 'none', 'MenuBar', 'None');
if ~verLessThan('matlab', '9.3')
menuLabel = 'Text';
menuSelectedFcn = 'MenuSelectedFcn';
else
menuLabel = 'Label';
menuSelectedFcn = 'Callback';
end
uix.tracking('off')
% % % % % % % % % % % % % % % % % % % % % %
% Creating menu
% NeuroScope2
UI.menu.cellExplorer.topMenu = uimenu(UI.fig,menuLabel,'NeuroScope2');
uimenu(UI.menu.cellExplorer.topMenu,menuLabel,'About NeuroScope2',menuSelectedFcn,@AboutDialog);
uimenu(UI.menu.cellExplorer.topMenu,menuLabel,'Benchmark NeuroScope2',menuSelectedFcn,@benchmarkStream);
uimenu(UI.menu.cellExplorer.topMenu,menuLabel,'Perform test suite of NeuroScope2',menuSelectedFcn,@performTestSuite);
uimenu(UI.menu.cellExplorer.topMenu,menuLabel,'Quit',menuSelectedFcn,@exitNeuroScope2,'Separator','on','Accelerator','W');
% File
UI.menu.file.topMenu = uimenu(UI.fig,menuLabel,'File');
uimenu(UI.menu.file.topMenu,menuLabel,'Load session from folder',menuSelectedFcn,@loadFromFolder);
uimenu(UI.menu.file.topMenu,menuLabel,'Load session from file',menuSelectedFcn,@loadFromFile,'Accelerator','O');
UI.menu.file.recentSessions.main = uimenu(UI.menu.file.topMenu,menuLabel,'Recent sessions...','Separator','on');
uimenu(UI.menu.file.topMenu,menuLabel,'Export figure data...',menuSelectedFcn,@exportPlotData,'Separator','on');
uimenu(UI.menu.file.topMenu,menuLabel,'Create video...',menuSelectedFcn,@createVideo,'Separator','on');
% Session
UI.menu.session.topMenu = uimenu(UI.fig,menuLabel,'Session');
uimenu(UI.menu.session.topMenu,menuLabel,'View metadata',menuSelectedFcn,@viewSessionMetaData);
uimenu(UI.menu.session.topMenu,menuLabel,'Save metadata',menuSelectedFcn,@saveSessionMetadata);
uimenu(UI.menu.session.topMenu,menuLabel,'Open basepath',menuSelectedFcn,@openSessionDirectory,'Separator','on');
% Cell metrics
UI.menu.cellExplorer.topMenu = uimenu(UI.fig,menuLabel,'Cell metrics');
UI.menu.cellExplorer.defineGroupData = uimenu(UI.menu.cellExplorer.topMenu,menuLabel,'Open group data dialog',menuSelectedFcn,@defineGroupData);
UI.menu.cellExplorer.saveCellMetrics = uimenu(UI.menu.cellExplorer.topMenu,menuLabel,'Save cell_metrics',menuSelectedFcn,@saveCellMetrics);
uimenu(UI.menu.cellExplorer.topMenu,menuLabel,'Open CellExplorer',menuSelectedFcn,@openCellExplorer);
% Settings
UI.menu.display.topMenu = uimenu(UI.fig,menuLabel,'Settings');
UI.menu.display.ShowHideMenu = uimenu(UI.menu.display.topMenu,menuLabel,'Show full menu',menuSelectedFcn,@ShowHideMenu);
UI.menu.display.removeDC = uimenu(UI.menu.display.topMenu,menuLabel,'Remove DC from ephys traces',menuSelectedFcn,@removeDC,'Separator','on');
UI.menu.display.medianFilter = uimenu(UI.menu.display.topMenu,menuLabel,'Apply median filter to ephys traces',menuSelectedFcn,@medianFilter);
UI.menu.display.plotTracesInColumns = uimenu(UI.menu.display.topMenu,menuLabel,'Multiple columns',menuSelectedFcn,@columnTraces,'Separator','on');
UI.menu.display.plotStyleDynamicRange = uimenu(UI.menu.display.topMenu,menuLabel,'Dynamic ephys range plot',menuSelectedFcn,@plotStyleDynamicRange,'Checked','on');
UI.menu.display.narrowPadding = uimenu(UI.menu.display.topMenu,menuLabel,'Narrow ephys padding',menuSelectedFcn,@narrowPadding);
UI.menu.display.resetZoomOnNavigation = uimenu(UI.menu.display.topMenu,menuLabel,'Reset zoom on navigation',menuSelectedFcn,@resetZoomOnNavigation);
UI.menu.display.showScalebar = uimenu(UI.menu.display.topMenu,menuLabel,'Show vertical scale bar',menuSelectedFcn,@showScalebar);
UI.menu.display.showTimeScalebar = uimenu(UI.menu.display.topMenu,menuLabel,'Show time scale bar',menuSelectedFcn,@showTimeScalebar);
UI.menu.display.showChannelNumbers = uimenu(UI.menu.display.topMenu,menuLabel,'Show channel numbers',menuSelectedFcn,@ShowChannelNumbers);
UI.menu.display.stickySelection = uimenu(UI.menu.display.topMenu,menuLabel,'Sticky selection of channels',menuSelectedFcn,@setStickySelection);
UI.menu.display.channelOrder.topMenu = uimenu(UI.menu.display.topMenu,menuLabel,'Channel order','Separator','on');
UI.menu.display.channelOrder.option(1) = uimenu(UI.menu.display.channelOrder.topMenu,menuLabel,'Electrode groups',menuSelectedFcn,@setChannelOrder);
UI.menu.display.channelOrder.option(2) = uimenu(UI.menu.display.channelOrder.topMenu,menuLabel,'Flipped electrode groups',menuSelectedFcn,@setChannelOrder);
UI.menu.display.channelOrder.option(3) = uimenu(UI.menu.display.channelOrder.topMenu,menuLabel,'Ascending channel order',menuSelectedFcn,@setChannelOrder);
UI.menu.display.channelOrder.option(4) = uimenu(UI.menu.display.channelOrder.topMenu,menuLabel,'Descending channel order',menuSelectedFcn,@setChannelOrder);
UI.menu.display.channelOrder.option(UI.settings.channelOrder).Checked = 'on';
UI.menu.display.colorgroups.topMenu = uimenu(UI.menu.display.topMenu,menuLabel,'Color groups');
UI.menu.display.colorgroups.option(1) = uimenu(UI.menu.display.colorgroups.topMenu,menuLabel,'By electrode groups',menuSelectedFcn,@setColorGroups);
UI.menu.display.colorgroups.option(2) = uimenu(UI.menu.display.colorgroups.topMenu,menuLabel,'By channel order',menuSelectedFcn,@setColorGroups);
UI.menu.display.colorgroups.option(3) = uimenu(UI.menu.display.colorgroups.topMenu,menuLabel,'By custom-sized channel groups',menuSelectedFcn,@setColorGroups);
UI.menu.display.colorgroups.option(UI.settings.colorByChannels).Checked = 'on';
UI.menu.display.colormap = uimenu(UI.menu.display.topMenu,menuLabel,'Color maps');
UI.menu.display.changeColormap = uimenu(UI.menu.display.colormap,menuLabel,'Change colormap of ephys traces',menuSelectedFcn,@changeColormap);
UI.menu.display.changeSpikesColormap = uimenu(UI.menu.display.colormap,menuLabel,'Change colormap of spikes',menuSelectedFcn,@changeSpikesColormap);
UI.menu.display.changeBackgroundColor = uimenu(UI.menu.display.colormap,menuLabel,'Change background color & primary color',menuSelectedFcn,@changeBackgroundColor);
UI.menu.display.colormap = uimenu(UI.menu.display.topMenu,menuLabel,'Trace parameters');
UI.menu.display.changeLinewidth = uimenu(UI.menu.display.colormap,menuLabel,'Change linewidth of ephys traces',menuSelectedFcn,@changeLinewidth);
UI.menu.display.detectedSpikes = uimenu(UI.menu.display.topMenu,menuLabel,'Detected spikes','Separator','on');
UI.menu.display.detectedSpikesBelowTrace = uimenu(UI.menu.display.detectedSpikes,menuLabel,'Show below traces',menuSelectedFcn,@detectedSpikesBelowTrace);
UI.menu.display.spikesDetectionPolarity = uimenu(UI.menu.display.detectedSpikes,menuLabel,'Detect both polarities',menuSelectedFcn,@detectedSpikesPolarity);
UI.menu.display.showDetectedSpikesPopulationRate = uimenu(UI.menu.display.detectedSpikes,menuLabel,'Show population rate',menuSelectedFcn,@showDetectedSpikesPopulationRate);
UI.menu.display.showDetectedSpikeWaveforms = uimenu(UI.menu.display.detectedSpikes,menuLabel,'Show waveforms',menuSelectedFcn,@showDetectedSpikeWaveforms);
UI.menu.display.colorDetectedSpikesByWidth = uimenu(UI.menu.display.detectedSpikes,menuLabel,'Color by waveform width',menuSelectedFcn,@toggleColorDetectedSpikesByWidth);
UI.menu.display.showDetectedSpikesPCAspace = uimenu(UI.menu.display.detectedSpikes,menuLabel,'Show PCA space (beta feature)',menuSelectedFcn,@showDetectedSpikesPCAspace);
UI.menu.display.showDetectedSpikesAmplitudeDistribution = uimenu(UI.menu.display.detectedSpikes,menuLabel,'Show spike amplitude distribution',menuSelectedFcn,@showDetectedSpikesAmplitudeDistribution);
UI.menu.display.showDetectedSpikesCountAcrossChannels = uimenu(UI.menu.display.detectedSpikes,menuLabel,'Show count across channels',menuSelectedFcn,@showDetectedSpikesCountAcrossChannels);
UI.menu.display.detectedEvents = uimenu(UI.menu.display.topMenu,menuLabel,'Detected events');
UI.menu.display.detectedEventsBelowTrace = uimenu(UI.menu.display.detectedEvents,menuLabel,'Show below traces',menuSelectedFcn,@detectedEventsBelowTrace);
UI.menu.display.debug = uimenu(UI.menu.display.topMenu,menuLabel,'Debug','Separator','on',menuSelectedFcn,@toggleDebug);
% Analysis
UI.menu.analysis.topMenu = uimenu(UI.fig,menuLabel,'Analysis');
try
initAnalysisToolsMenu
end
UI.menu.analysis.summaryFigure = uimenu(UI.menu.analysis.topMenu,menuLabel,'Summary figure',menuSelectedFcn,@summaryFigure,'Separator','on');
% BuzLabDB
if db_is_active
UI.menu.BuzLabDB.topMenu = uimenu(UI.fig,menuLabel,'BuzLabDB');
uimenu(UI.menu.BuzLabDB.topMenu,menuLabel,'Load session from BuzLabDB',menuSelectedFcn,@DatabaseSessionDialog,'Accelerator','D');
uimenu(UI.menu.BuzLabDB.topMenu,menuLabel,'Edit credentials',menuSelectedFcn,@editDBcredentials,'Separator','on');
uimenu(UI.menu.BuzLabDB.topMenu,menuLabel,'Edit repository paths',menuSelectedFcn,@editDBrepositories);
uimenu(UI.menu.BuzLabDB.topMenu,menuLabel,'View current session on website',menuSelectedFcn,@openSessionInWebDB,'Separator','on');
uimenu(UI.menu.BuzLabDB.topMenu,menuLabel,'View current animal subject on website',menuSelectedFcn,@showAnimalInWebDB);
end
% Help
UI.menu.help.topMenu = uimenu(UI.fig,menuLabel,'Help');
uimenu(UI.menu.help.topMenu,menuLabel,'Mouse and keyboard shortcuts',menuSelectedFcn,@HelpDialog);
uimenu(UI.menu.help.topMenu,menuLabel,'CellExplorer website',menuSelectedFcn,@openWebsite,'Separator','on');
uimenu(UI.menu.help.topMenu,menuLabel,'- About NeuroScope2',menuSelectedFcn,@openWebsite);
uimenu(UI.menu.help.topMenu,menuLabel,'- Tutorial on metadata',menuSelectedFcn,@openWebsite);
uimenu(UI.menu.help.topMenu,menuLabel,'- Documentation on session metadata',menuSelectedFcn,@openWebsite);
uimenu(UI.menu.help.topMenu,menuLabel,'Support',menuSelectedFcn,@openWebsite,'Separator','on');
uimenu(UI.menu.help.topMenu,menuLabel,'- Submit feature request',menuSelectedFcn,@openWebsite);
uimenu(UI.menu.help.topMenu,menuLabel,'- Report an issue',menuSelectedFcn,@openWebsite);
% % % % % % % % % % % % % % % % % % % % % %
% Creating UI/panels
UI.grid_panels = uix.GridFlex( 'Parent', UI.fig, 'Spacing', 5, 'Padding', 0); % Flexib grid box
UI.panel.left = uix.VBoxFlex('Parent',UI.grid_panels,'position',[0 0.66 0.26 0.31]); % Left panel
UI.panel.center = uix.VBox( 'Parent', UI.grid_panels, 'Spacing', 0, 'Padding', 0 ); % Center flex box
% UI.panel.right = uix.VBoxFlex('Parent',UI.grid_panels,'position',[0 0.66 0.26 0.31]); % Right panel
set(UI.grid_panels, 'Widths', [270 -1],'MinimumWidths',[220 1]); % set grid panel size
set(UI.grid_panels, 'Widths', [270 -1],'MinimumWidths',[5 1]); % set grid panel size
% Separation of the center box into three panels: title panel, plot panel and lower info panel
UI.panel.plots = uipanel('position',[0 0 1 1],'BorderType','none','Parent',UI.panel.center,'BackgroundColor','k'); % Main plot panel
UI.panel.info = uix.HBox('Parent',UI.panel.center, 'Padding', 1); % Lower info panel
set(UI.panel.center, 'Heights', [-1 20]); % set center panel size
% Left panel tabs
UI.uitabgroup = uiextras.TabPanel('Parent', UI.panel.left, 'Padding', 1,'FontSize',UI.settings.fontsize ,'TabSize',50);
UI.panel.general.main1 = uix.ScrollingPanel('Parent',UI.uitabgroup, 'Padding', 0 );
UI.panel.general.main = uix.VBox('Parent',UI.panel.general.main1, 'Padding', 1);
UI.panel.spikedata.main1 = uix.ScrollingPanel('Parent',UI.uitabgroup, 'Padding', 0 );
UI.panel.spikedata.main = uix.VBox('Parent',UI.panel.spikedata.main1, 'Padding', 1);
UI.panel.other.main1 = uix.ScrollingPanel('Parent',UI.uitabgroup, 'Padding', 0 );
UI.panel.other.main = uix.VBox('Parent',UI.panel.other.main1, 'Padding', 1);
UI.panel.analysis.main1 = uix.ScrollingPanel('Parent',UI.uitabgroup, 'Padding', 0 );
UI.panel.analysis.main = uix.VBox('Parent',UI.panel.analysis.main1, 'Padding', 1);
UI.uitabgroup.TabNames = {'General', 'Spikes','Other','Analysis'};
% % % % % % % % % % % % % % % % % % % % % %
% 1. PANEL: General elements
% Navigation
UI.panel.general.navigation = uipanel('Parent',UI.panel.general.main,'title','Navigation');
UI.buttons.play1 = uicontrol('Parent',UI.panel.general.navigation,'Style','pushbutton','Units','normalized','Position',[0.01 0.01 0.15 0.98],'String',char(9654),'Callback',@(~,~)streamDataButtons,'KeyPressFcn', @keyPress,'tooltip','Stream from current timepoint');
uicontrol('Parent',UI.panel.general.navigation,'Style','pushbutton','Units','normalized','Position',[0.17 0.01 0.15 0.98],'String',char(8592),'Callback',@(src,evnt)back,'KeyPressFcn', @keyPress,'tooltip','Go back in time');
uicontrol('Parent',UI.panel.general.navigation,'Style','pushbutton','Units','normalized','Position',[0.33 0.5 0.34 0.49],'String',char(8593),'Callback',@(src,evnt)increaseAmplitude,'KeyPressFcn', @keyPress,'tooltip','Increase amplitude of ephys data');
uicontrol('Parent',UI.panel.general.navigation,'Style','pushbutton','Units','normalized','Position',[0.33 0.01 0.34 0.49],'String',char(8595),'Callback',@(src,evnt)decreaseAmplitude,'KeyPressFcn', @keyPress,'tooltip','Decrease amplitude of ephys data');
uicontrol('Parent',UI.panel.general.navigation,'Style','pushbutton','Units','normalized','Position',[0.68 0.01 0.15 0.98],'String',char(8594),'Callback',@(src,evnt)advance,'KeyPressFcn', @keyPress,'tooltip','Forward in time');
UI.buttons.play2 = uicontrol('Parent',UI.panel.general.navigation,'Style','pushbutton','Units','normalized','Position',[0.84 0.01 0.15 0.98],'String',[char(9655) char(9654)],'Callback',@(~,~)streamDataButtons2,'KeyPressFcn', @keyPress,'tooltip','Stream from end of file');
% Electrophysiology
UI.panel.general.filter = uipanel('Parent',UI.panel.general.main,'title','Extracellular traces');
uicontrol('Parent',UI.panel.general.filter,'Style', 'text', 'String', 'Plot style', 'Units','normalized', 'Position', [0.01 0.87 0.3 0.1],'HorizontalAlignment','left','tooltip','Select plot style');
uicontrol('Parent',UI.panel.general.filter,'Style', 'text', 'String', 'Plot colors', 'Units','normalized', 'Position', [0.01 0.74 0.3 0.1],'HorizontalAlignment','left','tooltip','Select plot colors/greyscale');
UI.panel.general.plotStyle = uicontrol('Parent',UI.panel.general.filter,'Style', 'popup','String',{'Downsampled','Range','Raw','LFP (*.lfp file)','Image','No ephys traces'}, 'value', UI.settings.plotStyle, 'Units','normalized', 'Position', [0.3 0.86 0.69 0.12],'Callback',@changePlotStyle,'HorizontalAlignment','left');
UI.panel.general.colorScale = uicontrol('Parent',UI.panel.general.filter,'Style', 'popup','String',{'Colors','Colors 75%','Colors 50%','Colors 25%','Grey-scale','Grey-scale 75%','Grey-scale 50%','Grey-scale 25%'}, 'value', 1, 'Units','normalized', 'Position', [0.3 0.73 0.69 0.12],'Callback',@changeColorScale,'HorizontalAlignment','left');
UI.panel.general.filterToggle = uicontrol('Parent',UI.panel.general.filter,'Style', 'checkbox','String','Filter traces', 'value', 0, 'Units','normalized', 'Position', [0. 0.62 0.5 0.11],'Callback',@changeTraceFilter,'HorizontalAlignment','left','tooltip','Filter ephys traces');
UI.panel.general.extraSpacing = uicontrol('Parent',UI.panel.general.filter,'Style', 'checkbox','String','Group spacing', 'value', 0, 'Units','normalized', 'Position', [0.5 0.62 0.5 0.11],'Callback',@extraSpacing,'HorizontalAlignment','left','tooltip','Spacing between channels from different electrode groups');
if UI.settings.extraSpacing
UI.panel.general.extraSpacing.Value = 1;
end
uicontrol('Parent',UI.panel.general.filter,'Style', 'text', 'String', 'Lower filter (Hz)', 'Units','normalized', 'Position', [0.0 0.52 0.5 0.09],'HorizontalAlignment','center');
uicontrol('Parent',UI.panel.general.filter,'Style', 'text', 'String', 'Higher filter (Hz)', 'Units','normalized', 'Position', [0.5 0.52 0.5 0.09],'HorizontalAlignment','center');
UI.panel.general.lowerBand = uicontrol('Parent',UI.panel.general.filter,'Style', 'Edit', 'String', '400', 'Units','normalized', 'Position', [0.01 0.39 0.48 0.12],'Callback',@changeTraceFilter,'HorizontalAlignment','center','tooltip','Lower frequency boundary (Hz)');
UI.panel.general.higherBand = uicontrol('Parent',UI.panel.general.filter,'Style', 'Edit', 'String', '', 'Units','normalized', 'Position', [0.5 0.39 0.49 0.12],'Callback',@changeTraceFilter,'HorizontalAlignment','center','tooltip','Higher frequency band (Hz)');
UI.panel.general.plotEnergy = uicontrol('Parent',UI.panel.general.filter,'Style', 'checkbox','String','Absolute smoothing (sec)', 'value', 0, 'Units','normalized', 'Position', [0.01 0.26 0.68 0.12],'Callback',@plotEnergy,'HorizontalAlignment','left');
UI.panel.general.energyWindow = uicontrol('Parent',UI.panel.general.filter,'Style', 'Edit', 'String', num2str(UI.settings.energyWindow), 'Units','normalized', 'Position', [0.7 0.26 0.29 0.12],'Callback',@plotEnergy,'HorizontalAlignment','center','tooltip','Smoothing window (seconds)');
UI.panel.general.detectEvents = uicontrol('Parent',UI.panel.general.filter,'Style', 'checkbox','String',['Detect events (',char(181),'V)'], 'value', 0, 'Units','normalized', 'Position', [0.01 0.135 0.68 0.12],'Callback',@toogleDetectEvents,'HorizontalAlignment','left');
UI.panel.general.eventThreshold = uicontrol('Parent',UI.panel.general.filter,'Style', 'Edit', 'String', num2str(UI.settings.eventThreshold), 'Units','normalized', 'Position', [0.7 0.135 0.29 0.12],'Callback',@toogleDetectEvents,'HorizontalAlignment','center','tooltip',['Event detection threshold (',char(181),'V)']);
UI.panel.general.detectSpikes = uicontrol('Parent',UI.panel.general.filter,'Style', 'checkbox','String',['Detect spikes (',char(181),'V)'], 'value', 0, 'Units','normalized', 'Position', [0.01 0.01 0.68 0.12],'Callback',@toogleDetectSpikes,'HorizontalAlignment','left');
UI.panel.general.detectThreshold = uicontrol('Parent',UI.panel.general.filter,'Style', 'Edit', 'String', num2str(UI.settings.spikesDetectionThreshold), 'Units','normalized', 'Position', [0.7 0.01 0.29 0.12],'Callback',@toogleDetectSpikes,'HorizontalAlignment','center','tooltip',['Spike detection threshold (',char(181),'V)']);
% Electrode groups
UI.uitabgroup_channels = uiextras.TabPanel('Parent', UI.panel.general.main, 'Padding', 1,'FontSize',UI.settings.fontsize ,'TabSize',50);
UI.panel.electrodeGroups.main = uix.VBox('Parent',UI.uitabgroup_channels, 'Padding', 1);
UI.panel.chanelList.main = uix.VBox('Parent',UI.uitabgroup_channels, 'Padding', 1);
UI.panel.brainRegions.main = uix.VBox('Parent',UI.uitabgroup_channels, 'Padding', 1);
UI.panel.chanCoords.main = uix.VBox('Parent',UI.uitabgroup_channels, 'Padding', 1);
UI.uitabgroup_channels.TabNames = {'Groups', 'Channels','Regions','Layout'};
UI.table.electrodeGroups = uitable(UI.panel.electrodeGroups.main,'Data',{false,'','','',''},'Units','normalized','Position',[0 0 1 1],'ColumnWidth',{20 20 45 200 80},'columnname',{'','','Group','Channels ','Label'},'RowName',[],'ColumnEditable',[true false false false false],'CellEditCallback',@editElectrodeGroups,'CellSelectionCallback',@ClicktoSelectFromTable);
UI.panel.electrodeGroupsButtons = uipanel('Parent',UI.panel.general.main);
% Channel list
UI.listbox.channelList = uicontrol('Parent',UI.panel.chanelList.main,'Style','listbox','Position',[0 0 1 1],'Units','normalized','String',{'1'},'min',0,'Value',1,'fontweight', 'bold','Callback',@buttonChannelList,'KeyPressFcn', {@keyPress});
% Brain regions
UI.table.brainRegions = uitable(UI.panel.brainRegions.main,'Data',{false,'','',''},'Units','normalized','Position',[0 0 1 1],'ColumnWidth',{20 45 125 45},'columnname',{'','Region','Channels','Groups'},'RowName',[],'ColumnEditable',[true false false false],'CellEditCallback',@editBrainregionList);
% Channel coordinates
UI.chanCoordsAxes = axes('Parent',UI.panel.chanCoords.main,'Units','Normalize','Position',[0 0 1 1],'YLim',[0,1],'YTick',[],'XTick',[]); axis tight
% Group buttons
uicontrol('Parent',UI.panel.electrodeGroupsButtons,'Style','pushbutton','Units','normalized','Position',[0.01 0.01 0.32 0.98],'String','All','Callback',@buttonsElectrodeGroups,'KeyPressFcn', @keyPress,'tooltip','Select all');
uicontrol('Parent',UI.panel.electrodeGroupsButtons,'Style','pushbutton','Units','normalized','Position',[0.34 0.01 0.32 0.98],'String','None','Callback',@buttonsElectrodeGroups,'KeyPressFcn', @keyPress,'tooltip','Deselect all');
uicontrol('Parent',UI.panel.electrodeGroupsButtons,'Style','pushbutton','Units','normalized','Position',[0.67 0.01 0.32 0.98],'String','Edit','Callback',@buttonsElectrodeGroups,'KeyPressFcn', @keyPress,'tooltip','Edit metadata');
% Channel tags
UI.panel.channelTagsList = uipanel('Parent',UI.panel.general.main,'title','Channel tags');
UI.table.channeltags = uitable(UI.panel.channelTagsList,'Data', {'','',false,false,false,'',''},'Units','normalized','Position',[0 0 1 1],'ColumnWidth',{20 60 20 20 20 55 55},'columnname',{'','Tags',char(8226),'+','-','Channels','Groups'},'RowName',[],'ColumnEditable',[false false true true true true false],'CellEditCallback',@editChannelTags,'CellSelectionCallback',@ClicktoSelectFromTable2);
UI.panel.channelTagsButtons = uipanel('Parent',UI.panel.general.main);
uicontrol('Parent',UI.panel.channelTagsButtons,'Style','pushbutton','Units','normalized','Position',[0.01 0.01 0.485 0.98],'String','New tag','Callback',@buttonsChannelTags,'KeyPressFcn', @keyPress,'tooltip','Add channel tag');
uicontrol('Parent',UI.panel.channelTagsButtons,'Style','pushbutton','Units','normalized','Position',[0.505 0.01 0.485 0.98],'String','Delete tag(s)','Callback',@buttonsChannelTags,'KeyPressFcn', @keyPress,'tooltip','Delete channel tag');
% Notes
UI.panel.notes.main = uipanel('Parent',UI.panel.general.main,'title','Session notes');
UI.panel.notes.text = uicontrol('Parent',UI.panel.notes.main,'Style', 'Edit', 'String', '','Units' ,'normalized', 'Position', [0, 0, 1, 1],'HorizontalAlignment','left', 'Min', 0, 'Max', 200,'Callback',@getNotes);
% Epochs
UI.panel.epochs.main = uipanel('Parent',UI.panel.general.main,'title','Session epochs');
UI.epochAxes = axes('Parent',UI.panel.epochs.main,'Units','Normalize','Position',[0 0 1 1],'YLim',[0,1],'YTick',[],'ButtonDownFcn',@ClickEpochs,'XTick',[]); axis tight %,'Color',UI.settings.background,'XColor',UI.settings.primaryColor,'TickLength',[0.005, 0.001],'XMinorTick','on',,'Clipping','off');
% Time series data
UI.panel.timeseriesdata.main = uipanel('Title','Raw time series data','Position',[0 0.2 1 0.1],'Units','normalized','Parent',UI.panel.general.main);
UI.table.timeseriesdata = uitable(UI.panel.timeseriesdata.main,'Data',{false,'','',''},'Units','normalized','Position',[0 0.20 1 0.80],'ColumnWidth',{20 35 125 45},'columnname',{'','Tag','File name','nChan'},'RowName',[],'ColumnEditable',[true false false false],'CellEditCallback',@showIntan);
UI.panel.timeseriesdata.showTimeseriesBelowTrace = uicontrol('Parent',UI.panel.timeseriesdata.main,'Style','checkbox','Units','normalized','Position',[0 0 0.5 0.20], 'value', 0,'String','Below traces','Callback',@showTimeseriesBelowTrace,'KeyPressFcn', @keyPress,'tooltip','Show time series data below traces');
uicontrol('Parent',UI.panel.timeseriesdata.main,'Style','pushbutton','Units','normalized','Position',[0.5 0 0.49 0.19],'String','Metadata','Callback',@editIntanMeta,'KeyPressFcn', @keyPress,'tooltip','Edit session metadata');
% Defining flexible panel heights
set(UI.panel.general.main, 'Heights', [65 210 -210 35 -90 35 100 40 150],'MinimumHeights',[65 210 200 35 140 35 50 30 150]);
UI.panel.general.main1.MinimumWidths = 218;
UI.panel.general.main1.MinimumHeights = 975;
% % % % % % % % % % % % % % % % % % % % % %
% 2. PANEL: Spikes related metrics
% Spikes
UI.panel.spikes.main = uipanel('Parent',UI.panel.spikedata.main,'title','Spikes (*.spikes.cellinfo.mat)');
UI.panel.spikes.showSpikes = uicontrol('Parent',UI.panel.spikes.main,'Style', 'checkbox','String','Show spikes', 'value', 0, 'Units','normalized', 'Position', [0.01 0.85 0.48 0.14],'Callback',@toggleSpikes,'HorizontalAlignment','left','tooltip','Load and show spike rasters');
UI.panel.spikes.showSpikesBelowTrace = uicontrol('Parent',UI.panel.spikes.main,'Style', 'checkbox','String','Below traces', 'value', 0, 'Units','normalized', 'Position', [0.51 0.85 0.75 0.14],'Callback',@showSpikesBelowTrace,'HorizontalAlignment','left','tooltip','Show spike rasters below ephys traces');
uicontrol('Parent',UI.panel.spikes.main,'Style', 'text', 'String', ' Colors: ', 'Units','normalized', 'Position', [0 0.68 0.35 0.16],'HorizontalAlignment','left','tooltip','Define color groups');
UI.panel.spikes.setSpikesGroupColors = uicontrol('Parent',UI.panel.spikes.main,'Style', 'popup', 'String', {'UID','Single color','Electrode groups'}, 'Units','normalized', 'Position', [0.35 0.68 0.64 0.16],'HorizontalAlignment','left','Enable','off','Callback',@setSpikesGroupColors);
uicontrol('Parent',UI.panel.spikes.main,'Style', 'text', 'String', ' Sorting/Ydata: ', 'Units','normalized', 'Position', [0.0 0.51 0.4 0.16],'HorizontalAlignment','left','tooltip','Only applies to rasters shown below ephys traces');
UI.panel.spikes.setSpikesYData = uicontrol('Parent',UI.panel.spikes.main,'Style', 'popup', 'String', {''}, 'Units','normalized', 'Position', [0.35 0.51 0.64 0.16],'HorizontalAlignment','left','Enable','off','Callback',@setSpikesYData);
uicontrol('Parent',UI.panel.spikes.main,'Style', 'text', 'String', 'Width ', 'Units','normalized', 'Position', [0.37 0.34 0.3 0.13],'HorizontalAlignment','right','tooltip','Relative width of the spike waveforms');
UI.panel.spikes.showSpikeWaveforms = uicontrol('Parent',UI.panel.spikes.main,'Style', 'checkbox','String','Waveforms', 'value', 0, 'Units','normalized', 'Position', [0.01 0.34 0.43 0.16],'Callback',@showSpikeWaveforms,'HorizontalAlignment','left','tooltip','Show spike waveforms below ephys traces');
UI.panel.spikes.waveformsRelativeWidth = uicontrol('Parent',UI.panel.spikes.main,'Style', 'Edit', 'String',num2str(UI.settings.waveformsRelativeWidth), 'Units','normalized', 'Position', [0.67 0.34 0.32 0.16],'HorizontalAlignment','center','Callback',@showSpikeWaveforms);
uicontrol('Parent',UI.panel.spikes.main,'Style', 'text', 'String', 'Electrode group ', 'Units','normalized', 'Position', [0.17 0.17 0.5 0.13],'HorizontalAlignment','right','tooltip','Electrode group that the PCA representation is applied to');
UI.panel.spikes.showSpikesPCAspace = uicontrol('Parent',UI.panel.spikes.main,'Style', 'checkbox','String','PCAs', 'value', 0, 'Units','normalized', 'Position', [0.01 0.17 0.23 0.16],'Callback',@showSpikesPCAspace,'HorizontalAlignment','left');
UI.panel.spikes.PCA_electrodeGroup = uicontrol('Parent',UI.panel.spikes.main,'Style', 'Edit', 'String', num2str(UI.settings.PCAspace_electrodeGroup), 'Units','normalized', 'Position', [0.67 0.17 0.32 0.16],'HorizontalAlignment','center','Callback',@showSpikesPCAspace);
UI.panel.spikes.showSpikeMatrix = uicontrol('Parent',UI.panel.spikes.main,'Style', 'checkbox','String','Show matrix', 'value', 0, 'Units','normalized', 'Position', [0.01 0.01 0.45 0.15],'Callback',@showSpikeMatrix,'HorizontalAlignment','left');
%UI.panel.spikes.setSpikesGroupColors = uicontrol('Parent',UI.panel.spikes.main,'Style', 'popup', 'String', {'UID','Single color','Electrode groups'}, 'Units','normalized', 'Position', [0.35 0.60 0.64 0.16],'HorizontalAlignment','left','Enable','off','Callback',@setSpikesGroupColors);
UI.panel.spikes.reverseSpikeSorting = uicontrol('Parent',UI.panel.spikes.main,'Style', 'checkbox','String','Reverse spike sorting', 'value', 0, 'Units','normalized', 'Position', [0.51 0.01 0.50 0.14],'Callback',@reverseSpikeSorting,'HorizontalAlignment','left','tooltip','Reverse sorting of spike rasters below ephys traces');
% Cell metrics
UI.panel.cell_metrics.main = uipanel('Parent',UI.panel.spikedata.main,'title','Cell metrics (*.cell_metrics.cellinfo.mat)');
uicontrol('Parent',UI.panel.cell_metrics.main,'Style', 'text', 'String', ' Color groups', 'Units','normalized','Position', [0 0.74 0.5 0.12],'HorizontalAlignment','left');
uicontrol('Parent',UI.panel.cell_metrics.main,'Style', 'text', 'String', ' Sorting','Units','normalized','Position', [0 0.47 1 0.12],'HorizontalAlignment','left');
uicontrol('Parent',UI.panel.cell_metrics.main,'Style', 'text', 'String', ' Filter', 'Units','normalized','Position', [0 0.17 1 0.12], 'HorizontalAlignment','left');
UI.panel.cell_metrics.useMetrics = uicontrol('Parent',UI.panel.cell_metrics.main,'Style', 'checkbox','String','Use metrics', 'value', 0, 'Units','normalized','Position', [0 0.85 0.5 0.15], 'Callback',@toggleMetrics,'HorizontalAlignment','left');
UI.panel.cell_metrics.defineGroupData = uicontrol('Parent',UI.panel.cell_metrics.main,'Style','pushbutton','Units','normalized','Position',[0.5 0.82 0.49 0.18],'String','Group data','Callback',@defineGroupData,'KeyPressFcn', @keyPress,'tooltip','Filter and highlight by groups','Enable','off');
UI.panel.cell_metrics.groupMetric = uicontrol('Parent',UI.panel.cell_metrics.main,'Style', 'popup', 'String', {''}, 'Units','normalized','Position', [0.01 0.6 0.98 0.15],'HorizontalAlignment','left','Enable','off','Callback',@setGroupMetric);
UI.panel.cell_metrics.sortingMetric = uicontrol('Parent',UI.panel.cell_metrics.main,'Style', 'popup', 'String', {''}, 'Units','normalized','Position', [0.01 0.32 0.98 0.15],'HorizontalAlignment','left','Enable','off','Callback',@setSortingMetric);
UI.panel.cell_metrics.textFilter = uicontrol('Style','edit', 'Units','normalized','Position',[0.01 0.01 0.98 0.17],'String','','HorizontalAlignment','left','Parent',UI.panel.cell_metrics.main,'Callback',@filterCellsByText,'Enable','off','tooltip',sprintf('Search across cell metrics\nString fields: "CA1" or "Interneuro"\nNumeric fields: ".firingRate > 10" or ".cv2 < 0.5" (==,>,<,~=) \nCombine with AND // OR operators (&,|) \nEaxmple: ".firingRate > 10 & CA1"\nFilter by parent brain regions as well, fx: ".brainRegion HIP"\nMake sure to include spaces between fields and operators' ));
UI.panel.cellTypes.main = uipanel('Parent',UI.panel.spikedata.main,'title','Putative cell types');
UI.listbox.cellTypes = uicontrol('Parent',UI.panel.cellTypes.main,'Style','listbox', 'Units','normalized','Position',[0 0 1 1],'String',{''},'Enable','off','max',20,'min',0,'Value',[],'Callback',@setCellTypeSelectSubset,'KeyPressFcn', @keyPress,'tooltip','Filter putative cell types. Select to filter');
% Table with list of cells
UI.panel.cellTable.main = uipanel('Parent',UI.panel.spikedata.main,'title','List of cells');
UI.table.cells = uitable(UI.panel.cellTable.main,'Data', {false,'','',''},'Units','normalized','Position',[0 0 1 1],'ColumnWidth',{20 25 118 55},'columnname',{'','#','Cell type','Rate (Hz)'},'RowName',[],'ColumnEditable',[true false false false],'ColumnFormat',{'logical','char','char','numeric'},'CellEditCallback',@editCellTable,'Enable','off');
UI.panel.metricsButtons = uipanel('Parent',UI.panel.spikedata.main);
uicontrol('Parent',UI.panel.metricsButtons,'Style','pushbutton','Units','normalized','Position',[0.01 0.01 0.32 0.98],'String','All','Callback',@metricsButtons,'KeyPressFcn', @keyPress,'tooltip','Show all cells');
uicontrol('Parent',UI.panel.metricsButtons,'Style','pushbutton','Units','normalized','Position',[0.34 0.01 0.32 0.98],'String','None','Callback',@metricsButtons,'KeyPressFcn', @keyPress,'tooltip','Hide all cells');
uicontrol('Parent',UI.panel.metricsButtons,'Style','pushbutton','Units','normalized','Position',[0.67 0.01 0.32 0.98],'String','Metrics','Callback',@metricsButtons,'KeyPressFcn', @keyPress,'tooltip','Show table with metrics');
% Population analysis
UI.panel.populationAnalysis.main = uipanel('Parent',UI.panel.spikedata.main,'title','Population dynamics');
UI.panel.spikes.populationRate = uicontrol('Parent',UI.panel.populationAnalysis.main,'Style', 'checkbox','String','Show population rate', 'value', 0, 'Units','normalized', 'Position', [0.01 0.68 0.9 0.3],'Callback',@tooglePopulationRate,'HorizontalAlignment','left');
% UI.panel.spikes.populationRateBelowTrace = uicontrol('Parent',UI.panel.populationAnalysis.main,'Style', 'checkbox','String','Below traces', 'value', 0, 'Units','normalized', 'Position', [0.505 0.68 0.485 0.3],'Callback',@tooglePopulationRate,'HorizontalAlignment','left');
uicontrol('Parent',UI.panel.populationAnalysis.main,'Style', 'text','String','Binsize (in sec)', 'Units','normalized', 'Position', [0.01 0.33 0.68 0.25],'Callback',@tooglePopulationRate,'HorizontalAlignment','left');
UI.panel.spikes.populationRateWindow = uicontrol('Parent',UI.panel.populationAnalysis.main,'Style', 'Edit', 'String', num2str(UI.settings.populationRateWindow), 'Units','normalized', 'Position', [0.7 0.32 0.29 0.3],'Callback',@tooglePopulationRate,'HorizontalAlignment','center','tooltip','Binsize (seconds)');
uicontrol('Parent',UI.panel.populationAnalysis.main,'Style', 'text','String','Gaussian smoothing (bins)', 'Units','normalized', 'Position', [0.01 0.01 0.68 0.25],'Callback',@tooglePopulationRate,'HorizontalAlignment','left');
UI.panel.spikes.populationRateSmoothing = uicontrol('Parent',UI.panel.populationAnalysis.main,'Style', 'Edit', 'String', num2str(UI.settings.populationRateSmoothing), 'Units','normalized', 'Position', [0.7 0.01 0.29 0.3],'Callback',@tooglePopulationRate,'HorizontalAlignment','center','tooltip','Binsize (seconds)');
% Spike sorting pipelines
UI.panel.spikesorting.main = uipanel('Title','Other spike sorting formats','Position',[0 0.2 1 0.1],'Units','normalized','Parent',UI.panel.spikedata.main);
UI.panel.spikesorting.showKilosort = uicontrol('Parent',UI.panel.spikesorting.main,'Style','checkbox','Units','normalized','Position',[0.01 0.66 0.485 0.32], 'value', 0,'String','Kilosort','Callback',@showKilosort,'KeyPressFcn', @keyPress,'tooltip','Open a KiloSort rez.mat data and show detected spikes');
UI.panel.spikesorting.kilosortBelowTrace = uicontrol('Parent',UI.panel.spikesorting.main,'Style','checkbox','Units','normalized','Position',[0.505 0.66 0.485 0.32], 'value', 0,'String','Below traces','Callback',@showKilosort,'KeyPressFcn', @keyPress,'tooltip','Show KiloSort spikes below trace');
UI.panel.spikesorting.showKlusta = uicontrol('Parent',UI.panel.spikesorting.main,'Style','checkbox','Units','normalized','Position',[0.01 0.33 0.485 0.32], 'value', 0,'String','Klustakwik','Callback',@showKlusta,'KeyPressFcn', @keyPress,'tooltip','Open Klustakwik clustered data files and show detected spikes');
UI.panel.spikesorting.klustaBelowTrace = uicontrol('Parent',UI.panel.spikesorting.main,'Style','checkbox','Units','normalized','Position',[0.505 0.33 0.485 0.32], 'value', 0,'String','Below traces','Callback',@showKlusta,'KeyPressFcn', @keyPress,'tooltip','Show Klustakwik spikes below trace');
UI.panel.spikesorting.showSpykingcircus = uicontrol('Parent',UI.panel.spikesorting.main,'Style','checkbox','Units','normalized','Position',[0.01 0 0.485 0.32], 'value', 0,'String','Spyking Circus','Callback',@showSpykingcircus,'KeyPressFcn', @keyPress,'tooltip','Open SpyKING CIRCUS clustered data and show detected spikes');
UI.panel.spikesorting.spykingcircusBelowTrace = uicontrol('Parent',UI.panel.spikesorting.main,'Style','checkbox','Units','normalized','Position',[0.505 0 0.485 0.32], 'value', 0,'String','Below traces','Callback',@showSpykingcircus,'KeyPressFcn', @keyPress,'tooltip','Show SpyKING CIRCUS spikes below trace');
% Defining flexible panel heights
set(UI.panel.spikedata.main, 'Heights', [160 170 100 -200 35 100 95],'MinimumHeights',[160 170 60 160 35 60 95]);
UI.panel.spikedata.main1.MinimumWidths = 218;
UI.panel.spikedata.main1.MinimumHeights = 825;
% % % % % % % % % % % % % % % % % % % % % %
% 3. PANEL: Other datatypes
% Events
UI.panel.events.table = uipanel('Parent',UI.panel.other.main,'title','Events (*.events.mat)');
UI.table.events_data = uitable(UI.panel.events.table,'Data', {'','',false,false,false},'Units','normalized','Position',[0 0 1 1],'ColumnWidth',{20 85 42 50 45},'columnname',{'','Name','Show','Active','Below'},'RowName',[],'ColumnEditable',[false false true true true],'CellEditCallback',@setEventData,'CellSelectionCallback',@table_events_click);
UI.panel.events.main = uipanel('Parent',UI.panel.other.main);
UI.panel.events.showEventsIntervals = uicontrol('Parent',UI.panel.events.main,'Style','checkbox','Units','normalized','Position',[0.01 0.8 0.32 0.19], 'value', 0,'String','Intervals','Callback',@showEventsIntervals,'KeyPressFcn', @keyPress,'tooltip','Show events intervals');
UI.panel.events.processing_steps = uicontrol('Parent',UI.panel.events.main,'Style','checkbox','Units','normalized','Position',[0.34 0.8 0.32 0.19], 'value', 0,'String','Processing','Callback',@processing_steps,'KeyPressFcn', @keyPress,'tooltip','Show processing steps');
uicontrol('Parent',UI.panel.events.main,'Style','pushbutton','Units','normalized','Position',[0.665 0.8 0.32 0.20],'String','Save events','Callback',@saveEvent,'KeyPressFcn', @keyPress,'tooltip','Save');
UI.panel.events.eventNumber = uicontrol('Parent',UI.panel.events.main,'Style', 'Edit', 'String', '', 'Units','normalized', 'Position', [0.01 0.6 0.485 0.19],'HorizontalAlignment','center','tooltip','Event number','Callback',@gotoEvents);
UI.panel.events.eventCount = uicontrol('Parent',UI.panel.events.main,'Style', 'Edit', 'String', 'nEvents', 'Units','normalized', 'Position', [0.505 0.6 0.485 0.19],'HorizontalAlignment','center','Enable','off');
uicontrol('Parent',UI.panel.events.main,'Style','pushbutton','Units','normalized','Position',[0.01 0.4 0.32 0.19],'String',char(8592),'Callback',@previousEvent,'KeyPressFcn', @keyPress,'tooltip','Previous event');
uicontrol('Parent',UI.panel.events.main,'Style','pushbutton','Units','normalized','Position',[0.34 0.4 0.32 0.19],'String','Random','Callback',@(src,evnt)randomEvent,'KeyPressFcn', @keyPress,'tooltip','Random event');
uicontrol('Parent',UI.panel.events.main,'Style','pushbutton','Units','normalized','Position',[0.67 0.4 0.32 0.19],'String',char(8594),'Callback',@nextEvent,'KeyPressFcn', @keyPress,'tooltip','Next event');
uicontrol('Parent',UI.panel.events.main,'Style','pushbutton','Units','normalized','Position',[0.01 0.2 0.485 0.19],'String','Flag event','Callback',@flagEvent,'KeyPressFcn', @keyPress,'tooltip','Flag selected event');
UI.panel.events.flagCount = uicontrol('Parent',UI.panel.events.main,'Style', 'Edit', 'String', 'nFlags', 'Units','normalized', 'Position', [0.505 0.2 0.485 0.19],'HorizontalAlignment','center','Enable','off');
uicontrol('Parent',UI.panel.events.main,'Style','pushbutton','Units','normalized','Position',[0.01 0.01 0.32 0.19],'String','+ event','Callback',@addEvent,'KeyPressFcn', @keyPress,'tooltip','Add event. Define single timestamps with cursor. Also allows for removing added timestamps. Saved to .added');
uicontrol('Parent',UI.panel.events.main,'Style','pushbutton','Units','normalized','Position',[0.34 0.01 0.32 0.19],'String','+ interval','Callback',@addInterval,'KeyPressFcn', @keyPress,'tooltip','Add intervals. Define boundaries with mouse cursor. Saved to .added_intervals');
uicontrol('Parent',UI.panel.events.main,'Style','pushbutton','Units','normalized','Position',[0.67 0.01 0.32 0.19],'String','- interval','Callback',@removeInterval,'KeyPressFcn', @keyPress,'tooltip','Remove intervals. Define boundaries with mouse cursor. Affects only manually added intervals. Saved to .added_intervals');
% States
UI.panel.states.main = uipanel('Parent',UI.panel.other.main,'title','States (*.states.mat)');
UI.panel.states.files = uicontrol('Parent',UI.panel.states.main,'Style', 'popup', 'String', {''}, 'Units','normalized', 'Position', [0.01 0.67 0.98 0.31],'HorizontalAlignment','left','Callback',@setStatesData);
UI.panel.states.showStates = uicontrol('Parent',UI.panel.states.main,'Style','checkbox','Units','normalized','Position',[0.01 0.35 1 0.33], 'value', 0,'String','Show states','Callback',@showStates,'KeyPressFcn', @keyPress,'tooltip','Show states data');
UI.panel.states.previousStates = uicontrol('Parent',UI.panel.states.main,'Style','pushbutton','Units','normalized','Position',[0.505 0.35 0.24 0.32],'String',char(8592),'Callback',@previousStates,'KeyPressFcn', @keyPress,'tooltip','Previous state');
UI.panel.states.nextStates = uicontrol('Parent',UI.panel.states.main,'Style','pushbutton','Units','normalized','Position',[0.755 0.35 0.235 0.32],'String',char(8594),'Callback',@nextStates,'KeyPressFcn', @keyPress,'tooltip','Next state');
UI.panel.states.statesNumber = uicontrol('Parent',UI.panel.states.main,'Style', 'Edit', 'String', '', 'Units','normalized', 'Position', [0.01 0.01 0.485 0.32],'HorizontalAlignment','center','tooltip','State number','Callback',@gotoState);
UI.panel.states.statesCount = uicontrol('Parent',UI.panel.states.main,'Style', 'Edit', 'String', 'nStates', 'Units','normalized', 'Position', [0.505 0.01 0.485 0.32],'HorizontalAlignment','center','Enable','off');
% Behavior
UI.panel.behavior.main = uipanel('Parent',UI.panel.other.main,'title','Behavior (*.behavior.mat)');
UI.panel.behavior.files = uicontrol('Parent',UI.panel.behavior.main,'Style', 'popup', 'String', {''}, 'Units','normalized', 'Position', [0.01 0.79 0.98 0.19],'HorizontalAlignment','left','Callback',@setBehaviorData);
UI.panel.behavior.showBehavior = uicontrol('Parent',UI.panel.behavior.main,'Style','checkbox','Units','normalized','Position',[0 0.60 1 0.19], 'value', 0,'String','Show behavior','Callback',@showBehavior,'KeyPressFcn', @keyPress,'tooltip','Show behavior');
UI.panel.behavior.previousBehavior = uicontrol('Parent',UI.panel.behavior.main,'Style','pushbutton','Units','normalized','Position',[0.505 0.60 0.24 0.19],'String',['| ' char(8592)],'Callback',@previousBehavior,'KeyPressFcn', @keyPress,'tooltip','Start of behavior');
UI.panel.behavior.nextBehavior = uicontrol('Parent',UI.panel.behavior.main,'Style','pushbutton','Units','normalized','Position',[0.755 0.60 0.235 0.19],'String',[char(8594) ' |'],'Callback',@nextBehavior,'KeyPressFcn', @keyPress,'tooltip','End of behavior','BusyAction','cancel');
UI.panel.behavior.showBehaviorBelowTrace = uicontrol('Parent',UI.panel.behavior.main,'Style','checkbox','Units','normalized','Position',[0.505 0.41 0.485 0.19], 'value', 0,'String','Below traces','Callback',@showBehaviorBelowTrace,'KeyPressFcn', @keyPress,'tooltip','Show behavior data below traces');
UI.panel.behavior.plotBehaviorLinearized = uicontrol('Parent',UI.panel.behavior.main,'Style','checkbox','Units','normalized','Position',[0.01 0.41 0.485 0.19], 'value', 0,'String','Linearize','Callback',@plotBehaviorLinearized,'KeyPressFcn', @keyPress,'tooltip','Show linearized behavior');
UI.panel.behavior.showTrials = uicontrol('Parent',UI.panel.behavior.main,'Style', 'popup', 'String', {'Show trials'}, 'Units','normalized', 'Position', [0.01 0.22 0.485 0.19],'HorizontalAlignment','left','Callback',@showTrials);
UI.panel.behavior.previousTrial = uicontrol('Parent',UI.panel.behavior.main,'Style','pushbutton','Units','normalized','Position',[0.505 0.22 0.24 0.19],'String',char(8592),'Callback',@previousTrial,'KeyPressFcn', @keyPress,'tooltip','Previous trial');
UI.panel.behavior.nextTrial = uicontrol('Parent',UI.panel.behavior.main,'Style','pushbutton','Units','normalized','Position',[0.755 0.22 0.235 0.19],'String',char(8594),'Callback',@nextTrial,'KeyPressFcn', @keyPress,'tooltip','Next trial');
UI.panel.behavior.trialNumber = uicontrol('Parent',UI.panel.behavior.main,'Style', 'Edit', 'String', '', 'Units','normalized', 'Position', [0.01 0.01 0.485 0.20],'HorizontalAlignment','center','tooltip','Trial number','Callback',@gotoTrial);
UI.panel.behavior.trialCount = uicontrol('Parent',UI.panel.behavior.main,'Style', 'Edit', 'String', 'nTrials', 'Units','normalized', 'Position', [0.505 0.01 0.485 0.20],'HorizontalAlignment','center','Enable','off');
% Time series
UI.panel.timeseries.table = uipanel('Parent',UI.panel.other.main,'title','Time series (*.timeseries.mat)');
UI.table.timeseries_data = uitable(UI.panel.timeseries.table,'ColumnFormat',{'char','char','logical',{'Full trace','Window','Custom'},'char','char'},'Units','normalized','Position',[0 0 1 1],'ColumnWidth',{20 85 42 80 80 100},'columnname',{'','Name','Show','Range','Custom limits','Channels'},'RowName',[],'ColumnEditable',[false false true true true true],'CellEditCallback',@setTimeseriesData,'CellSelectionCallback',@table_timeseries_click);
UI.panel.timeseries.main = uipanel('Parent',UI.panel.other.main);
uicontrol('Parent',UI.panel.timeseries.main,'Style','pushbutton','Units','normalized','Position',[0.01 0.01 0.98 0.98],'String','Plot full timeseries','Callback',@plotTimeSeries,'KeyPressFcn', @keyPress,'tooltip','Show full trace in separate figure');
% Defining flexible panel heights
set(UI.panel.other.main, 'Heights', [-120 150 95 140 -120 40],'MinimumHeights',[120 150 100 150 120 40]);
UI.panel.other.main1.MinimumWidths = 218;
UI.panel.other.main1.MinimumHeights = 760;
% % % % % % % % % % % % % % % % % % % % % %
% 4. PANEL: Analysis
% Spectrogram
UI.panel.spectrogram.main = uipanel('Parent',UI.panel.analysis.main,'title','Spectrogram');
UI.panel.spectrogram.showSpectrogram = uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'checkbox','String','Show spectrogram', 'value', 0, 'Units','normalized', 'Position', [0.01 0.80 0.99 0.19],'Callback',@toggleSpectrogram,'HorizontalAlignment','left');
uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'text','String','Channel', 'Units','normalized', 'Position', [0.01 0.60 0.49 0.17],'HorizontalAlignment','left');
UI.panel.spectrogram.spectrogramChannel = uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'Edit', 'String', num2str(UI.settings.spectrogram.channel), 'Units','normalized', 'Position', [0.505 0.60 0.485 0.19],'Callback',@toggleSpectrogram,'HorizontalAlignment','center');
uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'text','String','Window width (sec)', 'Units','normalized', 'Position', [0.01 0.40 0.49 0.17],'HorizontalAlignment','left');
UI.panel.spectrogram.spectrogramWindow = uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'Edit', 'String', num2str(UI.settings.spectrogram.window), 'Units','normalized', 'Position', [0.505 0.40 0.485 0.19],'Callback',@toggleSpectrogram,'HorizontalAlignment','center');
uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'text','String','Low freq (Hz)', 'Units','normalized', 'Position', [0.01 0.20 0.32 0.14],'HorizontalAlignment','left');
UI.panel.spectrogram.freq_low = uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'Edit', 'String', num2str(UI.settings.spectrogram.freq_low), 'Units','normalized', 'Position', [0.01 0.01 0.32 0.19],'Callback',@toggleSpectrogram,'HorizontalAlignment','center');
uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'text','String','Step size (Hz)', 'Units','normalized', 'Position', [0.34 0.20 0.32 0.14],'HorizontalAlignment','center');
UI.panel.spectrogram.freq_step_size = uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'Edit', 'String', num2str(UI.settings.spectrogram.freq_step_size), 'Units','normalized', 'Position', [0.34 0.01 0.32 0.19],'Callback',@toggleSpectrogram,'HorizontalAlignment','center');
uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'text','String','High freq (Hz)', 'Units','normalized', 'Position', [0.67 0.20 0.32 0.14],'HorizontalAlignment','right');
UI.panel.spectrogram.freq_high = uicontrol('Parent',UI.panel.spectrogram.main,'Style', 'Edit', 'String', num2str(UI.settings.spectrogram.freq_high), 'Units','normalized', 'Position', [0.67 0.01 0.32 0.19],'Callback',@toggleSpectrogram,'HorizontalAlignment','center');
% Current Source Density
UI.panel.csd.main = uipanel('Parent',UI.panel.analysis.main,'title','Current Source Density');
UI.panel.csd.showCSD = uicontrol('Parent',UI.panel.csd.main,'Style', 'checkbox','String','Show Current Source Density', 'value', 0, 'Units','normalized', 'Position', [0.01 0.01 0.98 0.98],'Callback',@show_CSD,'HorizontalAlignment','left');
% plotRMSnoiseInset
UI.panel.RMSnoiseInset.main = uipanel('Parent',UI.panel.analysis.main,'title','RMS noise inset');
UI.panel.RMSnoiseInset.showRMSnoiseInset = uicontrol('Parent',UI.panel.RMSnoiseInset.main,'Style', 'checkbox','String','Show plot inset', 'value', 0, 'Units','normalized', 'Position', [0.01 0.67 0.48 0.30],'Callback',@toggleRMSnoiseInset,'HorizontalAlignment','left');
UI.panel.RMSnoiseInset.filter = uicontrol('Parent',UI.panel.RMSnoiseInset.main,'Style', 'popup','String',{'No filter','Ephys filter','Custom filter'}, 'value', UI.settings.plotRMSnoise_apply_filter, 'Units','normalized', 'Position', [0.50 0.67 0.49 0.30],'Callback',@toggleRMSnoiseInset,'HorizontalAlignment','left');
uicontrol('Parent',UI.panel.RMSnoiseInset.main,'Style', 'text', 'String', 'Lower filter (Hz)', 'Units','normalized', 'Position', [0.0 0.35 0.5 0.26],'HorizontalAlignment','center');
uicontrol('Parent',UI.panel.RMSnoiseInset.main,'Style', 'text', 'String', 'Higher filter (Hz)', 'Units','normalized', 'Position', [0.5 0.35 0.5 0.26],'HorizontalAlignment','center');
UI.panel.RMSnoiseInset.lowerBand = uicontrol('Parent',UI.panel.RMSnoiseInset.main,'Style', 'Edit', 'String', num2str(UI.settings.plotRMSnoise_lowerBand), 'Units','normalized', 'Position', [0.01 0.01 0.48 0.36],'Callback',@toggleRMSnoiseInset,'HorizontalAlignment','center','tooltip','Lower frequency boundary (Hz)');
UI.panel.RMSnoiseInset.higherBand = uicontrol('Parent',UI.panel.RMSnoiseInset.main,'Style', 'Edit', 'String', num2str(UI.settings.plotRMSnoise_higherBand), 'Units','normalized', 'Position', [0.5 0.01 0.49 0.36],'Callback',@toggleRMSnoiseInset,'HorizontalAlignment','center','tooltip','Higher frequency band (Hz)');
% Instantaneous metrics plot
UI.panel.instantaneousMetrics.main = uipanel('Parent',UI.panel.analysis.main,'title','Instantaneous metrics');
UI.panel.instantaneousMetrics.showPower = uicontrol('Parent',UI.panel.instantaneousMetrics.main,'Style', 'checkbox','String','Power', 'value', 0, 'Units','normalized', 'Position', [0.01 0.67 0.32 0.30],'Callback',@toggleInstantaneousMetrics,'HorizontalAlignment','left');
UI.panel.instantaneousMetrics.showPhase = uicontrol('Parent',UI.panel.instantaneousMetrics.main,'Style', 'checkbox','String','Phase', 'value', 0, 'Units','normalized', 'Position', [0.34 0.67 0.32 0.30],'Callback',@toggleInstantaneousMetrics,'HorizontalAlignment','left');
UI.panel.instantaneousMetrics.showSignal = uicontrol('Parent',UI.panel.instantaneousMetrics.main,'Style', 'checkbox','String','Signal', 'value', 0, 'Units','normalized', 'Position', [0.67 0.67 0.32 0.30],'Callback',@toggleInstantaneousMetrics,'HorizontalAlignment','left');
uicontrol('Parent',UI.panel.instantaneousMetrics.main,'Style', 'text', 'String', 'Channel', 'Units','normalized', 'Position', [0.01 0.35 0.32 0.26],'HorizontalAlignment','center');
uicontrol('Parent',UI.panel.instantaneousMetrics.main,'Style', 'text', 'String', 'Low freq (Hz)', 'Units','normalized', 'Position', [0.34 0.35 0.32 0.26],'HorizontalAlignment','center');
uicontrol('Parent',UI.panel.instantaneousMetrics.main,'Style', 'text', 'String', 'High freq (Hz)', 'Units','normalized', 'Position', [0.67 0.35 0.32 0.26],'HorizontalAlignment','center');
UI.panel.instantaneousMetrics.channel = uicontrol('Parent',UI.panel.instantaneousMetrics.main,'Style', 'Edit', 'String', num2str(UI.settings.instantaneousMetrics.channel), 'Units','normalized', 'Position', [0.01 0.01 0.32 0.36],'Callback',@toggleInstantaneousMetrics,'HorizontalAlignment','center','tooltip','Channel');
UI.panel.instantaneousMetrics.lowerBand = uicontrol('Parent',UI.panel.instantaneousMetrics.main,'Style', 'Edit', 'String', num2str(UI.settings.instantaneousMetrics.lowerBand), 'Units','normalized', 'Position', [0.34 0.01 0.32 0.36],'Callback',@toggleInstantaneousMetrics,'HorizontalAlignment','center','tooltip','Lower frequency boundary (Hz)');
UI.panel.instantaneousMetrics.higherBand = uicontrol('Parent',UI.panel.instantaneousMetrics.main,'Style', 'Edit', 'String', num2str(UI.settings.instantaneousMetrics.higherBand), 'Units','normalized', 'Position', [0.67 0.01 0.32 0.36],'Callback',@toggleInstantaneousMetrics,'HorizontalAlignment','center','tooltip','Higher frequency band (Hz)');
% Play audio-trace when streaming ephys
UI.panel.audio.main = uipanel('Parent',UI.panel.analysis.main,'title','Audio playback during streaming');
UI.panel.audio.playAudio = uicontrol('Parent',UI.panel.audio.main,'Style', 'checkbox','String','Play audio', 'value', 0, 'Units','normalized', 'Position', [0.01 0.64 0.48 0.34],'Callback',@togglePlayAudio,'HorizontalAlignment','left');
UI.panel.audio.gain = uicontrol('Parent',UI.panel.audio.main,'Style', 'popup','String',{'Gain: 1','Gain: 2','Gain: 5','Gain: 10','Gain: 20'}, 'value', UI.settings.audioGain, 'Units','normalized', 'Position', [0.5 0.64 0.49 0.34],'Callback',@togglePlayAudio,'HorizontalAlignment','left');
uicontrol('Parent',UI.panel.audio.main,'Style', 'text', 'String', 'Left channel', 'Units','normalized', 'Position', [0.0 0.38 0.5 0.24],'HorizontalAlignment','center');
uicontrol('Parent',UI.panel.audio.main,'Style', 'text', 'String', 'Right channel', 'Units','normalized', 'Position', [0.5 0.38 0.5 0.24],'HorizontalAlignment','center');
UI.panel.audio.leftChannel = uicontrol('Parent',UI.panel.audio.main,'Style', 'Edit', 'String', num2str(UI.settings.audioChannels(1)), 'Units','normalized', 'Position', [0.01 0 0.485 0.36],'HorizontalAlignment','center','tooltip','Left channel','Callback',@togglePlayAudio);
UI.panel.audio.rightChannel = uicontrol('Parent',UI.panel.audio.main,'Style', 'Edit', 'String', num2str(UI.settings.audioChannels(2)), 'Units','normalized', 'Position', [0.505 0 0.485 0.36],'HorizontalAlignment','center','tooltip','Right channel','Callback',@togglePlayAudio);
% Defining flexible panel heights
set(UI.panel.analysis.main, 'Heights', [150 60 100 100 100],'MinimumHeights',[150 60 100 100 100]);
UI.panel.analysis.main1.MinimumWidths = 218;
UI.panel.analysis.main1.MinimumHeights = 510;
% % % % % % % % % % % % % % % % % % % % % %
% Lower info panel elements
UI.elements.lower.timeText = uicontrol('Parent',UI.panel.info,'Style', 'text', 'String', 'Time (s)', 'Units','normalized', 'Position', [0.1 0 0.1 0.8],'HorizontalAlignment','center');
UI.elements.lower.time = uicontrol('Parent',UI.panel.info,'Style', 'Edit', 'String', '', 'Units','normalized', 'Position', [0.15 0 0.05 1],'HorizontalAlignment','right','tooltip','Current timestamp (seconds)','Callback',@setTime);
uicontrol('Parent',UI.panel.info,'Style', 'text', 'String', ' Window duration (s)', 'Units','normalized', 'Position', [0.25 0 0.05 0.8],'HorizontalAlignment','center');
UI.elements.lower.windowsSize = uicontrol('Parent',UI.panel.info,'Style', 'Edit', 'String', UI.settings.windowDuration, 'Units','normalized', 'Position', [0.3 0 0.05 1],'HorizontalAlignment','right','tooltip','Window size (seconds)','Callback',@setWindowsSize);
UI.elements.lower.scalingText = uicontrol('Parent',UI.panel.info,'Style', 'text', 'String', ' Scaling ', 'Units','normalized', 'Position', [0.0 0 0.05 0.8],'HorizontalAlignment','right');
UI.elements.lower.scaling = uicontrol('Parent',UI.panel.info,'Style', 'Edit', 'String', num2str(UI.settings.scalingFactor), 'Units','normalized', 'Position', [0.05 0 0.05 1],'HorizontalAlignment','right','tooltip','Ephys scaling','Callback',@setScaling);
UI.elements.lower.performance = uicontrol('Parent',UI.panel.info,'Style', 'text', 'String', 'Performance', 'Units','normalized', 'Position', [0.25 0 0.05 0.8],'HorizontalAlignment','center','KeyPressFcn', @keyPress);
UI.elements.lower.slider = uicontrol(UI.panel.info,'Style','slider','Units','normalized','Position',[0.5 0 0.5 1],'Value',0, 'SliderStep', [0.0001, 0.1], 'Min', 0, 'Max', 100,'Callback',@moveSlider,'Tag','slider');
addlistener(UI.elements.lower.slider, 'Value', 'PostSet',@movingSlider);
sliderMovedManually = true;
set(UI.panel.info, 'Widths', [130 80 120 60 120 60 280 -1],'MinimumWidths',[130 80 120 60 60 60 250 1]); % set grid panel size
% % % % % % % % % % % % % % % % % % % % % %
% Creating plot axes
UI.plot_axis1 = axes('Parent',UI.panel.plots,'Units','Normalize','Position',[0 0 1 1],'ButtonDownFcn',@ClickPlot,'Color',UI.settings.background,'XColor',UI.settings.primaryColor,'TickLength',[0.005, 0.001],'XMinorTick','on','XLim',[0,UI.settings.windowDuration],'YLim',[0,1],'YTickLabel',[],'Clipping','off');
hold on
UI.plot_axis1.XAxis.MinorTick = 'on';
UI.plot_axis1.XAxis.MinorTickValues = 0:0.01:2;
set(0,'units','pixels');
ce_dragzoom(UI.plot_axis1,'on');
UI.Pix_SS = get(0,'screensize');
UI.Pix_SS = UI.Pix_SS(3)*2;
setScalingText
end
function plotData
% Generates all data plots
UI.t0 = max([0,min([UI.t0,UI.t_total-UI.settings.windowDuration])]);
% Deletes existing plot data
delete(UI.plot_axis1.Children)
set(UI.fig,'CurrentAxes',UI.plot_axis1)
if UI.settings.resetZoomOnNavigation
resetZoom
end
UI.legend = {};
% Ephys traces
if ~UI.settings.playAudioFirst
load_ephys_data
end
plot_ephys
% KiloSort data
if UI.settings.showKilosort
plotKilosortData(UI.t0,UI.t0+UI.settings.windowDuration,'c')
end
% Klusta data
if UI.settings.showKlusta
plotKlustaData(UI.t0,UI.t0+UI.settings.windowDuration,'g')
end
% Spyking circus data
if UI.settings.showSpykingcircus
plotSpykingcircusData(UI.t0,UI.t0+UI.settings.windowDuration,'m')
end
% Spike data
if UI.settings.showSpikes
plotSpikeData(UI.t0,UI.t0+UI.settings.windowDuration,UI.settings.primaryColor,UI.plot_axis1)
end
% Spectrogram
if UI.settings.spectrogram.show && ephys.loaded
plotSpectrogram
end
% Instantaneous metrics
if UI.settings.instantaneousMetrics.show && ephys.loaded
plotInstantaneousMetrics
end
% States data
if UI.settings.showStates
plotTemporalStates(UI.t0,UI.t0+UI.settings.windowDuration)
end
% Event data
if any(UI.settings.showEvents)
if sum(UI.settings.showEvents)>1
addLegend('Events:')
end
for i = 1:numel(UI.settings.showEvents)
if UI.settings.showEvents(i)
eventName = UI.data.detectecFiles.events{i};
if sum(UI.settings.showEvents)>1
if strcmp(UI.settings.eventData,eventName)
addLegend(eventName,UI.settings.primaryColor);
else
addLegend(eventName,UI.colors_events(i,:));
end
end
plotEventData(eventName,UI.t0,UI.t0+UI.settings.windowDuration,UI.colors_events(i,:));
end
end
end
% Time series
if any([UI.table.timeseries_data.Data{:,3}])
if any([UI.table.timeseries_data.Data{:,3}])
addLegend('Timeseries:')
end
for i = 1:length(UI.data.detectecFiles.timeseries)
timeserieName = UI.data.detectecFiles.timeseries{i};
if UI.settings.timeseries.(timeserieName).show
%
% if any([UI.table.timeseries_data.Data{:,3}])
% if strcmp(UI.settings.timeserieData,timeserieName)
% addLegend(timeserieName,UI.settings.primaryColor);
% else
% addLegend(timeserieName,UI.colors_timeseries(i,:));
% end
% end
plotTimeseriesData(timeserieName,UI.t0,UI.t0+UI.settings.windowDuration,UI.colors_timeseries(i,:),2);
end
end
end
% Analog time series
if UI.settings.intan_showAnalog
plotAnalog('adc')
end
% Time series aux (analog)
if UI.settings.intan_showAux
plotAnalog('aux')
end
% Digital time series
if UI.settings.intan_showDigital
plotDigital('dig')
end
% Behavior
if UI.settings.showBehavior
plotBehavior(UI.t0,UI.t0+UI.settings.windowDuration,[0.5 0.5 0.5])
end
% Trials
if UI.settings.showTrials
plotTrials(UI.t0,UI.t0+UI.settings.windowDuration)
end
% Plotting RMS noise inset
if UI.settings.plotRMSnoiseInset && ~isempty(UI.channelOrder)
plotRMSnoiseInset
end
% Showing detected spikes in a spike-waveform-PCA plot inset
if UI.settings.detectSpikes && ~isempty(UI.channelOrder) && UI.settings.showDetectedSpikesPCAspace
plotSpikesPCAspace(raster,UI.settings.primaryColor,true)
end
% Showing amplitude distribution of detected spikes in plot inset
if UI.settings.detectSpikes && ~isempty(UI.channelOrder) && UI.settings.showDetectedSpikesAmplitudeDistribution
plotSpikesAmplitudeDistribution(raster,UI.settings.primaryColor,true)
end
% Showing amplitude distribution of detected spikes in plot inset
if UI.settings.detectSpikes && ~isempty(UI.channelOrder) && UI.settings.showDetectedSpikesCountAcrossChannels
plotSpikesCountAcrossChannels(raster,UI.settings.primaryColor,true)
end
if ~isempty(UI.legend)
text(1/400,0.005,UI.legend,'FontWeight', 'Bold','BackgroundColor',UI.settings.textBackground,'VerticalAlignment', 'bottom','Units','normalized','HorizontalAlignment','left','HitTest','off','Interpreter','tex')
end
end
function text_center(message)
text(UI.plot_axis1,0.5,0.5,message,'Color',UI.settings.primaryColor,'FontSize',14,'Units','normalized','FontWeight', 'Bold','BackgroundColor',UI.settings.textBackground)
end
function addLegend(text_string,clr)
% text_string: text string
% clr: numeric color
if nargin==1 % Considered a legend header
if ischar(UI.settings.primaryColor)
str2rgb=@(x)get(line('color',x),'color');
clr = str2rgb(UI.settings.primaryColor);
else
clr = UI.settings.primaryColor;
end
% Adding empty line above legend header
if ~isempty(UI.legend)
UI.legend = [UI.legend;' '];
end
end
text_string = (['\color[rgb]{',num2strCommaSeparated(clr),'} ',text_string]);
UI.legend = [UI.legend;text_string];
end
function load_ephys_data
% Setting booleans for validating ephys loading and plotting
ephys.loaded = false;
ephys.plotted = false;
if UI.settings.plotStyle == 4 % lfp file
if UI.fid.lfp == -1
UI.settings.stream = false;
ephys.loaded = false;
text_center('Failed to load LFP data')
return
end
ephys.sr = data.session.extracellular.srLfp;
fileID = UI.fid.lfp;
elseif UI.fid.ephys == -1 && UI.settings.plotStyle == 6
UI.settings.stream = false;
ephys.loaded = false;
return
elseif UI.settings.plotStyle == 6
ephys.sr = data.session.extracellular.sr;
fileID = UI.fid.ephys;
else % dat file
if UI.fid.ephys == -1
UI.settings.stream = false;
ephys.loaded = false;
text_center('Failed to load raw data')
return
end
ephys.sr = data.session.extracellular.sr;
fileID = UI.fid.ephys;
end
if strcmp(UI.settings.fileRead,'bof')
% Loading data
if UI.t0>UI.t1 && UI.t0 < UI.t1 + UI.settings.windowDuration && ~UI.forceNewData
t_offset = UI.t0-UI.t1;
newSamples = round(UI.samplesToDisplay*t_offset/UI.settings.windowDuration);
existingSamples = UI.samplesToDisplay-newSamples;
% Keeping existing samples
ephys.raw(1:existingSamples,:) = ephys.raw(newSamples+1:UI.samplesToDisplay,:);
% Loading new samples
fseek(fileID,round((UI.t0+UI.settings.windowDuration-t_offset)*ephys.sr)*data.session.extracellular.nChannels*2,'bof'); % bof: beginning of file
try
ephys.raw(existingSamples+1:UI.samplesToDisplay,:) = double(fread(fileID, [data.session.extracellular.nChannels, newSamples],UI.settings.precision))'*UI.settings.leastSignificantBit;
ephys.loaded = true;
catch
UI.settings.stream = false;
text_center('Failed to read file')
end
elseif UI.t0 < UI.t1 && UI.t0 > UI.t1 - UI.settings.windowDuration && ~UI.forceNewData
t_offset = UI.t1-UI.t0;
newSamples = round(UI.samplesToDisplay*t_offset/UI.settings.windowDuration);
% Keeping existing samples
existingSamples = UI.samplesToDisplay-newSamples;
ephys.raw(newSamples+1:UI.samplesToDisplay,:) = ephys.raw(1:existingSamples,:);
% Loading new data
fseek(fileID,round(UI.t0*ephys.sr)*data.session.extracellular.nChannels*2,'bof');
ephys.raw(1:newSamples,:) = double(fread(fileID, [data.session.extracellular.nChannels, newSamples],UI.settings.precision))'*UI.settings.leastSignificantBit;
ephys.loaded = true;
elseif UI.t0==UI.t1 && ~UI.forceNewData
ephys.loaded = true;
else
fseek(fileID,round(UI.t0*ephys.sr)*data.session.extracellular.nChannels*2,'bof');
ephys.raw = double(fread(fileID, [data.session.extracellular.nChannels, UI.samplesToDisplay],UI.settings.precision))'*UI.settings.leastSignificantBit;
ephys.loaded = true;
end
UI.forceNewData = false;
else
fseek(fileID,ceil(-UI.settings.windowDuration*ephys.sr)*data.session.extracellular.nChannels*2,'eof'); % eof: end of file
ephys.raw = double(fread(fileID, [data.session.extracellular.nChannels, UI.samplesToDisplay],UI.settings.precision))'*UI.settings.leastSignificantBit;
UI.forceNewData = true;
ephys.loaded = true;
end
ephys.nChannels = size(ephys.raw,2);
ephys.nSamples = size(ephys.raw,1);
UI.t1 = UI.t0;
if ~ephys.loaded
return
end
% Removing DC (substraction of the mean of each channel)
if UI.settings.removeDC
ephys.traces = ephys.raw-mean(ephys.raw);
else
ephys.traces = ephys.raw;
end
% Median filter (substraction of the median at each sample across channels)