forked from open-ephys/simpleclust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sc_plotclusters.m
176 lines (122 loc) · 6.22 KB
/
sc_plotclusters.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
function features=plotclusters(features)
plot([-1 1],[-1 -1]+0.01,'color',[1 1 .7],'LineWidth',5);
plot([-1 -1]+0.01,[-1 1],'color',[.8 1 1],'LineWidth',5);
fill([-1 1 1 -1 ],[-1 -1 1 1] ,'b','FaceColor',[0 0 0]);
%% scale
use=zeros(1,numel(features.ts));
for i=1:features.Nclusters
if features.clustervisible(i)
incluster=find(features.clusters==i );
use(incluster)=1;
end;
end;
% this is needed only when a feature was changed
if ~exist('features.updatezoom')
features.updatezoom=1;
end;
if features.updatezoom
features.updatezoom=0;
margin=0.1;
for i=1:2%size(features.data,1) % scale only the features we're looking at
x=features.data(features.featureselects(i),:);
%x=x-min(x(find(use))); x=x./max(x(find(use))); x=x*(2-margin*2); x=x-(1-margin);
%features.data_scaled(i,:)=x;
% scale to min-max
%features.data_scaled(features.featureselects(i),:)=sc_remap (features.data(features.featureselects(i),:),min(x(find(use))),max(x(find(use))) ,-.9,.9);
% scale to zoom boundaries
features.data_scaled(features.featureselects(i),:)=sc_remap(features.data(features.featureselects(i),:), features.zoomrange(features.featureselects(i),1) , features.zoomrange(features.featureselects(i),2) ,-.9,.9);
end;
% hide out of bounds points
features.zoomvisible = ( features.data(features.featureselects(1),:) <= features.zoomrange(features.featureselects(1),2) ).* ...
( features.data(features.featureselects(1),:) >= features.zoomrange(features.featureselects(1),1) ).* ...
( features.data(features.featureselects(2),:) <= features.zoomrange(features.featureselects(2),2) ).* ...
( features.data(features.featureselects(2),:) >= features.zoomrange(features.featureselects(2),1) );
end;
% indicate if some were cut off
% right
if min(( features.data(features.featureselects(1),:) <= features.zoomrange(features.featureselects(1),2) )) ==0
for i=linspace(-.7 ,.7, 9)
plot([0 0.04]+.95,i+[0 0],'color',[.5 .5 .5]);
plot([0 -0.02]+.99,i+[0 0.01],'color',[.5 .5 .5]);
plot([0 -0.02]+.99,i-[0 0.01],'color',[.5 .5 .5]);
end;
end;
% left
if min(( features.data(features.featureselects(1),:) >= features.zoomrange(features.featureselects(1),1) )) ==0
for i=linspace(-.7 ,.7, 9)
plot([0 0.04]-.95,i+[0 0],'color',[.5 .5 .5]);
plot([0 0.02]-.95,i+[0 0.01],'color',[.5 .5 .5]);
plot([0 0.02]-.95,i-[0 0.01],'color',[.5 .5 .5]);
end;
end;
% top
if min(( features.data(features.featureselects(2),:) <= features.zoomrange(features.featureselects(2),2) )) ==0
for i=linspace(-.7 ,.7, 9)
plot(i+[0 0],[0 0.04]+.95,'color',[.5 .5 .5]);
plot(i+[0 0.01],[0 -0.02]+.99,'color',[.5 .5 .5]);
plot(i-[0 0.01],[0 -0.02]+.99,'color',[.5 .5 .5]);
end;
end;
% bottom
if min(( features.data(features.featureselects(2),:) >= features.zoomrange(features.featureselects(2),1) )) ==0
for i=linspace(-.6 ,.7, 7)
plot(i+[0 0],[0 0.04]-.95,'color',[.5 .5 .5]);
plot(i+[0 0.01],[0 0.02]-.95,'color',[.5 .5 .5]);
plot(i-[0 0.01],[0 0.02]-.95,'color',[.5 .5 .5]);
end;
end;
%% plot
%ugly bug fix - figure out where this error comes from!
if size(features.timevisible,1)>size(features.timevisible,2)
features.timevisible=features.timevisible';
end;
if size(features.ts,1)>size(features.ts,2)
features.ts=features.ts';
end;
for i=1:features.Nclusters
if features.clustervisible(i)
incluster=find(features.clusters==i .*(features.randperm<features.Ndisplay) .* features.timevisible .* features.zoomvisible);
if numel(incluster)>0
sc_plotinbox(features.data_scaled(features.featureselects(1),incluster),features.data_scaled(features.featureselects(2),incluster),features.clusterfstrs{i},features.colors(i,:),features.plotsize);
end;
% plot cluster traces
mx=[]; my=[];
if features.timeselection
nsteps=100;
timebins=linspace(features.ts(1),features.ts(end),nsteps);
for j=2:nsteps
incluster_t=find((features.clusters==i ).*(features.ts > timebins(j-1)).* (features.ts < timebins(j)));
mx(j-1)=median( features.data_scaled(features.featureselects(1),incluster_t) );
my(j-1)=median( features.data_scaled(features.featureselects(2),incluster_t) );
end;
f=normpdf([-4:4],0,2); f=f./sum(f);
mx=conv(mx,f,'valid');
my=conv(my,f,'valid');
plot(mx,my,'r-','color',features.colors(i,:),'LineWidth',4);
plot(mx,my,'r--','color',[1 1 1],'LineWidth',1);
end;
end;
end;
% plot x/y range
if isfield(features,'range')
text(-0.95,-0.9,num2str( features.zoomrange(features.featureselects(2),1) ),'color',[.5 .5 .5]);
text(-0.95,0.95,num2str( features.zoomrange(features.featureselects(2),2) ),'color',[.5 .5 .5]);
text(-0.9,-0.95,num2str( features.zoomrange(features.featureselects(1),1) ),'color',[.5 .5 .5]);
text(0.9,-0.95,num2str( features.zoomrange(features.featureselects(1),2) ),'color',[.5 .5 .5]);
end;
if features.highlight>0
plot( features.data_scaled(features.featureselects(1),features.highlight),features.data_scaled(features.featureselects(2),features.highlight),'wo','MarkerSize',8);
%plot( features.data(features.featureselects(1),features.highlight),features.data(features.featureselects(2),features.highlight),'ko','MarkerSize',9);
if features.plotgroup
plot( features.data_scaled(features.featureselects(1),features.highlight_multiple),features.data_scaled(features.featureselects(2),features.highlight_multiple),'wo','MarkerSize',6,'color',[.6 .6 .6]);
end;
end;
% plot zoom button
plot([1 .9 ],[.9,1],'b','color',[1 1 1]);
xx=[]; yy=[];
for i=linspace(0,7,20)
xx(end+1)= sin(i)*.01;
yy(end+1)= cos(i)*.01;
end;
plot(xx+.96,yy+.98,'b','color',[.9 .9 .9],'LineWidth',2);
plot([.966 .98],[.975 .96],'b','color',[.9 .9 .9],'LineWidth',3);