-
Notifications
You must be signed in to change notification settings - Fork 0
/
microstim_dsi_170toEnd.m
executable file
·147 lines (147 loc) · 5.56 KB
/
microstim_dsi_170toEnd.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
%% User defined values
clear all; clc
close all
path_firing = 'E:\MT_MST\SuperTuneFiringMatrix\ms_rmvd_170toEnd\';
path_spktrain = 'E:\MT_MST\SuperTuneSpkTrains\ms_rmvd_170toEnd\';
condition = 'S'; % 'N' NoMicrostim, 'S' Microstim
mtype = 2; % '1' translation, '2' spirals
option = '';
switch option
case ''
% names = {'ytu310a','ytu312b','ytu316a','ytu321a','ytu323a','ytu329a','ytu333a','ytu335a'};
names = {'ytu310a','ytu312b','ytu316a','ytu321a','ytu323a','ytu329a','ytu333a','ytu335a','ytu337a'};
case 'MS'
% names = {'ytu310a','ytu312b','ytu316a','ytu323a','ytu333a','ytu335a','ytu337a'};
names = {'ytu312b','ytu316a','ytu323a','ytu329a','ytu335a','ytu337a'};
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_removed\Candidate Cells\','CLib_',names{1,j}(1:end-1),'.mat'])
load(['E:\MT_MST\Microstim\Cell_Lib\MST_MU_MT_SU\MT\','CLib_',names{1,j}(1:end-1),'.mat'])
case 'MS'
% load(['E:\MT_MST\Microstim\Cell_Lib\MS_removed\MS Cells\','CLib_',names{1,j}(1:end-1),'.mat']) % MUA-cleaned
load(['E:\MT_MST\Microstim\Cell_Lib\MST_MU_MT_SU\MST\','CLib_',names{1,j}(1:end-1),'.mat'])
end
chidx = CLib;
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,:));
load([path_spktrain,names{1,j}(1,1:end-1),condition,num2str(ch),num2str(u),'spktrain.mat']);
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);
firing_bl = load([path_firing,names{1,j}(1,1:end-1),condition,num2str(ch),num2str(u),'firingMat_bl.mat']);
baseline = firing_bl.firing_bl;
allstimfir = firing.firing;
% [h,p] = ttest(baseline(:),allstimfir(:));
% keepCriteria = (p <= 0.05)
p = 0;
keepCriteria = 1;
bl = mean(baseline(:));
[maxfir,I] = max(firing1(:));
[dir,pos] = ind2sub(size(firing1),I);
dirfir = squeeze(firing1(:,pos));
f = [f, maxfir]; b = [b, bl];
info(j).sp(ci).spktrain = squeeze(spktrain(:,dir,mtype,pos,:));
info(j).sp(ci).spktrain_bl = squeeze(spktrain_bl(:,dir,mtype,pos,:));
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, pos];
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_170toEnd\',sprintf('%s%s%s.mat',condition,type,option)],'info')
soundsc(rand(3000,1))