-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathperform_sort.m
63 lines (47 loc) · 1.74 KB
/
perform_sort.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
%% Performs the cell sorting
%% Pre-processing
if exist('data/Holger-CellSorter-processed.mat', 'file')
load('data/Holger-CellSorter-processed.mat')
else
% load the data from a local .mat file
load('data/Holger-CellSorter.mat')
% pre-process the data by removing failed data
failing = false(height(dataTable), 1);
for ii = 1:height(dataTable)
failing(ii) = any(any(isnan(dataTable.waveforms{ii})));
end
dataTable = dataTable(~failing, :);
% add the filenames and filecodes
r.filenames = r.filenames(~failing);
r.filecodes = r.filecodes(~failing, :);
dataTable = r.stitch(dataTable);
% stack the waveforms and impute the data matrix
% use the waveform with the highest spike height out of each channel
channels = zeros(height(dataTable), 1);
for ii = height(dataTable):-1:1
% X(ii, :) = corelib.vectorise(dataTable.waveforms{ii});
channels(ii) = findStrongestChannel(dataTable.waveforms{ii});
X(ii, :) = dataTable.waveforms{ii}(:, channels(ii));
end
% rescale within each time-series, to within the box [-1, 1]
for ii = 1:size(X, 1)
X(ii, :) = rescale(X(ii, :), -1, 1);
end
% add the firing rate as a feature
% X = [X dataTable.firing_rate];
%% Perform the cell sorting procedure
% instantiate the CellSorter object
cs = CellSorter;
cs.algorithm = 'umap';
%% Update the data table and visualize results
% perform dimensionality reduction and clustering
Y = cs.dimred(X);
labels = cs.kcluster(Y);
% add the strongest channel to the data table
dataTable.channels = channels;
% add the labels to the data table
dataTable.labels = labels;
% save the results by overwriting the existing .mat file
save('data/Holger-CellSorter-processed.mat', 'dataTable', 'r', 'Y')
end
return