0001 function ssgtest(spikes, assignments, show, mode)
0002
0003
0004
0005
0006 if (~ismember(mode, {'xy','xyz'})), error('Unknown mode.'); end;
0007
0008 if (isempty(assignments))
0009 if (isfield(spikes, 'hierarchy') && isfield(spikes.hierarchy, 'assigns'))
0010 assignments = spikes.hierarchy.assigns;
0011 elseif (isfield(spikes, 'overcluster'))
0012 assignments = spikes.overcluster.assigns;
0013 else
0014 assignments = ones(size(spikes.spiketimes));
0015 end
0016 end
0017 clusters = unique(assignments); numclusts = length(clusters);
0018
0019 if (isempty(show)), show = clusters; end;
0020 if (isfield(spikes, 'overcluster') && all(ismember(assignments, spikes.overcluster.assigns)))
0021 cmap = spikes.overcluster.colors;
0022 else
0023 cmap = jet(length(show));
0024 end
0025
0026 show(show == 0) = [];
0027
0028
0029 [pca.scores,pca.u,pca.s,pca.v] = pcasvd(spikes.waveforms);
0030 spikes.pca = pca;
0031 data = pca.scores;
0032
0033
0034 figure; hfig = gcf; hax = gca; hold on;
0035 for clu = 1:numclusts
0036 sel = find(assignments == clusters(clu));
0037 inds{clu} = sel;
0038 if (strcmp(mode, 'xyz'))
0039 hndl = plot3(data(sel,1), data(sel,2), data(sel,3),'.');
0040 else
0041 hndl = plot(data(sel,1), data(sel,2), '.');
0042 set(hndl, 'ButtonDownFcn', {@raise_me, hndl});
0043 end
0044
0045 if (clusters(clu) == 0), set(hndl, 'Color', [0 0 0], 'Marker', 'x');
0046 elseif (ismember(clusters(clu), show)), set(hndl, 'Color', cmap(clusters(clu),:));
0047 else set(hndl, 'Color', Clgy);
0048 end;
0049
0050 if (clusters(clu) == 0), h_out = hndl;
0051 elseif (ismember(clusters(clu), show)), h_pts(clusters(clu)) = hndl;
0052 end
0053
0054 ssghandle(clu) = hndl;
0055 end
0056 h_pts = h_pts(show);
0057
0058 if (length(find(h_pts)) == 1), set(h_pts, 'MarkerSize', 5, 'Marker', '.'); end;
0059 if (~strcmp(mode,'xyz')), uistack(h_pts, 'top'); end;
0060
0061 hold off;
0062
0063
0064 ssg.mode = mode;
0065 ssg.ss_object = spikes;
0066 ssg.ss_assigns = assignments;
0067 ssg.group_indices = inds; ssg.group_handles = ssghandle;
0068 ssg.xchoice = 'PC'; ssg.xparam1 = '1'; ssg.xcontrol = [];
0069 ssg.ychoice = 'PC'; ssg.yparam1 = '2'; ssg.ycontrol = [];
0070 ssg.zchoice = 'PC'; ssg.zparam1 = '3'; ssg.zcontrol = [];
0071 guidata(gcf, ssg);
0072
0073
0074 set(hax, 'XColor', [0.8 0 0.5], 'YColor', [0.1 0.7 0.3], 'ZColor', [0 0.4 0.7]);
0075
0076
0077 textprops = {'FontSize', 14, 'FontWeight', 'bold', 'Rotation', 0};
0078 hx = xlabel([ssg.xchoice ssg.xparam1]); set(hx, 'ButtonDownFcn', {@make_control, 'x'}, textprops{:});
0079 hy = ylabel([ssg.ychoice ssg.yparam1]); set(hy, 'ButtonDownFcn', {@make_control, 'y'}, textprops{:});
0080 if (strcmp(mode,'xyz'))
0081 hz = zlabel([ssg.zchoice ssg.zparam1]); set(hz, 'ButtonDownFcn', {@make_control, 'z'}, textprops{:});
0082 cameratoolbar('ResetCamera');
0083 cameratoolbar('SetMode', 'orbit');
0084 set(gcf, 'Renderer', 'OpenGL');
0085 grid on;
0086 else
0087 cameratoolbar('SetMode', 'nomode');
0088 set(gcf, 'Renderer', 'zbuffer');
0089 end
0090 axis equal;
0091
0092
0093 clustnames = cellstr(num2str(show));
0094 if (exist('h_out', 'var')), h_pts = [h_out, h_pts]; clustnames = cat(1, {'Outliers'}, clustnames); end;
0095
0096 if (numclusts < 12 && numclusts > 1)
0097 hleg = legend(h_pts, clustnames, 0);
0098 elseif (exist('h_out', 'var')),
0099 hleg = legend(h_pts(1), clustnames{1}, 0);
0100 end
0101 if (strcmp(mode,'xyz') && exist('hleg'))
0102 legpos = get(hleg, 'Position');
0103 legpos(2) = 0.78;
0104 set(hleg, 'Position', legpos);
0105 end
0106
0107 set(hfig, 'DeleteFcn', @delete_function);
0108 set(hfig, 'ButtonDownFcn', {@make_density, hax});
0109 figure(hfig);
0110
0111
0112 function delete_function(hObject, event)
0113
0114 ssg = guidata(hObject);
0115 delete([ssg.xcontrol, ssg.ycontrol, ssg.zcontrol]);
0116
0117
0118 function make_control(hObject, event, controlaxis)
0119
0120
0121
0122 ssg = guidata(hObject);
0123 controlhandle = ssg.([controlaxis 'control']);
0124 if (~isempty(controlhandle))
0125 figure(controlhandle);
0126 else
0127 ssg_featureselect(gca, controlaxis);
0128 end
0129
0130 function make_density(myfig, event, myaxes)
0131
0132 ssg = guidata(myfig);
0133 if(strcmp(get(myfig, 'SelectionType'), 'open'))
0134 [az,el] = view; T = view;
0135 properties2d = {'XLim', 'YLim', 'DataAspectRatio'};
0136 properties3d = cat(2, properties2d, {'Zlim', 'CameraViewAngle'});
0137 properties2d = cat(1, properties2d, get(gca,properties2d));
0138 properties3d = cat(1, properties3d, get(gca,properties3d));
0139
0140 xdata = []; ydata = []; zdata = [];
0141 for clust = 1:length(ssg.group_handles)
0142 xdata = [xdata get(ssg.group_handles(clust), 'XData')];
0143 ydata = [ydata get(ssg.group_handles(clust), 'YData')];
0144 if (strcmp(ssg.mode,'xyz'))
0145 zdata = [zdata get(ssg.group_handles(clust), 'ZData')];
0146 end
0147 end
0148 figure; hdens = gca;
0149 if (strcmp(ssg.mode,'xyz'))
0150 view(T); set(gca,properties3d{:});
0151 levels = logspace(-3,0,10);
0152 hist3d([xdata', ydata', zdata'], [], [], 20, [], 0);
0153 set(hdens, 'Box', 'on'); grid on;
0154 else
0155 histxy(xdata,ydata,250,1);
0156 set(gca,properties2d{:},'Color',[0 0 0.508]);
0157 HGlogmenu(findobj(gca,'Type','Image'));
0158 end
0159 end
0160