-
Notifications
You must be signed in to change notification settings - Fork 8
/
plotnet_treering.m
141 lines (124 loc) · 3.47 KB
/
plotnet_treering.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
function plotnet_treering(sbeG,sbeNode,ncenter,alwaysView)
%
% Systems Biology and Evolution Toolbox (SBEToolbox).
% Authors: James Cai, Kranti Konganti.
% (C) Texas A&M University.
%
% $LastChangedDate: 2012-12-28 19:01:43 -0600 (Fri, 28 Dec 2012) $
% $LastChangedRevision: 278 $
% $LastChangedBy: konganti $
%
[xy]=treering_layout(sbeG,ncenter);
[X, Y] = gplot(sbeG,xy,'-');
if (alwaysView)
overviewplot(X,Y);
zoom(2);
else
fig = figure;
box off;
mainAxes = axes('Parent', fig);
graph = plot(mainAxes, X, Y, '-o', 'LineSmoothing', 'On');
set(graph, 'color', [.6 .6 .6], 'MarkerEdgeColor','r',...
'MarkerFaceColor', 'r', 'MarkerSize', 4);
box(mainAxes, 'off');
set(findall(fig, 'Type', 'text'), 'FontSize', 5);
end
idx=find(sum(abs(xy)<=1,2)==2); % centeral nodes
c=1;
num = length(sbeNode)-ncenter;
angles = 0:(360/num):359;
%c1=1;
%num1 = ncenter;
%angles1 = 0:(360/num1):359;
%n2=ncenter+1;
%angles1 = linspace(0,2*pi,n2);
%x = 2*cos(angles*pi/180);
%y = 2*sin(angles*pi/180);
sbeNode=cellfun(@num2str,num2cell(1:size(sbeG,1)),'Uniform',false);
if ischar(sbeNode)
sbeNodetext=strrep(sbeNode,'_','\_');
sbeNodetext=strrep(sbeNodetext,'^','\^');
else
sbeNodetext = sbeNode;
end
for ind = 1:length(sbeNodetext)
if ismember(ind,idx)
%text(xy(ind,1), xy(ind,2), sbeNode{ind}, 'FontSize', 8, 'Rotation', 0);
try
text(xy(ind,1), xy(ind,2), sbeNodetext{ind}, 'Clipping', 'On');
catch exception
errordlg(exception.message);
return;
end
%{
if angles(c1)>90 && angles(c1)<270
text(xy(ind,1),xy(ind,2),sbeNode{ind},'Rotation',angles1(c1)+180,...
'HorizontalAlignment','right','fontsize',5)
else
text(xy(ind,1),xy(ind,2),sbeNode{ind},'Rotation',angles1(c1),...
'HorizontalAlignment','left','fontsize',5)
end
c1=c1+1;
%}
else
if angles(c)>90 && angles(c)<270
try
text(xy(ind,1),xy(ind,2),sbeNodetext{ind},'Rotation',...
angles(c)+180,'HorizontalAlignment','right', 'Clipping', 'On')
catch exception
errordlg(exception.message);
close(wb);
return;
end
else
try
text(xy(ind,1),xy(ind,2),sbeNodetext{ind},'Rotation',angles(c),...
'HorizontalAlignment','left', 'Clipping', 'On')
catch exception
errordlg(exception.message);
close(wb);
return;
end
end
c=c+1;
end
end
%axis equal
%axis square
%axis off
%box off
function [xy]=treering_layout(G,n_center)
%format compact
%format long e
n=num_vertices(G);
if nargin<2
n_center=5;
end
if ~(n_center>0&&n_center<=n)
error('N_CENTER needs to be >=1 and <=N')
end
degree_k=sum(G,2);
[~,y]=sort(degree_k);
idx=y(end-n_center+1:end); % top 5
xy=zeros(n,2);
n1=length(G)-n_center+1;
theta = linspace(0,2*pi,n1);
xy1 = zeros(n1,2);
x = 2*cos(theta);
y = 2*sin(theta);
xy1(1:n1,1) = x(1:n1);
xy1(1:n1,2) = y(1:n1);
xy1(end,:)=[];
n2=n_center+1;
theta = linspace(0,2*pi,n2);
xy2 = zeros(n2,2);
x = cos(theta);
y = sin(theta);
xy2(1:n2,1) = x(1:n2);
xy2(1:n2,2) = y(1:n2);
xy2(end,:)=[];
idx2=setdiff(1:n,idx);
xy(idx,:)=xy2;
xy(idx2,:)=xy1;
end
end