-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFCSFit.m
executable file
·2959 lines (2859 loc) · 123 KB
/
FCSFit.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 FCSFit(~,~)
global UserValues FCSData FCSMeta PathToApp
h.FCSFit=findobj('Tag','FCSFit');
addpath(genpath(['.' filesep 'functions']));
if isempty(PathToApp)
GetAppFolder();
end
if isempty(h.FCSFit) % Creates new figure, if none exists
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Figure generation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Disables uitabgroup warning
warning('off','MATLAB:uitabgroup:OldVersion');
%%% Loads user profile
[~,~]=LSUserValues(0);
%%% To save typing
Look=UserValues.Look;
%%% Generates the FCSFit figure
h.FCSFit = figure(...
'Units','normalized',...
'Tag','FCSFit',...
'Name','FCSFit',...
'NumberTitle','off',...
'Menu','none',...
'defaultUicontrolFontName',Look.Font,...
'defaultAxesFontName',Look.Font,...
'defaultTextFontName',Look.Font,...
'Toolbar','figure',...
'UserData',[],...
'OuterPosition',[0.01 0.1 0.98 0.9],...
'CloseRequestFcn',@CloseWindow,...
'Visible','on');
%h.FCSFit.Visible='off';
%%% Remove unneeded items from toolbar
toolbar = findall(h.FCSFit,'Type','uitoolbar');
toolbar_items = findall(toolbar);
if verLessThan('matlab','9.5') %%% toolbar behavior changed in MATLAB 2018b
delete(toolbar_items([2:7 9 13:17]));
else %%% 2018b and upward
%%% just remove the tool bar since the options are now in the axis
%%% (e.g. axis zoom etc)
delete(toolbar_items);
end
%%% Sets background of axes and other things
whitebg(Look.Axes);
%%% Changes Pam background; must be called after whitebg
h.FCSFit.Color=Look.Back;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Menubar %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% File menu with loading, saving and exporting functions
h.File = uimenu(...
'Parent',h.FCSFit,...
'Tag','File',...
'Label','File');
%%% Menu to load new Cor file
h.LoadCor = uimenu(h.File,...
'Tag','LoadCor',...
'Label','Load New Files',...
'Callback',{@Load_Cor,1});
%%% Menu to add Cor files to existing
h.AddCor = uimenu(h.File,...
'Tag','AddCor',...
'Label','Add Files',...
'Callback',{@Load_Cor,2});
%%% Menu to load fit function
h.LoadFit = uimenu(h.File,...
'Tag','LoadFit',...
'Label','Load Fit Function',...
'Callback',{@Load_Fit,1});
%%% Menu to load fit function
h.LoadSession = uimenu(h.File,...
'Tag','LoadSession',...
'Label','Load FCSFit Session',...
'Separator','on',...
'Callback',@LoadSave_Session);
h.SaveSession = uimenu(h.File,...
'Tag','SaveSession',...
'Label','Save FCSFit Session',...
'Callback',@LoadSave_Session);
%%% Menu to merge loaded Cor files
h.MergeCor = uimenu(h.File,...
'Tag','MergeCor',...
'Label','Merge Loaded Cor Files',...
'Separator','on',...
'Callback',@Merge_Cor);
%%% File menu to stop fitting
h.AbortFit = uimenu(...
'Parent',h.FCSFit,...
'Tag','AbortFit',...
'Label',' Stop....');
h.StopFit = uimenu(...
'Parent',h.AbortFit,...
'Tag','StopFit',...
'Label','...Fit',...
'Callback',@Stop_FCSFit);
%%% File menu for fitting
h.StartFit = uimenu(...
'Parent',h.FCSFit,...
'Tag','StartFit',...
'Label','Start...');
h.DoFit = uimenu(...
'Parent',h.StartFit,...
'Tag','Fit',...
'Label','...Fit',...
'Callback',@Do_FCSFit);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Fitting parameters Tab %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h.FitParams_Tab = uitabgroup(...
'Parent',h.FCSFit,...
'Tag','FitParams_Tab',...
'Units','normalized',...
'Position',[0.005 0.01 0.99 0.24]);
%% Fit function tab %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Tab for fit function inputs
h.Fit_Function_Tab= uitab(...
'Parent',h.FitParams_Tab,...
'Tag','Fit_Function_Tab',...
'Title','Fit');
%%% Panel for fit function inputs
h.Fit_Function_Panel = uibuttongroup(...
'Parent',h.Fit_Function_Tab,...
'Tag','Fit_Function_Panel',...
'Units','normalized',...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HighlightColor', Look.Control,...
'ShadowColor', Look.Shadow,...
'Position',[0 0 1 1]);
%%% Fitting table
h.Fit_Table = uitable(...
'Parent',h.Fit_Function_Panel,...
'Tag','Fit_Table',...
'Units','normalized',...
'ForegroundColor',Look.TableFore,...
'BackgroundColor',[Look.Table1;Look.Table2],...
'FontSize',10,...
'Position',[0 0 1 1],...
'CellEditCallback',{@Update_Table,3},...
'CellSelectionCallback',{@Update_Table,3});
h.Fit_Table_Menu = uicontextmenu;
h.Fit_Table.UIContextMenu = h.Fit_Table_Menu;
%%% Button for exporting excel sheet of results
h.Export_Clipboard = uimenu(...
'Parent',h.Fit_Table_Menu,...
'Label','Copy Results to Clipboard',...
'Callback',{@Plot_Menu_Callback,4});
%% Settings tab %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Tab for fit settings
h.Setting_Tab= uitab(...
'Parent',h.FitParams_Tab,...
'Tag','Setting_Tab',...
'Title','Settings');
%%% Panel for fit settings
h.Setting_Panel = uibuttongroup(...
'Parent',h.Setting_Tab,...
'Tag','Setting_Panel',...
'Units','normalized',...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HighlightColor', Look.Control,...
'ShadowColor', Look.Shadow,...
'Position',[0 0 1 1]);
%%% Text
uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Setting_Panel',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','Borders [s]:',...
'Position',[0.002 0.88 0.06 0.1]);
%%% Minimum and maximum for fitting and plotting
h.Fit_Min = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Setting_Panel',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','edit',...
'String',num2str(UserValues.FCSFit.Fit_Min),...
'Callback',@Update_Plots,...
'Position',[0.066 0.88 0.04 0.1]);
h.Fit_Max = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Setting_Panel',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','edit',...
'String',num2str(UserValues.FCSFit.Fit_Max),...
'Callback',@Update_Plots,...
'Position',[0.11 0.88 0.04 0.1]);
%%% Checkbox to toggle using weights
h.Fit_Weights = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Fit_Weights',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'Style','checkbox',...
'String','Use weights',...
'Value',UserValues.FCSFit.Use_Weights,...
'Callback',@Update_Plots,...
'Position',[0.002 0.76 0.1 0.1]);
%%% Checkbox to toggle errorbar plotting
h.Fit_Errorbars = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Fit_Errorbars',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'Style','checkbox',...
'String','Plot errorbars',...
'Value',UserValues.FCSFit.Plot_Errorbars,...
'Callback',@Update_Plots,...
'Position',[0.002 0.64 0.1 0.1]);
%%% Text
h.Norm_Text = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Setting_Panel',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','Normalization:',...
'Position',[0.002 0.51 0.08 0.1]);
%%% Popupmenu to choose normalization method
h.Normalize = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Normalize',...
'Units','normalized',...
'FontSize',10,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','popupmenu',...
'String',{'None';'Fit N 3D';'Fit minus offset';'Fit G(0)';'Fit N 2D'; 'Time';'Fit N 3D minus offset';'Fit N 3D * brightness';'Time minus offset'},...
'Value',UserValues.FCSFit.NormalizationMethod,...
'Callback',@Update_Plots,...
'Position',[0.082 0.52 0.06 0.1]);
%%% Editbox to set time used for normalization
h.Norm_Time = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Normalize',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','edit',...
'String','1e-6',...
'Visible','off',...
'Callback',@Update_Plots,...
'Position',[0.145 0.51 0.04 0.1]);
%%% Editbox for binning for FRET histograms
h.FRETbin_Text = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Setting_Panel',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','FRET bin width:',...
'Position',[0.002 0.51 0.08 0.1],...
'Visible','off');
%%% Popupmenu to choose normalization method
h.FRETbin = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Normalize',...
'Units','normalized',...
'FontSize',10,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','edit',...
'String',num2str(UserValues.FCSFit.FRETbin),...
'Callback',@rebinFRETdata,...
'Position',[0.082 0.52 0.06 0.1],...
'Visible','off');
%%% Checkbox to toggle confidence interval calculation
h.Conf_Interval = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'Style','checkbox',...
'String','Calculate confidence intervals',...
'Value',UserValues.FCSFit.Conf_Interval,...
'Callback',@Update_Plots,...
'Position',[0.002 0.37 0.2 0.1]);
%%% Popupmenu to choose confidence interval determination method
h.Conf_Interval_Method = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Conf_Interval_Method',...
'Units','normalized',...
'FontSize',10,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','popupmenu',...
'String',{'Jacobian';'Metropolis-Hastings Sampling'},...
'Value',1,...
'Callback',[],...
'Position',[0.082 0.23 0.06 0.1]);
%%% Text
uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Setting_Panel',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','Method:',...
'Position',[0.002 0.22 0.08 0.1]);
%%% Checkbox to toggle confidence interval calculation
h.Hide_Legend = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'Style','checkbox',...
'String','Hide Legend',...
'Value',UserValues.FCSFit.Hide_Legend,...
'Callback',@Update_Plots,...
'Position',[0.002 0.09 0.2 0.1]);
%%% Optimization settings
uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','Max interations:',...
'Position',[0.2 0.88 0.08 0.1]);
h.Iterations = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Iterations',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','edit',...
'String',num2str(UserValues.FCSFit.Max_Iterations),...
'Position',[0.285 0.88 0.04 0.1]);
uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','Tolerance:',...
'Position',[0.2 0.76 0.08 0.1]);
h.Tolerance = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Tolerance',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','edit',...
'String',num2str(UserValues.FCSFit.Fit_Tolerance),...
'Position',[0.285 0.76 0.04 0.1]);
%%% Textbox containing optimization termination output
h.Termination = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Termination',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','',...
'Position',[0.2 0.01 0.14 0.75]);
%%% Textbox containing the name of the current fit model
h.Loaded_Model_Name = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Loaded_Model',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','',...
'Position',[0.35 0.62 0.24 0.36]);
h.Loaded_Model_Description = uicontrol(...
'Parent',h.Setting_Panel,...
'Tag','Loaded_Model',...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','',...
'Position',[0.35 0.01 0.65 0.61]);
%%% Text for export size
uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','text',...
'String','Export size (X; Cor Y; Residuals Y) [pixels]:',...
'Position',[0.6 0.88 0.23 0.1]);
%%% Editbox for export size in X
h.Export_XSize = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','edit',...
'String',UserValues.FCSFit.Export_X,...
'Callback', @(src,event) LSUserValues(1,src,{'String','FCSFit','Export_X'}),...
'Position',[0.83 0.88 0.04 0.1]);
%%% Editbox for export size in Y for correlation
h.Export_YSize = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','edit',...
'String',UserValues.FCSFit.Export_Y,...
'Callback', @(src,event) LSUserValues(1,src,{'String','FCSFit','Export_Y'}),...
'Position',[0.875 0.88 0.04 0.1]);
%%% Editbox for export size in Y for residuals
h.Export_YSizeRes = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'Style','edit',...
'String',UserValues.FCSFit.Export_Res,...
'Callback', @(src,event) LSUserValues(1,src,{'String','FCSFit','Export_Res'}),...
'Position',[0.92 0.88 0.04 0.1]);
%%% Editbox for font name
h.Export_Font = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Control,...
'ForegroundColor', Look.Fore,...
'HorizontalAlignment','left',...
'Style','push',...
'Callback',@Misc,...
'String',UserValues.FCSFit.Export_Font.FontString,...
'UserData',UserValues.FCSFit.Export_Font,...
'Position',[0.6 0.75 0.36 0.1]);
%%% Checkbox for grid lines
h.Export_Grid = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'Value',UserValues.FCSFit.Export_Grid,...
'Callback', @(src,event) LSUserValues(1,src,{'Value','FCSFit','Export_Grid'}),...
'Style','checkbox',...
'String','Grid',...
'Position',[0.6 0.62 0.04 0.1]);
%%% Checkbox for minor grid lines
h.Export_MinorGrid = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'Value',UserValues.FCSFit.Export_GridM,...
'Callback', @(src,event) LSUserValues(1,src,{'Value','FCSFit','Export_GridM'}),...
'Style','checkbox',...
'String','Minor Grid',...
'Position',[0.65 0.62 0.09 0.1]);
%%% Checkbox for box
h.Export_Box = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'Value',UserValues.FCSFit.Export_Box,...
'Callback', @(src,event) LSUserValues(1,src,{'Value','FCSFit','Export_Box'}),...
'Style','checkbox',...
'String','Box',...
'Position',[0.735 0.62 0.04 0.1]);
%%% Checkbox for fit legend entry
h.Export_FitsLegend = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'Value',UserValues.FCSFit.Export_Legend,...
'Callback', @(src,event) LSUserValues(1,src,{'Value','FCSFit','Export_Legend'}),...
'Style','checkbox',...
'String','Fits in legend',...
'Position',[0.78 0.62 0.15 0.1]);
%%% Checkbox for show residuals entry
h.Export_Residuals = uicontrol(...
'Parent',h.Setting_Panel,...
'Units','normalized',...
'FontSize',12,...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'Value',UserValues.FCSFit.Export_Residuals,...
'Callback', @(src,event) LSUserValues(1,src,{'Value','FCSFit','Export_Residuals'}),...
'Style','checkbox',...
'String','Plot residuals',...
'Position',[0.88 0.62 0.15 0.1]);
%% Plotting style tab %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Tab for fit function inputs
h.Style_Tab= uitab(...
'Parent',h.FitParams_Tab,...
'Tag','Style_Tab',...
'Title','Plotting style');
%%% Panel for fit function inputs
h.Style_Panel = uibuttongroup(...
'Parent',h.Style_Tab,...
'Tag','Style_Panel',...
'Units','normalized',...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HighlightColor', Look.Control,...
'ShadowColor', Look.Shadow,...
'Position',[0 0 1 1]);
%%% Fitting table
h.Style_Table_Menu = uicontextmenu;
h.Style_Table_Autocolor = uimenu('Parent',h.Style_Table_Menu,'Label','Autocolor',...
'Callback',{@Update_Style,3});
h.Style_Table_Rainbow = uimenu('Parent',h.Style_Table_Menu,'Label','Use Rainbow',...
'Callback',{@Update_Style,3});
h.Style_Table = uitable(...
'Parent',h.Style_Panel,...
'Tag','Fit_Table',...
'Units','normalized',...
'ForegroundColor',Look.TableFore,...
'BackgroundColor',[Look.Table1;Look.Table2],...
'FontSize',8,...
'Position',[0 0 1 1],...
'CellEditCallback',{@Update_Style,2},...
'CellSelectionCallback',{@Update_Style,2},...
'UIContextMenu',h.Style_Table_Menu);
%% File History tab %%%%%%%%%%%%%%%%
h.Fit_Function_Tab= uitab(...
'Parent',h.FitParams_Tab,...
'Tag','Fit_Function_Tab',...
'Title','File History');
h.FileHistory = FileHistory(h.Fit_Function_Tab,'FCSFit',@(x) Load_Cor('FileHistory',[],1,x));
%% Main Plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Panel for fit plots
h.Fit_Plots_Panel = uibuttongroup(...
'Parent',h.FCSFit,...
'Tag','Fit_Plots_Panel',...
'Units','normalized',...
'BackgroundColor', Look.Back,...
'ForegroundColor', Look.Fore,...
'HighlightColor', Look.Control,...
'ShadowColor', Look.Shadow,...
'Position',[0.005 0.26 0.99 0.73]);
%%% Context menu for FCS plots
h.FCS_Plot_Menu = uicontextmenu;
h.FCS_Plot_XLog = uimenu(...
'Parent',h.FCS_Plot_Menu,...
'Label','X Log',...
'Tag','FCS_Plot_XLog',...
'Checked','on',...
'Callback',{@Plot_Menu_Callback,1});
h.FCS_Plot_Export2Fig = uimenu(...
'Parent',h.FCS_Plot_Menu,...
'Label','Export to figure',...
'Checked','off',...
'Tag','FCS_Plot_Export2Fig',...
'Callback',{@Plot_Menu_Callback,2});
h.FCS_Plot_Export2Base = uimenu(...
'Parent',h.FCS_Plot_Menu,...
'Label','Export to workspace',...
'Checked','off',...
'Tag','FCS_Plot_Export2Base',...
'Callback',{@Plot_Menu_Callback,3});
%%% Main axes for fcs plots
h.FCS_Axes = axes(...
'Parent',h.Fit_Plots_Panel,...
'Tag','Fit_Axes',...
'Units','normalized',...
'FontSize',12,...
'NextPlot','add',...
'XColor',Look.Fore,...
'YColor',Look.Fore,...
'XScale','log',...
'XLim',[10^-7,1],...
'LineWidth', Look.AxWidth,...
'YColor',Look.Fore,...
'UIContextMenu',h.FCS_Plot_Menu,...
'Position',[0.06 0.28 0.93 0.7],...
'Box','off');
h.FCS_Axes.XLabel.String = 'time lag {\it\tau{}} [s]';
h.FCS_Axes.XLabel.Color = Look.Fore;
h.FCS_Axes.YLabel.String = 'G({\it\tau{}})';
h.FCS_Axes.YLabel.Color = Look.Fore;
%%% Axes for fcs residuals
h.Residuals_Axes = axes(...
'Parent',h.Fit_Plots_Panel,...
'Tag','Residuals_Axes',...
'Units','normalized',...
'FontSize',12,...
'NextPlot','add',...
'XColor',Look.Fore,...
'YColor',Look.Fore,...
'LineWidth', Look.AxWidth,...
'XScale','log',...
'XAxisLocation','top',...
'YColor',Look.Fore,...
'Position',[0.06 0.02 0.93 0.18],...
'Box','off',...
'YGrid','on',...
'XGrid','on');
h.Residuals_Axes.GridColorMode = 'manual';
h.Residuals_Axes.GridColor = [0 0 0];
h.Residuals_Axes.XTickLabel=[];
h.Residuals_Axes.YLabel.String = 'weighted residuals';
h.Residuals_Axes.YLabel.Color = Look.Fore;
linkaxes([h.FCS_Axes h.Residuals_Axes],'x');
%% Mac upscaling of Font Sizes
if ismac
scale_factor = 1.2;
fields = fieldnames(h); %%% loop through h structure
for i = 1:numel(fields)
if isprop(h.(fields{i}),'FontSize')
h.(fields{i}).FontSize = (h.(fields{i}).FontSize)*scale_factor;
end
if isprop(h.(fields{i}),'Style')
if strcmp(h.(fields{i}).Style,'popupmenu')
h.(fields{i}).BackgroundColor = [1 1 1];
h.(fields{i}).ForegroundColor = [0 0 0];
end
end
end
end
%% Initializes global variables %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FCSData=[];
FCSData.Data=[];
FCSData.FileName=[];
FCSMeta=[];
FCSMeta.Data=[];
FCSMeta.Params=[];
FCSMeta.Confidence_Intervals = cell(1,1);
FCSMeta.Plots=cell(0);
FCSMeta.Model=[];
FCSMeta.Fits=[];
FCSMeta.Color=[1 1 0; 0 0 1; 1 0 0; 0 0.5 0; 1 0 1; 0 1 1];
FCSMeta.FitInProgress = 0;
FCSMeta.DataType = 'FCS averaged';
h.CurrentGui = 'FCS';
guidata(h.FCSFit,h);
Load_Fit([],[],0);
Update_Style([],[],0)
else
figure(h.FCSFit); % Gives focus to Pam figure
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Function to load .cor files %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Load_Cor(~,~,mode,filenames)
global UserValues FCSData FCSMeta
h = guidata(findobj('Tag','FCSFit'));
if nargin > 3 %%% called from file history
%%% only implemented for loading of *.mcor files at the moment, remove
%%% all other files
Type = 1;
%%% split filenames into FileName and pathname
for i = 1:numel(filenames)
[PathName{i},FileName{i},ext] = fileparts(filenames{i});
FileName{i} = [FileName{i} ext];
end
else
%%% there is an issue with selecting multiple files on MacOS Catalina,
%%% where only the first filter (.mcor) works, and no other file types
%%% can be selected.
%%% As a workaround, we avoid using the system file selection for now.
%%% 11/2019
if ~ismac | ~(ismac & strcmp(get_macos_version(),'10.15'))
%%% Choose files to load
[FileName,path,Type] = uigetfile({'*.mcor','Averaged correlation based on matlab filetype (*.mcor)';...
'*.cor','Averaged correlation based on text filetype (*.cor)';...
'*.mcor','Individual correlation curves based on matlab filetype (*.mcor)';...
'*.cor','Individual correlation curves based on text filetype (*.cor)';...
'*.his','FRET efficiency data from BurstBrowser (*.his)';...
'*.fcs','FCS Files from Zeiss ZEN software (*.fcs) - Averaged';...
'*.fcs','FCS Files from Zeiss ZEN software (*.fcs) - Individual Curves';...
'*.cor','FCS Files from Kistine Software (Seidel lab) (*.cor)'},...
'Choose FCS data files',...
UserValues.File.FCSPath,...
'MultiSelect', 'on');
else
%%% use workaround
%%% Choose files to load
[FileName, path, Type] = uigetfile_with_preview({'*.mcor','Averaged correlation based on matlab filetype (*.mcor)';...
'*.cor','Averaged correlation based on text filetype (*.cor)';...
'*.mcor','Individual correlation curves based on matlab filetype (*.mcor)';...
'*.cor','Individual correlation curves based on text filetype (*.cor)';...
'*.his','FRET efficiency data from BurstBrowser (*.his)';...
'*.fcs','FCS Files from Zeiss ZEN software (*.fcs) - Averaged';...
'*.fcs','FCS Files from Zeiss ZEN software (*.fcs) - Individual Curves';...
'*.cor','FCS Files from Kistine Software (Seidel lab) (*.cor)'},...
'Choose FCS data files',...
UserValues.File.FCSPath,...
'',... % empty callback
true); % Multiselect on
end
%%% Tranforms to cell array, if only one file was selected
if ~iscell(FileName)
FileName = {FileName};
end
%%% assign path to each filename
for i = 1:numel(FileName)
PathName{i} = path;
end
end
%%% Only esecutes, if at least one file was selected
if all(FileName{1}==0)
return
end
%%% Saves pathname to uservalues
UserValues.File.FCSPath=PathName{1};
LSUserValues(1);
%%% Deletes loaded data
if mode==1
FCSData=[];
FCSData.Data=[];
FCSData.FileName=[];
cellfun(@delete,FCSMeta.Plots);
FCSMeta.Data=[];
FCSMeta.Params=[];
FCSMeta.Plots=cell(0);
%h.Fit_Table.RowName(1:end-3)=[];
h.Fit_Table.Data(1:end-3,:)=[];
h.Style_Table.RowName(1:end-1,:)=[];
h.Style_Table.Data(1:end-1,:)=[];
end
switch Type
case {1,2} %%% Averaged correlation files
FCSMeta.DataType = 'FCS averaged';
for i=1:numel(FileName)
%%% Reads files (1 == .mcor; 2 == .cor)
if Type == 1
FCSData.Data{end+1} = load(fullfile(PathName{i},FileName{i}),'-mat');
%%% add file to file history
h.FileHistory.add_file(fullfile(PathName{i},FileName{i}));
else
FID = fopen(fullfile(PathName{i},FileName{i}));
Text = textscan(FID,'%s', 'delimiter', '\n','whitespace', '');
Text = Text{1};
Data.Header = Text{1};
Data.Valid = str2num(Text{find(~cellfun(@isempty,strfind(Text,'Valid bins:')),1)}(12:end)); %#ok<ST2NM>
Data.Counts(1) = str2num(Text{find(~cellfun(@isempty,strfind(Text,'Count rate channel 1 [kHz]:')),1)}(28:end)); %#ok<ST2NM>
Data.Counts(2) = str2num(Text{find(~cellfun(@isempty,strfind(Text,'Count rate channel 2 [kHz]:')),1)}(28:end)); %#ok<ST2NM>
Start = find(~cellfun(@isempty,strfind(Text,'Data starts here:')),1);
Values = zeros(numel(Text)-Start,numel(Data.Valid)+3);
k=1;
for j = Start+1:numel(Text)
Values(k,:) = str2num(Text{j}); %#ok<ST2NM>
k = k+1;
end
Data.Cor_Times = Values(:,1);
Data.Cor_Average = Values(:,2);
Data.Cor_SEM = Values(:,3);
Data.Cor_Array = Values(:,4:end);
FCSData.Data{end+1} = Data;
end
%%% Updates global parameters
FCSData.FileName{end+1} = FileName{i}(1:end-5);
FCSMeta.Data{end+1,1} = FCSData.Data{end}.Cor_Times;
FCSMeta.Data{end,2} = FCSData.Data{end}.Cor_Average;
FCSMeta.Data{end,2}(isnan(FCSMeta.Data{end,2})) = 0;
FCSMeta.Data{end,3} = FCSData.Data{end}.Cor_SEM;
FCSMeta.Data{end,3}(isnan(FCSMeta.Data{end,3})) = 1;
%%% Creates new plots
FCSMeta.Plots{end+1,1} = errorbar(...
FCSMeta.Data{end,1},...
FCSMeta.Data{end,2},...
FCSMeta.Data{end,3},...
'Parent',h.FCS_Axes);
FCSMeta.Plots{end,2} = line(...
'Parent',h.FCS_Axes,...
'XData',FCSMeta.Data{end,1},...
'YData',zeros(numel(FCSMeta.Data{end,1}),1));
FCSMeta.Plots{end,3} = line(...
'Parent',h.Residuals_Axes,...
'XData',FCSMeta.Data{end,1},...
'YData',zeros(numel(FCSMeta.Data{end,1}),1));
FCSMeta.Plots{end,4} = line(...
'Parent',h.FCS_Axes,...
'XData',FCSMeta.Data{end,1},...
'YData',FCSMeta.Data{end,2});
FCSMeta.Params(:,end+1) = cellfun(@str2double,h.Fit_Table.Data(end-2,5:3:end-1));
end
%%% change the gui
SwitchGUI(h,'FCS');
case {3,4} %% Individual curves from correlation files
FCSMeta.DataType = 'FCS individual';
for i=1:numel(FileName)
%%% Reads files (3 == .mcor; 4 == .cor)
if Type == 3
Data = load(fullfile(PathName{i},FileName{i}),'-mat');
else
FID = fopen(fullfile(PathName{i},FileName{i}));
Text = textscan(FID,'%s', 'delimiter', '\n','whitespace', '');
Text = Text{1};
Data.Header = Text{1};
Data.Valid = str2num(Text{find(~cellfun(@isempty,strfind(Text,'Valid bins:')),1)}(12:end)); %#ok<ST2NM>
Data.Counts(1) = str2num(Text{find(~cellfun(@isempty,strfind(Text,'Countrate channel 1 [kHz]:')),1)}(27:end)); %#ok<ST2NM>
Data.Counts(2) = str2num(Text{find(~cellfun(@isempty,strfind(Text,'Countrate channel 2 [kHz]:')),1)}(27:end)); %#ok<ST2NM>
Start = find(~cellfun(@isempty,strfind(Text,'Data starts here:')),1);
Values = zeros(numel(Text)-Start,numel(Data.Valid)+3);
k=1;
for j = Start+1:numel(Text)
Values(k,:) = str2num(Text{j}); %#ok<ST2NM>
k = k+1;
end
Data.Cor_Times = Values(:,1);
Data.Cor_Average = Values(:,2);
Data.Cor_SEM = Values(:,3);
Data.Cor_Array = Values(:,4:end);
end
%%% Creates entry for each individual curve
for j=1:size(Data.Cor_Array,2)
FCSData.Data{end+1} = Data;
FCSData.FileName{end+1} = [FileName{i}(1:end-5) ' Curve ' num2str(Data.Valid(j))];
FCSMeta.Data{end+1,1} = FCSData.Data{end}.Cor_Times;
FCSMeta.Data{end,2} = FCSData.Data{end}.Cor_Array(:,j);
FCSMeta.Data{end,3} = FCSData.Data{end}.Cor_SEM;
%%% Creates new plots
FCSMeta.Plots{end+1,1} = errorbar(...
FCSMeta.Data{end,1},...
FCSMeta.Data{end,2},...
FCSMeta.Data{end,3},...
'Parent',h.FCS_Axes);
FCSMeta.Plots{end,2} = line(...
'Parent',h.FCS_Axes,...
'XData',FCSMeta.Data{end,1},...
'YData',zeros(numel(FCSMeta.Data{end,1}),1));
FCSMeta.Plots{end,3} = line(...
'Parent',h.Residuals_Axes,...
'XData',FCSMeta.Data{end,1},...
'YData',zeros(numel(FCSMeta.Data{end,1}),1));
FCSMeta.Plots{end,4} = line(...
'Parent',h.FCS_Axes,...
'XData',FCSMeta.Data{end,1},...
'YData',FCSMeta.Data{end,2});
FCSMeta.Params(:,end+1) = cellfun(@str2double,h.Fit_Table.Data(end-2,5:3:end-1));
end
end
%%% change the gui
SwitchGUI(h,'FCS');
case {5} %% 2color FRET data from BurstBrowser
FCSMeta.DataType = 'FRET';
bin = UserValues.FCSFit.FRETbin;
x = (-0.25:bin:ceil(1.25/bin)*bin)';
for i=1:numel(FileName)
%%% Reads files
E = load(fullfile(PathName{i},FileName{i}),'-mat');
if isfield(E,'E')
E = E.E;
elseif isfield(E,'EGR') % three color data
E = E.EGR;
end
Data.E = E;
his = histcounts(E,x)';
Data.Cor_Average = his./sum(his)./min(diff(x));
error = sqrt(his)./sum(his)./min(diff(x));
Data.Cor_SEM = error; Data.Cor_SEM(Data.Cor_SEM == 0) = 1;
Data.Cor_Array = [];
Data.Valid = [];
Data.Counts = [numel(E), numel(E)];
Data.Cor_Times = x(1:end-1)+bin/2;
FCSData.Data{end+1} = Data;
%%% Updates global parameters
FCSData.FileName{end+1} = FileName{i}(1:end-5);
FCSMeta.Data{end+1,1} = FCSData.Data{end}.Cor_Times;
FCSMeta.Data{end,2} = FCSData.Data{end}.Cor_Average;
FCSMeta.Data{end,2}(isnan(FCSMeta.Data{end,2})) = 0;
FCSMeta.Data{end,3} = FCSData.Data{end}.Cor_SEM;
FCSMeta.Data{end,3}(isnan(FCSMeta.Data{end,3})) = 1;
%%% Creates new plots
FCSMeta.Plots{end+1,1} = errorbar(...
FCSMeta.Data{end,1},...
FCSMeta.Data{end,2},...
FCSMeta.Data{end,3},...
'Parent',h.FCS_Axes);
FCSMeta.Plots{end,2} = line(...
'Parent',h.FCS_Axes,...
'XData',FCSMeta.Data{end,1},...
'YData',zeros(numel(FCSMeta.Data{end,1}),1));
FCSMeta.Plots{end,3} = line(...
'Parent',h.Residuals_Axes,...
'XData',FCSMeta.Data{end,1},...
'YData',zeros(numel(FCSMeta.Data{end,1}),1));
FCSMeta.Plots{end,4} = stairs(...
FCSMeta.Data{end,1}-bin/2,...
FCSMeta.Data{end,2},...
'Parent',h.FCS_Axes);
FCSMeta.Params(:,end+1) = cellfun(@str2double,h.Fit_Table.Data(end-2,5:3:end-1));
end
%%% change the gui
SwitchGUI(h,'FRET');
case {6,7} %% FCS data from Zeiss microscopes (*.fcs file)
switch Type
case 6
FCSMeta.DataType = 'FCS averaged';
case 5
FCSMeta.DataType = 'FCS individual';
end
for i=1:numel(FileName)
%%% Reads file (file contains all sub-measurements)
[AC, mCountRate, Duration] = read_zeiss_fcs_file(fullfile(PathName{i},FileName{i}));
%%% convert the data into FCSFit data structure
% AC contains for each measurement: time, AC1, AC1_std, AC2, AC2_std, CC, CC_std
% std (i.e. error) is 1 for all since it is not computed by the
% software, instead we will recalculate it here based on the
% individual measurements
% Not all channels are used/correlated, find out how many
% channels we have and make a "file" for each
chan_used = find(AC{1}(1,2:2:end) ~= 0);
for c = chan_used
Cor_Times = AC{1}(:,1);
Cor_Array = [];
Counts = [];
for j = 1:numel(AC)
Cor_Array = [Cor_Array, AC{j}(:,2*c)];
Counts = [Counts, mCountRate{j}(c)];
end
Data = struct;
Data.Cor_Array = Cor_Array;
Data.Cor_Times = Cor_Times*1e-6;
Data.Cor_Average = mean(Cor_Array,2);
if ( size(Cor_Array,2) > 1 ) && ( Type == 6) % average to obtain error bars
Data.Cor_SEM = std(Cor_Array,[],2)./sqrt(size(Cor_Array,2)); % this is the standard error of the mean
% adjust the SEM based on the student's t distribution
p_value = normcdf(1)-normcdf(-1); % this is the probability to be within 1 sigma for a normal distribution (p = 0.68..)
Data.Cor_SEM = Data.Cor_SEM * tinv(p_value+(1-p_value)/2,size(Cor_Array,2)-1);
else % set std to one, individual sub-measurements are loaded
Data.Cor_SEM = ones(size(Cor_Array,1),1);
end
Data.Counts = repmat(mean(Counts),[1,2]);
Data.Valid = ones(1,size(Cor_Array,2));
Data.Header = '';
%%% add file to file history
h.FileHistory.add_file(fullfile(PathName{i},FileName{i}));
%%% Updates global parameters