forked from netstim/leaddbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathea_edit_regressor.m
299 lines (245 loc) · 9.91 KB
/
ea_edit_regressor.m
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
function varargout = ea_edit_regressor(varargin)
% EA_EDIT_REGRESSOR MATLAB code for ea_edit_regressor.fig
% EA_EDIT_REGRESSOR, by itself, creates a new EA_EDIT_REGRESSOR or raises the existing
% singleton*.
%
% H = EA_EDIT_REGRESSOR returns the handle to a new EA_EDIT_REGRESSOR or the handle to
% the existing singleton*.
%
% EA_EDIT_REGRESSOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EA_EDIT_REGRESSOR.M with the given input arguments.
%
% EA_EDIT_REGRESSOR('Property','Value',...) creates a new EA_EDIT_REGRESSOR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ea_edit_regressor_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ea_edit_regressor_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 ea_edit_regressor
% Last Modified by GUIDE v2.5 11-Oct-2015 15:47:25
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ea_edit_regressor_OpeningFcn, ...
'gui_OutputFcn', @ea_edit_regressor_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 ea_edit_regressor is made visible.
function ea_edit_regressor_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 ea_edit_regressor (see VARARGIN)
set(gcf,'Name','Edit Regressor');
% Choose default command line output for ea_edit_regressor
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
M=varargin{1};
[~,ptnames]=cellfun(@fileparts,M.patient.list,'UniformOutput',0);
set(handles.datatable,'RowName',ptnames);
try
regressor=M.clinical.vars{M.ui.clinicallist};
catch % new variable
regressor=nan(length(ptnames),1);
end
if iscell(regressor)
regressor=cell2mat(regressor);
end
set(handles.datatable,'Data',regressor);
set(handles.datatable,'ColumnEditable',true(1,size(regressor,2)));
if isperpatient(regressor)
switchperpatient(handles);
elseif isperhemisphere(regressor)
switchperhemisphere(handles);
elseif ispercontactpair(regressor)
switchpercontactpair(handles);
elseif ispercontact(regressor)
switchpercontact(handles);
end
try
set(handles.varname,'String',M.clinical.labels{M.ui.clinicallist});
end
% UIWAIT makes ea_edit_regressor wait for user response (see UIRESUME)
uiwait(hObject);
function switchperpatient(handles)
reg=get(handles.datatable,'Data');
if ~isempty(reg)
if ~isperpatient(reg)
answ=questdlg('Warning: switching variable type will delete/modify variable! Are you sure you want this?','Warning','Yes','No','No');
switch answ
case 'No'
return
end
end
end
set(handles.variabletype, 'Value', 1);
set(handles.datatable,'ColumnName',{'Value'});
reg=reg(1:size(reg,1),1);
set(handles.datatable,'Data',reg);
set(handles.datatable,'ColumnEditable',true(1,1));
function switchperhemisphere(handles)
reg=get(handles.datatable,'Data');
if ~isempty(reg)
if ~isperhemisphere(reg)
answ=questdlg('Warning: switching variable type will delete/modify variable! Are you sure you want this?','Warning','Yes','No','No');
switch answ
case 'No'
return
end
end
end
set(handles.variabletype, 'Value', 2);
set(handles.datatable,'ColumnName',{'Right','Left'});
try
reg=reg(1:size(reg,1),1:2);
catch
reg=[reg(1:size(reg,1),1),nan(size(reg,1),1)];
end
set(handles.datatable,'Data',reg);
set(handles.datatable,'ColumnEditable',true(1,1));
function switchpercontact(handles)
reg=get(handles.datatable,'Data');
if ~isempty(reg)
if ~ispercontact(reg)
answ=questdlg('Warning: switching variable type will delete/modify variable! Are you sure you want this?','Warning','Yes','No','No');
switch answ
case 'No'
return
end
end
end
set(handles.variabletype, 'Value', 3);
set(handles.datatable,'ColumnName',{'K0','K1','K2','K3','K8','K9','K10','K11'});
nreg=nan(size(reg,1),8);
nreg(1:size(reg,1),1:size(reg,2))=reg;
reg=nreg; clear('nreg');
set(handles.datatable,'Data',reg);
set(handles.datatable,'ColumnEditable',true(1,8));
function switchpercontactpair(handles)
reg=get(handles.datatable,'Data');
if ~isempty(reg)
if ~ispercontactpair(reg)
answ=questdlg('Warning: switching variable type will delete/modify variable! Are you sure you want this?','Warning','Yes','No','No');
switch answ
case 'No'
return
end
end
end
set(handles.variabletype, 'Value', 4);
set(handles.datatable,'ColumnName',{'K1-2','K2-3','K3-4','K8-9','K9-10','K10-11'});
nreg=nan(size(reg,1),6);
try
nreg(1:size(reg,1),1:size(nreg,2))=reg(1:size(reg,1),1:size(nreg,2));
catch
nreg(1:size(reg,1),1:size(reg,2))=reg(1:size(reg,1),1:size(reg,2));
end
reg=nreg; clear('nreg');
set(handles.datatable,'Data',reg);
set(handles.datatable,'ColumnEditable',true(1,6));
function yn=ispercontactpair(regressor)
yn=(iscell(regressor) && size(regressor{1},2)==3) || (~iscell(regressor) && size(regressor,2)==6);
function yn=ispercontact(regressor)
yn=(iscell(regressor) && size(regressor{1},2)==4) || (~iscell(regressor) && size(regressor,2)==8);
function yn=isperpatient(regressor)
yn=~iscell(regressor) && size(regressor,2)==1;
function yn=isperhemisphere(regressor)
yn=~iscell(regressor) && size(regressor,2)==2;
% --- Outputs from this function are returned to the command line.
function varargout = ea_edit_regressor_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 getappdata(gcf,'save')
varargout{1} = get(handles.datatable,'Data');
varargout{2}=get(handles.varname,'String');
else
varargout{1}=[];
varargout{2}=[];
end
delete(hObject);
% --- Executes on button press in save.
function save_Callback(hObject, eventdata, handles)
% hObject handle to save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
setappdata(gcf,'save',1);
close(gcf);
% --- Executes on button press in cancel.
function cancel_Callback(hObject, eventdata, handles)
% hObject handle to cancel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
setappdata(gcf,'save',0);
close(gcf);
% --- Executes when user attempts to close editregressor.
function editregressor_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to editregressor (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
%delete(hObject);
uiresume(hObject);
function varname_Callback(hObject, eventdata, handles)
% hObject handle to varname (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 varname as text
% str2double(get(hObject,'String')) returns contents of varname as a double
% --- Executes during object creation, after setting all properties.
function varname_CreateFcn(hObject, eventdata, handles)
% hObject handle to varname (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 selection change in variabletype.
function variabletype_Callback(hObject, eventdata, handles)
% hObject handle to variabletype (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns variabletype contents as cell array
% contents{get(hObject,'Value')} returns selected item from variabletype
popvals=get(hObject,'String');
variabletype=popvals{get(hObject,'Value')};
switch variabletype
case '1 variable per patient'
switchperpatient(handles);
case '1 variable per hemisphere'
switchperhemisphere(handles);
case '1 variable per contact'
switchpercontact(handles);
case '1 variable per contact pair'
switchpercontactpair(handles);
end
% --- Executes during object creation, after setting all properties.
function variabletype_CreateFcn(hObject, eventdata, handles)
% hObject handle to variabletype (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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