-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFilteringEditor.m
More file actions
446 lines (352 loc) · 13.9 KB
/
Copy pathFilteringEditor.m
File metadata and controls
446 lines (352 loc) · 13.9 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
function varargout = FilteringEditor(varargin)
% FILTERINGEDITOR M-file for FilteringEditor.fig
% FILTERINGEDITOR, by itself, creates a new FILTERINGEDITOR or raises the existing
% singleton*.
%
% H = FILTERINGEDITOR returns the handle to a new FILTERINGEDITOR or the handle to
% the existing singleton*.
%
% FILTERINGEDITOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FILTERINGEDITOR.M with the given input arguments.
%
% FILTERINGEDITOR('Property','Value',...) creates a new FILTERINGEDITOR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before FilteringEditor_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to FilteringEditor_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help FilteringEditor
% Last Modified by GUIDE v2.5 13-Jul-2013 20:02:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FilteringEditor_OpeningFcn, ...
'gui_OutputFcn', @FilteringEditor_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 FilteringEditor is made visible.
function FilteringEditor_OpeningFcn(hObject, eventdata, handles, varargin)
% Take as input the image analysis software in order to control whether to use means or
% medians
handles.imgsw=varargin{1};
% Set Window size and Position
screensize=get(0,'screensize');
winsize=get(handles.FilteringEditor,'Position');
winwidth=winsize(3);
winheight=winsize(4);
screenwidth=screensize(3);
screenheight=screensize(4);
winpos=[0.5*(screenwidth-winwidth),0.5*(screenheight-winheight),winwidth,winheight];
set(handles.FilteringEditor,'Position',winpos);
% Set default outputs
handles.export=0; % By default, do not export filtered spots
handles.meanmedian=1; % Use means by default
handles.filterMethod=1; % Signal to noise filter
handles.filterParameter=2; % For signal to noise
handles.outlierTest=0; % None
handles.pval=[]; % Since test defaults to none
handles.uori='intersect'; % Poor spots are the intersection of both channels
handles.dishis=0; % Do not display histograms
handles.cancel=false; % Cancel not pressed
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FilteringEditor wait for user response (see UIRESUME)
uiwait(handles.FilteringEditor);
% --- Outputs from this function are returned to the command line.
function varargout = FilteringEditor_OutputFcn(hObject, eventdata, handles)
if (get(handles.cancelButton,'Value')==0)
delete(handles.FilteringEditor);
elseif (get(handles.okButton,'Value')==0)
delete(handles.FilteringEditor);
end
% Get default command line output from handles structure
varargout{1}=handles.export;
varargout{2}=handles.meanmedian;
varargout{3}=handles.filterMethod;
varargout{4}=handles.filterParameter;
varargout{5}=handles.outlierTest;
varargout{6}=handles.pval;
varargout{7}=handles.uori;
varargout{8}=handles.dishis;
varargout{9}=handles.cancel;
% --- Executes on button press in meanmedianCheck.
function meanmedianCheck_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
handles.meanmedian=2;
else
handles.meanmedian=1;
end
guidata(hObject,handles);
% --- Executes on button press in exportExcel.
function exportExcel_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
handles.export=1;
else
handles.export=0;
end
guidata(hObject,handles);
% --- Executes on button press in ibutton.
function ibutton_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
handles.uori='intersect';
set(handles.ubutton,'Value',0);
end
guidata(hObject,handles);
% --- Executes on button press in ubutton.
function ubutton_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
handles.uori='union';
set(handles.ibutton,'Value',0);
end
guidata(hObject,handles);
% --- Executes on button press in noFilterRadio.
function noFilterRadio_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
% In case user leaves the default values
handles.filterMethod=4;
handles.filterParameter=[];
% Disable improper textboxes
set(handles.s2nthreshEdit,'Enable','off')
set(handles.text1,'Enable','off')
set(handles.sigbackDistSigEdit,'Enable','off')
set(handles.text2,'Enable','off')
set(handles.sigbackDistBackEdit,'Enable','off')
set(handles.customEdit,'Enable','off')
end
guidata(hObject,handles);
% Hint: get(hObject,'Value') returns toggle state of noFilterRadio
% --- Executes on button press in s2nthreshRadio.
function s2nthreshRadio_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
% Enable proper textboxes
set(handles.s2nthreshEdit,'Enable','on')
% In case user leaves the default values
handles.filterMethod=1;
handles.filterParameter=2;
% Disable improper textboxes
set(handles.text1,'Enable','off')
set(handles.sigbackDistSigEdit,'Enable','off')
set(handles.text2,'Enable','off')
set(handles.sigbackDistBackEdit,'Enable','off')
set(handles.customEdit,'Enable','off')
end
guidata(hObject,handles);
% --- Executes on button press in sigbackDistRadio.
function sigbackDistRadio_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
% Enable proper textboxes
set(handles.text1,'Enable','on')
set(handles.sigbackDistSigEdit,'Enable','on')
set(handles.text2,'Enable','on')
set(handles.sigbackDistBackEdit,'Enable','on')
% In case user leaves the default values
handles.filterMethod=2;
handles.filterParameter=[0 0];
% Disable improper textboxes
set(handles.s2nthreshEdit,'Enable','off')
set(handles.customEdit,'Enable','off')
end
guidata(hObject,handles);
% --- Executes on button press in customRadio.
function customRadio_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
% Enable proper textboxes
set(handles.customEdit,'Enable','on')
handles.filterMethod=2;
% Disable improper textboxes
set(handles.s2nthreshEdit,'Enable','off')
set(handles.text1,'Enable','off')
set(handles.sigbackDistSigEdit,'Enable','off')
set(handles.text2,'Enable','off')
set(handles.sigbackDistBackEdit,'Enable','off')
end
guidata(hObject,handles);
function s2nthreshEdit_Callback(hObject, eventdata, handles)
t=str2double(get(hObject,'String'));
if isnan(t) || t<=0
uiwait(errordlg('You must enter a positive number','Bad Input','modal'));
set(hObject,'String','2');
else
handles.filterMethod=1;
handles.filterParameter=t;
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function s2nthreshEdit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function sigbackDistSigEdit_Callback(hObject, eventdata, handles)
x=str2double(get(hObject,'String'));
if isnan(x)
uiwait(errordlg('You must enter a number','Bad Input','modal'));
set(hObject,'String','0');
else
handles.filterMethod=2;
handles.filterParameter(1)=x;
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function sigbackDistSigEdit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function sigbackDistBackEdit_Callback(hObject, eventdata, handles)
y=str2double(get(hObject,'String'));
if isnan(y)
uiwait(errordlg('You must enter a number','Bad Input','modal'));
set(hObject,'String','0');
else
handles.filterMethod=2;
handles.filterParameter(2)=y;
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function sigbackDistBackEdit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function customEdit_Callback(hObject, eventdata, handles)
expr=get(hObject,'String');
exprok=checkExpression(expr,handles.imgsw,handles.meanmedian);
if exprok
handles.filterMethod=3;
handles.filterParameter=expr;
else
set(handles.customEdit,'String','Your filter here')
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function customEdit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in outlierPopup.
function outlierPopup_Callback(hObject, eventdata, handles)
outstat=get(hObject,'Value');
switch outstat;
case 1
handles.outlierTest=0; % No test
case 2
handles.outlierTest=2; % t-test
set(handles.text4,'Enable','on')
set(handles.pvalcutoff,'Enable','on')
handles.pval=str2double(get(handles.pvalcutoff,'String'));
set(handles.dispOutlierHist,'Enable','on')
case 3
handles.outlierTest=1; % Wilcoxon
set(handles.text4,'Enable','on')
set(handles.pvalcutoff,'Enable','on')
handles.pval=str2double(get(handles.pvalcutoff,'String'));
set(handles.dispOutlierHist,'Enable','on')
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function outlierPopup_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pvalcutoff_Callback(hObject, eventdata, handles)
p=str2double(get(hObject,'String'));
if isnan(p) || p<0 || p>1
uiwait(errordlg('You must enter a number between 0 and 1','Bad Input','modal'));
set(hObject,'String','0.05');
else
handles.pval=p;
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function pvalcutoff_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in dispOutlierHist.
function dispOutlierHist_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
handles.dishis=1;
else
handles.dishis=0;
end
guidata(hObject,handles);
% --- Executes on button press in okButton.
function okButton_Callback(hObject, eventdata, handles)
uiresume(handles.FilteringEditor);
% --- Executes on button press in cancelButton.
function cancelButton_Callback(hObject, eventdata, handles)
% Resume defaults
handles.export=0;
handles.meanmedian=1;
handles.filterMethod=1;
handles.filterParameter=2;
handles.outlierTest=0;
handles.pval=[];
handles.uori='intersect';
handles.dishis=0;
handles.cancel=true; % Cancel pressed
guidata(hObject,handles);
uiresume(handles.FilteringEditor);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% HELP FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function allok = checkExpression(expr,imgsw,mm)
% If the expression is OK allok is true else false
allok=true;
% Form error messages
errmsg1={'Your filter expression is probably malformed.',...
'Please check your expression again.'};
errmsg2={'You cannot use parameters that are not supported by the',...
'image analysis software (e.g. QuantArray does not have a',...
'Median'' field. Also check your choice about using medians',...
'instead of means. Note that you cannot use standard deviations',...
'with medians.'};
% Preallocate some random numbers to check the validity of the expression
sigme=ones(3,1);
backme=ones(3,1);
sigmedi=ones(3,1);
backmedi=ones(3,1);
sigst=ones(3,1);
backst=ones(3,1);
if imgsw==1 || mm==1
if ~isempty(strmatch('SigMedian',expr)) | ...
~isempty(strmatch('BackMedian',expr))
uiwait(errordlg([errmsg2,lasterr],'Bad Input','modal'));
allok=false;
return
end
elseif imgsw==2 || imgsw==3 || imgsw==4 || mm==2
if ~isempty(strmatch('SigMean',expr)) | ...
~isempty(strmatch('BackMean',expr)) | ...
~isempty(strmatch('SigStd',expr)) | ...
~isempty(strmatch('BackStd',expr))
uiwait(errordlg([errmsg2,lasterr],'Bad Input','modal'));
allok=false;
return
end
end
expr=strrep(expr,'*','.*');
expr=strrep(expr,'/','./');
expr=strrep(expr,'SigMean','sigme');
expr=strrep(expr,'BackMean','backme');
expr=strrep(expr,'SigMedian','sigmedi');
expr=strrep(expr,'BackMedian','backmedi');
expr=strrep(expr,'SigStd','sigst');
expr=strrep(expr,'BackStd','backst');
expr=[expr ';'];
try
eval(expr);
catch
allok=false;
uiwait(errordlg([errmsg1,lasterr],'Bad Input','modal'));
end