-
Notifications
You must be signed in to change notification settings - Fork 0
/
f_spikeFeature.m
80 lines (61 loc) · 2.63 KB
/
f_spikeFeature.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
function f_spikeFeature(myKsDir)
% myKsDir = 'D:\matwork\Data\M145_2019_07_09';
%% Loading kilosort/phy data
sp = loadKSdir(myKsDir);
% good_cid = sp.cgs==2;
good_cid = sp.cids;%(good_cid); for all cluster
%% Computing some useful properties of the spikes and templates
[spikeAmps, spikeDepths, templateYpos, tempAmps, tempsUnW, tempDur, tempPeakWF] = ...
templatePositionsAmplitudes(sp.temps, sp.winv, sp.ycoords, sp.spikeTemplates, sp.tempScalingAmps);
clusterDepths=zeros(length(good_cid),1);
for i=1:length(good_cid)%%%loop over clusters
cid = sp.spikeCluster==good_cid(i);
spikes_in_cluster = spikeDepths(cid);
clusterDepths(i)=mean(spikes_in_cluster);
end
tempPerClu = findTempForEachClu( sp.spikeCluster, sp.spikeTemplates);
tempPerClu = rmmissing(tempPerClu);
% ma = max(abs(tempPeakWF),[],2);
% tempPeakWF=tempPeakWF./ma;
[mi,mi_ind]= min(tempPeakWF,[],2);
% ma = zeros(length(mi),1);
tpl = zeros(length(mi),1);
for i=1:length(mi)
[~,tpl(i)]= max(tempPeakWF(i,mi_ind(i):end));
end
tpl=tpl(tempPerClu+1);
ma = max(tempPeakWF,[],2);
tpr=ma./abs(mi);
tpr=tpr(tempPerClu+1);
Ntpr=(ma-mi)./(ma+mi);
Ntpr=Ntpr(tempPerClu+1);
% [spikeWidths, tempWidths, clusterWidths] = computeSpikeWidths(tempsUnW, sp.spikeTemplates, sp.spikeCluster);
% clusterDepths = clusterAverage(sp.clu, spikeDepths);
%% Loading raw waveforms
% gwfparams.dataDir = myKsDir; % KiloSort/Phy output folder
% apD = dir(fullfile(myKsDir, '*.dat')); % AP band file from spikeGLX specifically
% gwfparams.fileName = apD(1).name; % .dat file containing the raw
% gwfparams.dataType = 'int16'; % Data type of .dat file (this should be BP filtered)
% gwfparams.nCh = 32; % Number of channels that were streamed to disk in .dat file
% gwfparams.wfWin = [-40 41]; % Number of samples before and after spiketime to include in waveform
% gwfparams.nWf = 2000; % Number of waveforms per unit to pull out
% gwfparams.spikeTimes = ceil(sp.spikeTime*30000); % Vector of cluster spike times (in samples) same length as .spikeClusters
% gwfparams.spikeClusters = sp.spikeCluster;
%
% wf = getWaveForms(gwfparams);
sp.spikeAmps = spikeAmps;
sp.spikeDepths = spikeDepths;
% sp.spikeWidths = spikeWidths;
sp.templateYpos = templateYpos;
sp.tempAmps = tempAmps;
sp.tempsUnW = tempsUnW;
sp.tempDur = tempDur;
sp.tempPeakWF = tempPeakWF;
% sp.tempWidths = tempWidths;
sp.clusDepths = clusterDepths;
sp.clusTPlatency = tpl;
sp.clusTPratio = tpr;
sp.NclusTPratio = Ntpr;
% sp.clusWidths = clusterWidths;
sp.tempPerClu = tempPerClu;
save([myKsDir,'\spike_Feature.mat'],'sp')