-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapsAnalysis_MWLab.m
2459 lines (2418 loc) · 146 KB
/
MapsAnalysis_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 hMAP = MapsAnalysis_MWLab(varargin)
% MWLab program for analyzing baseline vs response "odor maps"
% MapsAnalysis_MWLab(varargin)
% varargin{1} = MapsData; (e.g. saved mapsdata loaded to workspace)
% mwmap.concentrations %concentration for each map image (#Trialsx1 cell, w/char elements, enter manually for now)
% %
% % MapsData %struct used to store all basic maps data (stored in hMAP.UserData)
% % MapsData.stim2use %which stimulus signal used to generate maps
% % MapsData.odorDuration (optional, if stim2use = 'AuxCombo' - used for scanimage auxiliary signals which do not encode odor off)
% % MapsData.def_stimulus (if stim2use = 'Defined Stimulus')
% % MapsData.stimulus.times, MapsData.stimulus.signal
% % MapsData.stimulus.delay
% % MapsData.stimulus.duration
% % MapsData.stimulus.interval
% % MapsData.stimulus.trials
% % MapsData.basetimes %times relative to stimulus TTL signal used to generate baseline images
% % MapsData.resptimes %times relative to stimulus TTL signal used to generate response images
% % MapsData.file %note: channels become separate files
% % MapsData.file().type %original data file
% % MapsData.file().name %original data file
% % MapsData.file().dir %original data file
% % MapsData.file().odors() %odor #s
% % MapsData.file().odor
% % MapsData.file().tenthprctileim % useful for deltaf/f option
% % MapsData.file().odor().trials() %starts at 1 for each odor, only includes valid trials
% % MapsData.file().odor().trial
% % MapsData.file().odor().concentration (optional)
% % MapsData.file().odor().trial().baseim
% % MapsData.file().odor().trial().baseframes
% % MapsData.file().odor().trial().respim
% % MapsData.file().odor().trial().respframes
% % MapsData.roi
% % MapsData.roi().mask
% % figdata{} used to store figure images,titles,details (stored in hMAP.UserData)
% % figdata{1}.im
% % figdata{1}.title{}. %text field for use in figures and saved in Tiff Tag "ImageDescription"
% % figdata{1}.details{}. %text field to be saved in Tiff Tag
% % "ImageDescription" includes file/odor/trial info plus image filter settings
% Written 2018 by Thomas C. Rust, Wachowiak Lab, University of Utah
tmppath=which('MapsAnalysis_MWLab');
[guipath,guiname,~]=fileparts(tmppath);
pathparts=strsplit(guipath,filesep);
guiname = [pathparts{end} '/' guiname];
prev = findobj('Name', guiname);
if ~isempty(prev); close(prev); end
persistent oldpath; if isempty(oldpath); oldpath = ''; end
typestr = getdatatypes;
stimstr = getauxtypes;
imagetypestr = {'Mean Baseline';'Mean Response'; ...
'DeltaF (Response-Baseline)'; '%DeltaFoverF [100*(Resp-Base)/Base]'};
% '10th Percentile (All Frames)'; '%DeltaFoverF [100*(Resp-Base)/10thPctile]'};
cmapstrings = getcmaps;
defaultaxescolor = [.5 .5 .5];
figdata = {};
%load previous settings file
try
load(fullfile(guipath,'MAsettings.mat'),'-mat','MAsettings');
catch
end
if ~exist('MAsettings','var')
MAsettings.basetimes = [-3.0 0.0]; MAsettings.resptimes = [0.0 3.0];
MAsettings.stim2use = stimstr{1};
MAsettings.delaystr = '4'; MAsettings.durstr = '8'; MAsettings.intstr = '32'; MAsettings.trialstr = '8';
MAsettings.imtypeval = 1;
MAsettings.fmaskstr = '1'; MAsettings.bgsubtractval = 0; MAsettings.bgroistr = 1;
MAsettings.avgtrialval = 0; MAsettings.avgodorval = 0; MAsettings.avgfileval = 0;
MAsettings.sortval = 0; MAsettings.odorlistval = 0; MAsettings.odorlistfilestr = '';
MAsettings.overlayval = 0; MAsettings.cmapval = 1; MAsettings.clim1val = 1;
MAsettings.clim2val = 0; MAsettings.clim3val = 0; MAsettings.cminstr = '0';
MAsettings.cmaxstr = '1'; MAsettings.loadfiltval = 0; MAsettings.filtfilestr = '';
MAsettings.lpfval = 0; MAsettings.lpfstr = ''; MAsettings.hpfval = 0; MAsettings.hpfstr = '';
MAsettings.cwfval = 0; MAsettings.cwfstr = ''; MAsettings.supval = 0; MAsettings.supstr = '';
MAsettings.lowval = 0; MAsettings.lowstr = ''; MAsettings.mincutval = 0; MAsettings.mincutstr = '';
MAsettings.maxcutval = 0; MAsettings.maxcutstr = ''; MAsettings.bilinval=0;
end
if nargin
MapsData = varargin{1};
% hAux.Value = MapsData.stim2use;
else
MapsData.file = []; MapsData.roi = [];
end
BGC = [255 204 255]/255; %background color
hMAP = figure('NumberTitle','off','Name', guiname, 'Units', 'Normalized', ...
'Color', BGC, 'Position', [0.01 0.05 0.25 0.85], 'DefaultAxesLineWidth', 3, ...
'DefaultAxesFontSize', 12, 'DefaultAxesFontWeight', 'Bold','CloseRequestFcn',@CB_CloseFig);
hmenu = uimenu(hMAP,'Text','GUI Settings');
uimenu(hmenu,'Text','Save Settings','Callback',@CBSaveSettings);
uimenu(hmenu,'Text','Load Settings','Callback',@CBLoadSettings);
roivsmapplot = []; %added by MW. Used to do sorting-by-ROI and de-sorting
% general commands and info
uicontrol(hMAP,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.01 .955 0.23 .04], 'String', 'Add File(s)','FontWeight','Bold', 'Callback', ...
@CBaddFiles);
uicontrol(hMAP,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.26 .955 0.23 .04], 'String', 'Clear File(s)','FontWeight','Bold', 'Callback', ...
@CBclearFiles);
uicontrol(hMAP,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.51 .955 0.23 .04], 'String', 'Load MapsData', 'Fontweight', 'Bold', 'Min', 0, 'Max', 1, ...
'Callback', @CBloadMapsData,'TooltipString','Load application data (Mapsdata) from <mydata>.mat file');
uicontrol(hMAP,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.76 .955 0.23 .04], 'String', 'Save MapsData', 'Fontweight', 'Bold', 'Min', 0, 'Max', 1, ...
'Callback', @CBsaveMapsData,'TooltipString',sprintf(['Save application data (Mapsdata) in .mat file '...
'so that it can be loaded again\n later (e.g. MapsAnalysis_MWLab(Mapsdata)']));
%ROI buttons
uicontrol(hMAP,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.01 .755 0.18 .04], 'String', 'Load ROIs','FontWeight','Bold', 'Callback', ...
@CBaddROIs);
uicontrol(hMAP,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.2 .755 0.18 .04], 'String', 'Draw ROI(s)','FontWeight','Bold', 'Callback', ...
@CBdrawROIs);
uicontrol(hMAP,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.4 .755 0.18 .04], 'String', 'Shift ROI(s)','FontWeight','Bold', 'Callback', ...
@CBshiftROIs);
uicontrol(hMAP,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.6 .755 0.18 .04], 'String', 'Clear ROI(s)','FontWeight','Bold', 'Callback', ...
@CBclearROIs);
uicontrol(hMAP,'Style', 'pushbutton', 'Units', 'normalized', 'Position', ...
[.8 .755 0.18 .04], 'String', 'Save ROIs','FontWeight','Bold', 'Callback', ...
@CBsaveROIs);
%Map Specifications
hMapSpecPanel = uipanel(hMAP,'Units','Normalized','Position', [0.01 0.8 0.98 0.15]);
uicontrol(hMapSpecPanel,'Style','text','String','MapsData Specifications:','FontSize',11,'FontWeight','Bold','Units','Normalized',...
'Position',[0.0 0.82 .68 .15],'HorizontalAlignment','right');
uicontrol(hMapSpecPanel,'Style','pushbutton','String','Change','Units','normalized','Position',[0.72 0.82 .18 .15],...
'Callback',@CBChangeSpecs);
uicontrol(hMapSpecPanel,'Style','text','String','Pre/Post Stimulus Times','Units','normalized',...
'Position',[0.02 0.6 .36 0.15],'FontSize',10,'FontWeight','Bold',...
'HorizontalAlignment','Center','Enable','off');
if isfield(MapsData,'basetimes'); basetimes = MapsData.basetimes; else; basetimes = MAsettings.basetimes; end
hBaseStart = uicontrol(hMapSpecPanel,'Style', 'edit', 'String', num2str(basetimes(1)),'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.02 0.42 .07 0.15],'HorizontalAlignment','Right','Enable','off');
uicontrol(hMapSpecPanel,'Style', 'text', 'String', 'to','Units','normalized' ...
,'Position',[0.1 0.40 .05 0.15],'HorizontalAlignment','Left','Enable','off');
hBaseEnd = uicontrol(hMapSpecPanel,'Style', 'edit', 'String', num2str(basetimes(2)),'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.13 0.42 .07 0.15],'HorizontalAlignment','Right','Enable','off');
uicontrol(hMapSpecPanel,'Style', 'text', 'String', '(secs) Pre-Stimulus','Units','normalized' ...
,'Position',[0.21 0.40 0.22 0.15],'HorizontalAlignment','Left','Enable','off');
if isfield(MapsData,'resptimes'); resptimes = MapsData.resptimes; else; resptimes = MAsettings.resptimes; end
hRespStart = uicontrol(hMapSpecPanel,'Style', 'edit', 'String', num2str(resptimes(1)),'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.02 0.20 .07 0.15],'HorizontalAlignment','Right','Enable','off');
uicontrol(hMapSpecPanel,'Style', 'text', 'String', 'to','Units','normalized' ...
,'Position',[0.1 0.18 .05 0.15],'HorizontalAlignment','Left','Enable','off');
hRespEnd = uicontrol(hMapSpecPanel,'Style', 'edit', 'String', num2str(resptimes(2)),'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.13 0.20 .07 0.15],'HorizontalAlignment','Right','Enable','off');
uicontrol(hMapSpecPanel,'Style', 'text', 'String', '(secs) Post-Stimulus','Units','normalized' ...
,'Position',[0.21 0.18 0.22 0.15],'HorizontalAlignment','Left','Enable','off');
if isfield(MapsData,'stim2use'); hauxvalue = find(strcmp(MapsData.stim2use,stimstr));
else; hauxvalue = find(strcmp(MAsettings.stim2use,stimstr));
end
hAux = uicontrol(hMapSpecPanel,'Tag','aux','Style','popupmenu','Units','normalized', 'Position', ...
[0.53 0.6 .35 0.15], 'String', stimstr, 'FontSize',9,'FontWeight', 'Bold', 'Enable', 'off', 'Value', hauxvalue);
if hAux.Value == 3; othervisible = 'off'; durvisible = 'on'; %AuxCombo
elseif hAux.Value == 4; othervisible = 'on'; durvisible = 'on'; %Defined Stimulus
else; othervisible = 'off'; durvisible = 'off'; %Aux1, Aux2
end
if isfield(MapsData,'def_stimulus'); delaystr = num2str(MapsData.def_stimulus.delay); else; delaystr = MAsettings.delaystr; end
if isfield(MapsData,'def_stimulus'); durstr = num2str(MapsData.def_stimulus.duration);
elseif isfield(MapsData,'odorDuration'); durstr = num2str(MapsData.odorDuration);
else; durstr = MAsettings.durstr;
end
if isfield(MapsData,'def_stimulus'); intstr = num2str(MapsData.def_stimulus.interval); else; intstr = MAsettings.intstr; end
if isfield(MapsData,'def_stimulus'); trialstr = num2str(MapsData.def_stimulus.trials); else; trialstr = MAsettings.trialstr; end
hDelay = uicontrol(hMapSpecPanel,'Tag','delay','Style', 'edit', 'String', delaystr,'Units','normalized', ...
'BackgroundColor',[1 1 1],'Position',[0.63 0.44 .05 0.1],'HorizontalAlignment','Right','Enable','off', ...
'Visible', othervisible);
hDelayLabel = uicontrol(hMapSpecPanel,'Style', 'text', 'String', 'Initial Delay(sec)','Units','normalized', ...
'Position',[0.69 0.44 .2 0.1],'HorizontalAlignment','Left','enable','off','Visible', othervisible);
hDuration = uicontrol(hMapSpecPanel,'Tag','duration','Style', 'edit', 'String', durstr,'Units','normalized', ...
'BackgroundColor',[1 1 1],'Position',[0.63 0.31 .05 0.1],'HorizontalAlignment','Right','Enable','off', ...
'Visible', durvisible);
hDurationLabel = uicontrol(hMapSpecPanel,'Style', 'text', 'String', 'Duration(sec)','Units','normalized', ...
'Position',[0.69 0.31 .2 0.1],'HorizontalAlignment','Left','enable','off','Visible', durvisible);
hInterval = uicontrol(hMapSpecPanel,'Tag','interval','Style', 'edit', 'String', intstr,'Units','normalized', ...
'BackgroundColor',[1 1 1],'Position',[0.63 0.18 .05 0.1],'HorizontalAlignment','Right','Enable','off', ...
'Visible', othervisible);
hIntervalLabel = uicontrol(hMapSpecPanel,'Style', 'text', 'String', 'Interval(sec)','Units','normalized', ...
'Position',[0.69 0.18 .2 0.1],'HorizontalAlignment','Left','enable','off', 'Visible', othervisible);
hTrials = uicontrol(hMapSpecPanel,'Tag','trials','Style', 'edit', 'String', trialstr,'Units','normalized', ...
'BackgroundColor',[1 1 1],'Position',[0.63 0.05 .05 0.1],'HorizontalAlignment','Right','Enable','off', ...
'Visible', othervisible);
hTrialsLabel = uicontrol(hMapSpecPanel,'Style', 'text', 'String', '# Trials','Units','normalized', ...
'Position',[0.69 0.05 .2 0.1],'HorizontalAlignment','Left','enable','off','Visible', othervisible);
function CBChangeSpecs(~,~)
hFig_ChangeSpecs = figure('NumberTitle','off','Toolbar','none','Name','Change MapsData Specifications',...
'Units', 'Normalized', 'Position',[0.01 0.73 0.25 0.13],'WindowStyle','Modal');
%Change Map Specifications
uicontrol(hFig_ChangeSpecs,'Style','pushbutton','String','Cancel','Units','normalized','Position',[0.22 0.82 .28 .15],...
'Callback',@CBdelete);
uicontrol(hFig_ChangeSpecs,'Style','pushbutton','String','Apply Changes','Units','normalized','Position',[0.62 0.82 .28 .15],...
'Callback',@CBapply);
uicontrol(hFig_ChangeSpecs,'Style','text','String','Pre/Post Stimulus Times','Units','normalized',...
'Position',[0.02 0.65 .36 0.15],'FontSize',10,'FontWeight','Bold', 'HorizontalAlignment','Center');
baseStart = uicontrol(hFig_ChangeSpecs,'Style', 'edit', 'String', hBaseStart.String,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.02 0.47 .07 0.15],'HorizontalAlignment','Right');
uicontrol(hFig_ChangeSpecs,'Style', 'text', 'String', 'to','Units','normalized' ...
,'Position',[0.1 0.45 .05 0.15],'HorizontalAlignment','Left');
baseEnd = uicontrol(hFig_ChangeSpecs,'Style', 'edit', 'String', hBaseEnd.String,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.13 0.47 .07 0.15],'HorizontalAlignment','Right');
uicontrol(hFig_ChangeSpecs,'Style', 'text', 'String', '(secs) Pre-Stimulus','Units','normalized' ...
,'Position',[0.21 0.45 0.22 0.15],'HorizontalAlignment','Left');
respStart = uicontrol(hFig_ChangeSpecs,'Style', 'edit', 'String', hRespStart.String,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.02 0.25 .07 0.15],'HorizontalAlignment','Right');
uicontrol(hFig_ChangeSpecs,'Style', 'text', 'String', 'to','Units','normalized' ...
,'Position',[0.1 0.23 .05 0.15],'HorizontalAlignment','Left');
respEnd = uicontrol(hFig_ChangeSpecs,'Style', 'edit', 'String', hRespEnd.String,'Units','normalized' ...
,'BackgroundColor',[1 1 1],'Position',[0.13 0.25 .07 0.15],'HorizontalAlignment','Right');
uicontrol(hFig_ChangeSpecs,'Style', 'text', 'String', '(secs) Post-Stimulus','Units','normalized' ...
,'Position',[0.21 0.23 0.22 0.15],'HorizontalAlignment','Left');
aux = uicontrol(hFig_ChangeSpecs,'Tag','aux','Style','popupmenu','Units','normalized',...
'Position', [0.53 0.6 .35 0.15], 'String', stimstr, 'FontSize',9, ...
'FontWeight', 'Bold', 'Value', hAux.Value, 'Callback',@CBchangestim);
if aux.Value == 3; othervisible = 'off'; durvisible = 'on'; %AuxCombo
elseif aux.Value == 4; othervisible = 'on'; durvisible = 'on'; %Defined Stimulus
else; othervisible = 'off'; durvisible = 'off'; %Aux1, Aux2
end
if isfield(MapsData,'def_stimulus'); delaystr = num2str(MapsData.def_stimulus.delay); else; delaystr = MAsettings.delaystr; end
if isfield(MapsData,'def_stimulus'); durstr = num2str(MapsData.def_stimulus.duration);
elseif isfield(MapsData,'odorDuration'); durstr = num2str(MapsData.odorDuration);
else; durstr = MAsettings.durstr;
end
if isfield(MapsData,'def_stimulus'); intstr = num2str(MapsData.def_stimulus.interval); else; intstr = MAsettings.intstr; end
if isfield(MapsData,'def_stimulus'); trialstr = num2str(MapsData.def_stimulus.trials); else; trialstr = MAsettings.trialstr; end
delay = uicontrol(hFig_ChangeSpecs,'Tag','delay','Style', 'edit', 'String', delaystr,'Units','normalized', ...
'BackgroundColor',[1 1 1],'Position',[0.63 0.44 .05 0.1],'HorizontalAlignment','Right', ...
'Visible', othervisible);
delaylabel = uicontrol(hFig_ChangeSpecs,'Style', 'text', 'String', 'Initial Delay(sec)','Units','normalized', ...
'Position',[0.69 0.44 .2 0.1],'HorizontalAlignment','Left','Visible', othervisible);
duration = uicontrol(hFig_ChangeSpecs,'Tag','duration','Style', 'edit', 'String', durstr,'Units','normalized', ...
'BackgroundColor',[1 1 1],'Position',[0.63 0.31 .05 0.1],'HorizontalAlignment','Right', ...
'Visible', durvisible);
durationlabel = uicontrol(hFig_ChangeSpecs,'Style', 'text', 'String', 'Duration(sec)','Units','normalized', ...
'Position',[0.69 0.31 .2 0.1],'HorizontalAlignment','Left','Visible', durvisible);
interval = uicontrol(hFig_ChangeSpecs,'Tag','interval','Style', 'edit', 'String', intstr,'Units','normalized', ...
'BackgroundColor',[1 1 1],'Position',[0.63 0.18 .05 0.1],'HorizontalAlignment','Right', ...
'Visible', othervisible);
intervallabel = uicontrol(hFig_ChangeSpecs,'Style', 'text', 'String', 'Interval(sec)','Units','normalized', ...
'Position',[0.69 0.18 .2 0.1],'HorizontalAlignment','Left', 'Visible', othervisible);
trials = uicontrol(hFig_ChangeSpecs,'Tag','trials','Style', 'edit', 'String', trialstr,'Units','normalized', ...
'BackgroundColor',[1 1 1],'Position',[0.63 0.05 .05 0.1],'HorizontalAlignment','Right', ...
'Visible', othervisible);
trialslabel = uicontrol(hFig_ChangeSpecs,'Style', 'text', 'String', '# Trials','Units','normalized', ...
'Position',[0.69 0.05 .2 0.1],'HorizontalAlignment','Left', 'Visible', othervisible);
function CBdelete(~,~); delete(hFig_ChangeSpecs); end
function CBapply(~,~)
hBaseStart.String = baseStart.String; hBaseEnd.String = baseEnd.String;
if isfield(MapsData,'basetimes'); MapsData.basetimes = [str2double(baseStart.String) str2double(baseEnd.String)]; end
hRespStart.String = respStart.String; hRespEnd.String = respEnd.String;
if isfield(MapsData,'resptimes'); MapsData.resptimes = [str2double(respStart.String) str2double(respEnd.String)]; end
hAux.Value = aux.Value; if isfield(MapsData,'stim2use'); MapsData.stim2use = stimstr{aux.Value}; end
hDelay.String = delay.String; hDelay.Visible = delay.Visible; hDelayLabel.Visible = delaylabel.Visible;
hDuration.String = duration.String; hDuration.Visible = duration.Visible; hDurationLabel.Visible = durationlabel.Visible;
hInterval.String = interval.String; hInterval.Visible = interval.Visible; hIntervalLabel.Visible = intervallabel.Visible;
hTrials.String = trials.String; hTrials.Visible = trials.Visible; hTrialsLabel.Visible = trialslabel.Visible;
delete(hFig_ChangeSpecs);
hMAP.UserData.MapsData = MapsData;
if isfield(MapsData,'file') && ~isempty(MapsData.file)
%remove 2-channel data
ch1 = [];
for n = 1:length(MapsData.file)
if isempty(strfind(MapsData.file(n).name,'_ch2')); ch1 = [ch1 n]; end
end
MapsData.file = MapsData.file(ch1);
tmpbar = waitbar(0,'Loading Files & Making Maps');
for n = 1:length(MapsData.file)
waitbar(n/length(MapsData.file),tmpbar);
skipch2 = []; %ch2 names are added during loop
if n>1; skipch2 = strfind(MapsData.file(n).name,'_ch2'); end
if isempty(skipch2)
dot = strfind(MapsData.file(n).name,'.'); %get raw data file name
orig = dot; %first character after end of original name
if strfind(MapsData.file(n).name,'_align')
orig = strfind(MapsData.file(n).name,'_align'); %added last
end
if strfind(MapsData.file(n).name,'_ch1')
orig = strfind(MapsData.file(n).name,'_ch1'); %added first
end
MapsData.file(n).name = [MapsData.file(n).name(1:orig-1) MapsData.file(n).name(dot:end)];
loadFileComputeMaps(n);
end
end
close(tmpbar);
end
%tcrtcrtcr reset odortrialval=1...
CBsortAndSelect;
end
function CBchangestim(src,~)
if src.Value == 1 %Aux1
othervisible = 'off'; durvisible = 'off';
elseif src.Value == 2 %Aux2
othervisible = 'off'; durvisible = 'off';
elseif src.Value == 3 %AuxCombo
othervisible = 'off'; durvisible = 'on';
elseif src.Value == 4 %Defined Stimulus
othervisible = 'on'; durvisible = 'on';
end
delay.Visible = othervisible; delaylabel.Visible = othervisible;
duration.Visible = durvisible; durationlabel.Visible = durvisible;
interval.Visible = othervisible; intervallabel.Visible = othervisible;
trials.Visible = othervisible; trialslabel.Visible = othervisible;
end
end
%Create tabs for each new figure
% TabGroup/Figure #1 Tab - controls for each plot
hTabgroup = uitabgroup(hMAP,'Units','Normalized','Position',[0 0 1 .75],'SelectionChangedFcn',@CBchangetabs);
uitab(hTabgroup,'Title','Figure #1','Tag','1','ForegroundColor','green','BackgroundColor',BGC);
tabsetup(hTabgroup.SelectedTab);
uitab(hTabgroup,'Title','Add Figure');
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 Figure')
hTabgroup.SelectedTab.Title = sprintf('Figure #%d',ntabs);
hTabgroup.SelectedTab.Tag = num2str(ntabs);
hTabgroup.SelectedTab.BackgroundColor = BGC;
hTabgroup.SelectedTab.ForegroundColor = 'green';
tabsetup(hTabgroup.SelectedTab);
uitab(hTabgroup,'Title','Add Figure');
else
hTabgroup.SelectedTab.ForegroundColor = 'green';
tmpfig = findobj('type','figure','Name',sprintf('Figure #%s',hTabgroup.SelectedTab.Tag));
if isempty(tmpfig)
tabsetup(hTabgroup.SelectedTab);
else
figure(tmpfig);
end
figure(hMAP);
end
CBsortAndSelect;
end
function tabsetup(tab)
if str2double(tab.Tag)>1
prevtab = findobj('Tag',num2str(str2double(tab.Tag)-1));
fileval = get(findobj(prevtab,'Tag','FILE_listbox'),'Value');
otval = get(findobj(prevtab,'Tag','OdorTrial_listbox'),'Value');
roival = get(findobj(prevtab,'Tag','ROIs_listbox'),'Value');
imtypeval = get(findobj(prevtab,'Tag','imagetype'),'Value');
fmaskstr = get(findobj(prevtab,'Tag','fmaskedit'),'String');
bgsubtractval = get(findobj(prevtab,'Tag','bgsubtract'),'Value');
bgroistr = get(findobj(prevtab,'Tag','bgroi'),'String');
avgtrialval = get(findobj(prevtab,'Tag','avgtrials'),'Value');
avgodorval = get(findobj(prevtab,'Tag','avgodors'),'Value');
avgfileval = get(findobj(prevtab,'Tag','avgfiles'),'Value');
sortval = get(findobj(prevtab,'Tag','sortbyodor'),'Value');
odorlistval = get(findobj(prevtab,'Tag','odorlist'),'Value');
odorlistfilestr = get(findobj(prevtab,'Tag','odorlistfile'),'String');
overlayval = get(findobj(prevtab,'Tag','overlay'),'Value');
cmapval = get(findobj(prevtab,'Tag','cmap_popupmenu'),'Value');
clim1val = get(findobj(prevtab,'Tag','clim1'),'Value');
clim2val = get(findobj(prevtab,'Tag','clim2'),'Value');
clim3val = get(findobj(prevtab,'Tag','clim3'),'Value');
cminstr = get(findobj(prevtab,'Tag','Cmin'),'String');
cmaxstr = get(findobj(prevtab,'Tag','Cmax'),'String');
loadfiltval = get(findobj(prevtab,'Tag','loadfilter'),'Value'); filtfilestr = get(findobj(prevtab,'Tag','filtfile'),'String');
lpfval = get(findobj(prevtab,'Tag','lpfilter'),'Value'); lpfstr = get(findobj(prevtab,'Tag','lpfilterparm'),'String');
hpfval = get(findobj(prevtab,'Tag','hpfilter'),'Value'); hpfstr = get(findobj(prevtab,'Tag','hpfilterparm'),'String');
cwfval = get(findobj(prevtab,'Tag','cwfilter'),'Value'); cwfstr = get(findobj(prevtab,'Tag','cweight'),'String');
supval = get(findobj(prevtab,'Tag','suppresshighpix'),'Value'); supstr = get(findobj(prevtab,'Tag','highpix'),'String');
lowval = get(findobj(prevtab,'Tag','lowthresh'),'Value'); lowstr = get(findobj(prevtab,'Tag','thresh'),'String');
mincutval = get(findobj(prevtab,'Tag','mincutoff'),'Value'); mincutstr = get(findobj(prevtab,'Tag','mincut'),'String');
maxcutval = get(findobj(prevtab,'Tag','maxcutoff'),'Value'); maxcutstr = get(findobj(prevtab,'Tag','maxcut'),'String');
bilinval = get(findobj(prevtab,'Tag','bilinear'),'Value');
else
fileval = 1; otval = 1; roival = 1;
imtypeval = MAsettings.imtypeval; fmaskstr = MAsettings.fmaskstr; bgsubtractval = MAsettings.bgsubtractval;
bgroistr = MAsettings.bgroistr; avgtrialval = MAsettings.avgtrialval; avgodorval = MAsettings.avgodorval;
avgfileval = MAsettings.avgfileval; sortval = MAsettings.sortval; odorlistval = MAsettings.odorlistval;
odorlistfilestr = MAsettings.odorlistfilestr; overlayval = MAsettings.overlayval; cmapval = MAsettings.cmapval;
clim1val = MAsettings.clim1val; clim2val = MAsettings.clim2val; clim3val = MAsettings.clim3val;
cminstr = MAsettings.cminstr; cmaxstr = MAsettings.cmaxstr; loadfiltval = MAsettings.loadfiltval;
filtfilestr = MAsettings.filtfilestr; lpfval = MAsettings.lpfval; lpfstr = MAsettings.lpfstr;
hpfval = MAsettings.hpfval; hpfstr = MAsettings.hpfstr; cwfval = MAsettings.cwfval; cwfstr = MAsettings.cwfstr;
supval = MAsettings.supval; supstr = MAsettings.supstr; lowval = MAsettings.lowval; lowstr = MAsettings.lowstr;
mincutval = MAsettings.mincutval; mincutstr = MAsettings.mincutstr; maxcutval = MAsettings.maxcutval;
maxcutstr = MAsettings.maxcutstr; bilinval = MAsettings.bilinval;
end
% Files/ROIs
uicontrol(tab,'Style', 'text', 'Units', 'normalized', 'Position', [.01 .96 0.4 .03],...
'BackgroundColor',BGC, 'String', 'Select File(s)','FontWeight','Bold');
filenamestr=cell(length(MapsData.file));
if ~isempty(MapsData.file)
for i = 1:length(MapsData.file); filenamestr{i}=MapsData.file(i).name; end
else; filenamestr{1} = '';
end
uicontrol(tab,'Style', 'listbox','Tag','FILE_listbox','Units', 'normalized', 'Position', ...
[0.01 0.53 0.4 0.43], 'String', filenamestr, 'Value', fileval, 'BackgroundColor', [1 1 1], ...
'Max', 100, 'Min', 0, 'Callback', @CBdrawnow, 'KeyPressFcn', @CBDeleteFile);
function CBdrawnow(src,~) %returns control to source object
CBsortAndSelect; figure(hMAP); hMAP.CurrentObject = src;
end
uicontrol(tab,'Style', 'text', 'Units', 'normalized', 'Position', [.42 .96 0.3 .03],...
'BackgroundColor',BGC,'String', 'Odor(s),Trial(s)','FontWeight','Bold');
uicontrol(tab,'Style', 'listbox','Tag','OdorTrial_listbox','Units', 'normalized', 'Position', ...
[0.42 0.53 0.3 0.43], 'String', '', 'Value', otval, 'BackgroundColor', [1 1 1], ...
'Max', 10000, 'Min', 0, 'Callback', @CBdrawnow, 'ButtonDownFcn',@CBodorSelect, 'KeyPressFcn', @CBDeleteOdorTrial);
uicontrol(tab,'Style', 'text', 'Units', 'normalized', 'Position', [.73 .96 0.25 .03],...
'BackgroundColor',BGC,'String', 'Select ROI(s)','FontWeight','Bold');
uicontrol(tab,'Style', 'listbox','Tag','ROIs_listbox','Units', 'normalized', 'Position', ...
[0.73 0.53 0.25 0.43], 'String', '', 'Value', roival, 'BackgroundColor', [1 1 1], ...
'Max', 10000, 'Min', 0, 'Callback', @CBdrawnow);
% Image Type
uicontrol(tab,'Style', 'popupmenu', 'Tag', 'imagetype', 'FontSize', 9, 'FontWeight', 'bold', ...
'String', imagetypestr, 'Value', imtypeval, 'Units', 'normalized', 'Position', ...
[0.04 0.48 0.38 0.03], 'Callback', @CBsortAndSelect);
uicontrol(tab,'Tag','fmasklabel','Style','text','Units','normalized','Position',[0.04 0.44 0.1 0.03], ...
'String', 'F mask:','HorizontalAlignment','left','BackgroundColor',BGC);
uicontrol(tab,'Tag','fmaskslider','Style','Slider','Units','Normalized','Position',[0.13 0.44 0.23 0.03],...
'Callback',@CBsetFmask);
uicontrol(tab,'Tag','fmaskedit', 'Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.37 0.44 0.06 0.03], 'String', fmaskstr, 'Callback',@CBsetFmask);
% Background subtraction
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.41 0.33 0.03], 'Value', bgsubtractval, ...
'String', 'Subtract Background ROI #:', 'BackgroundColor', BGC, 'Tag', 'bgsubtract', 'Callback', @CBsortAndSelect, ...
'ToolTipString','BACKGROUND SUBTRACTION IS ONLY APPLIED TO BASELINE AND RESPONSE IMAGES (NOT 10th Percentile)');
uicontrol(tab, 'Tag', 'bgroi', 'Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.37 0.41 0.06 0.03], 'String', bgroistr, 'Callback',@CBsortAndSelect);
% Average Files/Odors/Trials
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.38 0.33 0.03], 'Value', avgtrialval, ...
'String', 'Average Trials', 'BackgroundColor',BGC,'Tag','avgtrials','Callback',@CBsortAndSelect);
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.35 0.33 0.03], 'Value', avgodorval, ...
'String', 'Average Odors', 'BackgroundColor',BGC,'Tag','avgodors','Callback',@CBsortAndSelect);
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.32 0.3 0.03], 'Value', avgfileval, ...
'String', 'Average Files', 'BackgroundColor',BGC,'Tag','avgfiles','Callback',@CBsortAndSelect);
%Sort by Odor#
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.29 0.3 0.03],...
'String', 'Sort Images by Odor#', 'BackgroundColor',BGC, 'Value', sortval, ...
'Tag', 'sortbyodor', 'Callback', @CBsortAndSelect);
%Lookup odor name from list
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.26 0.15 0.03],...
'String', 'Odor List', 'BackgroundColor',BGC, 'Value', odorlistval, 'Tag','odorlist','Callback',@CBsortAndSelect);
uicontrol(tab,'Tag','odorlistfile','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.19 0.26 0.24 0.03], 'String', odorlistfilestr, 'Callback',@CBsortAndSelect);
%Overlay ROIs
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.23 0.3 0.03],...
'String', 'Overlay ROIs', 'BackgroundColor' ,BGC, 'Value', overlayval, 'Tag','overlay','Callback',@CBsortAndSelect);
%List of Colormaps
uicontrol(tab,'Style', 'text', 'String', 'Colormaps: ','Units','normalized', 'BackgroundColor',BGC,...
'FontWeight','bold','HorizontalAlignment','left','Position',[0.04 0.19 0.3 0.03]);
uicontrol(tab,'Style', 'popupmenu', 'Tag','cmap_popupmenu','Units', 'normalized', 'Position', ...
[0.04 0.17 0.3 0.03], 'String', cmapstrings,'FontSize', 9, 'Callback', @CBsortAndSelect, ...
'Value', cmapval, 'BackgroundColor', [1 1 1]);
uicontrol(tab,'Style', 'text', 'String', 'Colormap Limits: ','Units','normalized', 'BackgroundColor',BGC,...
'FontWeight','bold','HorizontalAlignment','left','Position',[0.04 0.13 0.3 0.03]);
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.11 0.33 0.03], ...
'Value', clim1val, 'String', 'Auto (min-max)','BackgroundColor',BGC,'Tag','clim1','Callback',@CBmapLimits);
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.08 0.33 0.03], ...
'Value', clim2val, 'String', 'Auto (0.2-99.8%)', 'BackgroundColor',BGC,'Tag','clim2','Callback',@CBmapLimits);
uicontrol(tab,'Style', 'checkbox', 'Units', 'normalized', 'Position', [0.04 0.05 0.33 0.03],...
'Value', clim3val, 'String', 'Manual', 'BackgroundColor',BGC,'Tag','clim3','Callback',@CBmapLimits);
uicontrol(tab,'Style', 'text', 'String', 'Cmin: ','Units','normalized' ...
,'BackgroundColor',BGC,'Position',[0.04 0.015 0.065 0.02],'HorizontalAlignment','Right');
uicontrol(tab,'Style', 'edit', 'String', cminstr,'Units','normalized', 'Callback', @CBsortAndSelect, ...
'BackgroundColor',[1 1 1],'Position',[0.1 0.015 0.08 0.03],'HorizontalAlignment','Right', ...
'Tag', 'Cmin', 'Enable', 'Off');
uicontrol(tab,'Style', 'text', 'String', 'Cmax: ','Units','normalized' ...
,'BackgroundColor',BGC,'Position',[0.195 0.015 0.07 0.02],'HorizontalAlignment','Right');
uicontrol(tab,'Style', 'edit', 'String', cmaxstr,'Units','normalized', 'Callback', @CBsortAndSelect, ...
'BackgroundColor',[1 1 1],'Position',[0.26 0.015 0.08 0.03],'HorizontalAlignment','Right', ...
'Tag', 'Cmax', 'Enable', 'Off');
%Image Processing / Filters
uicontrol(tab,'Style', 'text', 'String', 'Image Processing (Sequential): ','Units','normalized', 'BackgroundColor',BGC,...
'FontWeight','bold','HorizontalAlignment','left','Position',[0.47 0.48 0.5 0.03]);
uicontrol(tab,'Style','checkbox','string','Load Filter Kernel File','units','normalized', 'Tag', 'loadfilter',...
'BackgroundColor',BGC, 'position',[0.47 0.45 0.3 0.03],'Callback',@CBsortAndSelect, 'Value', loadfiltval);
uicontrol(tab,'Tag','filtfile','Style', 'edit', 'Units', 'normalized', 'Position', [0.75 0.45 0.22 0.03], ...
'String', filtfilestr, 'Fontweight', 'Bold', 'Callback',@CBsortAndSelect);
uicontrol(tab,'Style','checkbox','string','Low Pass Gaussian @','units','normalized', 'Tag', 'lpfilter',...
'BackgroundColor',BGC, 'position',[0.47 0.42 0.3 0.03],'Callback',@CBsortAndSelect, 'Value', lpfval);
uicontrol(tab,'Tag','lpfilterparm','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.75 0.42 0.08 0.03], 'String', lpfstr, 'Fontweight', 'Bold', 'Callback',@CBsortAndSelect);
uicontrol(tab,'Style', 'text','String', [char(963) ' Pixels'], 'Units', 'Normalized' ,'BackgroundColor',BGC, ...
'Position', [0.84 0.415 0.15 0.03],'HorizontalAlignment','Left');
uicontrol(tab,'Style','checkbox','string','High Pass Gaussian @','units','normalized', 'Tag', 'hpfilter',...
'BackgroundColor',BGC, 'position',[0.47 0.39 0.3 0.03],'Callback',@CBsortAndSelect, 'Value', hpfval);
uicontrol(tab,'Tag','hpfilterparm','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.75 0.39 0.08 0.03], 'String', hpfstr, 'Fontweight', 'Bold', 'Callback',@CBsortAndSelect);
uicontrol(tab,'Style', 'text', 'String', [char(963) ' Pixels'], 'Units', 'Normalized' ,'BackgroundColor',BGC, ...
'Position', [0.84 0.385 0.15 0.03],'HorizontalAlignment','Left');
uicontrol(tab,'Style','checkbox','string','3x3 Center Weighted','units','normalized', 'Tag', 'cwfilter', ...
'BackgroundColor',BGC, 'position',[0.47 0.36 0.3 0.03],'Callback',@CBsortAndSelect, 'Value', cwfval, ...
'TooltipString','Center Weighted Smoothing Kernel [1,1,1;1,weight,1;1,1,1]; enter center weight');
uicontrol(tab,'Tag','cweight','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.75 0.36 0.08 0.03], 'String', cwfstr, 'Fontweight', 'Bold', 'Callback',@CBsortAndSelect);
uicontrol(tab,'Style', 'text', 'String', 'Weight' , 'Units', 'Normalized' ,'BackgroundColor',BGC, ...
'Position', [0.84 0.355 0.1 0.03],'HorizontalAlignment','Left');
uicontrol(tab,'Style','checkbox','string','Suppress High Pixels','units','normalized', 'Tag', 'suppresshighpix', ...
'BackgroundColor',BGC, 'position',[0.47 0.33 0.3 0.03],'Callback',@CBsortAndSelect, 'Value', supval, ...
'TooltipString',sprintf(['Sort pixel values (excluding a 5 pixel border),'...
'then limit the max value in the image\n to be the mean of the high pixels selected. (enter # of high pixels']));
uicontrol(tab,'Tag','highpix','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.75 0.33 0.08 0.03], 'String', supstr, 'Fontweight', 'Bold', 'Callback',@CBsortAndSelect);
uicontrol(tab,'Style', 'text', 'String', '# Pixels', 'Units', 'Normalized' ,'BackgroundColor',BGC, ...
'Position', [0.84 0.325 0.1 0.03],'HorizontalAlignment','Left');
uicontrol(tab,'Style','checkbox','string','Low Threshold (0-1.0)','units','normalized', 'Tag', 'lowthresh', ...
'BackgroundColor',BGC, 'position',[0.47 0.30 0.3 0.03],'Callback',@CBsortAndSelect, 'Value', lowval, ...
'TooltipString','Limit the minumum value to a specified fraction of the total range (enter value 0-1)');
uicontrol(tab,'Tag','thresh','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.75 0.30 0.08 0.03], 'String', lowstr, 'Fontweight', 'Bold', 'Callback',@CBsortAndSelect);
uicontrol(tab,'Style', 'text', 'String', 'Fraction' , 'Units', 'Normalized' ,'BackgroundColor',BGC, ...
'Position', [0.84 0.295 0.1 0.03],'HorizontalAlignment','Left');
uicontrol(tab,'Style','checkbox','string','Minimum Cut-off','units','normalized', 'Tag', 'mincutoff',...
'BackgroundColor',BGC, 'position',[0.47 0.27 0.3 0.03],'Callback',@CBsortAndSelect, 'Value', mincutval);
uicontrol(tab,'Tag','mincut','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.75 0.27 0.08 0.03], 'String', mincutstr, 'Fontweight', 'Bold', 'Callback',@CBsortAndSelect, ...
'TooltipString','Limit the minumum to a specified value');
uicontrol(tab,'Style', 'text', 'String', 'Value' , 'Units', 'Normalized' ,'BackgroundColor',BGC, ...
'Position', [0.84 0.265 0.1 0.03],'HorizontalAlignment','Left');
uicontrol(tab,'Style','checkbox','string','Maximum Cut-off ','units','normalized', 'Tag', 'maxcutoff', ...
'BackgroundColor',BGC, 'position',[0.47 0.24 0.3 0.03],'Callback',@CBsortAndSelect, 'Value', maxcutval, ...
'TooltipString','Limit the maximum to a specified value');
uicontrol(tab,'Tag','maxcut','Style', 'edit', 'Units', 'normalized', 'Position', ...
[0.75 0.24 0.08 0.03], 'String', maxcutstr, 'Fontweight', 'Bold', 'Callback',@CBsortAndSelect);
uicontrol(tab,'Style', 'text', 'String', 'Value' , 'Units', 'Normalized' ,'BackgroundColor',BGC, ...
'Position', [0.84 0.235 0.1 0.03],'HorizontalAlignment','Left');
uicontrol(tab,'Style','checkbox','string','Bilinear Interpolation','units','normalized', 'Tag', 'bilinear',...
'BackgroundColor',BGC, 'position',[0.47 0.21 0.3 0.03],'Callback',@CBsortAndSelect, 'Value', bilinval);
%Analysis Methods
uicontrol(tab,'Style', 'text', 'String', 'Analysis Methods: ','Units','normalized', 'BackgroundColor',BGC,...
'FontWeight','bold','HorizontalAlignment','left','Position',[0.47 0.17 0.5 0.03]);
%Save Maps as Tif
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.47 0.13 0.24 .04],...
'String', 'Save Maps as Tiff','FontWeight','Bold', 'Callback', @CBsaveImage);
%Montage
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.47 0.09 0.24 0.04],...
'String', 'Montage', 'Fontweight', 'Bold', 'Value', 0, 'Tag','montage','Callback',@CB_montage);
%Correlation Image
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.47 0.05 0.24 0.04],...
'String', 'Sort by ROI', 'Fontweight', 'Bold', 'Value', 0, 'Callback',@CB_CorrImage);
%Max/Min Projection Image
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.47 0.01 0.24 0.04],...
'String', 'Un-Sort afer sorting', 'Fontweight', 'Bold', 'Value', 0, 'Callback',@CB_ProjectImage);
%ROIs
%RoiVsMap# Plot/Image
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.72 0.13 0.24 0.04],...
'String', 'ROI vs Map # Plot', 'Fontweight', 'Bold', 'Value', 0, 'Tag','plotrois','Callback',@CB_plotROIvalues);
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.72 0.09 0.24 0.04],...
'String', 'ROI vs Map # Image', 'Fontweight', 'Bold', 'Value', 0, 'Callback',@CB_ROIvsMapImage);
% % uicontrol(tab,'Tag','saveplotdata', 'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.75 0.37 0.23 .04],...
% % 'String', 'Save Plot Data','FontWeight','Bold', 'Callback', @CBsavePlotData,'Enable','off'); %RoiVsRoi#
%RoiVsROI# Plot/Image
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.72 0.05 0.24 0.04],...
'String', 'ROI vs ROI # Plot', 'Fontweight', 'Bold', 'Value', 0, 'Tag','plotrois','Callback',@CB_plotROIvsROInum);
% % %Save MattStack - This is some junk for Isaac/Matt
% % uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.72 0.01 0.23 .04],...
% % 'String', 'Save MattStack','FontWeight','Bold', 'Callback', @CBsaveMattStack);
uicontrol(tab,'Style', 'pushbutton', 'Units', 'normalized', 'Position', [0.72 0.01 0.24 0.04],...
'String', 'OdorRespFile', 'Fontweight', 'Bold', 'Value', 0, 'Tag','tcr','Callback',@CB_ORfile);
%setup new figure for image
figshift = 0.02*(str2double(tab.Tag)-1);
pos=hMAP.Position;
figure('NumberTitle','off','Name',sprintf('Figure #%s',tab.Tag),'Tag',guiname,...
'Units','normalized','Position',[(pos(1)+pos(3))+figshift+0.001 ...
pos(2)+0.5*pos(4)-figshift 0.35 0.5*pos(4)],'WindowButtonDownFcn',@CBfigClick,'CloseRequestFcn',@CBcloseTab);
imagesc(zeros(512,796)); set(gca,'Tag','mapax','DataAspectRatio',[1 1 1],'DataAspectRatioMode','manual','Position',[.05 .15 .9 .75]);
val = cmapval;
colormap(gca,[cmapstrings{val} '(256)']);
axis image off;
end
if isfield(MapsData,'file') && ~isempty(MapsData.file)
if isfield(MapsData.file(1),'odor') && ~isempty(MapsData.file(1).odor(1))
CBsortAndSelect;
end
end
hMAP.UserData.MapsData = MapsData;
%%
%Nested Callback Functions
function CB_CloseFig(~,~)
%save settings from current tab
updateSettings;
save(fullfile(guipath,'MAsettings.mat'),'MAsettings');
clear MAsettings;
delete(hMAP);
delete(findobj('Tag',guiname));
end
function CBSaveSettings(~, ~)
updateSettings;
[setfile,setpath] = uiputfile(fullfile(guipath,'myMAsettings.mat'));
save(fullfile(setpath,setfile),'MAsettings');
end
function updateSettings
tab = findobj(hTabgroup,'Tag','1'); %tcrtcrtcr tab = hTabgroup.SelectedTab;
MAsettings.basetimes = [str2double(hBaseStart.String) str2double(hBaseEnd.String)];
MAsettings.resptimes = [str2double(hRespStart.String) str2double(hRespEnd.String)];
MAsettings.stim2use = stimstr{hAux.Value};
MAsettings.delaystr = hDelay.String; MAsettings.durstr = hDuration.String;
MAsettings.intstr = hInterval.String; MAsettings.trialstr = hTrials.String;
MAsettings.imtypeval = get(findobj(tab,'Tag','imagetype'),'Value');
MAsettings.fmaskstr = get(findobj(tab,'Tag','fmaskedit'),'String');
MAsettings.bgsubtractval = get(findobj(tab,'Tag','bgsubtract'),'Value');
MAsettings.bgroistr = get(findobj(tab,'Tag','bgroi'),'String');
MAsettings.avgtrialval = get(findobj(tab,'Tag','avgtrials'),'Value');
MAsettings.avgodorval = get(findobj(tab,'Tag','avgodors'),'Value');
MAsettings.avgfileval = get(findobj(tab,'Tag','avgfiles'),'Value');
MAsettings.sortval = get(findobj(tab,'Tag','sortbyodor'),'Value');
MAsettings.odorlistval = get(findobj(tab,'Tag','odorlist'),'Value');
MAsettings.odorlistfilestr = get(findobj(tab,'Tag','odorlistfile'),'String');
MAsettings.overlayval = get(findobj(tab,'Tag','overlay'),'Value');
MAsettings.cmapval = get(findobj(tab,'Tag','cmap_popupmenu'),'Value');
MAsettings.clim1val = get(findobj(tab,'Tag','clim1'),'Value');
MAsettings.clim2val = get(findobj(tab,'Tag','clim2'),'Value');
MAsettings.clim3val = get(findobj(tab,'Tag','clim3'),'Value');
MAsettings.cminstr = get(findobj(tab,'Tag','Cmin'),'String');
MAsettings.cmaxstr = get(findobj(tab,'Tag','Cmax'),'String');
MAsettings.loadfiltval = get(findobj(tab,'Tag','loadfilter'),'Value');
MAsettings.filtfilestr = get(findobj(tab,'Tag','filtfile'),'String');
MAsettings.lpfval = get(findobj(tab,'Tag','lpfilter'),'Value');
MAsettings.lpfstr = get(findobj(tab,'Tag','lpfilterparm'),'String');
MAsettings.hpfval = get(findobj(tab,'Tag','hpfilter'),'Value');
MAsettings.hpfstr = get(findobj(tab,'Tag','hpfilterparm'),'String');
MAsettings.cwfval = get(findobj(tab,'Tag','cwfilter'),'Value');
MAsettings.cwfstr = get(findobj(tab,'Tag','cweight'),'String');
MAsettings.supval = get(findobj(tab,'Tag','suppresshighpix'),'Value');
MAsettings.supstr = get(findobj(tab,'Tag','highpix'),'String');
MAsettings.lowval = get(findobj(tab,'Tag','lowthresh'),'Value');
MAsettings.lowstr = get(findobj(tab,'Tag','thresh'),'String');
MAsettings.mincutval = get(findobj(tab,'Tag','mincutoff'),'Value');
MAsettings.mincutstr = get(findobj(tab,'Tag','mincut'),'String');
MAsettings.maxcutval = get(findobj(tab,'Tag','maxcutoff'),'Value');
MAsettings.maxcutstr = get(findobj(tab,'Tag','maxcut'),'String');
MAsettings.bilinval = get(findobj(tab,'Tag','bilinear'),'Value');
end
function CBLoadSettings(~, ~)
[setfile,setpath] = uigetfile(fullfile(guipath,'*.mat'));
try
load(fullfile(setpath,setfile),'-mat','MAsettings');
tab = findobj(hTabgroup,'Tag','1'); %tcrtcrtcr tab = hTabgroup.SelectedTab;
if ~isfield(MapsData,'file') || isempty(MapsData.file)
%only apply these settings if there are no maps loaded
hBaseStart.String = num2str(MAsettings.basetimes(1));
hBaseEnd.String = num2str(MAsettings.basetimes(2));
if isfield(MapsData,'basetimes'); MapsData.basetimes = [str2double(baseStart.String) str2double(baseEnd.String)]; end
hRespStart.String = num2str(MAsettings.resptimes(1));
hRespEnd.String = num2str(MAsettings.resptimes(2));
if isfield(MapsData,'resptimes'); MapsData.resptimes = [str2double(respStart.String) str2double(respEnd.String)]; end
hAux.Value = find(strcmp(MAsettings.stim2use,stimstr));
if isfield(MapsData,'stim2use'); MapsData.stim2use = stimstr{hAux.Value}; end
hDelay.String = MAsettings.delaystr; hDuration.String = MAsettings.durstr;
hInterval.String = MAsettings.intstr; hTrials.String = MAsettings.trialstr;
if hAux.Value == 4; othervisible = 'on'; durvisible = 'on';
else; othervisible = 'off'; durvisible = 'off';
end
hDelay.Visible = othervisible; hDuration.Visible = durvisible;
hInterval.Visible = othervisible; hTrials.Visible = othervisible;
end
%if above change recompute maps!
set(findobj(tab,'Tag','imagetype'),'Value',MAsettings.imtypeval);
set(findobj(tab,'Tag','fmaskedit'),'String',MAsettings.fmaskstr);
set(findobj(tab,'Tag','bgsubtract'),'Value',MAsettings.bgsubtractval);
set(findobj(tab,'Tag','bgroi'),'String',MAsettings.bgroistr);
set(findobj(tab,'Tag','avgtrials'),'Value',MAsettings.avgtrialval);
set(findobj(tab,'Tag','avgodors'),'Value',MAsettings.avgodorval);
set(findobj(tab,'Tag','avgfiles'),'Value',MAsettings.avgfileval);
set(findobj(tab,'Tag','sortbyodor'),'Value',MAsettings.sortval);
set(findobj(tab,'Tag','odorlist'),'Value',MAsettings.odorlistval);
set(findobj(tab,'Tag','odorlistfile'),'String',MAsettings.odorlistfilestr);
set(findobj(tab,'Tag','overlay'),'Value',MAsettings.overlayval);
set(findobj(tab,'Tag','cmap_popupmenu'),'Value',MAsettings.cmapval);
set(findobj(tab,'Tag','clim1'),'Value',MAsettings.clim1val);
set(findobj(tab,'Tag','clim2'),'Value',MAsettings.clim2val);
set(findobj(tab,'Tag','clim3'),'Value',MAsettings.clim3val);
set(findobj(tab,'Tag','Cmin'),'String',MAsettings.cminstr);
set(findobj(tab,'Tag','Cmax'),'String',MAsettings.cmaxstr);
set(findobj(tab,'Tag','loadfilter'),'Value',MAsettings.loadfiltval);
set(findobj(tab,'Tag','filtfile'),'String',MAsettings.filtfilestr);
set(findobj(tab,'Tag','lpfilter'),'Value',MAsettings.lpfval);
set(findobj(tab,'Tag','lpfilterparm'),'String',MAsettings.lpfstr);
set(findobj(tab,'Tag','hpfilter'),'Value',MAsettings.hpfval);
set(findobj(tab,'Tag','hpfilterparm'),'String',MAsettings.hpfstr);
set(findobj(tab,'Tag','cwfilter'),'Value',MAsettings.cwfval);
set(findobj(tab,'Tag','cweight'),'String',MAsettings.cwfstr);
set(findobj(tab,'Tag','suppresshighpix'),'Value',MAsettings.supval);
set(findobj(tab,'Tag','highpix'),'String',MAsettings.supstr);
set(findobj(tab,'Tag','lowthresh'),'Value',MAsettings.lowval);
set(findobj(tab,'Tag','thresh'),'String',MAsettings.lowstr);
set(findobj(tab,'Tag','mincutoff'),'Value',MAsettings.mincutval);
set(findobj(tab,'Tag','mincut'),'String',MAsettings.mincutstr);
set(findobj(tab,'Tag','maxcutoff'),'Value',MAsettings.maxcutval);
set(findobj(tab,'Tag','maxcut'),'String',MAsettings.maxcutstr);
set(findobj(tab,'Tag','bilinear'),'Value',MAsettings.bilinval);
CBsortAndSelect;
catch
end
end
function CBfigClick(~,~)
plotfig = gcf;
idx = strfind(plotfig.Name,'#');
hTabgroup.SelectedTab = findobj(hTabgroup,'Tag',plotfig.Name(idx+1:end)); CBchangetabs;
end
function CBsliderClick(obj,~)
figure(obj.Parent);
CBfigClick;
CBsortAndSelect;
end
function CBcloseTab(plotfig,~)
idx = strfind(plotfig.Name,'#');
plotnum = str2double(plotfig.Name(idx+1:end));
delete(plotfig);
if numel(hTabgroup.Children)>2 %not the last tab...
delete(hTabgroup.Children(plotnum));
hTabgroup.SelectedTab = hTabgroup.Children(1); CBchangetabs;
for i = 1:numel(hTabgroup.Children)
if ~strcmp(hTabgroup.Children(i).Tag,num2str(i)) && ~strcmp(hTabgroup.Children(i).Title,'Add Figure')
tmpfig = findobj('type','figure','Name',sprintf('Figure #%s',hTabgroup.Children(i).Tag));
hTabgroup.Children(i).Tag = num2str(i);
hTabgroup.Children(i).Title = sprintf('Figure #%d',i);
tmpfig.Name = sprintf('Figure #%s',num2str(i));
end
end
else %last tab
CB_CloseFig;
end
end
function CBodorSelect(obj,~)
tmplist = cell(numel(obj.String),1);
for i = 1:numel(obj.String)
ind1 = strfind(obj.String{i},'Odor');
ind2 = strfind(obj.String{i},'Trial');
tmplist{i} = obj.String{i}(ind1:ind2-1);
end
ind = obj.Value;
match = [];
for i = 1:length(ind)
ind1 = strfind(obj.String{ind(i)},'Odor');
ind2 = strfind(obj.String{ind(i)},'Trial');
tmpmatch = find(cellfun(@(X)strcmp(obj.String{ind(i)}(ind1:ind2-1),X),tmplist));
match = union(match,tmpmatch);
end
obj.Value = match;
CBsortAndSelect;
end
function CBaddFiles(~,~) %add image file(s) to list
% get data type if unknown
if isempty(MapsData.file) || ~isfield(MapsData.file(1),'type') || isempty(MapsData.file(1).type)
[typeval,ok]= listdlg('SelectionMode','single','PromptString','Select Data Type','SelectionMode','single','ListString',...
typestr);
if ok == 0
return;
end
MapsData.file(1).type = typestr{typeval};
end
%get pathname & filenames
if isfield(MapsData.file(1),'dir') && ~isempty(MapsData.file(1).dir); pathname = MapsData.file(1).dir;
elseif exist('oldpath','var'); pathname = oldpath; else; pathname = '';
end
switch MapsData.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');
MapsData.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(MapsData.file,'name') && ~isempty(MapsData.file(end).name)
cnt = length(MapsData.file);
imsize = MapsData.file(1).size;
else
cnt = 0;
if ischar(filename)
[imsize(1),imsize(2)] = getImageSize(MapsData.file(1).type,fullfile(pathname,filename));
else
[imsize(1),imsize(2)] = getImageSize(MapsData.file(1).type,fullfile(pathname,filename{1}));
end
end
if ischar(filename) %only adding 1 file
if cnt>0
[tmpsize(1),tmpsize(2)] = getImageSize(MapsData.file(1).type,fullfile(pathname,filename));
if ~isequal(imsize,tmpsize)
errordlg('File sizes do not match');
return;
end
end
numChannels = getNumChannels(MapsData.file(1).type,fullfile(pathname,filename));
if numChannels == 1
MapsData.file(cnt+1).name = filename;
MapsData.file(cnt+1).dir = pathname;
MapsData.file(cnt+1).type = MapsData.file(1).type; %tcrtcr currently limit all files to same type
MapsData.file(cnt+1).size = imsize;
%MapsData.file(cnt+1).numChannels = 1;
else %two channels
MapsData.file(cnt+1).name = filename; MapsData.file(cnt+2).name = filename;
MapsData.file(cnt+1).dir = pathname; MapsData.file(cnt+2).dir = pathname;
MapsData.file(cnt+1).type = MapsData.file(1).type; %tcrtcr currently limit all files to same type
MapsData.file(cnt+2).type = MapsData.file(1).type;
MapsData.file(cnt+1).size = imsize; MapsData.file(cnt+2).size = imsize;
%MapsData.file(cnt+1).numChannels = 2; MapsData.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 i = m1:length(filename) %check image size matches
[tmpsize(1),tmpsize(2)] = getImageSize(MapsData.file(1).type,fullfile(pathname,filename{i}));
if ~isequal(imsize,tmpsize)
errordlg('File sizes do not match');
return;
end
end
new = 0;
for i = 1:length(filename) %add the images
numChannels = getNumChannels(MapsData.file(1).type,fullfile(pathname,filename{1}));
if numChannels == 1
new = new+1;
MapsData.file(cnt+new).name = filename{i};
MapsData.file(cnt+new).dir = pathname;
MapsData.file(cnt+new).type = MapsData.file(1).type; %tcrtcr currently limit all files to same type
MapsData.file(cnt+new).size = imsize;
%MapsData.file(cnt+new).numChannels = 1;
else
new = new+2;
MapsData.file(cnt+new-1).name = filename{i}; MapsData.file(cnt+new).name = filename{i};
MapsData.file(cnt+new-1).dir = pathname; MapsData.file(cnt+new).dir = pathname;
MapsData.file(cnt+new-1).type = MapsData.file(1).type; %tcrtcr currently limit all files to same type
MapsData.file(cnt+new).type = MapsData.file(1).type;
MapsData.file(cnt+new-1).size = imsize; MapsData.file(cnt+new).size = imsize;
%MapsData.file(cnt+new-1).numChannels = 2; MapsData.file(cnt+new).numChannels = 2;
end
end
end
if ~isempty(MapsData.file(end).dir); oldpath = MapsData.file(end).dir; end
%in case ROIs were loaded, check roi size matches image size
if isfield(MapsData,'roi') && ~isempty(MapsData.roi)
if ~isequal(imsize,size(MapsData.roi(1).mask))
MapsData.roi = []; % Existing ROIs size does not match loaded images; delete ROIs.
end
end
%compute maps
if isfield(MapsData,'file') && ~isempty(MapsData.file(1).name)
tmpbar = waitbar(0,'Loading Files & Making Maps');
for n = cnt+1:length(MapsData.file)
waitbar(n/length(MapsData.file),tmpbar);
skipch2 = [];
if n>1; skipch2 = strfind(MapsData.file(n).name,'_ch2'); end
if isempty(skipch2)
loadFileComputeMaps(n);
end
end
close(tmpbar);
end
hMAP.UserData.MapsData = MapsData;
CBsortAndSelect;
end
function CBDeleteFile(~,keydata)
if strcmp(keydata.Key,'delete'); CBclearFiles; end
end
function CBclearFiles(~,~) %clear selected files and related timeseries
selectedfiles = get(findobj(hMAP,'Tag','FILE_listbox'),'Value');
keep = setdiff(1:length(MapsData.file),selectedfiles);
MapsData.file = MapsData.file(keep);
set(findobj(hMAP,'Tag','FILE_listbox'),'Value',1);
hMAP.UserData.MapsData = MapsData;
CBsortAndSelect;
end
function CBDeleteOdorTrial(~,keydata)
if ~strcmp(keydata.Key,'delete') || ~isfield(MapsData,'file') || isempty(MapsData.file); return; end
check = questdlg('Are you sure you want to delete the selected OdorTrials?','Ask before deleting','Yes','No','Yes');
if strcmp(check,'No'); return; end
tab = hTabgroup.SelectedTab;
files = get(findobj(tab,'Tag','FILE_listbox'),'Value');
odortrials = get(findobj(tab,'Tag','OdorTrial_listbox'),'Value');
cnt = 0; filesremoved = [];
for f = 1:length(files)
numodors = length(MapsData.file(files(f)).odor);
odorsremoved = [];
for o = 1:numodors
nTrials = length(MapsData.file(files(f)).odor(o).trial);
trialsremoved = [];
for t = 1:nTrials
cnt = cnt+1;
if max(cnt==odortrials)
trialsremoved = [trialsremoved o];
end
end
MapsData.file(files(f)).odor(o).trial = MapsData.file(files(f)).odor(o).trial(setdiff(1:nTrials,trialsremoved));
MapsData.file(files(f)).odor(o).trials = MapsData.file(files(f)).odor(o).trials(setdiff(1:nTrials,trialsremoved));
if isempty(MapsData.file(files(f)).odor(o).trial); odorsremoved = [odorsremoved o]; end
end
MapsData.file(files(f)).odor = MapsData.file(files(f)).odor(setdiff(1:numodors,odorsremoved));
MapsData.file(files(f)).odors = MapsData.file(files(f)).odors(setdiff(1:numodors,odorsremoved));
if isempty(MapsData.file(files(f)).odor); filesremoved = [filesremoved files(f)]; end
end
MapsData.file = MapsData.file(setdiff(1:length(MapsData.file),filesremoved));
hMAP.UserData.MapsData = MapsData;
CBsortAndSelect;
end
function CBloadMapsData(~,~)
[tmpfile, tmppath, ok] = uigetfile('*.mat', 'Open MapsData file');
if ~ok; return; end
MapsData = [];
load(fullfile(tmppath,tmpfile),'MapsData');
if strcmp(MapsData.stim2use,'AuxCombo'); MapsData.stim2use = stimstr{3}; end %this updates aux names for older saved MapsData
if strcmp(MapsData.stim2use,'Manually Defined Stimulus'); MapsData.stim2use = stimstr{4}; end
%set mapsdata specifications
hBaseStart.String = MapsData.basetimes(1); hBaseEnd.String = MapsData.basetimes(2);
hRespStart.String = MapsData.resptimes(1); hRespEnd.String = MapsData.resptimes(2);
hAux.Value = find(strcmp(MapsData.stim2use,stimstr));
if hAux.Value == 3 && isfield(MapsData,'odorDuration')
hDuration.String = num2str(MapsData.odorDuration); hDuration.Visible = 'on';
elseif hAux.Value == 4 && isfield(MapsData,'def_stimulus')
hDelay.String = num2str(MapsData.def_stimulus.delay); hDuration.String = num2str(MapsData.def_stimulus.duration);
hInterval.String = num2str(MapsData.def_stimulus.interval); hTrials.String = num2str(MapsData.def_stimulus.trials);
else
hDelay.Visible = 'off'; hDuration.Visible = 'off';
hDuration.Visible = 'off'; hTrials.Visible = 'off';
end
hMAP.UserData.MapsData = MapsData;
tab = hTabgroup.SelectedTab; set(findobj(tab,'Tag','FILE_listbox'),'Value',1);
CBsortAndSelect;
end
function CBsaveMapsData(~,~)
tab = hTabgroup.SelectedTab;
selected = get(findobj(tab,'Tag','FILE_listbox'),'Value');
[tmpfile, tmppath, ok] = uiputfile(fullfile(MapsData.file(selected(1)).dir,'MapsData.mat'), 'Save MapsData file');
if ~ok; return; end
m = matfile(fullfile(tmppath,tmpfile),'Writable',true);
m.MapsData = MapsData;
%save(fullfile(tmppath,tmpfile),'MapsData','-mat'); %This does not work as expected!!
disp('MapsData Saved');
end
function CBaddROIs(~,~) %load/add ROIs and compute timeseries
if isempty(MapsData.file); return; end
tab = hTabgroup.SelectedTab;
selectedfiles = get(findobj(tab,'Tag','FILE_listbox'),'Value');
newrois = loadROIs(MapsData.file(selectedfiles(1)).dir);
if ~isempty(newrois)
if isfield(MapsData,'file') && ~isempty(MapsData.file(1).name)
imsize = MapsData.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(MapsData,'roi') && ~isempty(MapsData.roi)
if ~isequal(size(MapsData.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(MapsData,'roi') && ~isempty(MapsData.roi)
cnt = length(MapsData.roi);
else; cnt = 0;
end
for rr = 1:length(newrois)
MapsData.roi(cnt+rr).mask = newrois(rr).mask;
end
hMAP.UserData.MapsData = MapsData;
CBsortAndSelect;
end
clear newrois;
end
function CBdrawROIs(~, ~) %draw your own ROI, add to list
if isempty(MapsData.file); return; end
tab = hTabgroup.SelectedTab;
tmpfig = findobj('type','figure','Name',sprintf('Figure #%s',tab.Tag)); figure(tmpfig);
mapax = findobj(tmpfig,'Tag','mapax');
if isempty(mapax); return; end
if numel(mapax)>1; mapax=mapax(end); end
cmap = colormap(mapax);
tmpclim = get(mapax, 'Clim');
if ~isfield(MapsData,'roi'); MapsData.roi = []; end
bgimage = get(mapax.Children(end),'CData');
[MapsData.roi] = drawROI_refine(MapsData.roi,bgimage,bgimage,cmap,tmpclim);
hMAP.UserData.MapsData = MapsData;
CBsortAndSelect;
end
function CBshiftROIs(~, ~) %move selected ROIs
if isempty(hMAP.UserData.MapsData.file) || ~isfield(hMAP.UserData.MapsData,'roi') ...
|| isempty(hMAP.UserData.MapsData.roi)
return;
end
colshift = inputdlg('Shift to the right (pixels)', 'Column Shift', 1, {'0.0'});