-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJaccard.m
69 lines (59 loc) · 3.47 KB
/
Jaccard.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
function[c]=Jaccard(Cover_range, REI_range, Analysis, Headers, extract)
%% Creating Jaccard similarity plot of reaction count between clusters of each threshold condition
cb_keep = [0.9200, 0.1100, 0.0267, 0.8150];
k=0
for c=1:numel(Cover_range)
for p=1:numel(REI_range)
k=k+1
Reactions=Analysis(k).Reaction_mat
Reactions.Properties.VariableNames = Headers;
Reaction_Matrix = table2array(Reactions(:,2:end));
J = squareform(pdist(Reaction_Matrix','jaccard'));
if numel(unique(J)) > 1
if sum(sum(isnan(J)))>0
altcolor = [0 0 255; 255 255 255;255 204 204; 255 153 153; 255 102 102; 255 51 51;...
255 0 0; 204 0 0; 152 0 0; 102 0 0; 51 0 0]/255;
else
altcolor = [255 255 255;255 204 204; 255 153 153; 255 102 102; 255 51 51;...
255 0 0; 204 0 0; 152 0 0; 102 0 0; 51 0 0]/255;
end
J(isnan(J)) = 1.1;
%get and save the default size
defaultPosition = get(0,'DefaultFigurePosition');
%get the current screen size
screensize = get(groot, 'Screensize');
%screensize = get(0, 'Screensize'); %for earlier Matlab versions (e.g. Matlab 2010)
%set default figure position to full screen
screensize = [1,1,800,800];
set(0, 'DefaultFigurePosition', screensize);
data_values_names = Reactions.Properties.VariableNames(2:end)';
cgo_J = clustergram(1-J,...
'RowLabels', data_values_names,...
'ColumnLabels', data_values_names,...
'ColumnLabelsRotate',340, ...
'Cluster', 'all', ...
'Annotate', 'true',...
'symmetric','False',...
'AnnotColor','k',...
'Colormap', altcolor)
%addTitle(cgo_J,{'Model similarity using Jaccard index',' based on the reconstructed models'' reactions', ['Cover ', num2str(Cover(c)) ,' and Percentage ', num2str(percent(p))]});
addTitle(cgo_J,{'Cluster similarity using Jaccard index',' based on the reconstructed models'' reactions'});
plot(cgo_J);
% cb = colorbar;
%cb.Position = cb_keep;
figureHandle = gcf;
%# make all text in the figure to size 14 and bold
fig_gcf = findall(0,'type','figure', 'tag', 'Clustergram');
set(findall(figureHandle,'type','text'),'fontSize',16,'fontWeight','bold')
set(findall(figureHandle, 'type','axes','tag','HeatMapAxes'),'fontsize',16)
saveas(gcf,[extract,'\Jaccard_Similarity\1Jaccard_C_',num2str(Cover_range(c)),'_P_',num2str(REI_range(p)),'.png']);
end
J = 1-J;
rowNames = Headers(2:end);
colNames = Headers(2:end);
Jac_table = array2table(J,'RowNames',rowNames,'VariableNames',colNames);
writetable(Jac_table,[extract,'\Jaccard_Similarity\1Jaccard_Similarity_Index_C_',num2str(Cover_range(c)),'_P_',num2str(REI_range(p)),'.txt'], 'WriteRowNames', true);
end
end
close all force
%'ColumnLabels', data_values_names,...