-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmds_on_human_genes_group_average_2D.m
131 lines (109 loc) · 3.19 KB
/
mds_on_human_genes_group_average_2D.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
131
%% Perform Barnes-Hut t-SNE on mouse gene data
clear variables
close all
addpath('../bh-tsne');
ids = {'9861','10021','12876','14380','15496','15697'};
nbrains = length(ids);
outdir = 'results_human_average_group_MDS/';
%% Load data
X = [];
coords = [];
color_RGB = [];
structure_id = [];
brain_id = [];
for bnr = 1:nbrains
id = ids{bnr};
datadir = ['/home/mvandegiessen/data/tSNE_ABA/rawData_25Feb2014/normalized_microarray_donor' id '/'];
% expressionlevels = load([datadir 'MicroarrayExpression']);
expressionlevels = load([datadir 'geneMicroarrayExpression']);
% % Load gene selection
% if bnr == 1
% indexdata = load([datadir 'probe2gene_index']);
% allgindices = 1:size(expressionlevels.MicroarrayExpression,1);
% selprobes = allgindices(indexdata.probe2gene_index>0);
% end
% Load gene coordinates, color, structure_ID
sampledata = load([datadir 'sample']);
coords = [coords; [sampledata.sample.mni_x,sampledata.sample.mni_y,sampledata.sample.mni_z]];
color_RGB = [color_RGB; sampledata.sample.color_RGB];
structure_id = [structure_id; sampledata.sample.structure_id];
brain_id = [brain_id; bnr*ones(length(sampledata.sample.mni_x),1)];
% Normalize data
Xnew = expressionlevels.geneMicroarrayExpression';
% Per gene
Xnew = zscore(Xnew,0,1);
% Data subselection
X = [X; Xnew];
end
X0 = X;
%% Compute distance matrix
disp('Distance matrix');
% D = pdist(X,'euclidean');
nsamples = size(X,1);
D = zeros(nsamples,nsamples);
tic
parfor snr1 = 1:nsamples
% fprintf('Sample %d/%d\n',snr1,nsamples);
dist = zeros(1,nsamples);
for snr2 = 1:nsamples
dist(snr2) = sqrt(1-xcov(X(snr1,:),X(snr2,:),0,'coeff')^2);
end
D(snr1,:) = dist;
end
toc
D = abs(D);
D(eye(size(D))>0) = 0;
%% MDS
disp('2D MDS');
mappedX2 = mdscale(D,2);
disp('3D MDS');
mappedX3 = mdscale(D,3);
%% Save mapped data
save([outdir 'MDSHumanGenesGroupAverageMeanSub'],'D','X','mappedX2','mappedX3','coords','color_RGB','structure_id','brain_id');
%% Visualize mapped data based on SVD coordinates
nsamples = size(X,1);
figure(2)
clf
hold on
for snr = 1:nsamples
c = color_RGB(snr,:);
plot3(mappedX3(snr,1),mappedX3(snr,2),mappedX3(snr,3),'.','Color',c);
end
view(3)
axis equal
saveas(2,[outdir 'MDSHumanGenesGroupAverageMeanSubRegions3D']);
%% Visualize mapped data using brain id colors
nsamples = size(X,1);
%
figure(3)
clf
hold on
cm = hsv(nbrains);
for bnr = 1:nbrains
c = cm(bnr,:);
plot3(mappedX3(brain_id==bnr,1),mappedX3(brain_id==bnr,2),mappedX3(brain_id==bnr,3),'.','Color',c);
end
view(3)
axis equal
saveas(3,[outdir 'MDSHumanGenesGroupAverageMeanSubBrainID3D']);
%% Visualize mapped data based on SVD coordinates
figure(4)
clf
hold on
for snr = 1:nsamples
c = color_RGB(snr,:);
plot(mappedX2(snr,1),mappedX2(snr,2),'.','Color',c);
end
saveas(4,[outdir 'MDSHumanGenesGroupAverageMeanSubRegions2D']);
%% Visualize mapped data using brain id colors
nsamples = size(X,1);
%
figure(5)
clf
hold on
cm = hsv(nbrains);
for bnr = 1:nbrains
c = cm(bnr,:);
plot(mappedX2(brain_id==bnr,1),mappedX2(brain_id==bnr,2),'.','Color',c);
end
saveas(5,[outdir 'MDSHumanGenesGroupAverageMeanSubBrainID2D']);