-
Notifications
You must be signed in to change notification settings - Fork 0
/
S_Figure_Residuals.m
108 lines (99 loc) · 3.35 KB
/
S_Figure_Residuals.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
102
103
104
105
106
107
function S_Figure_Residuals(nG,lambda,preloadinds,savenclose,directory)
if nargin < 5
directory = [cd filesep 'MatFiles'];
if nargin < 4
savenclose = 0;
if nargin < 3
preloadinds = [];
if nargin < 2
lambda = 90;
if nargin < 1
nG = 582;
end
end
end
end
end
load([directory filesep 'Tasic_Inputs.mat'],'genevct','voxvgene','gene_names','listBmap','nonzerovox','structIndex');
sampleinds = [70,92,186];
listBvec = listBmap(nonzerovox);
[E_red,C_red] = GeneSelector(genevct,voxvgene,gene_names,nG,lambda,'MRx3',preloadinds);
% [E_red, C_red] = GeneSelector(genevct,voxvgene,gene_names,nG,lambda,'MRx3');
D = CellDensityInference(E_red,C_red);
E_infer = C_red*D.';
residuals = zeros(1,size(E_infer,2));
for i = 1:length(residuals)
% residuals(i) = sum(abs(E_infer(:,i) - E_red(:,i)))/sum(E_red(:,i));
residuals(i) = sum(abs(E_infer(:,i) - E_red(:,i)));
end
samplebool = ismember(listBvec,sampleinds);
sample_errs = residuals(samplebool);
nonsample_errs = residuals(~samplebool);
datacell = {sample_errs,nonsample_errs};
rng('default');
xpos = zeros(length(residuals),1);
g = xpos;
xposscatter = @(x,y) 0.025 * (2*rand(length(x),1) - 1) + y;
plotindcell = {find(samplebool), find(~samplebool)};
for j = 1:length(plotindcell)
curinds = plotindcell{j};
g(curinds) = j;
xpos(curinds) = xposscatter(curinds,j);
end
cmap = [[0.3 0.3 0.7];[0.7 0.3 0.3]];
f3 = figure('Position',[0 0 800 800]); hold on;
% v = gscatter(xpos,residuals,g,cmap,[],10,'off');
b = boxplot(residuals,g,'Colors',cmap,'Symbol','');
% v = violin(datacell,'facecolor',cmap);
set(b,{'linew'},{3})
set(gca, 'XTick', 1:2, 'XTickLabel', {'Sampled Regions','Unsampled Regions'});
% set(gca, 'YTick', [0,0.25,0.5,0.75,1])
% set(gca, 'XTickLabelRotation', 45);
ylabel('\Sigma_g |{\it E}_{red} - {\it C}_{red} * {\it D}|');
% ylabel('Rel. Error');
xlabel('');
set(gca,'TickLength',[0 0])
title('Sum of Absolute Error per Voxel');
set(gca, 'FontSize', 24);
if savenclose
print('residuals','-dtiffn');
close;
end
% % load pervoxLayerMaps.mat
% % load default_mousereg.mat
%
load([directory filesep 'default_mouse.mat'],'input_struct');
input_struct.voxUreg = 1;
% input_struct.nbin = 5;
% input_struct.centered = [1 2];
input_struct.xfac = 1;
input_struct.sphere = 1;
input_struct.sphere_npts = 20;
% input_struct.size_constant = 3;
input_struct.pointsize = 0.1;
input_struct.savenclose = savenclose;
for j = 1:length(structIndex)
curres = residuals(listBvec==j);
residuals_reg(j) = mean(curres);
end
residuals_reg = ([residuals_reg(1:11) 0 residuals_reg(12:212) residuals_reg(1:11) 0 residuals_reg(12:212)]).';
testvals = residuals_reg;
% datamap = zeros(size(listBmap));
% for i = 1:length(structIndex)
% [~,voxinds] = ismember(structIndex{i},nonzerovox);
% allvox = nonzerovox(voxinds);
% curvox = testvals(i);
% datamap(allvox) = curvox;
% clear allvox curvox voxinds
% end
% interpmap = datamap;
% interpmap = imresize3(interpmap,[133 81 115]);
% interpmap(interpmap<0) = 0;
% datinput = interpmap;
input_struct.data = testvals;
input_struct.cmap = [[0.3 0.3 0.7];[0.7 0.3 0.3]];
reggroups = 2*ones(426,1); reggroups([sampleinds+1,sampleinds+214]) = 1;
input_struct.region_groups = reggroups;
input_struct.img_labels = 'mean_residual_error';
brainframe(input_struct);
end