0001 function varargout = ssg_featureselect(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 gui_Singleton = 0;
0012 gui_State = struct('gui_Name', mfilename, ...
0013 'gui_Singleton', gui_Singleton, ...
0014 'gui_OpeningFcn', @ssg_featureselect_OpeningFcn, ...
0015 'gui_OutputFcn', @ssg_featureselect_OutputFcn, ...
0016 'gui_LayoutFcn', [] , ...
0017 'gui_Callback', []);
0018 if nargin && ischar(varargin{1})
0019 gui_State.gui_Callback = str2func(varargin{1});
0020 end
0021
0022 if nargout
0023 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0024 else
0025 gui_mainfcn(gui_State, varargin{:});
0026 end
0027
0028
0029
0030
0031 function ssg_featureselect_OpeningFcn(hObject, eventdata, handles, varargin)
0032 handles.output = hObject;
0033
0034
0035
0036 if (length(varargin) < 2)
0037 error('SSG:invalid_init_arg', 'Incorrect initalization syntax.');
0038 end
0039 handles.axes_handle = varargin{1};
0040 handles.switchaxis = varargin{2};
0041
0042 if (~ishandle(handles.axes_handle) || ~strcmp(get(handles.axes_handle, 'Type'), 'axes') || ...
0043 isempty(guidata(handles.axes_handle)))
0044 error('SSG:invalid_init_arg', 'First initialization argument must be an axis handle created by an SSG function.');
0045 end
0046 if (~ischar(handles.switchaxis) || ~any(strcmpi({'x', 'y', 'z'}, handles.switchaxis)))
0047 error('SSG:invalid_init_arg', 'Second initialization argument must be one of ''x'', ''y'', or ''z''.');
0048 end
0049 ssg = guidata(handles.axes_handle);
0050
0051 choices = get(handles.popup_datatype, 'String');
0052 value = find(strcmpi(choices, ssg.([handles.switchaxis 'choice'])));
0053 if (isempty(value))
0054 error('SSG:invalid_default_choice', ['Invalid entry in initial ' handles.switchaxis 'choice.']);
0055 end
0056
0057
0058 set(handles.popup_datatype, 'Value', value);
0059 set(handles.edit_param1, 'String', ssg.([handles.switchaxis 'param1']));
0060 handles.oldparam = ssg.([handles.switchaxis 'param1']);
0061 handles.maxparam = size(ssg.ss_object.waveforms, 2);
0062 set(handles.figure_ssg_featureselect, 'Name', [upper(handles.switchaxis) '-Axis Selection']);
0063
0064
0065 set(handles.figure_ssg_featureselect, 'Units', 'Pixel');
0066 newpos = labelposition_screen_coords(handles);
0067 currpos = get(handles.figure_ssg_featureselect, 'Position');
0068 set(handles.figure_ssg_featureselect, 'Position', [(newpos-currpos(3:4)*0.75) currpos(3:4)]);
0069 set(handles.figure_ssg_featureselect, 'Color', get(handles.axes_handle, [handles.switchaxis 'Color']));
0070
0071
0072 ssg.([handles.switchaxis 'control']) = handles.figure_ssg_featureselect;
0073 guidata(handles.axes_handle, ssg);
0074 guidata(hObject, handles);
0075
0076
0077
0078 function varargout = ssg_featureselect_OutputFcn(hObject, eventdata, handles)
0079 varargout{1} = handles.output;
0080
0081
0082
0083
0084
0085
0086 function edit_param1_CreateFcn(hObject, eventdata, handles)
0087 if ispc, set(hObject,'BackgroundColor','white');
0088 else, set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
0089 end
0090
0091 function popup_datatype_CreateFcn(hObject, eventdata, handles)
0092 if ispc, set(hObject,'BackgroundColor','white');
0093 else, set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
0094 end
0095
0096 function slider_aspect_CreateFcn(hObject, eventdata, handles)
0097 set(hObject,'BackgroundColor', [.9 .9 .9]);
0098
0099
0100
0101
0102 function popup_datatype_Callback(hObject, eventdata, handles)
0103
0104 choices = get(hObject, 'String');
0105 choice = choices{get(hObject, 'Value')};
0106 paramhandles = [handles.edit_param1, handles.button_next, handles.button_last];
0107 switch (choice),
0108 case {'Signal', 'PC'}
0109 set(paramhandles, 'Enable', 'on');
0110 case {'Event Time', 'Height', 'Width', 'ISI Preceding', 'Total Energy', 'Cluster #'}
0111 set(paramhandles, 'Enable', 'off');
0112 end
0113 alter_data(handles);
0114
0115
0116 function edit_param1_Callback(hObject, eventdata, handles)
0117
0118 param1 = str2double(get(handles.edit_param1, 'String'));
0119 if (isnan(param1) || (param1 ~= round(param1)))
0120 set(handles.edit_param1, 'String', handles.oldparam);
0121 beep;
0122 else
0123 handles = param1_bounds_check(handles, param1);
0124 alter_data(handles);
0125 end
0126
0127
0128
0129
0130
0131 function button_next_Callback(hObject, eventdata, handles)
0132 param1 = str2double(get(handles.edit_param1, 'String'));
0133 handles = param1_bounds_check(handles, param1 + 1);
0134 alter_data(handles);
0135
0136 function button_last_Callback(hObject, eventdata, handles)
0137 param1 = str2double(get(handles.edit_param1, 'String'));
0138 handles = param1_bounds_check(handles, param1 - 1);
0139 alter_data(handles);
0140
0141
0142 function figure_delete_Callback(hObject, eventdata, handles)
0143
0144 ssg = guidata(handles.axes_handle);
0145 ssg.([handles.switchaxis 'control']) = [];
0146 guidata(handles.axes_handle, ssg);
0147
0148
0149
0150 function pos = labelposition_screen_coords(handles)
0151
0152
0153
0154
0155
0156 axeshndl = handles.axes_handle;
0157 figurehndl = get(axeshndl, 'Parent');
0158
0159 oldunits = get([figurehndl, axeshndl], 'Units');
0160 set([figurehndl, axeshndl], 'Units', 'Pixel');
0161
0162 axes_relative = get(axeshndl, 'Position');
0163 figure_pos = get(figurehndl, 'Position');
0164
0165 set(figurehndl, 'Units', oldunits{1});
0166 set(axeshndl, 'Units', oldunits{2});
0167
0168
0169
0170 offset = axes_relative(3:4);
0171 switch(handles.switchaxis),
0172 case 'x',
0173 offset = offset .* [0.75 0];
0174 case 'y',
0175 offset = offset .* [-0.10 0.10];
0176 case 'z',
0177 offset = offset .* [0 0.75];
0178 end
0179 pos = figure_pos + axes_relative;
0180 pos = pos(1:2) + offset;
0181
0182
0183 function handles = param1_bounds_check(handles, param1)
0184
0185
0186
0187
0188
0189
0190 if (param1 < 1)
0191 param1 = '1';
0192 elseif (param1 > handles.maxparam)
0193 param1 = num2str(handles.maxparam);
0194 else
0195 param1 = num2str(param1);
0196 end
0197 set(handles.edit_param1, 'String', param1);
0198 handles.oldparam = param1;
0199
0200
0201 function alter_data(handles)
0202
0203 choices = get(handles.popup_datatype, 'String');
0204 choice = choices{get(handles.popup_datatype, 'Value')};
0205 param1 = str2double(get(handles.edit_param1, 'String'));
0206 ssg = guidata(handles.axes_handle);
0207 axname = handles.switchaxis;
0208
0209
0210 switch (choice),
0211 case 'Signal',
0212 vector = ssg.ss_object.waveforms(:,param1);
0213
0214 case 'PC',
0215 if (~isfield(ssg.ss_object, 'pca'))
0216 parentfig = get(handles.axes_handle, 'Parent'); oldptr = get(parentfig, 'Pointer');
0217 set([handles.figure_ssg_featureselect, parentfig], 'Pointer', 'watch');
0218
0219 [pca.scores,pca.u,pca.s,pca.v] = pcasvd(ssg.ss_object.waveforms);
0220 ssg.ss_object.pca = pca;
0221
0222 set(handles.figure_ssg_featureselect, 'Pointer', 'arrow');
0223 set(parentfig, 'Pointer', oldptr);
0224 end
0225 vector = ssg.ss_object.pca.scores(:,param1);
0226
0227 case 'Cluster #',
0228 vector = ssg.ss_assigns;
0229
0230 case 'Event Time',
0231 vector = ssg.ss_object.spiketimes;
0232
0233 case 'ISI Preceding',
0234 vector = [NaN; diff(ssg.ss_object.spiketimes)];
0235
0236 case 'Total Energy',
0237 vector = sum(ssg.ss_object.waveforms.^2, 2);
0238
0239 case {'Height', 'Width'},
0240 if (~isfield(ssg.ss_object, 'heightwidth'))
0241 [hw.height, hw.width] = thresholded_peaks(ssg.ss_object);
0242 ssg.ss_object.heightwidth = hw;
0243 end
0244 vector = ssg.ss_object.heightwidth.(lower(choice));
0245
0246 end
0247 ssg.([axname 'choice']) = choice;
0248 ssg.([axname 'param1']) = num2str(param1);
0249
0250
0251 for gp = 1:length(ssg.group_handles)
0252 set(ssg.group_handles(gp), [axname 'Data'], vector(ssg.group_indices{gp}));
0253 end
0254
0255
0256 haxes = handles.axes_handle;
0257 axis(haxes, 'tight');
0258 if ~isempty(get(ssg.group_handles(1), 'ZData'))
0259 campos(haxes,'auto'); camtarget(haxes,'auto'); view(haxes,3);
0260 camva(haxes,'auto'); camup(haxes,'auto'); camva(haxes,camva(haxes));
0261 end
0262 daspect(haxes,'auto'); daspect(haxes,daspect(haxes));
0263
0264
0265 label = ssg.([axname 'choice']);
0266 if (strcmp(get(handles.edit_param1, 'Enable'), 'on'))
0267 label = [label ssg.([axname 'param1'])];
0268 end
0269 set(get(haxes, [axname 'Label']), 'String', label);
0270
0271
0272 guidata(handles.axes_handle, ssg);
0273 guidata(handles.figure_ssg_featureselect, handles);
0274 figure(handles.figure_ssg_featureselect);