-
Notifications
You must be signed in to change notification settings - Fork 0
/
PosAtPD.m
executable file
·221 lines (198 loc) · 6.75 KB
/
PosAtPD.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
function [x nn ss bl] = PosAtPD(datapath,type,MS,site)
% Function PosAtPD estimates the euclidean distance of a position from a
% reference point on the screen
%%%% Inputs %%%%
% x: x-axis coordinates / eg. x = [-17;0;17;-17;0;17;-17;0;17];
% y: y-axis coordinates / eg. y = [17;17;17;0;0;0;-17;-17;-17];
% ref: reference coordinates / eg. ref = [17 17];
%%%% Outputs %%%%
% dist: distance from reference point
% Written by Yavar Korkian on July.19.2021
switch type
case 'trans'
mot = 1;
case 'spiral'
mot = 2;
end
bin = 100;
Fs = 10000;
inf = load([datapath sprintf('N%sMS.mat',type)]);
MST = inf.info;
clear inf
inf = load([datapath sprintf('N%s.mat',type)]);
MTnms = inf.info;
clear inf
inf = load([datapath sprintf('S%s.mat',type)]);
MTms = inf.info;
clear inf
switch MS
case 1
sppath = 'D:\MT_MST\SuperTuneSpkTrains\ms_rmvd\';
for i = 1:size(MTnms,2)
for j = 1:size(MTnms(i).xr,2)
MTnms(i).spike(j) = load([sppath MTnms(i).fname sprintf('N%d1spktrain.mat',MTnms(i).gch(j))]);
MTms(i).spike(j) = load([sppath MTnms(i).fname sprintf('S%d1spktrain.mat',MTnms(i).gch(j))]);
end
end
case 0
sppath = 'D:\MT_MST\Microstim\MST-MUA\';
for i = 1:size(MTnms,2)
load([sppath MTnms(i).fname 'N.mat'],'spktNMS');
load([sppath MTnms(i).fname 'S.mat'],'spktMS');
for j = 1:size(MTnms(i).xr,2)
MTnms(i).spike(j).spktrain = squeeze(spktNMS(MTnms(i).gch(j),5000:8000,:,:,:,:));
MTms(i).spike(j).spktrain = squeeze(spktMS(MTnms(i).gch(j),5000:8000,:,:,:,:));
end
end
end
for i = 1:size(MTnms,2)
for j = 1:size(MTnms(i).xr,2)
MTms(i).df(:,j) = MTms(i).xr(j).firing(:,MTnms(i).pt(j));
end
end
bl(:,1) = vertcat(MTnms.spnt);
bl(:,2) = vertcat(MTms.spnt);
bl = mean(bl(:));
if MS == 1
MTnms(7) = [];
MTnms(4) = [];
MTnms(1) = [];
MTms(7) = [];
MTms(4) = [];
MTms(1) = [];
end
NMS = nan(200,6);
MS = NMS;
z0 = 1; z1 = 1; z2 = 1; z3 = 1; z4 = 1; z5 = 1;
x = [];
for i = 1:size(MTnms,2)
for j = 1:size(MTnms(i).xr,2)
FrMTnms = MTnms(i).xr(j).firing;
FrMTms = MTms(i).xr(j).firing;
[rval I] = max(FrMTnms(:));
[pdr pdc] = ind2sub(size(FrMTnms),I);
x(i).dist(:,j) = pos2dist(pdc);
x(i).FrmMTnms(:,j) = FrMTnms(pdr,:)';
x(i).FrmMTms(:,j) = FrMTms(pdr,:)';
% spike train
SpMTnms = squeeze(MTnms(i).spike(j).spktrain(:,pdr,mot,:,:));
SpMTms = squeeze(MTms(i).spike(j).spktrain(:,pdr,mot,:,:));
% psth
spbinNMS = []; spbinMS = [];
for z = 1:9 %
spbinNMS(:,z) = psth_sp(squeeze(SpMTnms(:,z,:)),bin,Fs);
spbinMS(:,z) = psth_sp(squeeze(SpMTms(:,z,:)),bin,Fs);
end
nms = x(i).FrmMTnms(:,j);
ms = x(i).FrmMTms(:,j);
b = x(i).dist(:,j);
upos = unique(b);
for w = 1:size(upos,1)
x(i).pos(j).MT(w,1) = upos(w);
x(i).pos(j).MT(w,2) = mean(nms(b == upos(w))); % NMS
x(i).pos(j).MT(w,3) = mean(ms(b == upos(w))); % MS
x(i).pos(j).spNMS(:,w) = mean(spbinNMS(:,b == upos(w)),2);
x(i).pos(j).spMS(:,w) = mean(spbinMS(:,b == upos(w)),2);
switch upos(w)
case 0
NMS(z0,1) = mean(nms(b == upos(w))); % NMS
MS(z0,1) = mean(ms(b == upos(w))); % MS
z0 = z0 + 1;
case 1
NMS(z1,2) = mean(nms(b == upos(w))); % NMS
MS(z1,2) = mean(ms(b == upos(w))); % MS
z1 = z1 + 1;
case 2
NMS(z2,3) = mean(nms(b == upos(w))); % NMS
MS(z2,3) = mean(ms(b == upos(w))); % MS
z2 = z2 + 1;
case 3
NMS(z3,4) = mean(nms(b == upos(w))); % NMS
MS(z3,4) = mean(ms(b == upos(w))); % MS
z3 = z3 + 1;
case 4
NMS(z4,5) = mean(nms(b == upos(w))); % NMS
MS(z4,5) = mean(ms(b == upos(w))); % MS
z4 = z4 + 1;
case 5
NMS(z5,6) = mean(nms(b == upos(w))); % NMS
MS(z5,6) = mean(ms(b == upos(w))); % MS
z5 = z5 + 1;
end
end
end
end
for w = 1:6
a = []; b = [];
c = 1;
for i = 1:size(x,2)
for j = 1:size(x(i).pos,2)
if size(x(i).pos(j).spNMS,2) >= w
a(:,c) = x(i).pos(j).spNMS(1:24,w);
b(:,c) = x(i).pos(j).spMS(1:24,w);
c = c + 1;
end
end
end
sptnms(:,w) = mean(a,2);
sptms(:,w) = mean(b,2);
end
nn = NMS;
ss = MS;
for i = 1:size(NMS,2)
n = NMS(~isnan(NMS(:,i)),i);
s = MS(~isnan(MS(:,i)),i);
errN(1,i) = (std(n)) / (sqrt(size(n,1)));
errS(1,i) = (std(s)) / (sqrt(size(s,1)));
n = []; s = [];
end
NMS = nanmean(NMS);
MS = nanmean(MS);
figure
dir = 1:6;
switch type
case 'trans'
col(1) = 'k';
col(2) = 'g';
tit = 'Translation';
case 'spiral'
col(1) = 'b';
col(2) = 'r';
tit = 'Spiral';
end
plot(dir,NMS,'Color',col(1),'LineWidth',2); hold on
plot(dir,MS,'Color',col(2),'LineWidth',2)
title(tit)
xlabel(sprintf('Position Deviation from %s',site))
ylabel 'Normalized Firing Rate'
legend({'NMS','MS'})
xticks([1 2 3 4 5 6])
xticklabels({'0','1','2','3','4','5'})
shade(dir,NMS+errN,sprintf('--%s',col(1)),dir,NMS-errN,sprintf('--%s',col(1)),'FillType',[1 2;1 2],'FillAlpha',.1,'FillColor',col(1))
shade(dir,MS+errS,sprintf(':%s',col(2)),dir,MS-errS,sprintf(':%s',col(2)),'FillType',[1 2;1 2],'FillAlpha',.1,'FillColor',col(2))
line([min(dir) max(dir)],[bl bl],'LineWidth',2,'Color',[0.9290, 0.6940, 0.1250],'LineStyle','--')
fig = figure;
time = 0:0.01:0.230;
c = 1;
for i = 1:6
if i == 1
subplot(6,6,1)
else
c = c + 7;
subplot(6,6,c)
end
bar(time,sptnms(:,i),'BarWidth',1,'FaceColor',col(1),'EdgeColor',col(1)); hold on
bar(time,sptms(:,i),'BarWidth',1,'FaceColor',col(2),'EdgeColor',col(2),'FaceAlpha',0.4)
xlim([min(time) max(time)])
gmin = min([min(sptnms(:,i)) min(sptms(:,i))]);
gmax = max([max(sptnms(:,i)) max(sptms(:,i))]);
ylim([0 gmax+1])
end
legend({'NMS','MS'})
han = axes(fig,'visible','off');
han.Title.Visible = 'on';
han.XLabel.Visible = 'on';
han.YLabel.Visible = 'on';
title(han,tit)
ylabel(han,'Firing Rate (spike/sec)')
xlabel(han,'Time after MS (sec)')