forked from lrvarshney/elegans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conncomp_chem.m
75 lines (67 loc) · 1.98 KB
/
conncomp_chem.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
function conncomp_chem(notion,varargin)
%CONNCOMP_CHEM Lists the connected components for the chemical network.
% CONNCOMP_CHEM(N) produces a listing of the connected components of the
% chemical network. The parameter N in {'strong','weak'} specifies
% whether strong connectedness or weak connectedness should be used.
%
% CONNCOMP_CHEM(N,A,L) produces a listing of the connected components of
% a directed graph with adjacency matrix A and node labels L.
%
% See also GRAPHCONNCOMP, CONNCOMP_GAP.
% Copyright 2006-2009. Lav R. Varshney
%
% This software is provided without warranty.
% Related article:
%
% L. R. Varshney, B. L. Chen, E. Paniagua, D. H. Hall, and D. B.
% Chklovskii, "Structural properties of the Caenorhabditis elegans
% neuronal network," 2009, in preparation.
if (nargin == 1)
%load the gap junction network
[A,labels] = datareader('chem','unweighted');
elseif (nargin == 3)
A = varargin{1};
labels = varargin{2};
else
error('CONNCOMP_CHEM: incorrect number of inputs');
end
%compute connected components
if isequal(notion,'strong')
[S,C] = graphconncomp(A);
elseif isequal(notion,'weak')
[S,C] = graphconncomp(A,'weak',true);
else
error('CONNCOMP_CHEM: incorrect inputs.')
end
%list the giant component
gc = mode(C);
giantcomp = find(C == gc);
disp('Giant Component')
for ii = 1:length(giantcomp)
disp(labels(giantcomp(ii)));
end
%list the smaller components
n = hist(C,S);
zz = 2;
for ii = 1:S
if (n(ii) > 1 ) && (ii ~= gc)
disp(strcat('Component ',num2str(zz)));
component = find(C == ii);
for jj = 1:n(ii)
disp(labels(component(jj)));
end
zz = zz + 1;
end
end
%list the unconnected neurons
zz = 1;
for ii = 1:S
if (n(ii) == 1)
if zz
disp('Unconnected');
zz = 0;
end
component = find(C == ii);
disp(labels(component));
end
end