-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTracesView2.m
More file actions
656 lines (558 loc) · 23 KB
/
TracesView2.m
File metadata and controls
656 lines (558 loc) · 23 KB
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
function varargout = TracesView2(varargin)
% TRACESVIEW2 MATLAB code for TracesView2.fig
% TRACESVIEW2, by itself, creates a new TRACESVIEW2 or raises the existing
% singleton*.
%
% H = TRACESVIEW2 returns the handle to a new TRACESVIEW2 or the handle to
% the existing singleton*.
%
% TRACESVIEW2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TRACESVIEW2.M with the given input arguments.
%
% TRACESVIEW2('Property','Value',...) creates a new TRACESVIEW2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before TracesView2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to TracesView2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% Last Modified by GUIDE v2.5 01-Sep-2014 16:03:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @TracesView2_OpeningFcn, ...
'gui_OutputFcn', @TracesView2_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
function varargout = TracesView2_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;
% start below are the custome callback functions
function slider1_Callback(hObject, eventdata, handles)
%set(handles.buttongroupDisp,'SelectedObject',[]);
i = round(get(hObject,'Value'));
N = round(get(hObject,'Max'));
set(handles.statText_num,'String',sprintf('%d of %d',i,N)); % disp number of traces
handles.trLength = size(handles.traces(i).donr,1);
x = [1:handles.trLength];
set(handles.statText_trLength,'String',sprintf('%d frame', handles.trLength)); %disp trace length (number of frames)
donr = handles.traces(i).donr;
acptr = handles.traces(i).acptr;
idealAcptr=handles.traces(i).idealAcptr;
idealDonr=handles.traces(i).idealDonr;
%rebinning if nececary the checkbox is checked
if ( get(handles.rebinCheckbox,'Value') == get(handles.rebinCheckbox,'Max') )
binsize = str2double( get(handles.rebinTextBox,'String') );
if isnan(binsize)
errordlg('bins needs to be an integer greater than');
else
donr=rebin(donr,binsize);
acptr=rebin(acptr,binsize);
if ~isempty(idealAcptr) && ~isempty(idealDonr)
idealAcptr=rebin(idealAcptr, binsize);
idealDonr=rebin(idealDonr,binsize);
end
x=rebin(x,binsize);
end
end
if ~isempty(idealAcptr)&& ~isempty(idealDonr)
handles.plots = [plot(handles.axes_Donor, x,donr,'b',x,idealDonr,'k'),plot(handles.axes_Acceptor,x,acptr,'m',x,idealAcptr,'k')];
else
handles.plots = [plot(handles.axes_Donor, x,donr,'b'),plot(handles.axes_Acceptor,x,acptr,'m')];
end
handles.miniplot=plot(handles.axes_crosscor, xcorr(acptr,donr,50));
if handles.traces(i).IndT == 1
set(handles.plots(1,1),'Color','g');
set(handles.plots(1,2),'Color','r');
end
set(handles.axes_Donor, 'YGrid','on');
set(handles.axes_Acceptor, 'YGrid','on');
if (get(handles.checkbox_xlimAll,'Value')==get(handles.checkbox_xlimAll,'Max')) && ~isempty(handles.Xscale)
set(handles.axes_Donor,'XLim',handles.Xscale);
set(handles.axes_Acceptor,'XLim',handles.Xscale);
end
if (get(handles.checkbox_ylimAll,'Value')==get(handles.checkbox_ylimAll,'Max')) && ~isempty(handles.Yscale)
set(handles.axes_Donor,'YLim',handles.Yscale);
set(handles.axes_Acceptor,'YLim',handles.Yscale);
end
handles.currentFrame = i;
set(handles.axes_Acceptor, 'ButtonDownFcn', {@axes_Acceptor_ButtonDownFcn handles});
set(handles.catagoryText,'String',handles.traces(i).catagory);
guidata(hObject, handles);
function buttongroupDisp_SelectionChangeFcn(hObject,eventdata)
handles = guidata(hObject);
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
case 'radiobutton_showAll'
set(handles.plots(1,1),'LineStyle','-');
set(handles.plots(1,2),'LineStyle','-');
case 'radiobutton_showD'
set(handles.plots(1,1),'LineStyle','-');
set(handles.plots(1,2),'LineStyle','none');
case 'radiobutton_showA'
set(handles.plots(1,1),'LineStyle','none');
set(handles.plots(1,2),'LineStyle','-');
otherwise
%set(handles.buttongroupDisp,'SelectedObject',[]);
set(handles.plots(1,1),'LineStyle','-');
set(handles.plots(1,2),'LineStyle','-');
end
guidata(hObject, handles);
function button_Open_Callback(hObject, eventdata, handles)
%set(handles.buttongroupDisp,'SelectedObject',[]);
[fname,pathname,temp] = uigetfile('.mat','Open a .mat file');
load(fullfile(pathname,fname));
handles.traces = traces;
handles.currentFrame = 1;
handles.Xscale = [];
handles.Yscale = [];
i = handles.currentFrame;
%Catagory of trace. eg 1 for no FRET, 2 for fast photobleach, etc
handles.traces(i).catagory='';
N = size(handles.traces,2); % number of total traces
set(handles.statText_fname,'String',fname);
set(handles.statText_num,'String',sprintf('1 of %d',N)); % disp number of traces
handles.trLength = size(handles.traces(i).donr,1);
set(handles.statText_trLength,'String',sprintf('%d frame', handles.trLength)); %disp trace length (number of frames)
if N > 10
majorstep = 0.1;
else
majorstep = 0.5;
end
if N == 1
minorstep = 1;
else
minorstep = 1/(N-1);
end
sliderstep = [minorstep, majorstep];
set(handles.slider1,'Value',i,'Min',1,'Max',N,'SliderStep',sliderstep,'Enable','on');
x = [1:handles.trLength];
donr = handles.traces(i).donr;
acptr = handles.traces(i).acptr;
if ~isfield(handles.traces(i),'idealAcptr')
handles.traces(i).idealAcptr=[];
handles.traces(i).idealDonr=[];
end
idealAcptr=handles.traces(i).idealAcptr;
idealDonr=handles.traces(i).idealDonr;
if ~isempty(idealAcptr) && ~isempty(idealDonr)
handles.plots = [plot(handles.axes_Donor, x,donr,'b',x,idealDonr,'k'),plot(handles.axes_Acceptor,x,acptr,'m',x,idealAcptr,'k')];
else
handles.plots = [plot(handles.axes_Donor, x,donr,'b'),plot(handles.axes_Acceptor,x,acptr,'m')];
end
handles.miniplot=plot(handles.axes_crosscor, xcorr(acptr,donr,50));
if handles.traces(i).IndT == 1
set(handles.plots(1,1),'Color','g');
set(handles.plots(1,2),'Color','r');
end
set(handles.axes_Donor, 'YGrid','on');
set(handles.axes_Acceptor, 'YGrid','on');
set(handles.edit_truncH,'String',[]);
set(handles.edit_truncT,'String',[]);
set(handles.edit_xlimH,'String',[]);
set(handles.edit_xlimL,'String',[]);
set(handles.edit_ylimH,'String','3500');
set(handles.edit_ylimL,'String','2000');
set(handles.checkbox_xlimAll,'Value',0);
set(handles.checkbox_ylimAll,'Value',1);
set(handles.checkbox_truncAll,'Value',0);
set(handles.button_Save,'Enable','on');
set(handles.button_select,'Enable','on');
set(handles.button_deselect,'Enable','on');
set(handles.button_setYlim,'Enable','on');
set(handles.button_setXlim,'Enable','on');
set(handles.button_trunc,'Enable','on');
set(handles.button_remove0,'Enable','on');
set(handles.axes_Acceptor, 'ButtonDownFcn', {@axes_Acceptor_ButtonDownFcn handles});
guidata(hObject, handles);
function button_Save_Callback(hObject, eventdata, handles)
traces = handles.traces;
N = size(handles.traces,2);
j = 1; % j record the number of tags
for i = 1:N
if handles.traces(i).IndT == 1
traces(j) = handles.traces(i);
j = j+1;
end
end
traces(j:N)=[];
%vbFRET likes the data in a cell array called data
data = cell(1,j-1);
for i=1:j-1
data(i)={[traces(i).donr,traces(i).acptr]};
end
saveVars = {'traces','data'};
sname = get(handles.statText_fname,'String');
disp(sname)
uisave(saveVars,sname);
guidata(hObject, handles);
function button_select_Callback(hObject, eventdata, handles)
i = handles.currentFrame;
if handles.traces(i).IndT ~= 1
handles.traces(i).IndT = 1;
set(handles.plots(1,1),'Color','g');
set(handles.plots(1,2),'Color','r');
end
guidata(hObject, handles);
function button_deselect_Callback(hObject, eventdata, handles)
i = handles.currentFrame;
if handles.traces(i).IndT ~= 0
handles.traces(i).IndT = 0;
set(handles.plots(1,1),'Color','b');
set(handles.plots(1,2),'Color','m');
end
guidata(hObject, handles);
function button_trunc_Callback(hObject, eventdata, handles)
i = handles.currentFrame;
head = get(handles.edit_truncH,'String');
tail = get(handles.edit_truncT,'String');
if ~isempty(head) && ~isempty(tail)
hd = str2double(head);
tl = str2double(tail);
if (~isnan(hd) && ~isnan(tl)) && (hd < tl)
if get(handles.checkbox_truncAll,'Value') == get(handles.checkbox_truncAll,'Max') % if 'truncAll' checked
N = round(get(handles.slider1,'Max'));
for m = 1:N
handles.traces(m).donr(tl+1:handles.trLength) = [];
handles.traces(m).acptr(tl+1:handles.trLength) = [];
handles.traces(m).donr(1:hd-1) = [];
handles.traces(m).acptr(1:hd-1) = [];
end % trunc all traces
else % else just trunc the current trace
handles.traces(i).donr(tl+1:handles.trLength) = [];
handles.traces(i).acptr(tl+1:handles.trLength) = [];
handles.traces(i).donr(1:hd-1) = [];
handles.traces(i).acptr(1:hd-1) = [];
end
handles.trLength = size(handles.traces(i).donr,1); % disp truncated trace
x = [1:handles.trLength];
set(handles.statText_trLength,'String',sprintf('%d frame', handles.trLength)); %disp trace length (number of frames)
donr = handles.traces(i).donr;
acptr = handles.traces(i).acptr;
idealAcptr=handles.traces(i).idealAcptr;
idealDonr=handles.traces(i).idealDonr;
if ~isempty(idealAcptr) && ~isempty(idealDonr)
idealAcptr=handles.traces(i).idealAcptr;
idealDonr=handles.traces(i).idealDonr;
handles.plots = [plot(handles.axes_Donor, x,donr,'b',x,idealDonr,'k'),plot(handles.axes_Acceptor,x,acptr,'m',x,idealAcptr,'k')];
else
handles.plots = [plot(handles.axes_Donor, x,donr,'b'),plot(handles.axes_Acceptor,x,acptr,'m')];
end
if handles.traces(i).IndT == 1
set(handles.plots(1,1),'Color','g');
set(handles.plots(1,2),'Color','r');
end
set(handles.axes_Donor, 'YGrid','on');
set(handles.axes_Acceptor, 'YGrid','on');
%set(handles.edit_xlimH,'String',[]); % reset the axis scale settings
%set(handles.edit_xlimL,'String',[]);
%set(handles.edit_ylimH,'String',[]);
%set(handles.edit_ylimL,'String',[]);
%set(handles.checkbox_xlimAll,'Value',0);
%set(handles.checkbox_ylimAll,'Value',0);
else
set(handles.edit_truncH,'String',1);
set(handles.edit_truncT,'String',sprintf('%d',handles.trLength));
end
end
set(handles.axes_Acceptor, 'ButtonDownFcn', {@axes_Acceptor_ButtonDownFcn handles});
guidata(hObject, handles);
function button_setXlim_Callback(hObject, eventdata, handles)
From = get(handles.edit_xlimL,'String');
To = get(handles.edit_xlimH,'String');
if ~isempty(From) && ~isempty(To)
xL = str2double(From);
xH = str2double(To);
if ~isnan(xL) && ~isnan(xH)
set(handles.axes_Donor,'XLim',[xL,xH]);
set(handles.axes_Acceptor,'XLim',[xL,xH])
else
set(handles.edit_xlimL,'String','0');
set(handles.edit_xlimH,'String','2000');
end
end
if (get(handles.checkbox_xlimAll,'Value')==get(handles.checkbox_xlimAll,'Max'))
handles.Xscale = [xL, xH];
end
guidata(hObject, handles);
function button_remove0_Callback(hObject, eventdata, handles)
% remove the zero-read data point in all loaded traces.
num = size(handles.traces,2);
trlength = handles.trLength;
i = handles.currentFrame;
IndZ = zeros(1,trlength);
m = 1;
for l = 1:trlength
if handles.traces(i).donr(l)==0
IndZ(m) = l;
m = m+1;
end
end
IndZ(m:trlength)=[];
for n = 1:num
for k = m-1:-1:1
handles.traces(n).donr(IndZ(k)) = [];
handles.traces(n).acptr(IndZ(k)) = [];
end
end
handles.trLength = size(handles.traces(i).donr,1); % disp truncated trace
x = [1:handles.trLength];
set(handles.statText_trLength,'String',sprintf('%d frame', handles.trLength)); %disp trace length (number of frames)
donr = handles.traces(i).donr;
acptr = handles.traces(i).acptr;
idealAcptr=handles.traces(i).idealAcptr;
idealDonr=handles.traces(i).idealDonr;
if ~isempty(idealAcptr)
idealAcptr=handles.traces(i).idealAcptr;
idealDonr=handles.traces(i).idealDonr;
handles.plots = [plot(handles.axes_Donor, x,donr,'b',x,idealDonr,'k'),plot(handles.axes_Acceptor,x,acptr,'m',x,idealAcptr,'k')];
else
handles.plots = [plot(handles.axes_Donor, x,donr,'b'),plot(handles.axes_Acceptor,x,acptr,'m')];
end
if handles.traces(i).IndT == 1
set(handles.plots(1,1),'Color','g');
set(handles.plots(1,2),'Color','r');
end
set(handles.axes_Donor, 'YGrid','on');
set(handles.axes_Acceptor, 'YGrid','on');
set(handles.axes_Acceptor, 'ButtonDownFcn', {@axes_Acceptor_ButtonDownFcn handles});
guidata(hObject, handles);
function button_setYlim_Callback(hObject, eventdata, handles)
From = get(handles.edit_ylimL,'String');
To = get(handles.edit_ylimH,'String');
if ~isempty(From) && ~isempty(To)
yL = str2double(From);
yH = str2double(To);
if ~isnan(yL) && ~isnan(yH)
set(handles.axes_Donor,'YLim',[yL,yH]);
set(handles.axes_Acceptor,'YLim',[yL,yH]);
else
set(handles.edit_ylimL,'String','1400');
set(handles.edit_ylimH,'String','2100');
end
end
if (get(handles.checkbox_ylimAll,'Value')==get(handles.checkbox_ylimAll,'Max'))
handles.Yscale = [yL, yH];
end
guidata(hObject, handles);
%autogen functions below ++++++++++++++++++++++++++++++++++++++++
function slider1_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function edit_truncH_Callback(hObject, eventdata, handles)
function edit_truncH_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_truncT_Callback(hObject, eventdata, handles)
function edit_truncT_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function checkbox_truncAll_Callback(hObject, eventdata, handles)
function edit_xlimL_Callback(hObject, eventdata, handles)
function edit_xlimL_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_xlimH_Callback(hObject, eventdata, handles)
function edit_xlimH_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function checkbox_xlimAll_Callback(hObject, eventdata, handles)
function edit_ylimL_Callback(hObject, eventdata, handles)
function edit_ylimL_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_ylimH_Callback(hObject, eventdata, handles)
function edit_ylimH_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function checkbox_ylimAll_Callback(hObject, eventdata, handles)
% --- Executes on button press in rebinCheckbox.
function rebinCheckbox_Callback(hObject, eventdata, handles)
% hObject handle to rebinCheckbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function rebinTextBox_Callback(hObject, eventdata, handles)
% hObject handle to rebinTextBox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of rebinTextBox as text
% str2double(get(hObject,'String')) returns contents of rebinTextBox as a double
% --- Executes during object creation, after setting all properties.
function rebinTextBox_CreateFcn(hObject, eventdata, handles)
% hObject handle to rebinTextBox (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
function TracesView2_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 TracesView2 (see VARARGIN)
% Choose default command line output for TracesView2
handles.output = hObject;
% set buttongroup slectionChangeFunction alias
%set(handles.buttongroupDisp,'SelectionChangeFcn',@buttongroupDisp_SelectionChangeFcn);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes TracesView2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Executes on mouse press over axes background.
function axes_Acceptor_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes_Acceptor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axesHandle = get(hObject,'Parent');
coordinates = get(axesHandle,'CurrentPoint');
%the range of coordinates in the x direction goes from 10 to 230 I don't
%know if that's pixles or whatever. I don't care.
traceLength=size(handles.traces(handles.currentFrame).acptr,1);
coordinates = round((coordinates(1,1)-10)/220*traceLength);
head = get(handles.edit_truncH,'String');
tail = get(handles.edit_truncT,'String');
if isempty(tail)
set(handles.edit_truncT,'String',num2str(coordinates(1)));
else
if isempty(head)
set(handles.edit_truncH,'String',num2str(coordinates(1)));
else
set(handles.edit_truncT,'String','');
set(handles.edit_truncH,'String','');
end
end
% --- Executes on key press with focus on figure1 or any of its controls.
function figure1_WindowKeyPressFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata structure with the following fields (see FIGURE)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
switch eventdata.Key
case 's'
button_select_Callback(hObject, eventdata, handles)
case 'd'
button_deselect_Callback(hObject, eventdata, handles)
case 'rightarrow'
case 'leftarrow'
case 'uparrow'
case 'downarrow'
otherwise
handles.traces(handles.currentFrame).catagory=eventdata.Key;
set(handles.catagoryText,'String',eventdata.Key);
guidata(hObject, handles);
end
% --- Executes on button press in tallyButton.
function tallyButton_Callback(hObject, eventdata, handles)
% hObject handle to tallyButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
catagories={'uncat'};%holds catagory names
counts=[0]; %holds corresponding catagory counts
%go through the traces to get a count for each catagory
for i=1:size(handles.traces,2)
%if this trace has a catagory
if ~isempty(handles.traces(i).catagory)
%if the catagory is already in catagory
if ismember(handles.traces(i).catagory,catagories)
%find the index of that catagory
ind=strcmp(catagories,handles.traces(i).catagory);
%and incrament the respective counter
counts(ind)=counts(ind)+1;
else
%if it's not in yet, add it and set the counter to 1
catagories{size(catagories,2)+1}=handles.traces(i).catagory;
counts(size(counts,2)+1)=1;
end
else
counts(1)=counts(1)+1;
end
end
%sort alphabetially
[tmp,sortedInd]=sort(catagories);
catagories=catagories(sortedInd);
counts=counts(sortedInd);
%build the output string
outString='';
for i=1:size(counts,2)
outString=sprintf('%s%s %s\n',outString,char(catagories(i)),int2str(counts(i)));
end
%display the tally in a message box
msgbox(outString);
% --- Executes on button press in saveAll.
function saveAll_Callback(hObject, eventdata, handles)
% hObject handle to saveAll (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%right now this just saves everything
traces = handles.traces;
N = size(handles.traces,2);
j = 1; % j record the number of tags
for i = 1:N
% if handles.traces(i).IndT == 1
traces(j) = handles.traces(i);
j = j+1;
% end
end
traces(j:N)=[];
%vbFRET likes the data in a cell array called data
data = cell(1,j-1);
for i=1:j-1
data(i)={[traces(i).donr,traces(i).acptr]};
end
saveVars = {'traces','data'};
sname = get(handles.statText_fname,'String');
disp(sname)
uisave(saveVars,sname);
guidata(hObject, handles);
% --- Executes on button press in saveCat.
function saveCat_Callback(hObject, eventdata, handles)
% hObject handle to saveCat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
traces = handles.traces;
N = size(handles.traces,2);
j = 1; % j record the number of tags
for i = 1:N
% if handles.traces(i).IndT == 1
traces(j) = handles.traces(i);
j = j+1;
% end
end
traces(j:N)=[];
%vbFRET likes the data in a cell array called data
data = cell(1,j-1);
for i=1:j-1
data(i)={[traces(i).donr,traces(i).acptr]};
end
saveVars = {'traces','data'};
sname = get(handles.statText_fname,'String');
disp(sname)
uisave(saveVars,sname);
guidata(hObject, handles);