-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelectConditionsEditor.m
More file actions
437 lines (367 loc) · 16.1 KB
/
Copy pathSelectConditionsEditor.m
File metadata and controls
437 lines (367 loc) · 16.1 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
function varargout = SelectConditionsEditor(varargin)
% SELECTCONDITIONSEDITOR M-file for SelectConditionsEditor.fig
% SELECTCONDITIONSEDITOR, by itself, creates a new SELECTCONDITIONSEDITOR or raises the existing
% singleton*.
%
% H = SELECTCONDITIONSEDITOR returns the handle to a new SELECTCONDITIONSEDITOR or the handle to
% the existing singleton*.
%
% SELECTCONDITIONSEDITOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SELECTCONDITIONSEDITOR.M with the given input arguments.
%
% SELECTCONDITIONSEDITOR('Property','Value',...) creates a new SELECTCONDITIONSEDITOR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SelectConditionsEditor_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SelectConditionsEditor_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 SelectConditionsEditor
% Last Modified by GUIDE v2.5 18-May-2007 15:26:57
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SelectConditionsEditor_OpeningFcn, ...
'gui_OutputFcn', @SelectConditionsEditor_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 SelectConditionsEditor is made visible.
function SelectConditionsEditor_OpeningFcn(hObject, eventdata, handles, varargin)
% Set Window size and Position
screensize=get(0,'screensize');
winsize=get(handles.SelectConditionsEditor,'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.SelectConditionsEditor,'Position',winpos);
% Get data for listboxes
handles.conditionNames=varargin{1};
handles.exprp=varargin{2};
preproDone=varargin{3};
% Set repeat state and listbox contents
if ~preproDone
set(handles.repeatPreprocess,'Enable','off')
end
set(handles.conditionList,'String',handles.conditionNames')
handles.repliNames=cell(max(size(handles.exprp{1})),1);
for i=1:max(size(handles.exprp{1}))
handles.repliNames{i}=handles.exprp{1}{i};
end
set(handles.replicateList,'String',handles.repliNames','Max',length(handles.repliNames))
temp=zeros(1,length(handles.conditionNames));
for i=1:length(handles.conditionNames)
temp(i)=max(size(handles.exprp{i}));
end
set(handles.chosenReplicateList,'Value',1,'Max',max(temp))
% Choose default command line output for SelectConditionsEditor
handles.repeat=0; % Do not repeat preprocessing steps
handles.newConditions=handles.conditionNames; % Default output all conditions
defReps=cell(1,length(handles.conditionNames));
for i=1:length(handles.conditionNames)
defReps{i}=1:max(size(handles.exprp{i}));
end
handles.newReplicates=defReps; % Default output all replicates
handles.newExprp=handles.exprp; % Default exprp
handles.newNumber=length(handles.conditionNames); % Default number of conditions
handles.newIndex=1:length(handles.conditionNames); % Default index of conditions
handles.takeAllReps=0; % By default do not take all replicates for
% each conditions if user acts
handles.cancel=false; % Do not proceed to normalization if
% cancel is pressed
% Initialize temporary variables for selected conditions in the case of not taking all the
% replicates for each condition. When OK is pressed, if they are not empty,
% handloes.newSomething variables take these values, else the defaults
handles.tempNewNumber=0;
handles.tempNewIndex=[];
handles.tempNewConditions={};
handles.tempNewReplicates={};
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes SelectConditionsEditor wait for user response (see UIRESUME)
uiwait(handles.SelectConditionsEditor);
% --- Outputs from this function are returned to the command line.
function varargout = SelectConditionsEditor_OutputFcn(hObject, eventdata, handles)
if (get(handles.cancelButton,'Value')==0)
delete(handles.SelectConditionsEditor);
elseif (get(handles.okButton,'Value')==0)
delete(handles.SelectConditionsEditor);
end
% Get default command line output from handles structure
varargout{1}=handles.repeat;
varargout{2}=handles.newNumber; % New number of conditions
varargout{3}=handles.newIndex; % New index of condition names
varargout{4}=handles.newConditions; % New condition names
varargout{5}=handles.newReplicates; % New indices of replicates
varargout{6}=handles.newExprp; % New exprp output
varargout{7}=handles.cancel; % If user presses cancel
% --- Executes on button press in repeatPreprocess.
function repeatPreprocess_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
handles.repeat=1;
else
handles.repeat=0;
end
guidata(hObject,handles);
% --- Executes on button press in selectAllReplicates.
function selectAllReplicates_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1
set(handles.text2,'Enable','off')
set(handles.conditionList,'Max',length(handles.conditionNames))
set(handles.replicateList,'String',' ','Value',1,'Enable','off',...
'BackgroundColor',[235/255 233/255 237/255])
set(handles.text3,'Enable','off')
set(handles.chosenReplicateList,'String',' ','Value',1,'Enable','off',...
'BackgroundColor',[235/255 233/255 237/255])
set(handles.addReplicate,'Enable','off')
set(handles.removeReplicate,'Enable','off')
handles.takeAllReps=1;
else
set(handles.text2,'Enable','on')
set(handles.conditionList,'Value',1)
set(handles.conditionList,'Max',1)
set(handles.replicateList,'Enable','on','String',handles.repliNames,...
'BackgroundColor','white')
set(handles.text3,'Enable','on')
set(handles.chosenReplicateList,'String',' ','Enable','on',...
'BackgroundColor','white')
set(handles.addReplicate,'Enable','on')
% set(handles.removeReplicate,'Enable','on')
handles.takeAllReps=0;
end
guidata(hObject,handles);
% --- Executes on selection change in conditionList.
function conditionList_Callback(hObject, eventdata, handles)
selected=get(hObject,'Value');
allItems=get(hObject,'String');
set(handles.replicateList,'Value',1) % Avoid leave previous selections highlighted
if ~handles.takeAllReps
corrReps=cell(max(size(handles.exprp{selected})),1);
for i=1:max(size(handles.exprp{selected}))
corrReps{i}=handles.exprp{selected}{i};
end
set(handles.replicateList,'String',corrReps)
set(handles.chosenReplicateList,'String','')
[mbr,loc]=ismember(selected,handles.tempNewIndex);
if mbr
selRepsInd=handles.tempNewReplicates{loc};
if ~isempty(selRepsInd)
selReps=handles.exprp{selected}(selRepsInd);
set(handles.chosenReplicateList,'String',selReps)
end
end
else
handles.newNumber=length(selected);
handles.newIndex=selected;
handles.newConditions=allItems(selected)';
defReps=cell(1,length(handles.conditionNames));
for i=1:length(handles.conditionNames)
defReps{i}=1:max(size(handles.exprp{i}));
end
handles.newReplicates=defReps(selected);
handles.newExprp=handles.exprp(selected);
set(handles.okButton,'Enable','on')
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function conditionList_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in replicateList.
function replicateList_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function replicateList_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in chosenReplicateList.
function chosenReplicateList_Callback(hObject, eventdata, handles)
% If the list is not empty enable remove button
if ~isempty(get(hObject,'String'))
set(handles.removeReplicate,'Enable','on')
end
% --- Executes during object creation, after setting all properties.
function chosenReplicateList_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in addReplicate.
function addReplicate_Callback(hObject, eventdata, handles)
% Do some preallocation
tempNames=cell(1,length(handles.conditionNames));
tempReps=cell(1,length(handles.conditionNames));
% Get some variables
allConds=get(handles.conditionList,'String');
allReps=get(handles.replicateList,'String');
selectedCond=get(handles.conditionList,'Value');
selectedReps=get(handles.replicateList,'Value');
selectedCondName=allConds(selectedCond);
% Do the job
oldstr=get(handles.chosenReplicateList,'String');
addstr=allReps(selectedReps);
verify=ismember(addstr,oldstr);
if isempty(oldstr)
newstr=[oldstr;addstr];
elseif length(verify)==1
if ~ismember(addstr,oldstr)
newstr=[oldstr;addstr];
else
newstr=oldstr;
end
elseif any(verify)
newind=find(verify==0);
newstr=[oldstr;addstr(newind)];
elseif ~all(verify)
newstr=[oldstr;addstr];
else
newstr=oldstr;
end
set(handles.chosenReplicateList,'String',newstr)
tempNames{selectedCond}=selectedCondName;
tempReps{selectedCond}=selectedReps;
[handles.tempNewNumber,handles.tempNewIndex,handles.tempNewConditions,...
handles.tempNewReplicates]=updateCondsReps(handles.tempNewNumber,handles.tempNewIndex,...
handles.tempNewConditions,handles.tempNewReplicates,tempNames,tempReps,1);
% Enable Remove and OK buttons
if handles.tempNewNumber~=0
set(handles.removeReplicate,'Enable','on')
set(handles.okButton,'Enable','on')
end
guidata(hObject,handles);
% disp('------------------------------')
% disp(handles.tempNewNumber)
% disp(handles.tempNewIndex)
% disp(handles.tempNewConditions)
% for i=1:length(handles.tempNewReplicates)
% disp(handles.tempNewReplicates{i})
% end
% disp('------------------------------')
% disp(' ')
% --- Executes on button press in removeReplicate.
function removeReplicate_Callback(hObject, eventdata, handles)
% Do some preallocation
tempNames=cell(1,length(handles.conditionNames));
tempReps=cell(1,length(handles.conditionNames));
% Get some variables
allConds=get(handles.conditionList,'String');
selectedCond=get(handles.conditionList,'Value');
[mbr,loc]=ismember(selectedCond,handles.tempNewIndex);
selectedCondName=allConds(selectedCond);
selectedChosenRepsPre=get(handles.chosenReplicateList,'Value');
selectedChosenReps=handles.tempNewReplicates{loc}(selectedChosenRepsPre);
% Do the job
str=get(handles.chosenReplicateList,'String');
set(handles.chosenReplicateList,'Value',1)
str(selectedChosenRepsPre)=[];
set(handles.chosenReplicateList,'String',str)
% If the list is empty disable the Remove button
if isempty(get(handles.chosenReplicateList,'String'))
set(handles.removeReplicate,'Enable','off')
end
tempNames{selectedCond}=selectedCondName;
tempReps{selectedCond}=selectedChosenReps;
[handles.tempNewNumber,handles.tempNewIndex,handles.tempNewConditions,...
handles.tempNewReplicates]=updateCondsReps(handles.tempNewNumber,handles.tempNewIndex,...
handles.tempNewConditions,handles.tempNewReplicates,tempNames,tempReps,0);
% If everything empty disable OK button
if handles.tempNewNumber==0
set(handles.okButton,'Enable','off')
end
guidata(hObject,handles);
% disp('------------------------------')
% disp(handles.tempNewNumber)
% disp(handles.tempNewIndex)
% disp(handles.tempNewConditions)
% for i=1:length(handles.tempNewReplicates)
% disp(handles.tempNewReplicates{i})
% end
% disp('------------------------------')
% disp(' ')
% --- Executes on button press in okButton.
function okButton_Callback(hObject, eventdata, handles)
% Return the final values
if handles.tempNewNumber~=0 && ~handles.takeAllReps
handles.newNumber=handles.tempNewNumber;
handles.newIndex=handles.tempNewIndex;
handles.newConditions=handles.tempNewConditions;
handles.newReplicates=handles.tempNewReplicates;
for i=1:length(handles.newIndex)
handles.tempNewExprp{i}=handles.exprp{handles.newIndex(i)}(handles.newReplicates{i});
end
handles.newExprp=handles.tempNewExprp;
guidata(hObject,handles);
end
uiresume(handles.SelectConditionsEditor);
% --- Executes on button press in cancelButton.
function cancelButton_Callback(hObject, eventdata, handles)
% Resume default outputs
handles.repeat=0;
handles.newConditions=handles.conditionNames;
defReps=cell(1,length(handles.conditionNames));
for i=1:length(handles.conditionNames)
defReps{i}=1:max(size(handles.exprp{i}));
end
handles.newReplicates=defReps;
handles.newNumber=length(handles.conditionNames);
handles.newIndex=1:length(handles.conditionNames);
handles.takeAllReps=0;
handles.cancel=true; % Cancel pressed
guidata(hObject,handles);
uiresume(handles.SelectConditionsEditor);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% HELP FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [newNumber,newIndex,newConditions,newReplicates] = updateCondsReps(newNumber,...
newIndex,...
newConditions,...
newReplicates,...
nams,reps,add)
% If add=1 then add to list else if add=0 remove from list
ind=newNumber;
if add
for i=1:length(nams)
if ~isempty(nams{i}) && ~isempty(reps{i})
[mbr,loc]=ismember(nams{i},newConditions);
if ~mbr
newConditions=[newConditions,nams{i}];
ind=ind+1;
newNumber=ind;
newIndex=[newIndex,i];
newReplicates=[newReplicates,reps{i}];
else
if ~isempty(setdiff(reps{i},newReplicates{loc}))
newReplicates{loc}=union(reps{i},newReplicates{loc});
end
end
end
end
else
for i=1:length(nams)
if ~isempty(reps{i})
[mbr,loc]=ismember(nams{i},newConditions);
newreps=setdiff(newReplicates{loc},reps{i});
if ~isempty(newreps)
newReplicates{loc}=newreps;
else
newConditions(loc)=[];
ind=ind-1;
newNumber=ind;
newIndex(loc)=[];
newReplicates(loc)=[];
end
end
end
end