-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathSTORMfinder.m
1145 lines (982 loc) · 43.5 KB
/
STORMfinder.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 varargout = STORMfinder(varargin)
% STORMFINDER MATLAB code for STORMfinder.fig
% STORMFINDER, by itself, creates a new STORMFINDER or raises the existing
% singleton*.
%
% H = STORMFINDER returns the handle to a new STORMFINDER or the handle to
% the existing singleton*.
%
% STORMFINDER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in STORMFINDER.M with the given input arguments.
%
% STORMFINDER('Property','Value',...) creates a new STORMFINDER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before STORMfinder_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to STORMfinder_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% -------------------------------------------------------------------------
% Outputs
% parfile_temp.ini -- .ini parameters being used by the system
% parfile_temp.xml
% parfile_temp_1frame.xml
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help STORMfinder
% Last Modified by GUIDE v2.5 29-Dec-2013 17:25:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @STORMfinder_OpeningFcn, ...
'gui_OutputFcn', @STORMfinder_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before STORMfinder is made visible.
function STORMfinder_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to STORMfinder (see VARARGIN)
global daxfile SF
if isempty(SF)
SF = cell(1,1);
else
SF = [SF;cell(1,1)];
end
gui_number = length(SF);
set(handles.SFinstance,'String',['inst id',num2str(gui_number)]);
handles.gui_number = gui_number;
if length(varargin) > 1
daxfile = varargin{2};
SF{handles.gui_number}.daxfile = daxfile;
else
SF{handles.gui_number}.daxfile = daxfile;
end
STORMfinderDefaults(handles);
% Choose default command line output for STORMfinder
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% If any daxfile has been loaded, open it along with opening the GUI.
try
UpdateDax_Callback(hObject, eventdata, handles)
catch
disp('please load a dax file into matlab');
disp('drag and drop a .dax file in the command window, then press Update Dax File');
disp('Or select File > Load Dax File');
end
% set(handles.FitMethod,'Value',2); % set default method to DaoSTORM
% 1 = InsightM, 3 = GPUmultifit
axes(handles.axes1); axis off;
% UIWAIT makes STORMfinder wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = STORMfinder_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --------------------------------------------------------------------
function FindDots_ClickedCallback(hObject, eventdata, handles)
% hObject handle to FindDots (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF insightExe daoSTORMexe scratchPath
FitMethod = get(handles.FitMethod,'Value');
% k = strfind(daxfile,filesep);
% fpath = daxfile(1:k(end));
% daxroot = regexprep(daxfile(k(end)+1:end),'.dax','');
if FitMethod == 1 % InsightM
if isempty(insightExe)
error(['insightExe not found. ',...
'Please set the global variable insightExe ',...
'to specify the location of insightM.exe in the ',...
'Insight3 folder on your computer.']);
end
insight = insightExe;
% InsightM /.ini files don't have a max frames parameter, so
% instead we write a new dax menufile that has only 1 frame.
% if no inifile has been loaded, use default values
if isempty(SF{handles.gui_number}.inifile)
ReadParameterFile(FitMethod,handles); % make default file the inifile
end
% write temp daxfile
mov_temp = 'mov_temp.dax';
daxtemp = [scratchPath, mov_temp];
ftemp = fopen(daxtemp,'w+');
fwrite(ftemp,SF{handles.gui_number}.impars.Im(:),'*uint16',0,'b');
fclose(ftemp);
% write temp inf file
InfoFile_temp = SF{handles.gui_number}.impars.infofile;
InfoFile_temp.number_of_frames = 1;
InfoFile_temp.localName = 'mov_temp.inf';
InfoFile_temp.localPath = scratchPath;
WriteInfoFiles(InfoFile_temp,'verbose',false);
% call insight
ccall = ['!', insight,' "',daxtemp,'" ',...
' "',SF{handles.gui_number}.inifile,'" ',...
' "',SF{handles.gui_number}.inifile,'" '];
disp(ccall);
eval(ccall);
binfile = regexprep([scratchPath,'mov_temp.dax'],'\.dax','_list.bin');
elseif FitMethod == 2
% load parameter files if missing
if isempty(SF{handles.gui_number}.xmlfile)
ReadParameterFile(FitMethod,handles) % make default file the 'xmlfile'
end
if isempty(daoSTORMexe)
error(['daoSTORMexe not found. ',...
'Please set the global variable daoSTORMexe ',...
'to specify the location of mufit_analysis.py in the ',...
'DaoSTORM folder on your computer and its dll paths.',...
'See startup_example in \Templates folder']);
end
% update xmlfile to current frame
% save a new xmlfile which has 1frame appended onto the default one.
xmlfile_temp = make_temp_parameters(handles,'1frame');
parameters = {'<start_frame type="int">',...
'<max_frame type="int">',...
'<drift_correction type="int">'};
new_values = {num2str(SF{handles.gui_number}.impars.cframe-1),...
num2str(SF{handles.gui_number}.impars.cframe),...
'0'};
modify_script(SF{handles.gui_number}.xmlfile,xmlfile_temp,...
parameters,new_values,'<');
% need to delete any existing bin menufile before we overwrite, or
% DaoSTORM tries to pick up analysis where it left off.
binfile = regexprep([scratchPath,'mov_temp.dax'],'\.dax','_mlist.bin');
if exist(binfile,'file')
delete(binfile);
end
% Call DaoSTORM.
disp('locating dots by DaoSTORM');
disp(SF{handles.gui_number}.daxfile)
disp(xmlfile_temp);
system([daoSTORMexe,' "',...
SF{handles.gui_number}.daxfile,...
'" "',binfile,'" "',xmlfile_temp,'"']);
elseif FitMethod == 3
TempPars = SF{handles.gui_number}.FitPars;
TempPars.startFrame = mat2str(SF{handles.gui_number}.impars.cframe);
TempPars.endFrame = mat2str(SF{handles.gui_number}.impars.cframe+1);
SF{handles.gui_number}.mlist = ...
GPUmultifitDax(SF{handles.gui_number}.daxfile,TempPars);
end
if FitMethod~=3
try
SF{handles.gui_number}.mlist = ...
ReadMasterMoleculeList(binfile,'verbose',false);
catch %#ok<*CTCH>
disp('no molecules found to display!');
disp('Try changing fit pars');
clear mlist;
SF{handles.gui_number}.mlist.x = [];
SF{handles.gui_number}.mlist.y = [];
end
end
handles.axes1; cla;
imagesc(SF{handles.gui_number}.impars.Im(:,:,1)');
caxis([SF{handles.gui_number}.impars.cmin,...
SF{handles.gui_number}.impars.cmax]); colormap gray;
set(handles.title1,'String',SF{handles.gui_number}.daxfile); % ,'interpreter','none');
hold on;
plot(SF{handles.gui_number}.mlist.x(:),...
SF{handles.gui_number}.mlist.y(:),'yo','MarkerSize',20);
axis off;
% rectangle(mlist.x(:),mlist.y(:),mlist.w(:),mlist.w(:));
% --------------------------------------------------------------------
function Plotdots3D_ClickedCallback(hObject, eventdata, handles)
% hObject handle to Plotdots3D (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
try
figure(2); clf;
plot3(SF{handles.gui_number}.mlist.y(:),...
SF{handles.gui_number}.mlist.x(:),...
SF{handles.gui_number}.mlist.z(:),'k.','MarkerSize',10);
grid on;
xlabel('y'); ylabel('x'); zlabel('z');
xlim([0,SF{handles.gui_number}.impars.w]);
ylim([0,SF{handles.gui_number}.impars.h]);
catch er
disp(er.message);
disp('no molecules found to plot!');
end
% --------------------------------------------------------------------
function MenuLoadDax_Callback(hObject, eventdata, handles)
% hObject handle to MenuLoadDax (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
if ~isempty(SF{handles.gui_number}.daxfile)
startfolder = ExtractPath(SF{handles.gui_number}.daxfile);
else
startfolder = pwd;
end
[FileName,PathName,FilterIndex] = uigetfile({'*.dax','Dax file (*.dax)';...
'*.*','All Files (*.*)'},'Select dax file',startfolder);
if FilterIndex ~= 0 % loading operation was not canceled
SF{handles.gui_number}.daxfile = [PathName,FileName];
LoadDax(hObject,handles);
end
% --------------------------------------------------------------------
function MenuLoadBin_Callback(hObject, eventdata, handles)
global SF
if ~isempty(SF{handles.gui_number}.daxfile)
startfolder = ExtractPath(SF{handles.gui_number}.daxfile);
else
startfolder = pwd;
end
[FileName,PathName,FilterIndex] = uigetfile({'*.bin','Bin file (*.bin)';...
'*.*','All Files (*.*)'},'Select molecule list',startfolder);
if FilterIndex ~= 0 % loading operation was not canceled
SF{handles.gui_number}.binpath = [PathName,FileName];
try
SF{handles.gui_number}.fullmlist = ...
ReadMasterMoleculeList(SF{handles.gui_number}.binpath);
catch er
disp(er.message);
disp(['loading failed. Is ',[PathName,FileName],...
' a valid .bin file?']);
end
end
% --------------------------------------------------------------------
function MenuClearBin_Callback(hObject, eventdata, handles)
global SF
SF{handles.gui_number}.fullmlist = [];
% --- Executes on button press in UpdateDax.
function UpdateDax_Callback(hObject, eventdata, handles)
global SF daxfile
% reads in global daxfile from
SF{handles.gui_number}.daxfile = daxfile;
LoadDax(hObject,handles);
function LoadDax(hObject,handles)
global SF
% Read info menufile
iminfo = ReadInfoFile(SF{handles.gui_number}.daxfile);
SF{handles.gui_number}.impars.h = iminfo.frame_dimensions(2);
SF{handles.gui_number}.impars.w = iminfo.frame_dimensions(1);
SF{handles.gui_number}.impars.infofile = iminfo;
% setup default intensities
% fid = fopen(SF{handles.gui_number}.daxfile);
% Im = fread(fid, SF{handles.gui_number}.impars.h*SF{handles.gui_number}.impars.w, '*uint16',0,'b');
% fclose(fid);
Im = ReadDax(SF{handles.gui_number}.daxfile,'endFrame',1)';
SF{handles.gui_number}.impars.cmax = max(Im(:));
SF{handles.gui_number}.impars.cmin = min(Im(:));
% set up framer slider
SF{handles.gui_number}.impars.cframe = 1; % reset to 1
set(handles.currframe,'String',num2str(SF{handles.gui_number}.impars.cframe));
% str2double(get(handles.currframe,'String'));
fid = fopen(SF{handles.gui_number}.daxfile);
fseek(fid,0,'eof');
fend = ftell(fid);
fclose(fid);
TFrames = fend/(16/8)/(SF{handles.gui_number}.impars.h*SF{handles.gui_number}.impars.w); % total number of frames
set(handles.FrameSlider,'Min',0);
set(handles.FrameSlider,'Max',TFrames);
set(handles.FrameSlider,'Value',SF{handles.gui_number}.impars.cframe);
set(handles.FrameSlider,'SliderStep',[1/TFrames,50/TFrames]);
UpdateFrame(hObject, handles);
function UpdateFrame(hObject,handles)
global SF
% shorthand, load
cframe = SF{handles.gui_number}.impars.cframe;
h = SF{handles.gui_number}.impars.h;
w = SF{handles.gui_number}.impars.w;
% fid = fopen(SF{handles.gui_number}.daxfile);
% L = 1; % number of frames to read in
% fseek(fid,(h*w*(cframe-1))*16/8,'bof'); % bits/(bytes per bit)
% Im = fread(fid, h*w*L, '*uint16',0,'b');
% fclose(fid);
% Im = reshape(Im,w,h,L);
Im = ReadDax(SF{handles.gui_number}.daxfile,'startFrame',cframe,'endFrame',cframe,'verbose',false)';
handles.axes1; cla;
imagesc(Im(:,:,1)'); caxis([SF{handles.gui_number}.impars.cmin,SF{handles.gui_number}.impars.cmax]); colormap gray;
axis off;
set(handles.title1,'String',SF{handles.gui_number}.daxfile);
set(handles.FrameSlider,'Value',SF{handles.gui_number}.impars.cframe); % update slider
axis image;
% If a binfile has been loaded, plot the localizations in this frame;
if ~isempty(SF{handles.gui_number}.fullmlist)
hold on;
inframe = (SF{handles.gui_number}.fullmlist.frame == cframe);
plot(SF{handles.gui_number}.fullmlist.x(inframe),...
SF{handles.gui_number}.fullmlist.y(inframe),'yo','MarkerSize',20);
axis off;
end
guidata(hObject, handles);
% the transpose here is merely to match insight.
SF{handles.gui_number}.impars.Im = Im;
function [FitPars,parameters] = ReadParameterFile(FitMethod,handles)
% loads contents of inifile or xmlfile into data structure FitPars
% depending on whether fit method is insightM or DaoSTORM respectively.
% if no inifile or xmlfile has been loaded yet, load default files.
%
global SF defaultIniFile defaultXmlFile defaultGPUmFile
% clear fitPars
if FitMethod == 1
if isempty(SF{handles.gui_number}.inifile)
SF{handles.gui_number}.inifile = defaultIniFile; % '..\Parameters\647zcal_storm2.ini';
disp('no inifile found to load, using default file ');
disp(SF{handles.gui_number}.inifile);
disp('to load a file, drag and drop it into matlab');
end
parameters = {
'min height=',...
'max height=',...
'default background=',...
'min width=',...
'max width=',...
'default width=',...
'axial ratio tolerance=',...
'Fit ROI=',...
'displacement=',...
'start frame='...
'allow drift=',...
'number of molecules in each correlation time step (XY)=',...
'number of molecules in each correlation time step (Z)=',...
'minimum time step size (frame)=',...
'maximum time step size (frame)=',...
'xy grid size (nm) in xy correlation=',...
'xy grid size (nm) in z correlation=',...
'points for moving average in generating drift correlation (XY)=',...
'points for moving average in generating drift correlation (Z)=',...
'z method=',...
'z calibration expression=',...
'z calibration outlier rejection percentile=',...
'z calibration start=',...
'z calibration end=',...
'z calibration step=',...
'ROI Valid=',...
'ROI_x0=',...
'ROI_x1=',...
'ROI_y0=',...
'ROI_y1=',...
};
% Get values from loaded inifile
target_values = read_parameterfile(SF{handles.gui_number}.inifile,parameters,'');
% save these values into global FitPars;
Pfields = {'minheight','maxheight','bkd','minwidth','maxwidth',...
'initwidth','maxaxratio','fitROI','displacement','startFrame','CorDrift',...
'xymols','zmols','minframes','maxframes','xygridxy','xygridz',...
'movAxy','movAz','Fit3D','zcaltxt','zop','zstart','zend','zstep',...
'useROI','xmin','xmax','ymin','ymax'};
FitPars = cell2struct(target_values,Pfields,2);
parsfile = SF{handles.gui_number}.inifile;
elseif FitMethod == 2
if isempty(SF{handles.gui_number}.xmlfile)
SF{handles.gui_number}.xmlfile = defaultXmlFile; % ;
disp('no xmlfile parameter file found to load.')
disp(['using default file',SF{handles.gui_number}.xmlfile]);
disp('to load a file, drag and drop into matlab');
end
parameters = {
'<model type="string">',... method
'<threshold type="float">'... threshold
'<iterations type="int">',... maxits
'<baseline type="float">',... bkd
'<pixel_size type="float">',... ppnm
'<sigma type="float">',... initwidth
'<descriptor type="string">',... descriptor
'<radius type="float">',... displacement
'<start_frame type="int">',... startFrame
'<max_frame type="int">',... endFrame
'<drift_correction type="int">',... % CorDrift
'<frame_step type="int">',... dframes
'<d_scale type="int">',...dscales
'<do_zfit type="int">',... Fit3D
'<cutoff type="float">',... zcutoff
'<min_z type="float">',... zstart
'<max_z type="float">',... zend
'<wx_wo type="float">',... wx0
'<wx_c type="float">',... gx
'<wx_d type="float">',... zrx
'<wxA type="float">',... Ax
'<wxB type="float">',... Bx
'<wxC type="float">',... Cx
'<wxD type="float">',... Dx
'<wy_wo type="float">',... wy0
'<wy_c type="float">',... gy
'<wy_d type="float">',... zry
'<wyA type="float">',... Ay
'<wyB type="float">',... By
'<wyC type="float">',... Cy
'<wyD type="float">',... Dy
'<x_start type="int">',... xmin
'<x_stop type="int">',... xmax
'<y_start type="int">',... ymin
'<y_stop type="int">',... ymax
};
% Read in current parameter values from xmlfile
target_values = read_parameterfile(SF{handles.gui_number}.xmlfile,parameters,'<');
% save these values into global FitPars;
Pfields = {'method','threshold','maxits','bkd','ppnm','initwidth',...
'descriptor','displacement','startFrame','endFrame','CorDrift',...
'dframes','dscale','Fit3D','zcutoff','zstart','zend','wx0','gx',...
'zrx','Ax','Bx','Cx','Dx','wy0','gy','zry','Ay','By','Cy','Dy',...
'xmin','xmax','ymin','ymax'};
FitPars = cell2struct(target_values,Pfields,2);
parsfile = SF{handles.gui_number}.xmlfile;
elseif FitMethod == 3
if isempty(SF{handles.gui_number}.gpufile)
disp('no gpu parameter file found, loading defaults');
SF{handles.gui_number}.gpufile = defaultGPUmFile;
end
load(SF{handles.gui_number}.gpufile);
parsfile = SF{handles.gui_number}.gpufile;
FitPars = GPUmultiPars;
parameters = '';
end
set(handles.CurrentPars,'String',parsfile);
% save('C:\Users\Alistair\Documents\Projects\General_STORM\Test_data\test3.mat');
function parfile = make_temp_parameters(handles,temp)
% append '_temp' to parameterfile, save in scratch directory
global SF
FitMethod = get(handles.FitMethod,'Value');
if FitMethod == 1
parflag = '.ini';
parfile = scratch_parameters(SF{handles.gui_number}.inifile,temp,parflag);
elseif FitMethod == 2
parflag = '.xml';
parfile = scratch_parameters(SF{handles.gui_number}.xmlfile,temp,parflag);
elseif FitMethod == 3
parflag = '.mat';
parfile = scratch_parameters(SF{handles.gui_number}.gpufile,temp,parflag);
end
function parfile = scratch_parameters(parfile,temp,parflag)
global scratchPath
[currpath,currpar] = ExtractPath(parfile);
if isempty(strfind(currpar,temp)) || isempty(strfind(scratchPath,currpath))
parfile = [scratchPath,currpar(1:end-4),'_',temp,parflag];
else
% no change needed
end
% --- Executes on button press in FitParameters.
function FitParameters_Callback(hObject, eventdata, handles)
% hObject handle to FitParameters (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF scratchPath
% disp('loading inifile');
% disp(inifile);
FitMethod = get(handles.FitMethod,'Value');
[SF{handles.gui_number}.FitPars,parameters] = ReadParameterFile(FitMethod,handles);
parfile = make_temp_parameters(handles,'temp'); % if _temp.ini / .xml parameter files have not been made, make them.
SF{handles.gui_number}.FitPars.OK = false;
if FitMethod == 1 % InsightM
f = GUIFitParameters(handles.gui_number);
waitfor(f); % need to wait until parameter selection is closed.
if SF{handles.gui_number}.FitPars.OK
new_values = struct2cell(SF{handles.gui_number}.FitPars)';
modify_script(SF{handles.gui_number}.inifile,parfile,parameters,new_values,'');
SF{handles.gui_number}.inifile = parfile;
end
% disp(inifile);
elseif FitMethod == 2 % DaoSTORM
disp(['SF instanceID = ', num2str(handles.gui_number)]);
f = GUIDaoParameters(handles.gui_number);
waitfor(f); % need to wait until parameter selection is closed.
if SF{handles.gui_number}.FitPars.OK % only update parameters if user presses save button
new_values = struct2cell(SF{handles.gui_number}.FitPars)';
modify_script(SF{handles.gui_number}.xmlfile,parfile,parameters,new_values,'<');
SF{handles.gui_number}.xmlfile = parfile;
end
elseif FitMethod == 3
f = GUIgpuParameters(handles.gui_number);
waitfor(f);
if SF{handles.gui_number}.FitPars.OK
GPUmultiPars = SF{handles.gui_number}.FitPars; %#ok<NASGU>
SF{handles.gui_number}.gpufile = parfile;
save(SF{handles.gui_number}.gpufile,'GPUmultiPars');
end
end
set(handles.CurrentPars,'String',parfile);
% save([scratchPath 'test10.mat']);
% load([scratchPath 'test10.mat']);
% --- Executes on selection change in FitMethod.
function FitMethod_Callback(hObject, eventdata, handles)
% hObject handle to FitMethod (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
FitMethod = get(handles.FitMethod,'Value');
SF{handles.gui_number}.FitPars = ReadParameterFile(FitMethod,handles);
% Important that FitPars matches the current Fitting method.
% --- Executes on slider movement.
function FrameSlider_Callback(hObject, eventdata, handles)
% hObject handle to FrameSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
cframe = round(get(handles.FrameSlider,'Value')); % get current frame
SF{handles.gui_number}.impars.cframe = cframe;
set(handles.currframe,'String',num2str(SF{handles.gui_number}.impars.cframe));
UpdateFrame(hObject, handles);
% --------------------------------------------------------------------
function ManualContrast_ClickedCallback(hObject, eventdata, handles)
% hObject handle to ManualContrast (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
dlg_title = 'Manual Contrast';
num_lines = 1;
prompt = {
'Min Intensity',...
'Max Intensity'};
default_opts = {
num2str(SF{handles.gui_number}.impars.cmin),...
num2str(SF{handles.gui_number}.impars.cmax)};
default_opts = inputdlg(prompt,dlg_title,num_lines,default_opts);
if ~isempty(default_opts) % was not canceled
SF{handles.gui_number}.impars.cmin = str2double(default_opts{1});
SF{handles.gui_number}.impars.cmax = str2double(default_opts{2});
UpdateFrame(hObject, handles);
end
% --------------------------------------------------------------------
function AutoContrast_ClickedCallback(hObject, eventdata, handles)
% hObject handle to AutoContrast (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
SF{handles.gui_number}.impars.cmax = max(SF{handles.gui_number}.impars.Im(:));
SF{handles.gui_number}.impars.cmin = min(SF{handles.gui_number}.impars.Im(:));
UpdateFrame(hObject, handles);
function currframe_Callback(hObject, eventdata, handles)
% hObject handle to currframe (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
SF{handles.gui_number}.impars.cframe = str2double(get(handles.currframe,'String'));
UpdateFrame(hObject, handles);
% --------------------------------------------------------------------
function MenuSavePars_Callback(hObject, eventdata, handles)
% hObject handle to MenuSavePars (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
FitMethod = get(handles.FitMethod,'Value');
% setup starting folder for uigetfile
if ~isempty(SF{handles.gui_number}.daxfile)
startfolder = ExtractPath(SF{handles.gui_number}.daxfile);
else
startfolder = pwd;
end
[FitPars,parameters] = ReadParameterFile(FitMethod,handles); % load current parameters in FitPars
[savename, savepath,hadinput] = uiputfile(...
{'*.ini;*.xml;*.mat','Parameter Files (*.ini, *.xml, *.mat)'},...
'Save Parameter File',startfolder); % get file path and save name
if hadinput > 0
k = strfind(savename,'.');
if ~isempty(k);
savename = savename(1:k-1);
end
% save current parameters with menufile name / directory specified above
if FitMethod == 1
savename = [savename,'.ini'];
modify_script(SF{handles.gui_number}.inifile,...
[savepath,savename],parameters,...
struct2cell(FitPars),'');
elseif FitMethod == 2
savename = [savename,'.xml'];
modify_script(SF{handles.gui_number}.xmlfile,...
[savepath,savename],parameters,...
struct2cell(FitPars),'<');
elseif FitMethod == 3
savename = [savename,'.mat'];
GPUmultiPars = FitPars; %#ok<NASGU>
SF{handles.gui_number}.gpufile =[savepath,filesep,savename];
save(SF{handles.gui_number}.gpufile,'GPUmultiPars');
end
end
parsfile = [savepath,savename];
if FitMethod == 1
SF{handles.gui_number}.inifile = parsfile;
elseif FitMethod == 2
SF{handles.gui_number}.xmlfile = parsfile; % remove temp flag.
end
set(handles.CurrentPars,'String',parsfile);
% --------------------------------------------------------------------
function MenuLoadPars_Callback(hObject, eventdata, handles)
% hObject handle to MenuLoadPars (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
% setup starting folder for uigetfile
if ~isempty(SF{handles.gui_number}.daxfile)
startfolder = ExtractPath(SF{handles.gui_number}.daxfile);
else
startfolder = pwd;
end
[filename,filepath,hadinput] = uigetfile(...
{'*.ini;*.xml;*.mat','Parameter Files (*.ini, *.xml, *.mat)'},...
'Select Parameter File',startfolder); % get file path and save name
if hadinput > 0
k = strfind(filename,'.');
if strcmp(filename(k:end),'.ini');
SF{handles.gui_number}.inifile = [filepath,filename];
parsfile = SF{handles.gui_number}.inifile;
method = 1;
elseif strcmp(filename(k:end),'.xml');
SF{handles.gui_number}.xmlfile = [filepath,filename];
parsfile = SF{handles.gui_number}.xmlfile;
method = 2;
elseif strcmp(filename(k:end),'.mat');
SF{handles.gui_number}.gpufile = [filepath,filename];
parsfile = SF{handles.gui_number}.gpufile;
method = 3;
else
disp([filename,' is not a recognized parameter file']);
end
set(handles.CurrentPars,'String',parsfile);
set(handles.FitMethod,'Value',method);
end
% --------------------------------------------------------------------
function MenuAnalyzeCurrent_Callback(hObject, eventdata, handles)
% hObject handle to MenuAnalyzeCurrent (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
FitMethod = get(handles.FitMethod,'Value');
runinMatlab = ~eval(SF{handles.gui_number}.defaultAopts{1});
printprogress = ~eval(SF{handles.gui_number}.defaultAopts{1});
hideterminal = eval(SF{handles.gui_number}.defaultAopts{2});
overwrite = eval(SF{handles.gui_number}.defaultAopts{3});
minsize = eval(SF{handles.gui_number}.defaultAopts{4})*1E6;
maxCPU = eval(SF{handles.gui_number}.defaultAopts{5});
verbose = eval(SF{handles.gui_number}.defaultAopts{6});
binname = SF{handles.gui_number}.defaultAopts{7};
if FitMethod == 1
method = 'insight';
parsfile = SF{handles.gui_number}.inifile;
elseif FitMethod == 2
method= 'DaoSTORM';
parsfile = SF{handles.gui_number}.xmlfile;
end
RunDotFinder('daxfile',SF{handles.gui_number}.daxfile,'parsfile',...
parsfile,'method',method,'maxCPU',maxCPU,'verbose',verbose,...
'runinMatlab',runinMatlab,'printprogress',printprogress,...
'hideterminal',hideterminal,'overwrite',overwrite,'minsize',minsize,...
'binname',binname);
% --------------------------------------------------------------------
function MenuAnalyzeAll_Callback(hObject, eventdata, handles)
% hObject handle to MenuAnalyzeAll (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF
maxCPU = eval(SF{handles.gui_number}.defaultAopts{5});
verbose = eval(SF{handles.gui_number}.defaultAopts{6});
FitMethod = get(handles.FitMethod,'Value');
if FitMethod == 1
parsfile = SF{handles.gui_number}.inifile;
method = 'insight';
partype = '.ini';
elseif FitMethod == 2
parsfile = regexprep(SF{handles.gui_number}.xmlfile,'_1frame',''); % remove temp flag.
method = 'DaoSTORM';
partype = '.xml';
elseif FitMethod == 3
parsfile = SF{handles.gui_number}.gpufile;
method = 'GPUmultifit';
partype = '.mat';
end
if isempty(parsfile)
parsfile = '';
end
dlg_title = 'Run all dax files in folder';
num_lines = 1;
Dprompt = {
'batch size (number of jobs to run at once)';
'all dax files containing string'; %
'parameter file name or unique part of name'; %
'overwrite existing? (1=yes all, 0=no all, 2=ask me)';
'min file size (Mb)';
'run silently? (no cmd windows will be opened)';
'new mlist name (''=current, DAX = append daxfile, # = index)'};
Dopts = {
'3',...
'',...
parsfile,...
'false',...
'60',...
'false',...
''};
Dopts = inputdlg(Dprompt,dlg_title,num_lines,Dopts);
% If a parameter file with file ending is specified, call RunDotFinder with
% that specific parameter file. Otherwise, assume it is parameter root and
% find automatically any parameter file with that root in the name.
if ~isempty(Dopts) % dealing with cancel
if isempty(strfind(Dopts{3},partype))
parflag = 'parsroot';
else
parflag = 'parsfile';
end
k = strfind(SF{handles.gui_number}.daxfile,filesep);
fpath = SF{handles.gui_number}.daxfile(1:k(end));
RunDotFinder('path',fpath,'batchsize',eval(Dopts{1}),'daxroot',Dopts{2},...
parflag,Dopts{3},'overwrite',eval(Dopts{4}),'method',method,...
'minsize',eval(Dopts{5})*1E6,'hideterminal',eval(Dopts{6}),...
'binname',Dopts{7},'maxCPU',maxCPU,'verbose',verbose);
end
% --- Executes during object creation, after setting all properties.
function FrameSlider_CreateFcn(hObject, eventdata, handles)
% hObject handle to FrameSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes during object creation, after setting all properties.
function currframe_CreateFcn(hObject, eventdata, handles)
% hObject handle to currframe (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function FitMethod_CreateFcn(hObject, eventdata, handles)
% hObject handle to FitMethod (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function MenuFile_Callback(hObject, eventdata, handles)
% hObject handle to MenuFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function MenuAnalysis_Callback(hObject, eventdata, handles)
% hObject handle to MenuAnalysis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function MenuComputeZcal_Callback(hObject, eventdata, handles)
% hObject handle to MenuComputeZcal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global SF scratchPath
daxfile = SF{handles.gui_number}.daxfile;
FitMethod = get(handles.FitMethod,'Value');
if FitMethod == 1
parsfile = SF{handles.gui_number}.inifile;
method = 'insight';
elseif FitMethod == 2
parsfile = SF{handles.gui_number}.xmlfile;
method = 'DaoSTORM';
elseif FitMethod == 3
disp('Z-fitting not available for GPU multifit');
end
if isempty(parsfile)
disp('warning no parameter file selected');
disp('perhaps Fit Method does not match current parameter type?');
end
dlg_title = 'Compute Z-calibration';
num_lines = 1;
Zprompt = {
'New Parameter file name (will have daxname if blank)'; %
'Template Parameter file name (type "open" to get file selection window)';
'Run in Matlab?';
'Run Silently?';
'overwrite? (1=y,0=n,2=ask me)';
'Show plots?';
'Show extra plots?';
'Edit calibration parameters?'};
try
Zopts = inputdlg(Zprompt,dlg_title,num_lines,...
SF{handles.gui_number}.Zopts);
catch % Reset defaults if nothing is loaded
Zopts = {
'',...
'',...
'true',...
'false',...
'4',...
'true',...
'false',...
'false'};
Zopts = inputdlg(Zprompt,dlg_title,num_lines,Zopts);
end
if ~isempty(Zopts) % If Options was canceled, do nothing
if ~isfield(SF{handles.gui_number},'Zpars')
SF{handles.gui_number}.Zpars = {...
'1'
'1'
'0.8'
'300'
'0.1'
'1500'
'[100 600]'
'[100 700]'
'[-600 600]'
};
end
Zpars = SF{handles.gui_number}.Zpars;
if strcmp(Zopts{2},'open')
startfolder = ExtractPath(daxfile);
[filename,pathname,okay] = uigetfile({'*.xml','DaoSTORM pars (*.xml)';...
'*.ini','Insight pars (*.ini)'},'Select parameter file',startfolder);
if okay~=0
Zopts{2} = [pathname,filesep,filename];
end
end
if eval(Zopts{8})
dlg_title = 'Set Z-calibration parameters';
num_lines = 1;
parameterDescriptions = {...
'start frame to ID feducials'
'max allowed drift of feducial during movie'
'molecule on for at least this fraction of frames'
'max outlier from preliminary z-fit (nm)'
'fraction of ends of curve to ignore'
'max width of beads PSF (nm)'
'range of allowed w0'
'range of allowed zr'
'range of allowed g'
};
Zpars = inputdlg(parameterDescriptions,dlg_title,num_lines,...
SF{handles.gui_number}.Zpars);
end
if ~isempty(Zpars) %
RunDotFinder('daxfile',daxfile,'parsfile',parsfile,'method',method,...
'runinMatlab',eval(Zopts{3}),'hideterminal',eval(Zopts{4}),...