-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpikeClusterMetaExtract.m
127 lines (92 loc) · 3.65 KB
/
SpikeClusterMetaExtract.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
function [clustStruct, waveStruct, fileInfo, debug] = SpikeClusterMetaExtract(fileLoc, matNames, eleSelect, usePlot)
% SPIKECLUSTERMETAEXTRACT - Runs the spike extraction code on an entire
% session and creates a struct output with results. Use debugging field to
% determine if any files failed.
%
% Is run with PLOTMULTIWINDOWSPIKEINFO.m
% DOES NOT REQUIRE INPUTS or HAVE ANY DEFAULT INPUTS
%
% Dependencies:
% 1. set_parameters_AO.m
% 2. SpikeThresholdCreate.m
% 3. SpikeTimeExtract.m
% 4. ExtractWaveFeatures.m
% 5. ClusterSpikes.m
% 6. GetClusIndex_WCalg.m
% numOfspikes = vector of spike counts for all traces
% Spike Debug Script
if nargin == 0
fileLoc = 'Y:\PreProcessEphysData\06_19_2014';
cd(fileLoc);
fileDir = dir('*.mat');
fileNames = {fileDir.name};
fileIndex = randperm(length(fileNames),round(length(fileNames)/2));
matNames = fileNames(fileIndex);
eleSelect = repmat({[1 2 3]}, 1, length(matNames));
usePlot = 0;
elseif nargin == 1
cd(fileLoc)
fileDir = dir('*.mat');
fileNames = {fileDir.name};
fileIndex = randperm(length(fileNames),round(length(fileNames)/2));
matNames = fileNames(fileIndex);
eleSelect = repmat({[1 2 3]}, 1, length(matNames));
usePlot = 0;
end
cd(fileLoc);
debug = struct;
debug.fName = {};
debug.ele = {};
debug.err = {};
debugNum = 1;
eleCount = 1;
waveStruct = cell(3*round(length(matNames)/2),1);
clustStruct = cell(3*round(length(matNames)/2),1);
fileInfo = cell(3*round(length(matNames)/2),2);
for fli = 1:length(matNames)
fileName = matNames{fli};
% AbvTrgt_34_06015.mat problematic for my algorithm
load(matNames{fli})
for ei = 1:length(eleSelect{fli})
eleNum = eleSelect{fli}(ei);
tempSpkData = eval(strcat('CElectrode',num2str(eleNum)));
sampFreq = sampFreqMER*1000;
handles.datatype = 'unClustered';
handles.params = set_parameters_AO(sampFreq, fileName, handles);
try
[thrOut] = SpikeThresholdCreate(tempSpkData, handles, 'Min9sig');
filtSpkData = thrOut.Filtered;
threshold = thrOut.AveThresh;
if usePlot
[jat_Struct] = SpikeTimeExtract_Plot(filtSpkData, threshold, handles);
else
[jat_Struct] = SpikeTimeExtract(filtSpkData, threshold, handles);
end
% Get threshold data and spike number
if ~isstruct(jat_Struct)
tempStruct = nan;
tempClust = nan;
else
tempStruct = jat_Struct;
[waveFeat] = ExtractWaveFeatures(tempStruct.spkWaveforms, handles);
[clustOUT, treeOUT, ipermut] = ClusterSpikes(waveFeat, handles);
[~, ~, clusterAll] = GetClusIndex_WCalg(clustOUT, treeOUT, tempStruct.spkIndex, tempStruct.spkWaveforms, ipermut, handles);
tempClust = clusterAll;
end
catch error
debug.fName{debugNum,1} = fileName;
debug.ele{debugNum,1} = strcat('CElectrode',num2str(eleNum));
debug.err{debugNum,1} = error;
tempStruct = nan;
tempClust = nan;
debugNum = debugNum + 1;
end
waveStruct{eleCount,1} = tempStruct;
clustStruct{eleCount,1} = tempClust;
fileInfo{eleCount,1} = fileName;
fileInfo{eleCount,2} = strcat('CElectrode',num2str(eleNum));
eleCount = eleCount + 1;
end
fprintf('File # %d out of %d done! \n',fli, length(matNames));
end
end