-
Notifications
You must be signed in to change notification settings - Fork 0
/
microstim_dsi.m
executable file
·136 lines (136 loc) · 4.82 KB
/
microstim_dsi.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
clear all; clc
%% User defined values
path_firing = 'E:\MT_MST\SuperTuneFiringMatrix\ms_rmvd_150300\';
path_spktrain = 'E:\MT_MST\SuperTuneSpkTrains\ms_rmvd_150300\';
condition = 'N';
mtype = 2;
option = '';
switch option
case ''
names = {'ytu312b','ytu316a','ytu323a','ytu329a','ytu335a','ytu337a'};
case 'MS'
names = {'ytu310a','ytu312b','ytu316a','ytu323a','ytu333a','ytu335a'};
end
switch mtype
case 1
type = 'trans';
case 2
type = 'spiral';
end
Fs = 10000;
info = struct;
%%
for j = 1:length(names)
params = load(['E:\MT_MST\Plexon\RFiles\',names{1,j},'_TrialStructure.mat']);
switch option
case ''
% load(['E:\MT_MST\Microstim\Cell_Lib\MS_rmvd_V1\MT\','CLib_',names{1,j}(1:end-1),'.mat'])
load(['E:\MT_MST\Microstim\Cell_Lib\ms_rmvd_150300\MT\','CLib_',names{1,j}(1:end-1),'.mat'])
case 'MS'
load(['E:\MT_MST\Microstim\Cell_Lib\MS_rmvd_V1\MST\','CLib_',names{1,j}(1:end-1),'.mat'])
end
chidx = CLib;%chunum(chunum(:,2) == 1);
clear CLib
units = chidx;
units(:,2) = 1;
Dprime = [];
bl = [];
PD = [];
ND = [];
discard = [];
FRp = []; FRn = [];
f = [];
b = [];
pt = [];
gch = [];
df = [];
chid = [];
xr = [];
for ci = 1:size(units,1)
ch = units(ci,1);
u = units(ci,2);
firing = load([path_firing,names{1,j}(1,1:end-1),condition,num2str(ch),num2str(u),'firingMat.mat']);
firing1 = squeeze(firing.firing(:,mtype,:));
spktrain = load([path_spktrain,names{1,j}(1,1:end-1),condition,num2str(ch),num2str(u),'spktrain.mat']);
spktrainbl = load([path_spktrain,names{1,j}(1,1:end-1),condition,num2str(ch),num2str(u),'spktrain_bl.mat']);
baseline = squeeze(sum(spktrainbl.spktrain_bl,1))*Fs/size(spktrainbl.spktrain_bl,1);
allstimfir = squeeze(sum(spktrain.spktrain,1))*Fs/size(spktrain.spktrain,1);
[h,p] = ttest(baseline(:),allstimfir(:));
keepCriteria = 1;%(p <= 0.05)
bl = mean(baseline(:));
[maxfir,I] = max(firing1(:));
[dir,mot,pos,siz,coh] = ind2sub(size(firing1),I);
dirfir = squeeze(firing1(:,mot,pos,siz,coh));
f = [f, maxfir]; b = [b, bl];
if keepCriteria == 1
disp(sprintf('p = %d --> Pass!',p))
if maxfir ~= 0
PrefdirD = dirfir(dir);
if dir <= params.file.taskDialogValues.numberOfDirections/2
NulldirD = dirfir(dir + (params.file.taskDialogValues.numberOfDirections/2));
else
NulldirD = dirfir(dir - (params.file.taskDialogValues.numberOfDirections/2));
end
dprimeDots = (PrefdirD - NulldirD)/((PrefdirD - bl) + (NulldirD - bl));
PD = [PD, dir];
if dir <= params.file.taskDialogValues.numberOfDirections/2
ND = [ND, (dir+(params.file.taskDialogValues.numberOfDirections/2))];
else
ND = [ND, (dir-(params.file.taskDialogValues.numberOfDirections/2))];
end
discard = [discard, nan];
pt = [pt, mot];
gch = [gch, ch];
df = [df dirfir];
elseif maxfir == 0
warning('!')
discard = [discard, ci];
PD = [PD, nan];
ND = [ND, nan];
dprimeDots = nan;
PrefdirD = nan;
NulldirD = nan;
bl = nan;
pt = [pt, nan];
df = [df,nan(8,1)];
end
elseif keepCriteria == 0
disp(sprintf('p = %d --> Fail!',p))
warning('!!')
discard = [discard, ci];
PD = [PD, nan];
ND = [ND, nan];
dprimeDots = nan;
PrefdirD = nan;
NulldirD = nan;
bl = nan;
pt = [pt, nan];
df = [df,nan(8,1)];
end
Dprime = [Dprime,dprimeDots];
FRp = [FRp, PrefdirD];
FRn = [FRn, NulldirD];
bl = [bl,bl];
chid = [chid ch];
xr(ci).firing = firing1;
end
info(j).discard = discard;
info(j).df = df;
info(j).xr = xr;
info(j).Dir(:,1) = PD';
info(j).Dir(:,2) = ND';
info(j).DSI = Dprime;
info(j).bl = bl;
info(j).FR(:,1) = FRp;
info(j).FR(:,2) = FRn;
info(j).ctl(:,1) = f;
info(j).ctl(:,2) = b;
info(j).pt = pt';
info(j).gch = gch';
info(j).fname = names{1,j}(1,1:end-1);
info(j).condition = condition;
info(j).ch = chid';
info(j).fid = size(units,1);
end
save(['E:\MT_MST\Microstim\PSTH\ms_rmvd_150300\',sprintf('%s%s%s.mat',condition,type,option)],'info')
soundsc(rand(3000,1))