-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentify_classifier.m
88 lines (70 loc) · 2.46 KB
/
identify_classifier.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
function [h]= identify_classifier(h)
% load classifier files
rootS2p = which('run_pipeline');
if isempty(rootS2p)
warndlg('Suite2p location not in PATH! where is run_pipeline.m?')
[filename1,rootS2p]=uigetfile(root, 'Select Data File');
end
rootS2p = fileparts(rootS2p);
rootS2p = fullfile(rootS2p, 'configFiles');
flag = 0;
if isfield(h.dat.ops, 'classifier') && ~isempty(h.dat.ops.classifier)
if ~exist(fullfile(rootS2p, h.dat.ops.classifier), 'file')
% warndlg('specified classifier database not found, reverting to last used');
else
def_file = dat.ops.classifier;
flag = 1;
end
else
% warning('no specified classifier database, reverting to last used');
end
if (flag==0)
fs = dir(fullfile(rootS2p, '*.mat'));
if isempty(fs)
warndlg('no classifier found, please make a new one!')
h = make_classifier(h);
else
[~, imax] = max([fs.datenum]);
def_file = fs(imax).name;
h.dat.cl.fpath = fullfile(rootS2p, def_file);
hload = load(h.dat.cl.fpath);
if ~isfield(hload, 'st') || ~isfield(hload, 'statLabels') || ~isfield(hload, 'prior')
error('found a non-classifier file in configFiles, called %s. \n Please remove and try again!', def_file)
end
h.st = hload.st;
h.prior = hload.prior;
h.statLabels = hload.statLabels;
end
end
end
function h = make_classifier(h)
% new classifier button
rootS2p = which('run_pipeline');
if isempty(rootS2p)
warndlg('Suite2p location not in PATH! where is run_pipeline.m?')
[filename1,rootS2p]=uigetfile(root, 'Select run_pipeline.m');
end
rootS2p = fileparts(rootS2p);
rootS2p = fullfile(rootS2p, 'configFiles');
def_name = fullfile(rootS2p, 'cl_new.mat');
[FileName,PathName] = uiputfile('*.mat', 'Create new classifier', def_name);
if FileName
load(fullfile(rootS2p, 'priors', 'prior_default.mat'));
st = [];
save(fullfile(PathName, FileName), 'st', 'prior', 'statLabels')
h.st = st;
h.prior = prior;
h.statLabels = statLabels;
h.dat.cl.fpath = fullfile(PathName, FileName);
h = classROI(h);
% h = splitROIleftright(h);
% h = buildLambdaValue(h);
% redraw_figure(h);
hload = load(h.dat.cl.fpath);
h.st = hload.st;
h.statLabels = hload.statLabels;
h.prior = hload.prior;
else
error('you must make a new classifier first!')
end
end