-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeSeriesAnalysis_MWLab.m
2903 lines (2856 loc) · 184 KB
/
TimeSeriesAnalysis_MWLab.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 hTS = TimeSeriesAnalysis_MWLab(varargin)
%hTS = TimeSeriesAnalysis_MWLab(varargin)
% This program is for viewing and analyzing timeseries data
% hTS is the GUI figure handle, TSdata and plotdata are stored in hTS.UserData
% varargin is for loading TSdata(struct), which must include:
% TSdata.file.type
% TSdata.file.name - filenames (cellstr)
% TSdata.roi - ROIs, array w/roi(#).mask for each roi
tmppath=which('TimeSeriesAnalysis_MWLab');
[guipath,guiname,~]=fileparts(tmppath);
pathparts=strsplit(guipath,filesep);
guiname = [pathparts{end} '/' guiname];
prev = findobj('Tag',guiname);
if ~isempty(prev); close(prev); end
persistent oldpath; if isempty(oldpath); oldpath = ''; end
typestr = getdatatypes; %{'scanimage', 'scanbox', 'prairie', 'neuroplex', 'tif'};
auxstr = ['-Select Auxiliary Signal' getauxtypes']; %{'Aux1(odor)'; 'Aux2(sniff)'; 'AuxCombo(sniff w/odor)'; 'Define Stimulus Manually'}
bDefaultSelectAllOdorTrials = 1;
%load previous settings file
try
load(fullfile(guipath,'TSsettings.mat'),'-mat','TSsettings');
catch
end
if ~exist('TSsettings','var') || isempty(TSsettings.byfileval)
TSsettings.byfileval = 1; TSsettings.byroival = 0; TSsettings.byodorval = 0;
TSsettings.bytrialval = 0; TSsettings.stimselectval = 1;
TSsettings.delaystr = '4'; TSsettings.durstr = '4';
TSsettings.intstr = '16'; TSsettings.trialstr = '24';
TSsettings.hidestimval = 0;
TSsettings.prestr = '4.0'; TSsettings.poststr = '8.0';
TSsettings.supval = 0; TSsettings.avgtrialval = 0; TSsettings.avgfileval = 0;
TSsettings.avgroival = 0; TSsettings.avgodorval = 0; TSsettings.bgroival = 0; TSsettings.bgroistr = '1';
TSsettings.hpfval = 0; TSsettings.hpfstr = '0.01'; TSsettings.lpfval = 0; TSsettings.lpfstr = '0.5';
TSsettings.confval=0; TSsettings.dfval = 0; TSsettings.dffval = 0;
TSsettings.fstartstr = '0'; TSsettings.fstopstr = '4'; TSsettings.showchangeval = 0;
TSsettings.basestartstr = '0'; TSsettings.basedurstr = '4'; TSsettings.respstartstr = '0';
TSsettings.respdurstr = '4'; TSsettings.ylimval = 0; TSsettings.yminstr = '0';
TSsettings.ymaxstr = '1'; TSsettings.tlimval = 0; TSsettings.tminstr = '0'; TSsettings.tmaxstr = '1';
end
if nargin > 0
TSdata = varargin{1};
bloadnow = 1;
else
TSdata.file = []; TSdata.roi = [];
bloadnow = 0;
end
BGC = [255 255 204]/255; %background color
hTS = figure('NumberTitle','off','Name',guiname,'Tag',guiname,'Units', 'Normalized', ...
'Position', [0.01 0.05 0.22 0.85],'DefaultAxesLineWidth', 3, 'DefaultAxesFontSize', 12, ...
'DefaultAxesFontWeight', 'Bold','CloseRequestFcn',@CB_CloseFig);
hmenu = uimenu(hTS,'Text','GUI Settings');
uimenu(hmenu,'Text','Save Settings','Callback',@CBSaveSettings);
uimenu(hmenu,'Text','Load Settings','Callback',@CBLoadSettings);
hTS.UserData.TSdata = TSdata; %update this every time it is changed!
% TabGroup/Plot #1 Tab - controls for each plot
htabgroup = uitabgroup(hTS,'Units','Normalized','Position',[0 .09 1 .91],'SelectionChangedFcn',@CBchangetabs);
uitab(htabgroup,'Title','Plot #1','Tag','1','ForegroundColor','green','BackgroundColor',BGC);
tabsetup(htabgroup.SelectedTab);
uitab(htabgroup,'Title','Add Plot');
% general commands
uicontrol(hTS,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.02 .045 0.3 .04], 'String', 'Add File(s)','FontWeight','Bold', 'Callback', ...
@CBaddFiles);
uicontrol(hTS,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.02 .005 0.3 .04], 'String', 'Clear File(s)','FontWeight','Bold', 'Callback', ...
@CBclearFiles);
uicontrol(hTS,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.35 .045 0.3 .04], 'String', 'Add ROI(s)','FontWeight','Bold', 'Callback', ...
@CBaddROIs);
uicontrol(hTS,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.35 .005 0.3 .04], 'String', 'Clear ROI(s)','FontWeight','Bold', 'Callback', ...
@CBclearROIs);
uicontrol(hTS,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.68 .045 0.3 .04], 'String', 'Load App Data', 'Fontweight', 'Bold', 'Min', 0, 'Max', 1, ...
'Callback', @CBloadTSData,'TooltipString','Load application data (TSdata) from <mydata>.mat file');
uicontrol(hTS,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.68 .005 0.3 .04], 'String', 'Save App Data', 'Fontweight', 'Bold', 'Min', 0, 'Max', 1, ...
'Callback', @CBsaveTSData,'TooltipString',sprintf(['Save application data (TSdata) in .mat file '...
'so that it can be loaded again\n later (e.g. TimeSeriesAnalysis_MWLab(TSdata)']));
function CBchangetabs(~,~)
ntabs = numel(htabgroup.Children);
for tabs = 1:ntabs %turn all tab names black
htabgroup.Children(tabs).ForegroundColor = 'black';
end
if strcmp(htabgroup.SelectedTab.Title,'Add Plot')
htabgroup.SelectedTab.Title = sprintf('Plot #%d',ntabs);
htabgroup.SelectedTab.Tag = num2str(ntabs);
htabgroup.SelectedTab.BackgroundColor = BGC;
htabgroup.SelectedTab.ForegroundColor = 'green';
tabsetup(htabgroup.SelectedTab);
uitab(htabgroup,'Title','Add Plot');
CBSelectAndSortColors;
else
htabgroup.SelectedTab.ForegroundColor = 'green';
tmpfig = findobj('type','figure','Name',sprintf('Plot #%s',htabgroup.SelectedTab.Tag));
if isempty(tmpfig)
tabsetup(htabgroup.SelectedTab); %tcr maybe have a separate figsetup fxn... or drawfig...
else
figure(tmpfig);
end
figure(hTS);
end
end
function tabsetup(tab)
%get previous tab info to copy to new tab - as requested
if str2double(tab.Tag)>1
prevtab = findobj(htabgroup,'Tag',num2str(str2double(tab.Tag)-1));
fileval = get(findobj(prevtab,'Tag','FILE_listbox'),'Value');
roival = get(findobj(prevtab,'Tag','ROI_listbox'),'Value');
odortrialval = get(findobj(prevtab,'Tag','OdorTrial_listbox'),'Value');
byfileval = get(findobj(prevtab,'Tag','byfile'),'Value');
byroival = get(findobj(prevtab,'Tag','byroi'),'Value');
byodorval = get(findobj(prevtab,'Tag','byodor'),'Value');
bytrialval = get(findobj(prevtab,'Tag','bytrial'),'Value');
stimselectval = get(findobj(prevtab,'Tag','stimselect'),'Value');
delaystr = get(findobj(prevtab,'Tag','delay'),'String');
durstr = get(findobj(prevtab,'Tag','duration'),'String');
intstr = get(findobj(prevtab,'Tag','interval'),'String');
trialstr = get(findobj(prevtab,'Tag','trials'),'String');
hidestimval = get(findobj(prevtab,'Tag','hidestim'),'Value');
prestr = get(findobj(prevtab,'Tag','prestim'),'String');
poststr = get(findobj(prevtab,'Tag','poststim'),'String');
supval = get(findobj(prevtab,'Tag','superimpose'),'Value');
avgtrialval = get(findobj(prevtab,'Tag','avgtrials'),'Value');
avgfileval = get(findobj(prevtab,'Tag','avgfiles'),'Value');
avgroival = get(findobj(prevtab,'Tag','avgrois'),'Value');
avgodorval = get(findobj(prevtab,'Tag','avgodors'),'Value');
bgroival = get(findobj(prevtab,'Tag','subtractbgroi'),'Value');
bgroistr = get(findobj(prevtab,'Tag','bgroi'),'String');
hpfval = get(findobj(prevtab,'Tag','hpfilter'),'Value');
hpfstr = get(findobj(prevtab,'Tag','hpfilterparm'),'String');
lpfval = get(findobj(prevtab,'Tag','lpfilter'),'Value');
lpfstr = get(findobj(prevtab,'Tag','lpfilterparm'),'String');
confval = get(findobj(prevtab,'Tag','confint'),'Value');
dfval = get(findobj(prevtab,'Tag','deltaf'),'Value');
dffval = get(findobj(prevtab,'Tag','deltafoverf'),'Value');
fstartstr = get(findobj(prevtab,'Tag','fstart'),'String');
fstopstr = get(findobj(prevtab,'Tag','fstop'),'String');
showchangeval = get(findobj(prevtab,'Tag','showchange'),'Value');
basestartstr = get(findobj(prevtab,'Tag','basestart'),'String');
basedurstr = get(findobj(prevtab,'Tag','basedur'),'String');
respstartstr = get(findobj(prevtab,'Tag','respstart'),'String');
respdurstr = get(findobj(prevtab,'Tag','respdur'),'String');
ylimval = get(findobj(prevtab,'Tag','Ylims'),'Value');
yminstr = get(findobj(prevtab,'Tag','Ymin'),'String');
ymaxstr = get(findobj(prevtab,'Tag','Ymax'),'String');
tlimval = get(findobj(prevtab,'Tag','Tlims'),'Value');
tminstr = get(findobj(prevtab,'Tag','Tmin'),'String');
tmaxstr = get(findobj(prevtab,'Tag','Tmax'),'String');
else
fileval = 1; roival = 1; odortrialval = 1;
byfileval = TSsettings.byfileval; byroival = TSsettings.byroival;
byodorval = TSsettings.byodorval; bytrialval = TSsettings.bytrialval;
stimselectval = TSsettings.stimselectval;
delaystr = TSsettings.delaystr; durstr = TSsettings.durstr;
intstr = TSsettings.intstr; trialstr = TSsettings.trialstr;
hidestimval = TSsettings.hidestimval;
prestr = TSsettings.prestr; poststr=TSsettings.poststr;
supval = TSsettings.supval; avgtrialval = TSsettings.avgtrialval;
avgfileval = TSsettings.avgfileval; avgroival = TSsettings.avgroival;
avgodorval = TSsettings.avgodorval;
bgroival = TSsettings.bgroival; bgroistr = TSsettings.bgroistr;
hpfval = TSsettings.hpfval; hpfstr = TSsettings.hpfstr;
lpfval = TSsettings.lpfval; lpfstr = TSsettings.lpfstr;
confval=TSsettings.confval; dfval = TSsettings.dfval;
dffval = TSsettings.dffval; fstartstr = TSsettings.fstartstr;
fstopstr = TSsettings.fstopstr; showchangeval = TSsettings.showchangeval;
basestartstr = TSsettings.basestartstr; basedurstr = TSsettings.basedurstr;
respstartstr = TSsettings.respstartstr; respdurstr = TSsettings.respdurstr;
ylimval = TSsettings.ylimval; yminstr = TSsettings.yminstr; ymaxstr = TSsettings.ymaxstr;
tlimval = TSsettings.tlimval; tminstr = TSsettings.tminstr; tmaxstr = TSsettings.tminstr;
end
% Files/ROIs
uicontrol(tab,'Style', 'text', 'Units', 'normalized', 'Position', [.02 .95 0.24 .04],...
'BackgroundColor',BGC, 'String', 'Select File(s)','FontWeight','Bold');
filenamestr=cell(length(TSdata.file));
if ~isempty(TSdata.file)
for f = 1:length(TSdata.file); filenamestr{f}=TSdata.file(f).name; end
else; filenamestr{1} = '';
end
uicontrol(tab,'Style', 'listbox','Tag','FILE_listbox','Units', 'normalized', 'Position', ...
[0.01 0.605 0.48 0.36], 'String', filenamestr, 'Value', fileval, 'BackgroundColor', [1 1 1], ...
'Max', 100, 'Min', 0, 'Callback', @CBSelectAndSortColors);
% if ~isempty(prevtab); set(get(findobj(tab,'Tag','FILE_listbox'),'Value', get(findobj(prevtab,'Tag','FILE_listbox'),'Value'))); end
uicontrol(tab,'Style', 'text', 'Units', 'normalized', 'Position', [.485 .94 0.24 .05],...
'BackgroundColor',BGC,'String', 'Select ROI(s)','FontWeight','Bold');
uicontrol(tab,'Style', 'listbox','Tag','ROI_listbox','Units', 'normalized', 'Position', ...
[0.51 0.605 0.24 0.36], 'String', '', 'Value', roival, 'BackgroundColor', [1 1 1], ...
'Max', 100, 'Min', 0, 'Callback', @CBSelectAndSortColors);
uicontrol(tab,'Style', 'text', 'Units', 'normalized', 'Position', [.75 .94 0.25 .05],...
'BackgroundColor',BGC,'String', 'Odor(s),Trial(s)','FontWeight','Bold');
uicontrol(tab,'Style', 'listbox','Tag','OdorTrial_listbox','Units', 'normalized', 'Position', ...
[0.76 0.605 0.24 0.36], 'String', '', 'Value', odortrialval, 'BackgroundColor', [1 1 1], ...
'Max', 10000, 'Min', 0, 'Callback', @CBSelectAndSortColors);
if isfield(TSdata,'roi')
roistr = cell(numel(TSdata.roi),1);
for i = 1:numel(TSdata.roi)
tmpcl = myColors(i).*255;
roistr{i} = ['<HTML><FONT color=rgb(' num2str(tmpcl(1)) ',' num2str(tmpcl(2)) ',' ...
num2str(tmpcl(3)) ')>' ['ROI # ' num2str(i)] '</Font></html>'];
end
set(findobj(tab,'Tag','ROI_listbox'), 'String', roistr);
else
set(findobj(tab,'Tag','ROI_listbox'), 'String','');
end
% Group plot line colors by ROI or by File (default set to group by ROI, value = 1)
bg=uibuttongroup(tab,'Tag','sortColors','Position',[0.0 0.565 1 0.04],'SelectionChangedFcn',@CBSelectAndSortColors);
uicontrol(bg,'Style', 'radiobutton', 'Units', 'normalized', 'Position', ...
[0.01 0.01 0.4 0.98], 'String', 'Sort Colors by File', 'Fontweight', 'Bold', ...
'Min', 0, 'Max', 1, 'Value', byfileval, 'Tag','byfile');
uicontrol(bg,'Style', 'radiobutton', 'Units', 'normalized', 'Position', ...
[0.4 0.01 0.2 0.98], 'String', 'by ROI', 'Fontweight', 'Bold', ...
'Min', 0, 'Max', 1, 'Value', byroival, 'Tag','byroi');
uicontrol(bg,'Style', 'radiobutton', 'Units', 'normalized', 'Position', ...
[0.6 0.01 0.2 0.98], 'String', 'by Odor', 'Fontweight', 'Bold', ...
'Min', 0, 'Max', 1, 'Value', byodorval, 'Tag','byodor');
uicontrol(bg,'Style', 'radiobutton', 'Units', 'normalized', 'Position', ...
[0.8 0.01 0.2 0.98], 'String', 'by Trial', 'Fontweight', 'Bold', ...
'Min', 0, 'Max', 1, 'Value', bytrialval, 'Tag','bytrial'); %bg.SelectedObject = bg.Children(2); %default to sort by ROI
set(bg.Children,'Enable','off');
if numel(TSdata.file) == 1
set(findobj(tab,'Tag','sortColors_button'),'Enable','off');
end
%Aux/Defined Stimulus
stimpanel = uipanel(tab,'Units','Normalized','Position', [0.0 0.35 1.0 0.22]);
% stimstr = {'-Select Auxiliary Signal-';'Aux1(odor)';'Aux2(sniff)';'AuxCombo';'Manually Defined Stimulus'};
uicontrol(stimpanel,'Tag','stimselect','Style','popupmenu','Units','normalized','Position',...
[0.05 0.85 0.55 0.12],'String',auxstr, 'Value',stimselectval, 'Callback', @CBSelectStimulus);
uicontrol(stimpanel,'Tag','delay','Style', 'edit', 'String', delaystr,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.05 0.75 .08 0.1],'HorizontalAlignment','Right', ...
'Callback', @CBdefineStimulus, 'Visible', 'off');
uicontrol(stimpanel,'Tag','delaystr', 'Style', 'text', 'String', 'Initial Delay(sec)','Units','normalized' ...
,'Position',[0.15 0.74 .35 0.1],'HorizontalAlignment','Left', 'Visible', 'off');
uicontrol(stimpanel,'Tag','duration','Style', 'edit', 'String', durstr,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.05 0.65 .08 0.1],'HorizontalAlignment','Right', ...
'Callback', @CBdefineStimulus, 'Visible', 'off');
uicontrol(stimpanel,'Tag','durationstr','Style', 'text', 'String', 'Duration(sec)','Units','normalized' ...
,'Position',[0.15 0.64 .35 0.1],'HorizontalAlignment','Left', 'Visible', 'off');
uicontrol(stimpanel,'Tag','interval','Style', 'edit', 'String', intstr,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.05 0.55 .08 0.1],'HorizontalAlignment','Right', ...
'Callback', @CBdefineStimulus, 'Visible', 'off');
uicontrol(stimpanel,'Tag','intervalstr','Style', 'text', 'String', 'Interval(sec)','Units','normalized' ...
,'Position',[0.15 0.54 .35 0.1],'HorizontalAlignment','Left', 'Visible', 'off');
uicontrol(stimpanel,'Tag','trials','Style', 'edit', 'String', trialstr,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.05 0.45 .08 0.1],'HorizontalAlignment','Right', ...
'Callback', @CBdefineStimulus, 'Visible', 'off');
uicontrol(stimpanel,'Tag','trialsstr','Style', 'text', 'String', '# Trials','Units','normalized' ...
,'Position',[0.15 0.44 .35 0.1],'HorizontalAlignment','Left', 'Visible', 'off');
uicontrol(stimpanel,'Tag','hidestim','Style', 'checkbox', 'Units', 'normalized', 'Position', ...
[0.65 0.85 .35 0.12], 'String', 'Hide stimuli', 'Fontweight', 'Bold', 'Value', hidestimval, ...
'Fontsize',10,'Callback', @CBSelectAndSortColors,'Enable','off')
ephysstr = {'-ephys signals-','odor','sniff','puff'};
uicontrol(stimpanel,'Tag','ephys','Style','listbox','Units','normalized','Position', ...
[0.65 0.45 .35 .4],'String',ephysstr,'Max',8,'Visible','off');
uicontrol(stimpanel,'style','text','Units','normalized','Position',[0.05 0.33 .9 0.1],...
'String','-------------------------------------------------------------------------','HorizontalAlignment','center');
% Show/Average Trials
uicontrol(stimpanel,'Style', 'text', 'String', 'Pre-Stimulus','Units','normalized' ...
,'Position',[0.04 0.20 .18 0.1],'HorizontalAlignment','Left');
uicontrol(stimpanel,'Tag','prestim','Style', 'edit', 'String', prestr,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.22 0.21 .11 0.1],'HorizontalAlignment','Right', ...
'Callback', @CBSelectAndSortColors);
uicontrol(stimpanel,'Style', 'text', 'String', '(sec)','Units','normalized' ...
,'Position',[0.34 0.20 .4 0.1],'HorizontalAlignment','Left');
uicontrol(stimpanel,'Style', 'text', 'String', 'Post-Stimulus','Units','normalized' ...
,'Position',[0.50 0.20 .2 0.1],'HorizontalAlignment','Left');
uicontrol(stimpanel,'Tag','poststim','Style', 'edit', 'String', poststr,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.71 0.21 .11 0.1],'HorizontalAlignment','Right', ...
'Callback', @CBSelectAndSortColors);
uicontrol(stimpanel,'Style', 'text', 'String', '(sec)','Units','normalized' ...
,'Position',[0.83 0.2 .4 0.1],'HorizontalAlignment','Left');
uicontrol(stimpanel,'Tag','superimpose','Style', 'checkbox', 'Units', 'normalized', 'Position', ...
[0.05 0.05 .4 0.1], 'String', 'Superimpose Trials', 'Fontweight', 'Bold', 'Value', supval, ...
'FontSize',10,'Callback', @CBSupOrAvgTrials,'Enable','off');
uicontrol(stimpanel,'Tag','avgtrials','Style', 'checkbox', 'Units', 'normalized', 'Position', ...
[0.5 0.05 .5 0.1], 'String', 'Average Trials (by Odor)', 'Fontweight', 'Bold', 'Value', avgtrialval, ...
'FontSize',10,'Callback', @CBSupOrAvgTrials,'Enable','off');
% Average Files/ROIs/Odors
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.02 0.32 0.3 0.03], ...
'String', 'Average Files', 'Fontweight', 'Bold', 'BackgroundColor', BGC, 'Value', avgfileval, ...
'Enable','off','Tag','avgfiles','Callback',@CBSelectAndSortColors);
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.35 0.32 0.3 0.03], ...
'String', 'Average ROIs', 'Fontweight', 'Bold', 'BackgroundColor', BGC, 'Value', avgroival, ...
'Enable','off','Tag','avgrois','Callback',@CBSelectAndSortColors,...
'TooltipString',sprintf(['"Average ROIs" is done using a weighted average of time series data\n'...
'with weights based on the number of pixels in each ROI mask\n']));
%average rois ***note: to average/combine roimasks, do weighted average based on mask sizes
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.67 0.32 0.33 0.03], ...
'String', 'Average Odors', 'Fontweight', 'Bold', 'BackgroundColor', BGC, 'Value', avgodorval, ...
'Enable','off','Tag','avgodors','Callback',@CBSelectAndSortColors);
%subtract background roi
uicontrol(tab,'Tag','subtractbgroi','Style', 'checkbox', 'Units', 'normalized', 'Position', ...
[0.02 0.285 0.42 0.03], 'String', 'Subtract Background ROI #:', 'Value', bgroival, ...
'BackgroundColor',BGC,'Callback', @CBSelectAndSortColors);
uicontrol(tab,'Tag','bgroi','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.43 0.29 0.08 0.025], 'String', bgroistr, 'Fontweight', 'Bold', 'Callback', ...
@CBSelectAndSortColors);
% Filter Buttons
uicontrol(tab,'Tag','hpfilter','Style', 'checkbox', 'Units', 'normalized', 'Position', ...
[0.02 0.255 0.25 0.03], 'String', 'High Pass Filter', 'Value', hpfval, ...
'BackgroundColor',BGC,'Callback', @CBSelectAndSortColors);
uicontrol(tab,'Tag','hpfilterparm','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.27 0.26 0.10 0.025], 'String', hpfstr, 'Fontweight', 'Bold', 'Callback', ...
@CBSelectAndSortColors);
uicontrol(tab,'Style', 'text', 'String', 'Hz' , 'Units', 'Normalized' ...
,'BackgroundColor',BGC,'Position', [0.38 0.25 0.05 0.03],'HorizontalAlignment','Left');
uicontrol(tab,'Tag','lpfilter','Style', 'checkbox', 'Units', 'normalized', 'Position', ...
[0.02 0.23 0.25 0.03], 'String', 'Low Pass Filter', 'Value', lpfval, ...
'BackgroundColor',BGC,'Callback', @CBSelectAndSortColors);
uicontrol(tab,'Tag','lpfilterparm','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.27 0.235 0.10 0.025], 'String', lpfstr, 'Fontweight', 'Bold', 'Callback', ...
@CBSelectAndSortColors);
uicontrol(tab,'Style', 'text', 'String', 'Hz' , 'Units', 'Normalized' ...
,'BackgroundColor',BGC,'Position', [0.38 0.225 0.25 0.03],'HorizontalAlignment','Left');
uicontrol(tab,'Tag','confint','Style', 'checkbox', 'Units', 'normalized', 'Position', ...
[0.02 0.205 0.54 0.03], 'String', 'Show 95% Confidence Intervals', 'Value', confval, ...
'BackgroundColor',BGC,'Callback', @CBSelectAndSortColors);
% % % Deconvolve
% % uicontrol(tab,'Tag','deconv','Style', 'checkbox', 'Value', 0,'Units','normalized', ...
% % 'Position',[0.02 0.175 0.24 0.03],'HorizontalAlignment','Left', 'BackgroundColor',BGC,...
% % 'String', 'Deconvolution:', 'Callback', @CBSelectAndSortColors);
% % uicontrol(tab,'Style', 'text', 'String', 'Rise (sec)' , 'Units', 'Normalized' ...
% % ,'Position',[0.26 0.177 0.16 0.02],'BackgroundColor',BGC,'HorizontalAlignment','Right');
% % uicontrol(tab,'Tag','tauRise','Style', 'edit', 'Units', 'normalized', 'Position', ...
% % [0.43 0.175 0.1 0.025], 'String', '0.2', 'Fontweight', 'Bold', 'Callback', @CBSelectAndSortColors);
% % uicontrol(tab,'Style', 'text', 'String', 'Decay(sec)' , 'Units', 'Normalized' ...
% % ,'Position',[0.25 0.152 0.17 0.02],'BackgroundColor',BGC,'HorizontalAlignment','Right');
% % uicontrol(tab,'Tag','tauDecay','Style', 'edit', 'Units', 'normalized', 'Position', ...
% % [0.43 0.15 0.1 0.025], 'String', '0.5', 'Fontweight', 'Bold','Callback', @CBSelectAndSortColors);
% Delta F
deltafgroup = uibuttongroup(tab,'Tag','deltafgroup','Position',[0.53 0.21 0.47 0.11]);
uicontrol(deltafgroup,'Tag','deltaf','Style', 'checkbox', 'Value', dfval,'Units','normalized' ...
,'Position',[0.1 .75 1 .25],'HorizontalAlignment','Left', ...
'String', '<html><b>Delta F</b> (F-F<sub>0</sub>)</html>', 'FontSize', 10, 'Callback', @CBdeltaF);
uicontrol(deltafgroup,'Tag','deltafoverf','Style', 'checkbox', 'Value', dffval,'Units','normalized' ...
,'Position',[0.1 .5 1 .25],'HorizontalAlignment','Left', ...
'String', '<html><b>Percent Delta F/F<sub>0</sub></b></html>','FontSize', 10, 'Callback', @CBdeltaF);
uicontrol(deltafgroup,'Style','text','Units','normalized','Position',...
[0 .3 1 .2],'String','F0 time window (sec):','FontSize', 9);
uicontrol(deltafgroup,'Tag','fstart','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.1 0.05 .3 .25], 'String', fstartstr, 'Fontweight', 'Bold', 'Callback', ...
@CBSelectAndSortColors);
uicontrol(deltafgroup,'Style', 'text', 'String', 'to' , 'Units', 'Normalized' ...
,'Position',[0.45 0.051 .1 .2],'FontSize', 9);
uicontrol(deltafgroup,'Tag','fstop','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.58 0.05 .3 .25], 'String', fstopstr, 'Fontweight', 'Bold', 'Callback', ...
@CBSelectAndSortColors);
% Show Mean Change vs Baseline
uicontrol(tab, 'Tag', 'showchange','Style', 'checkbox', 'Units', 'normalized', 'Position', ...
[0.02 0.18 0.9 0.03], 'String', 'Show Mean Change vs Baseline - edit start/duration (sec) -or- use slider',...
'Value', showchangeval, 'BackgroundColor',BGC, 'Callback', @CBSelectAndSortColors);
uicontrol(tab, 'Style', 'text', 'Units', 'normalized', 'Position', [0.01 0.147 0.15 0.025],...
'BackgroundColor',BGC,'String','Baseline:','HorizontalAlignment','right');
uicontrol(tab, 'Tag', 'basestart', 'Style', 'edit', 'Units', 'normalized', 'Position',...
[0.16 0.15 0.09 0.025],'String',basestartstr, 'Callback', @CBEditBaseline);
uicontrol(tab, 'Tag', 'baseslider', 'Style', 'Slider', 'Units', 'normalized', 'Position', ...
[0.25 0.15 0.5 0.025],'Max',1000, 'Callback', @CBAdjustSlider);
uicontrol(tab, 'Style', 'text', 'Units', 'normalized', 'Position', [0.76 0.147 0.14 0.025],...
'BackgroundColor',BGC,'String','Duration:');
uicontrol(tab, 'Tag', 'basedur', 'Style', 'edit', 'Units', 'normalized', 'Position',...
[0.89 0.15 0.09 0.025],'String',basedurstr,'Callback', @CBSelectAndSortColors);
uicontrol(tab, 'Style', 'text', 'HorizontalAlignment', 'right', 'Units', 'normalized', 'Position', [0.01 0.112 0.15 0.025],...
'BackgroundColor',BGC,'String','Response:');
uicontrol(tab, 'Tag', 'respstart', 'Style', 'edit', 'Units', 'normalized', 'Position',...
[0.16 0.115 0.09 0.025],'String',respstartstr,'Callback', @CBEditBaseline);
uicontrol(tab, 'Tag', 'changeslider', 'Style', 'Slider', 'Units', 'normalized', 'Position', ...
[0.25 0.115 0.5 0.025],'Max',1000, 'Callback', @CBAdjustSlider);
uicontrol(tab, 'Style', 'text', 'Units', 'normalized', 'Position', [0.76 0.112 0.14 0.025],...
'BackgroundColor',BGC,'String','Duration:');
uicontrol(tab, 'Tag', 'respdur', 'Style', 'edit', 'Units', 'normalized', 'Position',...
[0.89 0.115 0.09 0.025],'String',respdurstr,'Callback', @CBSelectAndSortColors);
% Y-axis (Fluorescence) range controls (INITIAL VALUE of 'String' = '')
uicontrol(tab,'Tag','Ylims','Style', 'checkbox', 'String', 'Y-Axis Limits:' , 'Units', 'Normalized', ...
'BackgroundColor',BGC,'ForegroundColor',[0 0 1],'Position',[0.05 0.07 0.35 0.04],'Value',ylimval, ...
'HorizontalAlignment','Left','FontSize', 10,'FontWeight','Bold','Callback',@CBplotLimits);
uicontrol(tab,'Style', 'text', 'String', 'Min:' , 'Units', 'Normalized', ...
'BackgroundColor',BGC,'Position',[0.04 0.04 0.13 0.03],'HorizontalAlignment','Left',...
'FontSize', 8);
uicontrol(tab,'Tag','Ymin','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.12 0.05 0.12 0.025], 'String', yminstr, 'Fontweight', 'Bold', 'Enable','off',...
'Callback', @CBSelectAndSortColors);
uicontrol(tab,'Style', 'text', 'String', 'Max:' , 'Units', 'Normalized' ...
,'BackgroundColor',BGC,'Position',[0.26 0.04 0.13 0.03],'HorizontalAlignment','Left'...
,'FontSize', 8);
uicontrol(tab,'Tag','Ymax','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.35 0.05 0.12 0.025], 'String', ymaxstr, 'Fontweight', 'Bold', 'Enable','off',...
'Callback', @CBSelectAndSortColors);
%X-axis (Time) range controls
uicontrol(tab,'Tag','Tlims','Style', 'checkbox', 'String', 'X-Axis Limits:' , 'Units', 'Normalized' ...
,'BackgroundColor',BGC,'ForegroundColor',[0 0 1],'Position',[0.55 0.07 0.35 0.04],'Value',tlimval, ...
'HorizontalAlignment','Left','FontSize', 10,'FontWeight','Bold','Callback',@CBplotLimits);
uicontrol(tab,'Style', 'text', 'String', 'Min:' , 'Units', 'Normalized' ...
,'BackgroundColor',BGC,'Position',[0.54 0.04 0.13 0.03],'HorizontalAlignment','Left'...
,'FontSize', 8);
uicontrol(tab,'Tag','Tmin','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.62 0.05 0.12 0.025], 'String', tminstr, 'Fontweight', 'Bold', 'Enable','off',...
'Callback', @CBSelectAndSortColors);
uicontrol(tab,'Style', 'text', 'String', 'Max:' , 'Units', 'Normalized' ...
,'BackgroundColor',BGC,'Position',[0.76 0.04 0.13 0.03],'HorizontalAlignment','Left'...
,'FontSize', 8);
uicontrol(tab,'Tag','Tmax','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.85 0.05 0.12 0.025], 'String', tmaxstr, 'Fontweight', 'Bold', 'Enable','off',...
'Callback', @CBSelectAndSortColors);
% Save Plot/Data
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position',[.05 .005 0.27 .04],...
'String', 'Save Plot Figure', 'Fontweight', 'Bold', 'Min', 0, 'Max', 1, ...
'Callback', @CBsaveFigure, 'TooltipString', 'Save plot as matlab .fig file, to open: openfig(''myfile.fig'')');
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.365 .005 0.27 .04], 'String', 'Save Plot Data', 'Fontweight', 'Bold', 'Min', 0, 'Max', 1, ...
'Callback', @CBsaveFigData, 'TooltipString', ['Save data from lines shown on plot '...
'as .mat or .txt file (not including stimulus)']);
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.68 .005 0.27 .04], 'String', 'Behavior Analysis', 'Fontweight', 'Bold', 'Min', 0, 'Max', 1, ...
'Callback', @CBBehave, 'TooltipString', ['Create trialsdata struct from TSdata and run '...
'BehaviorAnalysis_MWLab']);
%figure for plot
figshift = 0.02*(str2double(tab.Tag)-1);
pos=hTS.Position;
figure('NumberTitle','off','Name',sprintf('Plot #%s',tab.Tag),'Tag',guiname,...
'Units','normalized','Position',[(pos(1)+pos(3))+figshift+0.001 ...
pos(2)+0.5*pos(4)-figshift 0.50 0.5*pos(4)],'CloseRequestFcn',@CBclosePlot);
axes('Tag','tsax');
end
% % % %
% % % % % Plot ROIs on same time-axis or "align" end-to-end (this is turned off, does not work!!!)
% % % % % hTS.stackButton = uicontrol('Style', 'togglebutton', 'Units', 'normalized', 'Position', ...
% % % % % [.01 .01 0.08 .05], 'String', 'Stacked', 'Fontweight', 'Bold', ...
% % % % % 'Min', 0, 'Max', 1, 'Value', 0, 'Callback', @CBstackButton_fcn,'Enable','off','Visible','off');
% % % % % function CBstackButton_fcn(~, ~)
% % % % % groupstr = {'Stacked'; 'Aligned'};
% % % % % val = get(hTS.stackButton, 'Value');
% % % % % set(hTS.stackButton, 'String', groupstr{1+val});
% % % % % do_time_series_plot;
% % % % % end
% % % %
if isfield(TSdata,'file') && ~isempty(TSdata.file) && isfield(TSdata,'roi') && ~isempty(TSdata.roi)
if isfield(TSdata.file(1).roi(1),'series') && ~isempty(TSdata.file(1).roi(1).series)
bloadnow = 0;
CBSelectStimulus;
else
CBaddFiles;
end
end
%%
%Nested Callback Functions
function CB_CloseFig(~,~)
updateSettings;
save(fullfile(guipath,'TSsettings.mat'),'TSsettings');
delete(findobj('Tag',guiname));
delete(hTS);
end
function CBSaveSettings(~, ~)
updateSettings;
[setfile,setpath] = uiputfile(fullfile(guipath,'myTSsettings.mat'));
save(fullfile(setpath,setfile),'TSsettings');
end
function updateSettings
%save settings from current tab
tab = htabgroup.SelectedTab;
TSsettings.byfileval = get(findobj(tab,'Tag','byfile'),'Value');
TSsettings.byroival = get(findobj(tab,'Tag','byroi'),'Value');
TSsettings.byodorval = get(findobj(tab,'Tag','byodor'),'Value');
TSsettings.bytrialval = get(findobj(tab,'Tag','bytrial'),'Value');
TSsettings.stimselectval = get(findobj(tab,'Tag','stimselect'),'Value');
TSsettings.delaystr = get(findobj(tab,'Tag','delay'),'String');
TSsettings.durstr = get(findobj(tab,'Tag','duration'),'String');
TSsettings.intstr = get(findobj(tab,'Tag','interval'),'String');
TSsettings.trialstr = get(findobj(tab,'Tag','trials'),'String');
TSsettings.hidestimval = get(findobj(tab,'Tag','hidestim'),'Value');
TSsettings.prestr = get(findobj(tab,'Tag','prestim'),'String');
TSsettings.poststr = get(findobj(tab,'Tag','poststim'),'String');
TSsettings.supval = get(findobj(tab,'Tag','superimpose'),'Value');
TSsettings.avgtrialval = get(findobj(tab,'Tag','avgtrials'),'Value');
TSsettings.avgfileval = get(findobj(tab,'Tag','avgfiles'),'Value');
TSsettings.avgroival = get(findobj(tab,'Tag','avgrois'),'Value');
TSsettings.avgodorval = get(findobj(tab,'Tag','avgodors'),'Value');
TSsettings.bgroival = get(findobj(tab,'Tag','subtractbgroi'),'Value');
TSsettings.bgroistr = get(findobj(tab,'Tag','bgroi'),'String');
TSsettings.hpfval = get(findobj(tab,'Tag','hpfilter'),'Value');
TSsettings.hpfstr = get(findobj(tab,'Tag','hpfilterparm'),'String');
TSsettings.lpfval = get(findobj(tab,'Tag','lpfilter'),'Value');
TSsettings.lpfstr = get(findobj(tab,'Tag','lpfilterparm'),'String');
TSsettings.confval = get(findobj(tab,'Tag','confint'),'Value');
TSsettings.dfval = get(findobj(tab,'Tag','deltaf'),'Value');
TSsettings.dffval = get(findobj(tab,'Tag','deltafoverf'),'Value');
TSsettings.fstartstr = get(findobj(tab,'Tag','fstart'),'String');
TSsettings.fstopstr = get(findobj(tab,'Tag','fstop'),'String');
TSsettings.showchangeval = get(findobj(tab,'Tag','showchange'),'Value');
TSsettings.basestartstr = get(findobj(tab,'Tag','basestart'),'String');
TSsettings.basedurstr = get(findobj(tab,'Tag','basedur'),'String');
TSsettings.respstartstr = get(findobj(tab,'Tag','respstart'),'String');
TSsettings.respdurstr = get(findobj(tab,'Tag','respdur'),'String');
TSsettings.ylimval = get(findobj(tab,'Tag','Ylims'),'Value');
TSsettings.yminstr = get(findobj(tab,'Tag','Ymin'),'String');
TSsettings.ymaxstr = get(findobj(tab,'Tag','Ymax'),'String');
TSsettings.tlimval = get(findobj(tab,'Tag','Tlims'),'Value');
TSsettings.tminstr = get(findobj(tab,'Tag','Tmin'),'String');
TSsettings.tmaxstr = get(findobj(tab,'Tag','Tmax'),'String');
end
function CBLoadSettings(~, ~)
[setfile,setpath] = uigetfile(fullfile(guipath,'*.mat'));
try
load(fullfile(setpath,setfile),'-mat','TSsettings');
tab = htabgroup.SelectedTab; %only apply settings to current tab
set(findobj(tab,'Tag','byfile'),'Value',TSsettings.byfileval);
set(findobj(tab,'Tag','byroi'),'Value',TSsettings.byroival);
set(findobj(tab,'Tag','byodor'),'Value',TSsettings.byodorval);
set(findobj(tab,'Tag','bytrial'),'Value',TSsettings.bytrialval);
set(findobj(tab,'Tag','stimselect'),'Value',TSsettings.stimselectval);
set(findobj(tab,'Tag','delay'),'String',TSsettings.delaystr);
set(findobj(tab,'Tag','duration'),'String',TSsettings.durstr);
set(findobj(tab,'Tag','interval'),'String',TSsettings.intstr);
set(findobj(tab,'Tag','trials'),'String',TSsettings.trialstr);
set(findobj(tab,'Tag','hidestim'),'Value',TSsettings.hidestimval);
set(findobj(tab,'Tag','prestim'),'String',TSsettings.prestr);
set(findobj(tab,'Tag','poststim'),'String',TSsettings.poststr);
set(findobj(tab,'Tag','superimpose'),'Value',TSsettings.supval);
set(findobj(tab,'Tag','avgtrials'),'Value',TSsettings.avgtrialval);
set(findobj(tab,'Tag','avgfiles'),'Value',TSsettings.avgfileval);
set(findobj(tab,'Tag','avgrois'),'Value',TSsettings.avgroival);
set(findobj(tab,'Tag','avgodors'),'Value',TSsettings.avgodorval);
set(findobj(tab,'Tag','subtractbgroi'),'Value',TSsettings.bgroival);
set(findobj(tab,'Tag','bgroi'),'String',TSsettings.bgroistr);
set(findobj(tab,'Tag','hpfilter'),'Value',TSsettings.hpfval);
set(findobj(tab,'Tag','hpfilterparm'),'String',TSsettings.hpfstr);
set(findobj(tab,'Tag','lpfilter'),'Value',TSsettings.lpfval);
set(findobj(tab,'Tag','lpfilterparm'),'String',TSsettings.lpfstr);
set(findobj(tab,'Tag','confint'),'Value',TSsettings.confval);
set(findobj(tab,'Tag','deltaf'),'Value',TSsettings.dfval);
set(findobj(tab,'Tag','deltafoverf'),'Value',TSsettings.dffval);
set(findobj(tab,'Tag','fstart'),'String',TSsettings.fstartstr);
set(findobj(tab,'Tag','fstop'),'String',TSsettings.fstopstr);
set(findobj(tab,'Tag','showchange'),'Value',TSsettings.showchangeval);
set(findobj(tab,'Tag','basestart'),'String',TSsettings.basestartstr);
set(findobj(tab,'Tag','basedur'),'String',TSsettings.basedurstr);
set(findobj(tab,'Tag','respstart'),'String',TSsettings.respstartstr);
set(findobj(tab,'Tag','respdur'),'String',TSsettings.respdurstr);
set(findobj(tab,'Tag','Ylims'),'Value',TSsettings.ylimval);
set(findobj(tab,'Tag','Ymin'),'String',TSsettings.yminstr);
set(findobj(tab,'Tag','Ymax'),'String',TSsettings.ymaxstr);
set(findobj(tab,'Tag','Tlims'),'Value',TSsettings.tlimval);
set(findobj(tab,'Tag','Tmin'),'String',TSsettings.tminstr);
set(findobj(tab,'Tag','Tmax'),'String',TSsettings.tmaxstr);
CBSelectStimulus;
catch
end
end
function CBclosePlot(plotfig,~)
idx = strfind(plotfig.Name,'#');
plotnum = str2double(plotfig.Name(idx+1:end));
if numel(htabgroup.Children) > 2 %not the last plot
delete(plotfig);
delete(htabgroup.Children(plotnum));
for i = 1:numel(htabgroup.Children)
if ~strcmp(htabgroup.Children(i).Tag,num2str(i)) && ~strcmp(htabgroup.Children(i).Title,'Add Plot')
tmpfig = findobj('type','figure','Name',sprintf('Plot #%s',htabgroup.Children(i).Tag));
htabgroup.Children(i).Tag = num2str(i);
htabgroup.Children(i).Title = sprintf('Plot #%d',i);
tmpfig.Name = sprintf('Plot #%s',num2str(i));
end
end
else %last plot
CB_CloseFig; return;
end
end
function CBaddFiles(~,~) %add image file(s) to list (and/or load scanbox realtime data)
if bloadnow %path & filenames provided on function call
bloadnow = 0; cnt=0;
[imsize(1),imsize(2)] = getImageSize(TSdata.file(1).type,fullfile(TSdata.file(1).dir,TSdata.file(1).name));
TSdata.file(1).size = imsize;
if length(TSdata.file) > 1
for mm = 2:length(TSdata.file) %check image XY size matches
[tmpsize(1),tmpsize(2)] = getImageSize(TSdata.file(1).type,fullfile(TSdata.file(mm).dir,TSdata.file(mm).name));
if ~isequal(imsize,tmpsize)
errordlg('File sizes do not match');
TSdata.file = []; TSdata.roi = [];
CBSelectStimulus;
return;
end
TSdata.file(mm).size = imsize;
end
end
else %add files button press
% get data type if unknown
if isempty(TSdata.file) || ~isfield(TSdata.file(1),'type') || isempty(TSdata.file(1).type)
[typeval,ok]= listdlg('SelectionMode','single','PromptString','Select Data Type','SelectionMode','single','ListString',...
typestr);
if ok == 0
return;
end
TSdata.file(1).type = typestr{typeval};
end
%get pathname & filenames
if isfield(TSdata.file(1),'dir') && ~isempty(TSdata.file(1).dir); pathname = TSdata.file(1).dir; elseif exist('oldpath','var'); pathname = oldpath; else pathname = ''; end
switch TSdata.file(1).type
case 'scanimage' %ScanImage .tif (aka MWScope)
ext = {'*.tif;*.dat','Scanimage Files';'*.*','All Files'};
[filename, pathname, ok] = uigetfile(ext, 'Select data file(s)', pathname, 'MultiSelect', 'On');
case 'scanbox'
ext = '.sbx';
[filename, pathname, ok] = uigetfile(ext, 'Select data file(s)', pathname, 'MultiSelect', 'On');
case 'prairie'
ext = '.xml'; %might try using uigetfolder for multiple files
[filename, pathname, ok] = uigetfile(ext, 'Select data file(s)', pathname, 'MultiSelect', 'Off');
case 'neuroplex'
ext = '.da';
[filename, pathname, ok] = uigetfile(ext, 'Select data file(s)', pathname, 'MultiSelect', 'On');
TSdata.aux2bncmap = assignNeuroplexBNC;
case 'tif' %Standard .tif
ext = '.tif';
[filename, pathname, ok] = uigetfile(ext, 'Select data file(s)', 'MultiSelect', 'On');
end
if ~ok; return; end
% add to any existing files, and check image file sizes match
if isfield(TSdata.file,'name') && ~isempty(TSdata.file(end).name)
cnt = length(TSdata.file);
imsize = TSdata.file(1).size;
else
cnt = 0;
if ischar(filename)
[imsize(1),imsize(2)] = getImageSize(TSdata.file(1).type,fullfile(pathname,filename));
else
[imsize(1),imsize(2)] = getImageSize(TSdata.file(1).type,fullfile(pathname,filename{1}));
end
end
if ischar(filename) %only adding 1 file
if cnt>0
[tmpsize(1),tmpsize(2)] = getImageSize(TSdata.file(1).type,fullfile(pathname,filename));
if ~isequal(imsize,tmpsize)
errordlg('File sizes do not match');
return;
end
end
numChannels = getNumChannels(TSdata.file(1).type,fullfile(pathname,filename));
if numChannels == 1
TSdata.file(cnt+1).name = filename;
TSdata.file(cnt+1).dir = pathname;
TSdata.file(cnt+1).type = TSdata.file(1).type; %tcrtcr currently limit all files to same type
TSdata.file(cnt+1).size = imsize;
TSdata.file(cnt+1).numChannels = 1;
else %two channels
TSdata.file(cnt+1).name = filename; TSdata.file(cnt+2).name = filename;
TSdata.file(cnt+1).dir = pathname; TSdata.file(cnt+2).dir = pathname;
TSdata.file(cnt+1).type = TSdata.file(1).type; %tcrtcr currently limit all files to same type
TSdata.file(cnt+2).type = TSdata.file(1).type;
TSdata.file(cnt+1).size = imsize; TSdata.file(cnt+2).size = imsize;
TSdata.file(cnt+1).numChannels = 2; TSdata.file(cnt+2).numChannels = 2;
end
else %add more than 1 file
%check all file sizes
if cnt>0; m1=1; else; m1=2; end
for mm = m1:length(filename) %check image size matches
[tmpsize(1),tmpsize(2)] = getImageSize(TSdata.file(1).type,fullfile(pathname,filename{mm}));
if ~isequal(imsize,tmpsize)
errordlg('File sizes do not match');
return;
end
end
new = 0;
for mm = 1:length(filename) %add the images
numChannels = getNumChannels(TSdata.file(1).type,fullfile(pathname,filename{1}));
if numChannels == 1
new = new+1;
TSdata.file(cnt+new).name = filename{mm};
TSdata.file(cnt+new).dir = pathname;
TSdata.file(cnt+new).type = TSdata.file(1).type; %tcrtcr currently limit all files to same type
TSdata.file(cnt+new).size = imsize;
TSdata.file(cnt+new).numChannels = 1;
else
new = new+2;
TSdata.file(cnt+new-1).name = filename{mm}; TSdata.file(cnt+new).name = filename{mm};
TSdata.file(cnt+new-1).dir = pathname; TSdata.file(cnt+new).dir = pathname;
TSdata.file(cnt+new-1).type = TSdata.file(1).type; %tcrtcr currently limit all files to same type
TSdata.file(cnt+new).type = TSdata.file(1).type;
TSdata.file(cnt+new-1).size = imsize; TSdata.file(cnt+new).size = imsize;
TSdata.file(cnt+new-1).numChannels = 2; TSdata.file(cnt+new).numChannels = 2;
end
end
end
end
if ~isempty(TSdata.file(end).dir); oldpath = TSdata.file(end).dir; end
%in case ROIs were loaded, check roi size matches image size
if isfield(TSdata,'roi') && ~isempty(TSdata.roi)
if ~isequal(imsize,size(TSdata.roi(1).mask))
TSdata.roi = []; % Existing ROIs size does not match loaded images; delete ROIs.
end
end
%If ROIs are present, compute timeseries data (requires loading file), or use scanbox realtime.mat file
if isfield(TSdata,'file') && ~isempty(TSdata.file(1).name) && isfield(TSdata,'roi') && ~isempty(TSdata.roi)
if ~strcmp(TSdata.file(1).type,'scanbox')
for n = cnt+1:length(TSdata.file)
skipch2 = [];
if n>1; skipch2 = strfind(TSdata.file(n).name,'_ch2'); end
if isempty(skipch2)
loadFileComputeTimeSeries(n);
end
end
else %scanbox data, check for realtime.mat file(s)
for n = cnt+1:length(TSdata.file)
if ~isempty(dir(fullfile(TSdata.file(n).dir,[TSdata.file(n).name(1:end - 4) '_realtime.mat'])))
%load realtime file: if all ROIs match use realtime, otherwise loadComputeTimeSeries
realtime = load(fullfile(TSdata.file(n).dir,[TSdata.file(n).name(1:end - 4) '_realtime.mat']));
sameRois = 0; %make sure all rois match
for j = 1:numel(TSdata.roi)
roipix = find(TSdata.roi(j).mask);
if numel(realtime.roipix) >= j
sameRois = sameRois + isequal(roipix,realtime.roipix{j}); %rois match
end
end
if sameRois == numel(TSdata.roi) %all rois match
for j = 1:numel(TSdata.roi)
TSdata.file(n).roi(j).series = double(intmax('uint16'))-realtime.rtdata(:,j);
end
% get the frameRate/frames (no file loaded) and Aux signals
[~,sbxinfo] = mysbxread(fullfile(TSdata.file(1).dir,TSdata.file(1).name(1:end-4)),0,0);
sbxinfo.frameRate = sbxinfo.resfreq/sbxinfo.recordsPerBuffer; TSdata.file(n).frameRate = sbxinfo.frameRate;
sbxinfo.frames = sbxinfo.max_idx+1; TSdata.file(n).frames = sbxinfo.frames;
if isfield(sbxinfo,'event_id') && ~isempty(sbxinfo.event_id)
[TSdata.file(n).aux1,TSdata.file(n).aux2,TSdata.file(n).aux3] = loadScanboxStimulus(sbxinfo);
end
%load ephys data - currently, scanbox is only type with ephys files
if isfile(fullfile(TSdata.file(1).dir,[TSdata.file(1).name(1:end-4) '.ephys']))
TSdata.file(n).ephys = loadScanboxEphys(fullfile(TSdata.file(1).dir,[TSdata.file(1).name(1:end-4) '.ephys']));
if isempty(TSdata.file(n).ephys); TSdata.file(n)=rmfield(TSdata.file(n),'ephys'); end
end
else %realtime rois do not match
skipch2 = [];
if n>1; skipch2 = strfind(TSdata.file(n).name,'_ch2'); end
if isempty(skipch2)
loadFileComputeTimeSeries(n);
end
end
else %no realtime.mat file
skipch2 = [];
if n>1; skipch2 = strfind(TSdata.file(n).name,'_ch2'); end
if isempty(skipch2)
loadFileComputeTimeSeries(n);
end
end
end
end
end
hTS.UserData.TSdata = TSdata;
CBSelectStimulus;
end
function CBclearFiles(~,~) %clear selected files and related timeseries
if isempty(TSdata.file); return; end
tab = htabgroup.SelectedTab;
selectedfiles = get(findobj(tab,'Tag','FILE_listbox'),'Value');
keep = setdiff(1:length(TSdata.file),selectedfiles);
TSdata.file = TSdata.file(keep);
if isempty(TSdata.file) %cleared all files, reinitialize variables for next time
TSdata.file = [];
end
set(findobj(tab,'Tag','FILE_listbox'),'Value',1);
hTS.UserData.TSdata = TSdata;
CBSelectStimulus;
end
function CBaddROIs(~,~) %load/add ROIs and compute timeseries
tab = htabgroup.SelectedTab;
if isempty(TSdata.file)
newrois = loadROIs;
else
newrois = loadROIs(TSdata.file(1).dir);
end
if ~isempty(newrois)
if isfield(TSdata,'file') && ~isempty(TSdata.file) && ~isempty(TSdata.file(1).name)
imsize = TSdata.file(1).size;
if ~isequal(imsize,size(newrois(1).mask))
errordlg('New ROIs size does not match image size'); uiwait;
clear newrois; return;
end
elseif isfield(TSdata,'roi') && ~isempty(TSdata.roi)
if ~isequal(size(TSdata.roi(1).mask),size(newrois(1).mask))
errordlg('New ROIs size does not match old ROI size'); uiwait;
clear newrois; return;
end
end
% add to list of rois
if isfield(TSdata,'roi') && ~isempty(TSdata.roi)
cnt = length(TSdata.roi);
else; cnt = 0;
end
for rr = 1:length(newrois)
TSdata.roi(cnt+rr).mask = newrois(rr).mask;
end
set(findobj(tab,'Tag','ROI_listbox'),'Value',1);
%roi labels/options - only if no files are loaded
if ~isempty(newrois)
roistr = cell(numel(TSdata.roi),1);
for i = 1:numel(TSdata.roi)
roistr{i} = ['ROI #' num2str(i)];
end
set(findobj(tab,'Tag','ROI_listbox'), 'String', roistr);
end
%compute timeseries data or use scanbox realtime.mat file for new ROIs
if isfield(TSdata,'file') && ~isempty(TSdata.file) && ~isempty(TSdata.file(1).name)...
&& isfield(TSdata,'roi') && ~isempty(TSdata.roi)
for n = 1:length(TSdata.file)
if ~isempty(dir(fullfile(TSdata.file(n).dir,[TSdata.file(n).name(1:end - 4) '_realtime.mat'])))
%load realtime file: if all ROIs match use realtime, otherwise loadComputeTimeSeries
realtime = load(fullfile(TSdata.file(n).dir,[TSdata.file(n).name(1:end - 4) '_realtime.mat']));
sameRois = 0; %make sure all rois match
for j = 1:numel(TSdata.roi)
roipix = find(TSdata.roi(j).mask);
if numel(realtime.roipix) >= j
sameRois = sameRois + isequal(roipix,realtime.roipix{j}); %rois match
end
end
if sameRois == numel(TSdata.roi) %all rois match
fprintf('using realtime data, file %d\n',n);
for j = 1:numel(TSdata.roi)
TSdata.roi(j).time_series{n} = double(intmax('uint16'))-realtime.rtdata(:,j);
%tcrtcrtcr might want to check at least one timeframe by computation
end
sbxtmp = load(fullfile(TSdata.file(1).dir,TSdata.file(1).name(1:end-4)));
sbxtmp.info.frameRate = sbxtmp.info.resfreq/sbxtmp.info.recordsPerBuffer;
%tcrtcrtcr repeat of potential error
sbxtmp.info.max_idx = TSdata.frames-1;
TSdata.file(n).frameRate = sbxtmp.info.frameRate;
%get aux signals
if isfield(sbxtmp.info,'event_id') && ~isempty(sbxtmp.info.event_id)
[TSdata.file(n).aux1,TSdata.file(n).aux2,TSdata.file(n).aux3] = loadScanboxStimulus(sbxtmp.info);
end
% load scanbox Ephys file
if isfile(fullfile(TSdata.file(1).dir,[TSdata.file(1).name(1:end-4) '.ephys']))
TSdata.file(n).ephys = loadScanboxEphys(fullfile(TSdata.file(1).dir,[TSdata.file(1).name(1:end-4) '.ephys']));
if isempty(TSdata.file(n).ephys); TSdata.file(n)=rmfield(TSdata.file(n),'ephys'); end
end
else %rois do not match ***currently recomputes all rois
fprintf('computing time series, file %d\n',n);
skipch2 = [];
if n>1; skipch2 = strfind(TSdata.file(n).name,'_ch2'); end
if isempty(skipch2)
%check for name changes due to alignment and two-channel data
al = strfind(TSdata.file(n).name,'_align'); dot = strfind(TSdata.file(n).name,'.');
if ~isempty(al); TSdata.file(n).name = [TSdata.file(n).name(1:al-1) TSdata.file(n).name(dot:end)]; end
ch = strfind(TSdata.file(n).name,'_ch1'); dot = strfind(TSdata.file(n).name,'.');
if ~isempty(ch); TSdata.file(n).name = [TSdata.file(n).name(1:ch-1) TSdata.file(n).name(dot:end)]; end
loadFileComputeTimeSeries(n);
end
end
else %no realtime.mat file
%skip channel 2
skipch2 = [];
if n>1; skipch2 = strfind(TSdata.file(n).name,'_ch2'); end
if isempty(skipch2)
%check for name changes due to alignment and two-channel data
al = strfind(TSdata.file(n).name,'_align'); dot = strfind(TSdata.file(n).name,'.');
if ~isempty(al); TSdata.file(n).name = [TSdata.file(n).name(1:al-1) TSdata.file(n).name(dot:end)]; end
ch = strfind(TSdata.file(n).name,'_ch1'); dot = strfind(TSdata.file(n).name,'.');
if ~isempty(ch); TSdata.file(n).name = [TSdata.file(n).name(1:ch-1) TSdata.file(n).name(dot:end)]; end
loadFileComputeTimeSeries(n);
end
end
end
end
hTS.UserData.TSdata = TSdata;
CBSelectStimulus; %CBSelectAndSortColors;
end
clear newrois;
end
function CBclearROIs(~,~) %clear selected ROIs and related data
if ~isfield(TSdata,'roi') || isempty(TSdata.roi); return; end
tab = htabgroup.SelectedTab;
selectedrois = get(findobj(tab,'Tag','ROI_listbox'),'Value');
keepers = setdiff(1:length(TSdata.roi),selectedrois);
if isempty(keepers)
TSdata.roi = [];
if isfield(TSdata.file,'roi'); TSdata.file = rmfield(TSdata.file,'roi'); end
else
TSdata.roi = TSdata.roi(keepers);
for f = 1:length(TSdata.file)
if isfield(TSdata.file(f),'roi')
TSdata.file(f).roi = TSdata.file(f).roi(keepers);
end
end
end
set(findobj(tab,'Tag','ROI_listbox'),'Value',1);
hTS.UserData.TSdata = TSdata;
CBSelectStimulus; %CBSelectAndSortColors;
end
function loadFileComputeTimeSeries(n) %load image file and compute time series (one at a time)
tmpname = TSdata.file(n).name;
if strcmp(TSdata.file(n).type,'neuroplex')
tmpdata = loadFile_MWLab(TSdata.file(n).type,TSdata.file(n).dir,tmpname,TSdata.aux2bncmap);
else
tmpdata = loadFile_MWLab(TSdata.file(n).type,TSdata.file(n).dir,tmpname);
end
%automatically align file if tmpname.align is present
dot = strfind(tmpdata.name,'.');
alignfile = fullfile(tmpdata.dir,[tmpdata.name(1:dot) 'align']);
if exist(alignfile,'file')==2
tmp = load(alignfile,'-mat');
T = tmp.T; idx = tmp.idx;
if iscell(tmpdata.im)
for f = 1:length(idx)
tmpdata.im{1}(:,:,idx(f)) = circshift(tmpdata.im{1}(:,:,idx(f)),T(f,:));
tmpdata.im{2}(:,:,idx(f)) = circshift(tmpdata.im{2}(:,:,idx(f)),T(f,:));
end
else
for f = 1:length(idx)
tmpdata.im(:,:,idx(f)) = circshift(tmpdata.im(:,:,idx(f)),T(f,:));
end
end
tmpname = [tmpname(1:dot-1) '_align' tmpname(dot:end)];
end
if iscell(tmpdata.im)
dot = strfind(tmpdata.name,'.');
TSdata.file(n).name = [tmpname(1:dot-1) '_ch1' tmpname(dot:end)];
TSdata.file(n+1).name = [tmpname(1:dot-1) '_ch2' tmpname(dot:end)];
TSdata.file(n).frameRate = tmpdata.frameRate; TSdata.file(n).frames = size(tmpdata.im{1},3);
TSdata.file(n+1).frameRate = tmpdata.frameRate; TSdata.file(n+1).frames = size(tmpdata.im{2},3);
tmptsdata.file = TSdata.file(n:n+1); tmptsdata.roi = TSdata.roi;
tmptsdata.file(1).im = tmpdata.im{1}; tmptsdata.file(2).im = tmpdata.im{2};
tmptsdata = computeTimeSeries(tmptsdata,tmptsdata.roi);
tmptsdata.file = rmfield(tmptsdata.file,'im');
TSdata.file(n).roi = []; TSdata.file(n+1).roi = [];
TSdata.file(n) = tmptsdata.file(1);TSdata.file(n+1) = tmptsdata.file(2);
%Save the stimulus signals here, use later when file(s) selected!
TSdata.file(n).aux1 = []; TSdata.file(n).aux2 = [];
TSdata.file(n+1).aux1 = []; TSdata.file(n+1).aux2 = [];
if isfield(tmpdata,'aux1')
TSdata.file(n).aux1 = tmpdata.aux1; TSdata.file(n+1).aux1 = tmpdata.aux1;
end
if isfield(tmpdata,'aux2')
TSdata.file(n).aux2 = tmpdata.aux2; TSdata.file(n+1).aux2 = tmpdata.aux2;
end
if isfield(tmpdata,'aux3')
TSdata.file(n).aux3 = tmpdata.aux3; TSdata.file(n+1).aux3 = tmpdata.aux3;
end
if isfield(tmpdata,'ephys')
TSdata.file(n).ephys = tmpdata.ephys; TSdata.file(n+1).ephys = tmpdata.ephys;
end
else %single channel
TSdata.file(n).name = tmpname;
TSdata.file(n).frameRate = tmpdata.frameRate; TSdata.file(n).frames = size(tmpdata.im,3);
tmptsdata.file = TSdata.file(n);
tmptsdata.file.im = tmpdata.im;
tmptsdata = computeTimeSeries(tmptsdata,TSdata.roi);
tmptsdata.file = rmfield(tmptsdata.file,'im');
TSdata.file(n).roi = []; TSdata.file(n) = tmptsdata.file;
%Save the stimulus signals here, use later when file(s) selected!
TSdata.file(n).aux1 = []; TSdata.file(n).aux2 = [];
if isfield(tmpdata,'aux1')
TSdata.file(n).aux1 = tmpdata.aux1;
end
if isfield(tmpdata,'aux2')
TSdata.file(n).aux2 = tmpdata.aux2;
end
if isfield(tmpdata,'aux3')
TSdata.file(n).aux3 = tmpdata.aux3;
end
if isfield(tmpdata,'ephys')
TSdata.file(n).ephys = tmpdata.ephys;
end
end
clear tmpdata;
hTS.UserData.TSdata = TSdata;
end
function CBSelectStimulus(~,~)
tab = htabgroup.SelectedTab;
if ~isfield(TSdata,'file') || isempty(TSdata.file)
set(findobj(tab,'Tag','stimselect'),'Value',1);
end
bDefaultSelectAllOdorTrials = 1;
doAux_combo;
CBSelectAndSortColors;
end
function doAux_combo %create or remove aux_combo stimulus
tab = htabgroup.SelectedTab;
if get(findobj(tab,'Tag','stimselect'),'Value')==4