-
Notifications
You must be signed in to change notification settings - Fork 0
/
classify_cells.m
76 lines (66 loc) · 2.01 KB
/
classify_cells.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
function result = classify_cells(genes, tcounts, initids, initmarkers, options)
arguments
genes
tcounts
initids
initmarkers = []
options.marker_selectby = "min_cohen_d"
options.marker_method = "top"
options.marker_nTop = 20
options.score_method = "expr" %corr
options.select_method = "otsu" %quantile
options.refine = true
options.refine_ptile = 95
end
CTs=categories(initids);
nCells=size(tcounts,2);
if isempty(initmarkers)
ges=GroupedExpressionSummary(genes,tcounts,initids);
ges.computeEffectSizes();
M=table;
for i=1:length(options.marker_selectby)
M=ges.topMarkers(options.marker_selectby(i), options.marker_method, nTop=options.marker_nTop);
end
M=M(:,1:2);
M=unique(M,'rows');
end
% compute ct-scores
scores=zeros(length(CTs),nCells);
for i=1:length(CTs)
thisCT=CTs(i);
mnames=M.gene(M.celltype==thisCT);
scores(i,:)=score_genes(mnames,tcounts, genes.name, ctrl_size=50);
end
% select thresholds from score distributions, assign labels
% - otsu, quantile, ...
% - SingleR uses correlation values as scores, allowing numeric
% first/second comparisons.
% - Problem with genescores is they are not on the same scale (or are
% they?) - normalize them???
scorethr=false(length(CTs),nCells);
thr=zeros(length(CTs),1);
for i=1:length(CTs)
this_score=scores(i,:);
thr(i,1)=geneThresholdOtsu(this_score);
scorethr(i,:)=this_score>thr(i,1);
end
utype=sum(scorethr,1)==1;
type=strings(nCells,1);
CTrep=repmat(CTs,1,nCells);
uCTs=CTrep(scorethr(:,utype));
type(utype)=uCTs;
type(sum(scorethr,1)==0)="Unc";
type(sum(scorethr,1)>1)="Amb";
ctplus=[CTs,"Unc","Amb"];
type=categorical(type,ctplus,ctplus);
summary(type')
if options.refine
ges=GroupedExpressionSummary(genes,tcounts,type);
ges.computeEffectSizes();
M=table;
for i=1:length(options.marker_selectby)
M=ges.topMarkers(options.marker_selectby(i), options.marker_method, nTop=options.marker_nTop);
end
M=M(:,1:2);
M=unique(M,'rows');
end