IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
sheload.m
Go to the documentation of this file.
1 %> @ingroup guigroup sheware mainguis
2 %> @file
3 %> @brief GUI for loading datasets from the SHEware database.
4 %>
5 %> The parameters names <b>Experiment</b>, <b>Domain</b>, <b>Deactivation Scheme</b>, <b>Tray</b>, and <b>Classifier</b> match SHEware terminology (e.g. "classifier" in IRootLab has another meaning).
6 %>
7 %> Each <b>Classifier</b> selected will generate one class level in the dataset.
8 %>
9 %> After clicking on <b>Generate dataset</b>:
10 %> @arg data will be retrieved from the SHEware database
11 %> @arg the Window will close
12 %> @arg a new dataset will appear in @c datatool (and in MATLAB workspace).
13 %>
14 %> @image html Screenshot-sheload.png
15 
16 %> @cond
17 function varargout = sheload(varargin)
18 % Last Modified by GUIDE v2.5 22-Nov-2012 16:15:46
19 
20 % Begin initialization code - DO NOT EDIT
21 gui_Singleton = 1;
22 gui_State = struct('gui_Name', mfilename, ...
23  'gui_Singleton', gui_Singleton, ...
24  'gui_OpeningFcn', @sheload_OpeningFcn, ...
25  'gui_OutputFcn', @sheload_OutputFcn, ...
26  'gui_LayoutFcn', [] , ...
27  'gui_Callback', []);
28 if nargin && ischar(varargin{1})
29  gui_State.gui_Callback = str2func(varargin{1});
30 end
31 
32 if nargout
33  [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
34 else
35  gui_mainfcn(gui_State, varargin{:});
36 end
37 % End initialization code - DO NOT EDIT
38 
39 
40 % --- Executes just before sheload is made visible.
41 function sheload_OpeningFcn(hObject, eventdata, handles, varargin)
42 try
44  handles.output.flag_ok = 0;
45  handles.ids_experiment = [];
46  handles.ids_domain = [];
47  handles.ids_deact = [];
48  handles.ids_judge = [];
49  handles.ids_tray = [];
50  handles.idxs_judge = []; % will be synchronized with which is shown in edit_judge
51  guidata(hObject, handles);
52  gui_set_position(hObject);
53  populate_experiment(handles);
54 catch ME
55  send_error(ME);
56 end;
57 
58 
59 
60 % --- Outputs from this function are returned to the command clae.
61 function varargout = sheload_OutputFcn(hObject, eventdata, handles)
62 try
63  uiwait(handles.figure1);
64  handles = guidata(hObject);
65  varargout{1} = handles.output;
66  delete(gcf);
67 catch
68  output.flag_ok = 0;
69  output.params = {};
70  varargout{1} = output;
71 end;
72 varargout{1} = handles.output;
73 
74 %############################################
75 
76 %#########
77 function z = get_idexperiment(hh)
78 idx = get(hh.popupmenu_experiment, 'Value');
79 if idx == 1
80  z = [];
81 else
82  z = hh.ids_experiment(idx-1);
83 end;
84 
85 %#########
86 function z = get_iddomain(hh)
87 idx = get(hh.popupmenu_domain, 'Value');
88 if idx == 1
89  z = [];
90 else
91  z = hh.ids_domain(idx-1);
92 end;
93 
94 %#########
95 function z = get_iddeact(hh)
96 idx = get(hh.popupmenu_deact, 'Value');
97 if idx == 1
98  z = [];
99 else
100  z = hh.ids_deact(idx-1);
101 end;
102 
103 %#########
104 function z = get_idtray(hh)
105 idx = get(hh.popupmenu_tray, 'Value');
106 if idx == 1
107  z = [];
108 else
109  z = hh.ids_tray(idx-1);
110 end;
111 
112 %#########
113 function z = get_idjudge(hh)
114 z = [];
115 if numel(hh.idxs_judge) > 0
116  z = hh.ids_judge(hh.idxs_judge);
117 end;
118 
119 
120 %#########
121 function populate_experiment(hh)
122 a = {'(Select)'};
123 b = irquery(sprintf('select id, name from experiment order by name'));
124 ids = b.id;
125 names = b.name;
126 for i = 1:numel(ids)
127  a = [a sprintf('%s (id %d)', names{i}, ids(i))];
128 end;
129 set(hh.popupmenu_experiment, 'Value', 1);
130 set(hh.popupmenu_experiment, 'String', a);
131 switch_experiment(hh);
132 hh.ids_experiment = ids;
133 guidata(hh.figure1, hh);
134 
135 
136 %#########
137 function populate_domain(hh)
138 a = {'(Select)'};
139 idexperiment = get_idexperiment(hh);
140 if idexperiment > 0
141  b = irquery(sprintf('select domain.id, domain.name, count(*) as ccc from series left join domain on domain.id = series.iddomain where series.idexperiment = %d group by series.iddomain order by domain.name', idexperiment));
142  ids = b.id;
143  names = b.name;
144  counts = b.ccc;
145  for i = 1:numel(ids)
146  a = [a sprintf('%s (id %d) - %d series', names{i}, ids(i), counts(i))];
147  end;
148  hh.ids_domain = ids;
149  guidata(hh.figure1, hh);
150 end;
151 set(hh.popupmenu_domain, 'Value', 1);
152 set(hh.popupmenu_domain, 'String', a);
153 switch_domain(hh);
154 
155 
156 %#########
157 function populate_deact(hh)
158 a = {'(Leave blank)'};
159 idexperiment = get_idexperiment(hh);
160 b = irquery(sprintf('select id, name from deact order by name'));
161 ids = b.id;
162 names = b.name;
163 if idexperiment > 0
164  for i = 1:length(ids)
165  b = irquery(sprintf('select count(*) as ccc from deact_spectrum left join spectrum on deact_spectrum.idspectrum = spectrum.id where iddeact = %d and spectrum.idexperiment = %d', ids(i), idexperiment));
166  count = b.ccc;
167  a = [a sprintf('%s (id %d) - %d outliers', names{i}, ids(i), count)];
168  end;
169 else
170  for i = 1:numel(ids)
171  a = [a sprintf('%s (id %d)', names{i}, ids(i))];
172  end;
173 end;
174 set(hh.popupmenu_deact, 'String', a);
175 hh.ids_deact = ids;
176 guidata(hh.figure1, hh);
177 
178 %#########
179 function populate_tray(hh)
180 a = {'(Leave blank)'};
181 idexperiment = get_idexperiment(hh);
182 if idexperiment > 0
183  b = irquery(sprintf(['select tray.id, tray.code, count(*) as ccc from spectrum ' ...
184  'left join colony on spectrum.idcolony = colony.id ' ...
185  'left join slide on colony.idslide = slide.id ' ...
186  'left join tray on slide.idtray = tray.id ' ...
187  'where spectrum.idexperiment = %d group by tray.id order by tray.code'], idexperiment));
188  ids = b.id;
189  names = b.code;
190  counts = b.ccc;
191  for i = 1:numel(ids)
192  a = [a sprintf('%s (id %d) - %d scans', names{i}, ids(i), counts(i))];
193  end;
194  hh.ids_tray = ids;
195  guidata(hh.figure1, hh);
196 end;
197 set(hh.popupmenu_tray, 'Value', 1);
198 set(hh.popupmenu_tray, 'String', a);
199 switch_tray(hh);
200 
201 %#########
202 function populate_judge(hh)
203 a = {};
204 idexperiment = get_idexperiment(hh);
205 if idexperiment > 0
206  b = irquery(sprintf(['select judge.id, judge.name, count(*) as ccc from spectrum_judge ' ...
207  'left join spectrum on spectrum_judge.idspectrum = spectrum.id ' ...
208  'left join judge on spectrum_judge.idjudge = judge.id ' ...
209  'where spectrum.idexperiment = %d and judge.class_name = "judge_score_human" group by judge.id order by judge.name'], idexperiment));
210  ids = b.id;
211  names = b.name;
212  counts = b.ccc;
213  for i = 1:numel(ids)
214  a = [a sprintf('%s (id %d)', names{i}, ids(i))];
215  end;
216  hh.ids_judge = ids;
217 end;
218 hh.idxs_judge = [];
219 set(hh.listbox_judge, 'Value', 1);
220 set(hh.listbox_judge, 'String', a);
221 guidata(hh.figure1, hh);
222 sync_judge(hh);
223 
224 
225 %#########
226 function sync_judge(hh)
227 if isempty(hh.idxs_judge)
228  a = '';
229 else
230  aa = get(hh.listbox_judge, 'String');
231  a = aa(hh.idxs_judge);
232 end;
233 set(hh.edit_judge, 'String', a);
234 
235 
236 
237 
238 %#########
239 function switch_experiment(hh)
240 populate_domain(hh);
241 populate_deact(guidata(hh.figure1));
242 populate_tray(guidata(hh.figure1));
243 populate_judge(guidata(hh.figure1));
244 
245 %#########
246 function switch_domain(hh)
247 
248 %#########
249 function switch_deact(hh)
250 
251 %#########
252 function switch_tray(hh)
253 
254 %#########
255 function switch_judge(hh)
256 
257 
258 
259 
260 %############################################
261 %############################################
262 
263 
264 % --- Executes on button press in pushbutton_ok.
265 function pushbutton_ok_Callback(hObject, eventdata, handles)
266 try
267  idexperiment = get_idexperiment(handles);
268  iddomain = get_iddomain(handles);
269  idjudge = get_idjudge(handles);
270  iddeact = get_iddeact(handles);
271  idtray = get_idtray(handles);
272 
273  if isempty(idexperiment)
274  irerror('Please select an experiment!');
275  end;
276  if isempty(iddomain)
277  irerror('Please select a domain!');
278  end;
279 
280  name = find_varname('ds_she');
281  scode = [...
282 'o = dataio_db();', 10, ...
283 sprintf('o.idexperiment = %s;\n', mat2str(idexperiment)), ...
284 sprintf('o.idjudge = %s;\n', mat2str(idjudge)), ...
285 sprintf('o.iddomain = %s;\n', mat2str(iddomain)), ...
286 sprintf('o.iddeact = %s\n', mat2str(iddeact)), ...
287 sprintf('o.idtray = %s;\n', mat2str(idtray)), ...
288 sprintf('%s = o.load();\n', name) ...
289 ];
290  ircode_eval(scode, 'Loads dataset from SHEware database');
291  handles.output.flag_ok = 1;
292  guidata(hObject, handles);
293  uiresume();
294 catch ME
295  irerrordlg(ME.message, 'Cannot continue');
296 
297 end;
298 
299 % --- Executes on selection change in popupmenu_experiment.
300 function popupmenu_experiment_Callback(hObject, eventdata, handles)
301 switch_experiment(handles);
302 
303 % --- Executes during object creation, after setting all properties.
304 function popupmenu_experiment_CreateFcn(hObject, eventdata, handles)
305 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
306  set(hObject,'BackgroundColor','white');
307 end
308 
309 % --- Executes on selection change in popupmenu_domain.
310 function popupmenu_domain_Callback(hObject, eventdata, handles)
311 
312 
313 % --- Executes during object creation, after setting all properties.
314 function popupmenu_domain_CreateFcn(hObject, eventdata, handles)
315 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
316  set(hObject,'BackgroundColor','white');
317 end
318 
319 
320 % --- Executes on selection change in popupmenu_deact.
321 function popupmenu_deact_Callback(hObject, eventdata, handles)
322 
323 
324 % --- Executes during object creation, after setting all properties.
325 function popupmenu_deact_CreateFcn(hObject, eventdata, handles)
326 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
327  set(hObject,'BackgroundColor','white');
328 end
329 
330 
331 % --- Executes on selection change in popupmenu_tray.
332 function popupmenu_tray_Callback(hObject, eventdata, handles)
333 
334 
335 % --- Executes during object creation, after setting all properties.
336 function popupmenu_tray_CreateFcn(hObject, eventdata, handles)
337 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
338  set(hObject,'BackgroundColor','white');
339 end
340 
341 
342 % --- Executes on selection change in listbox_judge.
343 function listbox_judge_Callback(hObject, eventdata, handles)
344 
345 % --- Executes during object creation, after setting all properties.
346 function listbox_judge_CreateFcn(hObject, eventdata, handles)
347 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
348  set(hObject,'BackgroundColor','white');
349 end
350 
351 % --- Executes on button press in pushbutton_add.
352 function pushbutton_add_Callback(hObject, eventdata, handles)
353 if numel(handles.ids_judge) > 0
354  handles.idxs_judge(end+1) = get(handles.listbox_judge, 'Value');
355  guidata(handles.figure1, handles);
356  sync_judge(handles);
357 end;
358 
359 % --- Executes on button press in pushbutton_restart.
360 function pushbutton_restart_Callback(hObject, eventdata, handles)
361 handles.idxs_judge = [];
362 guidata(handles.figure1, handles);
363 sync_judge(handles);
364 
365 
366 function edit_judge_Callback(hObject, eventdata, handles)
367 
368 
369 % --- Executes during object creation, after setting all properties.
370 function edit_judge_CreateFcn(hObject, eventdata, handles)
371 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
372  set(hObject,'BackgroundColor','white');
373 end
374 
375 %#####
376 function pushbutton_launch_objtool_Callback(hObject, eventdata, handles)
377 objtool;
378 
379 %#####
380 function pushbutton_launch_datatool_Callback(hObject, eventdata, handles)
381 datatool();
382 %> @endcond
function send_error(in ME)
function irerror(in s)
function objtool(in varargin)
Dataset loader/saver for the SHEWare database.
Definition: dataio_db.m:5
function connect_to_cells()
function ircode_eval(in s, in title)
function gui_set_position(in hObject)
function irquery(in varargin)
Analysis Session (AS) base class.
Definition: as.m:6
function find_varname(in prefix)
function irerrordlg(in errorstring, in dlgname)