-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedisa.m
executable file
·183 lines (115 loc) · 4.66 KB
/
edisa.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
function [g, c, dev] = edisa(E, gedisa_sample, gene_threshold, condition_threshold, coherent, penalty)
dataset=E;
g=gedisa_sample;
g_star = g;
for i = 1:100 %maximum number of iterations; in practice, convergence is reached earlier
%c(n+1) = f_{t_C} ( E_G * g(n) ):
%--------------------------------
E.submatrix = E.submatrix';
p_genes = project_genes(E,g);
%look either for all clusters (including IRC) or for coherent clusters
%only:
if strcmp(coherent,'coherent')
av_column = average_column(p_genes);
dist_column = distance_to_average_column(p_genes, av_column);
c = threshold(dist_column, condition_threshold);
else %IR:
column_av = column_average2(p_genes);
dist_column = distance_to_column_average2(p_genes, column_av);
end
%use adaptive parameters if no thresholds are specified:
%-------------------------------------------------------
if (gene_threshold == -1 || condition_threshold==-1)
try
partitions = kmeans(dist_column.pearson_distance', 2);
par1= dist_column.pearson_distance(find(partitions==1));
par2 = dist_column.pearson_distance(find(partitions==2));
condition_threshold = min(max(par1), max(par2))+0.01;
catch
end
end
c = threshold(dist_column, condition_threshold);
if (length(c)<=1)
E=p_genes;
break;
end
%g(n+1) = f_{t_G} ( E_C * c(n+1) ):
%----------------------------------
E=p_genes;
E.submatrix = E.submatrix';
p_conditions = project_conditions2(E,c);
%again, decide whether to look for coherent or IR clusters:
if strcmp(coherent, 'coherent')
av_row = average_row(p_conditions);
dist_to_av = distance_to_average_row(p_conditions, av_row);
%if the Pearson correlation is not applicable to the data an error code
%is returned:
%if(dist_to_av_row.pearson_distance ~= -1)
% g = threshold(dist_row, gene_threshold);
%end
else %IR:
dist_to_av = dist_to_average_col2(p_conditions);
end
l = length(dist_to_av.pearson_distance);
penalty_vec = exprnd(penalty,l,1); %exponential distribution
penalty_vec = sort(penalty_vec,'ascend');
dist_to_av.pearson_distance = dist_to_av.pearson_distance.*penalty_vec;
%use adaptive parameters if no thresholds are specified:
%-------------------------------------------------------
if (gene_threshold == -1 || condition_threshold==-1)
try
partitions = kmeans(dist_to_av.pearson_distance, 2);
cluster1 = find(partitions==1);
par1= dist_to_av.pearson_distance(cluster1);
cluster2= find(partitions==2);
par2 = dist_to_av.pearson_distance(cluster2);
gene_threshold = min(max(par1), max(par2))+0.01;
catch
end
end
if(dist_to_av.pearson_distance ~= -1)
g = threshold(dist_to_av, gene_threshold);
end
E=p_conditions;
if length(g) < 2
break;
end
%convergence criterion:
%----------------------
if ((length(g_star)-length(g)) / (length(g_star)+length(g))<0.01)
break;
else
g_star = g;
end
end
%return the current gene and conditions sets, as well as the cluster score:
%--------------------------------------------------------------------------
g=E.genenumbers;
c=E.conditionnumbers;
%timepoints of the current module
NumberOfConditions = length(c);
for i = 1:NumberOfConditions
NumberOfTimePoints(i) = length(E.timepoints{i});
end
%timepoints of the whole dataset:
for i = 1:length(dataset.timepoints)
DatasetTimePoints(i) = length(dataset.timepoints{i});
end
tp = zeros(1,sum(NumberOfTimePoints));
for i = 1:NumberOfConditions
index_offset = sum(NumberOfTimePoints(1:i-1))+1;
value_offset = sum(DatasetTimePoints(1:c(i)-1))+1;
tp(index_offset:index_offset+NumberOfTimePoints(i)-1) = value_offset:value_offset+DatasetTimePoints(c(i))-1;
end
if strcmp(coherent,'coherent')
%Pearson on all trajectories:
dev = bicluster_dev( extract_all_trajectories(dataset.submatrix(dataset.genes_internal(g),tp), NumberOfTimePoints) );
else %IR clusters:
start = 1;
for i= 1:NumberOfConditions
dev_c(i) = bicluster_dev(dataset.submatrix(dataset.genes_internal(g),tp(start:start+NumberOfTimePoints(i)-1)) );
start = start + NumberOfTimePoints(i);
end
dev = mean(dev_c);
end
g = dataset.genes_internal(g);