-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdz_classifyAllUnits.m
More file actions
81 lines (65 loc) · 2.85 KB
/
dz_classifyAllUnits.m
File metadata and controls
81 lines (65 loc) · 2.85 KB
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
function dz_classifyAllUnits(varargin)
% By Diksha Zutshi
% Function to run dz_Curate on all .dat files in the current folder and subfolders.
% - mainDir: path to the code folder
% - thresholds: optional struct or cell array of thresholds
% Example:
% pipeline={'lowFiring','amplitude','halfWidth','slope','correlation','acgEmpty','acgAll','mua'};
% dz_classifyAllUnits('mode','strict','maxHW',0.8,'minAmp',50...,'pipeline'=pipeline)
%look for all kilosort files in SpikeCleaner folder
spikeCleaner=fullfile(pwd,'SpikeCleaner');
if isfolder(spikeCleaner)
% Detect .npy and .dat files
npyFiles = dz_getAllExtFiles(spikeCleaner, 'npy', 0); % 1 = include subfolders
datFiles = dz_getAllExtFiles(pwd, 'dat', 1);
else
error('Please run dz_runFirst.m to create SpikeCleaner Folder');
end
[~,basename]=fileparts(pwd);
datfilematch=[basename '.dat'];
matchIdx=find(contains(datFiles,datfilematch),1,'first');
if ~isempty(matchIdx)
datfile=datFiles{matchIdx};
else
%
error('Dat file isnt available: %s',datfilematch);
end
fname=datfile;
% Parse name-value pair inputs
p = inputParser;
addParameter(p, 'mode', 'strict'); % ACG evaluation mode
addParameter(p, 'maxHW', 0.8); % Half-width threshold in ms
addParameter(p, 'minAmp', 50); % Minimum amplitude in uV
addParameter(p, 'maxAmp', 500); % Maximum amplitude in uV
addParameter(p, 'minSlope', 100); % Minimum slope in uV/ms
addParameter(p, 'firingThreshold', 0.05); % Minimum firing rate in Hz
addParameter(p, 'acgallthreshold', 1); % Threshold for all center bins vs shoulder
addParameter(p, 'acgalllabel', 'Noise'); % Label for acgany threshold
addParameter(p, 'corrThreshold', 0.95); % Max correlation threshold
addParameter(p, 'pipeline', ...
{'lowFiring','correlation','amplitude','halfWidth','slope','acgEmpty','acgAll','mua'});
parse(p, varargin{:});
R = p.Results;
% Convert parsed values into the cell format expected by dz_Curate
thresholds = { ...
R.mode, ...
R.maxHW, ...
R.minAmp, ...
R.maxAmp, ...
R.minSlope, ...
R.firingThreshold, ...
R.acgallthreshold, ...
R.acgalllabel, ...
R.corrThreshold ...
};
%Extracting pipeline after parsing
pipeline = R.pipeline;
%% Process .dat file
fprintf('Processing file: %s\n', datfile);
% Find the corresponding spike_clusters.npy file
clusterfile = npyFiles(contains(npyFiles, 'spike_clusters'));
clufile = clusterfile{1}; % Select the first match
% Run curation
dz_Curate(basename,fname, clufile,thresholds,pipeline)
fprintf('Finished processing file: %s\n', fname);
end