-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRN_extractionSetupGUI.m
More file actions
executable file
·452 lines (389 loc) · 15.5 KB
/
RN_extractionSetupGUI.m
File metadata and controls
executable file
·452 lines (389 loc) · 15.5 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
function varargout = RN_extractionSetupGUI(varargin)
% RN_EXTRACTIONSETUPGUI MATLAB code for RN_extractionSetupGUI.fig
% RN_EXTRACTIONSETUPGUI, by itself, creates a new RN_EXTRACTIONSETUPGUI or raises the existing
% singleton*.
%
% H = RN_EXTRACTIONSETUPGUI returns the handle to a new RN_EXTRACTIONSETUPGUI or the handle to
% the existing singleton*.
%
% RN_EXTRACTIONSETUPGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in RN_EXTRACTIONSETUPGUI.M with the given input arguments.
%
% RN_EXTRACTIONSETUPGUI('Property','Value',...) creates a new RN_EXTRACTIONSETUPGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before RN_extractionSetupGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to RN_extractionSetupGUI_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 RN_extractionSetupGUI
% Last Modified by GUIDE v2.5 15-Nov-2017 20:31:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @RN_extractionSetupGUI_OpeningFcn, ...
'gui_OutputFcn', @RN_extractionSetupGUI_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 RN_extractionSetupGUI is made visible.
function RN_extractionSetupGUI_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 RN_extractionSetupGUI (see VARARGIN)
% Choose default command line output for RN_extractionSetupGUI
handles.output = hObject;
setappdata(handles.output,'ExPath',varargin{1})
exDat = varargin{2};
dayNames = {exDat.day_name};
animalNames = {exDat.animal_name};
[~,idx] = sort(animalNames);
animalNames = animalNames(idx);
dayNames = dayNames(idx);
exDat = exDat(idx);
dayList = {};
dayIdx = zeros(numel(dayNames),1);
prevAnim = '';
for i=1:numel(dayNames),
a = animalNames{i};
if ~strcmp(a,prevAnim)
prevAnim = a;
dayList = [dayList;a];
end
dayList = [dayList;['--' dayNames{i}]];
dayIdx(i) = numel(dayList);
end
setappdata(handles.output,'dayIdx',dayIdx)
setappdata(handles.output,'ExDat',exDat)
set(handles.dir_list,'String',dayList,'Value',2)
allExTypes = {'Spikes','LFP','Time','DIO','MDA','Phy'};
setappdata(handles.output,'allExportTypes',allExTypes)
setappdata(handles.output,'origDat',exDat)
handles.i = 1;
handles.submit = 0;
updateGUI(handles);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes RN_extractionSetupGUI wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = RN_extractionSetupGUI_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
if handles.submit
out = getappdata(handles.output,'ExDat');
out2 = str2double(get(handles.parallel_edit,'String'));
else
out = [];
out2 = [];
end
varargout{1} = out;
varargout{2} = out2;
delete(handles.figure1)
% --- Updates GUI to reflect the base data structures ExPath and ExDat
function updateGUI(handles)
%
i = handles.i;
h = handles.output;
dayIdx = getappdata(h,'dayIdx');
ExDat = getappdata(h,'ExDat');
ExPath = getappdata(h,'ExPath');
ed = ExDat(i);
set(handles.info_text,'String',sprintf(...
'Animal: %s\nDay Dir: %s',ed.animal_name,ed.day_name))
set(handles.export_text,'String','')
exText = {};
exportTypes = getappdata(handles.output,'allExportTypes');
for j=1:numel(ExPath),
exItem = ExPath{j};
switch exItem
case 'Fix Filenames'
set(handles.prefix_text,'String',['Prefix: ' ed.prefix])
set(handles.prefix_panel,'Visible','On')
case 'Create Trodes Comments'
set(handles.rec_list,'String',ed.rec_order)
set(handles.rec_panel,'Visible','On')
case 'Generate Matclusts'
set(handles.parallel_panel,'Visible','On')
set(handles.prefix_panel,'Visible','On')
otherwise
[a,b] = strtok(exItem);
% Display export flags
if strcmp(a,'Export')
set(handles.config_panel,'Visible','On')
if ~isempty(ed.config)
confStr = ed.config;
[~,confStr] = fileparts(ed.config);
confStr = ['...' filesep confStr];
set(handles.config_text,'String',['Config: ' confStr])
else
set(handles.config_text,'String','Config: Default')
end
set(handles.export_panel,'Visible','On')
set(handles.prefix_panel,'Visible','On')
set(handles.prefix_text,'String',['Prefix: ' ed.prefix])
b = strtrim(b);
exIdx = find(strcmpi(exportTypes,b));
k = ed.export_flags{exIdx};
b = [b ':'];
if isempty(k)
exText = [exText b];
else
exText = [exText b k];
end
exText{end+1} = '';
end
end
end
if ~any(strcmp(ExPath,'Fix Filenames'))
set(handles.prefix_text,'String',['Prefix: ' ed.prefix])
set(handles.change_pre_push,'Visible','off')
end
set(handles.export_text,'String',char(exText));
% --- Executes on selection change in dir_list.
function dir_list_Callback(hObject, eventdata, handles)
% hObject handle to dir_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dayIdx = getappdata(handles.output,'dayIdx');
i = get(hObject,'Value');
if ~any(dayIdx==i)
i = find(dayIdx>i,1,'first');
set(hObject,'Value',dayIdx(i))
else
i = find(dayIdx==i);
end
handles.i = i;
updateGUI(handles);
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function dir_list_CreateFcn(hObject, eventdata, handles)
% hObject handle to dir_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 on button press in cancel_push.
function cancel_push_Callback(hObject, eventdata, handles)
% hObject handle to cancel_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(handles.figure1)
% --- Executes on button press in submit_push.
function submit_push_Callback(hObject, eventdata, handles)
% hObject handle to submit_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.submit = 1;
guidata(hObject,handles)
close(handles.figure1);
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
if isequal(get(hObject, 'waitstatus'), 'waiting')
uiresume(hObject);
else
delete(hObject);
end
% --- Executes on button press in change_pre_push.
function change_pre_push_Callback(hObject, eventdata, handles)
% hObject handle to change_pre_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
i = handles.i;
exDat = getappdata(handles.output,'ExDat');
prefix = inputdlg('Set new file prefix:','Change Prefix',1,{exDat(i).prefix});
if isempty(prefix)
return;
else
exDat(i).prefix = prefix;
setappdata(handles.output,'ExDat',exDat)
updateGUI(handles)
guidata(hObject,handles)
end
% --- Executes on button press in change_rec_push.
function change_rec_push_Callback(hObject, eventdata, handles)
% hObject handle to change_rec_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
i = handles.i;
exDat = getappdata(handles.output,'ExDat');
RO = exDat(i).rec_order;
RO2 = ListGUI(RO,'Order Rec Files:');
if isempty(RO2)
return;
else
exDat(i).rec_order = RO;
end
setappdata(handles.output,'ExDat',exDat)
updateGUI(handles)
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function rec_list_CreateFcn(hObject, eventdata, handles)
% hObject handle to rec_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 on button press in change_conf_push.
function change_conf_push_Callback(hObject, eventdata, handles)
% hObject handle to change_conf_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
i = handles.i;
exDat = getappdata(handles.output,'ExDat');
q1 = questdlg('Create new config or choose existing?','Change Config File','New','Existing','Cancel','Cancel');
switch q1
case 'New'
cf = RN_customizeTrodesConfig();
case 'Existing'
[a,b] = uigetfile('*.trodesconf','Choose Config File');
cf = [b,a];
case 'Cancel'
cf = exDat(i).config;
end
exDat(i).config = cf;
setappdata(handles.output,'ExDat',exDat)
updateGUI(handles)
guidata(hObject,handles)
function parallel_edit_Callback(hObject, eventdata, handles)
% hObject handle to parallel_edit (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 parallel_edit as text
% str2double(get(hObject,'String')) returns contents of parallel_edit as a double
if isempty(str2double(get(handles.parallel_edit,'String')))
h = msgbox('Choose a valid number.','Invalid Input');
waitfor(h);
set(hObject,'String','8')
end
updateGUI(handles);
% --- Executes during object creation, after setting all properties.
function parallel_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to parallel_edit (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 on button press in change_export_push.
function change_export_push_Callback(hObject, eventdata, handles)
% hObject handle to change_export_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
i = handles.i;
allExTypes = getappdata(handles.output,'allExportTypes');
exPath = getappdata(handles.output,'ExPath');
exDat = getappdata(handles.output,'ExDat');
[a,b] = strtok(exPath,' ');
exIdx = strcmpi(a,'Export');
exTs = strtrim(b(exIdx));
allExIdx = zeros(1,numel(exTs));
for j=1:numel(exTs),
k = find(strcmpi(allExTypes,exTs{j}));
allExIdx(j) = k;
end
Qs = cellfun(@(x) ['Extra Export ' x ' Flags:'],exTs,'UniformOutput',0);
exFlags = exDat(i).export_flags;
As = inputdlg(Qs,'Custom Export Flags',1,exFlags(allExIdx));
if isempty(As)
return;
end
exFlags(allExIdx) = As;
exDat(i).export_flags = exFlags;
setappdata(handles.output,'ExDat',exDat)
guidata(hObject,handles)
updateGUI(handles)
% --- Executes on button press in reset_config_push.
function reset_config_push_Callback(hObject, eventdata, handles)
% hObject handle to reset_config_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
i = handles.i;
exDat = getappdata(handles.output,'ExDat');
exDat(i).config = '';
setappdata(handles.output,'ExDat',exDat)
updateGUI(handles)
guidata(hObject,handles)
% --- Executes on button press in copyConfig_push.
function copyConfig_push_Callback(hObject, eventdata, handles)
% hObject handle to copyConfig_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
i = handles.i;
exDat = getappdata(handles.output,'ExDat');
choice = 1:numel(exDat);
choice = choice(choice~=i);
choice = cellstr(num2str(choice'));
[s,ok] = listdlg('ListSrting',choice);
if ~ok
return;
end
choice = choice(s);
choice = str2double(choice);
exDat(choice).config = exDat(i).config;
setappdata(handles.output,'ExDat',exDat)
updateGUI(handles)
guidata(hObject,handles)
% --------------------------------------------------------------------
function save_menu_Callback(hObject, eventdata, handles)
% hObject handle to save_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
appVars = {'ExPath','dayIdx','ExDat','dayList','allExportTypes','origDat'};
i = handles.i;
submit = handles.submit;
for i=1:numel(appVars),
eval([appVars{i} ' = getappdata(handles.output,appVars{i});']);
end
anim = unique({ExDat.animal_name});
saveFile = [strjoin(anim,'-') '_ExtractionSetup.mat'];
[saveFile,savePath] = uiputfile(saveFile,'Save Extraction Setup as...');
if isempty(saveFile)
return;
end
saveStr = ['save(' savePath filesep saveFile '''i'',''submit'',''' strjoin(appVars,''',''') ''')'];
eval(saveStr)
% --------------------------------------------------------------------
function load_menu_Callback(hObject, eventdata, handles)
% hObject handle to load_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[openFile,openPath] = uigetfile('*.mat','Extraction Setup file to open');
appVars = {'ExPath','dayIdx','ExDat','dayList','allExportTypes','origDat'};
load([openPath filesep openFile]);
for i=1:numel(appVars),
eval(['setappdata(handles.output,appVars{i},' appVars{i} ');']);
end
handles.i = i;
handles.submit = 0;
updateGUI(handles);
guidata(hObject,handles)