-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualize_mouse_tsne_coronal_perplexity_sweep3D.m
131 lines (111 loc) · 3.59 KB
/
visualize_mouse_tsne_coronal_perplexity_sweep3D.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
%% Make the plots for the mouse tsne coronal view
clear variables
close all
% Load additional color data
datadir = '/home/mvandegiessen/data/tSNE_ABA/AllenMouseBrain_coronal/';
colors = load([datadir 'voxels']);
[cx,cy,cz] = ind2sub([67 41 58],colors.voxel.brain_idx);
coords = [cx cy cz];
perp = '256';
%% Figure a
% t-SNE mapping colored by region with 10 components
% Load data
load(['results_mouse_genes_perplexity_sweep_th0p2/MappedMouseGenesPerplexitySweep3Dperp' perp '.mat'],'mappedX','mappedRGB');
% Plot figure
cm = jet(58/2+1);
nsamples = size(mappedX,1);
figure(1)
clf
hold on
for snr = 1:nsamples
plot(mappedX(snr,1),mappedX(snr,2),'.','Color',cm(abs(coords(snr,3)-58/2)+1,:));
end
% Format the plot
axis off equal tight
set(gcf,'Color','white')
dpi = 300;
figsizeinch = [7 7]/2.54;
set(gcf,'Units','pixel','Position',[50 50 dpi*figsizeinch])
saveas(1,['MappedMousePerplexitySweepWidthMirrored3Dperp' perp '.png']);
saveas(1,['MappedMousePerplexitySweepWidthMirrored3Dperp' perp '.fig']);
%% Same plot with regions
load(['results_mouse_genes_perplexity_sweep_th0p2/MappedMouseGenesPerplexitySweep3Dperp' perp '.mat'],'mappedX','mappedRGB');
% Plot figure
nsamples = size(mappedX,1);
figure(2)
clf
hold on
colorRGB = zeros(nsamples,3);
for snr = 1:nsamples
if ~isempty(colors.voxel.color_HEX{snr})
colorRGB(snr,:) = rgbconv(colors.voxel.color_HEX{snr});
else
colorRGB(snr,:) = [0 0 0];
end
plot3(mappedX(snr,1),mappedX(snr,2),mappedX(snr,3),'.','Color',colorRGB(snr,:));
end
% Format the plot
axis off equal tight
view(3)
set(gcf,'Color','white')
dpi = 300;
figsizeinch = [7 7]/2.54;
set(gcf,'Units','pixel','Position',[50 50 dpi*figsizeinch])
saveas(2,['MappedMousePerplexitySweepRegion3D2perp' perp '.png']);
saveas(2,['MappedMousePerplexitySweepRegion3Dperp' perp '.fig']);
%% Same plot with regions
load(['results_mouse_genes_perplexity_sweep_th0p2/MappedMouseGenesPerplexitySweep3Dperp' perp '.mat'],'mappedX','mappedRGB');
% Plot figure
nsamples = size(mappedX,1);
figure(3)
clf
hold on
cm = (mappedX-min(mappedX(:)))/(max(mappedX(:))-min(mappedX(:)));
for snr = 1:nsamples
plot(mappedX(snr,1),mappedX(snr,2),'.','Color',cm(snr,:));
end
% Format the plot
axis off equal tight
set(gcf,'Color','white')
dpi = 300;
figsizeinch = [7 7]/2.54;
set(gcf,'Units','pixel','Position',[50 50 dpi*figsizeinch])
saveas(3,['MappedMousePerplexitySweepMappedColors3Dperp' perp '.png']);
saveas(3,['MappedMousePerplexitySweepMappedColors3Dperp' perp '.fig']);
%% Interpolated plot
caxis = linspace(min(mappedX(:)),max(mappedX(:)),200);
[mx,my,mz] = meshgrid(caxis,caxis,caxis);
dt = DelaunayTri(mappedX);
[id,dist] = nearestNeighbor(dt,[mx(:) my(:) mz(:)]);
%% Put colors in space
imgr = reshape(colorRGB(id,1),[1 1 1]*length(caxis));
imgg = reshape(colorRGB(id,2),[1 1 1]*length(caxis));
imgb = reshape(colorRGB(id,3),[1 1 1]*length(caxis));
dth = 1;
imgr(dist>dth) = 0;
imgg(dist>dth) = 0;
imgb(dist>dth) = 0;
%% Select and show slice
slice = 80;
cimg = cat(3,imgr(:,:,slice),imgg(:,:,slice),imgb(:,:,slice));
figure(3)
imagesc(cimg)
axis equal off
set(gcf,'Color','white')
%% Volume with 3D images
ind = colors.voxel.brain_idx;
imgr = zeros([67 41 58]);
imgg = zeros([67 41 58]);
imgb = zeros([67 41 58]);
cm = (mappedX-min(mappedX(:)))/(max(mappedX(:))-min(mappedX(:)));
imgr(ind) = cm(:,1);
imgg(ind) = cm(:,2);
imgb(ind) = cm(:,3);
%% Select and show slice
slice = 20;
cimg = cat(3,imgr(:,:,slice),imgg(:,:,slice),imgb(:,:,slice));
figure(4)
imagesc(cimg)
axis equal off
set(gcf,'Color','white')
save(['results_mouse_genes_perplexity_sweep_th0p2/MappedMousePerplexitySweepVolume3Dperp' perp],'imgr','imgg','imgb');