forked from erhanbas/pipeline-reconBrain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
workflow3.m~
103 lines (87 loc) · 3.5 KB
/
workflow3.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
function workflow3(Gin,subs,opt)
tr=tic;
%% PREPROCESSING: prune & filter graph
if opt.prune == 1
if isfield(opt,'size_pruning_Thr')
size_pruning_Thr = opt.size_pruning_Thr;
else
size_pruning_Thr = [100 50];
end
[Gpruned,subspruned] = pruneGraph(Gin,subs,size_pruning_Thr,[]);
save(fullfile(tempfold,'Gpruned'),'Gpruned','subspruned')
elseif opt.prune == 2
load(fullfile(tempfold,'Gpruned'),'Gpruned','subspruned')
else
end
sprintf('TOTAL TIME: %d secs',round(toc(tr)))
%% CONVERSION to branch
G = Gpruned;
subs = subspruned;
save(fullfile(tempfold,'G_and_subs.mat'),'G','subs','-v7.3')
if opt.graph2branch == 1
% [branches,nodeBrid] = graph2branch(Gfilt,subsfilt);
[branches,nodeBrid] = graphfuncs.graph2branch(G,subs);
save(fullfile(tempfold,['branchlist',tag]),'branches','nodeBrid')
elseif opt.graph2branch == 2
load(fullfile(tempfold,['branchlist',tag]),'branches','nodeBrid')
else
end
sprintf('TOTAL TIME: %d secs',round(toc(tr)))
%%
if opt.branch2conn == 1
if isfield(opt,'querdist')
querdist = opt.querdist; % masking distance to calculate pair scores
else
querdist = [50];
end
tr=tic;
branch_pair_distance = graphfuncs.branchConn(branches,subs,nodeBrid,querdist); % pwdist of branches
sprintf('branchConn done in: %d secs',round(toc(tr)))
[aa,bb,cc] = find(branch_pair_distance);
tr=tic;
branch_pair_connectivity = sparse(aa,bb,cc<=querdist,size(branch_pair_distance,1),size(branch_pair_distance,1)); %pwcost of branches
branch_pair_dissimilarity = graphfuncs.calcDists(branches,branch_pair_connectivity);
sprintf('calcDists done in: %d secs',round(toc(tr)))
save(fullfile(tempfold,['branchConn',tag]),'branch_pair_distance','branch_pair_dissimilarity','opt')
elseif opt.branch2conn == 2
else
end
%% apply allen transformation
allenH5 = '/groups/mousebrainmicro/mousebrainmicro/Software/Matlab/Registration tools/Dependencies/OntologyAtlas.h5';
transformFile = '/groups/mousebrainmicro/mousebrainmicro/registration/Database/2018-08-01/Transform.2018-08-01.h5';
[ids,subsallen,vectorField,tFormVecField,allentForm,atlas] = getAllenAtlasIds(params,subs,transformFile,allenH5);
[subsallen,ids] = subs2allensubs(subs,params,vectorField,tFormVecField,allentForm,atlas);
%% train classifier based on repo
neuronrepo = load('/groups/mousebrainmicro/home/base/CODE/MATLAB/pipeline/pipeline-reconBrain/temp/wrapJRC/20180801_prob0_lev-6_chunk-111_111_masked-0/neurons-181220.mat')
feats = featsFromRecons(neurons_repo,atlas);
% feat set for junctions [allen compartment, D]
% D(1): Euclidean
% D(2): theta
% D(3): PCA
% D(4): KL
% D(5 [end]): hit
% save(fullfile(tempfold,['GT_feats_qd_1']),'feats')
%%
feats_array = cat(1,feats{1:917}); % upto 2018-08-01 sample
feats_array = feats_array(isfinite(feats_array(:,1)),:);
compartments = unique(feats_array(:,1))';
hists = histcounts(feats_array(:,1),compartments);
%%
for icomp = compartments
% skip;
if icomp==0;continue;end
inds_in_compartment = feats_array(:,1)==icomp;
feat_subset = feats_array(inds_in_compartment,:);
%%
figure(13),
subplot(3,1,1);
histogram(feat_subset(feat_subset(:,3)<10,3))
subplot(3,1,2);
histogram(feat_subset(:,4))
subplot(3,1,3);
histogram(feat_subset(:,5))
end
%% filter out based on Allen mask and context (edge density or alignment).
% Implements a binary classifier to decide if an edge should be kept or
% deleted as a function of Allen compartment ids, and
% branch_pair_dissimilarity