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