motif4funct_wei.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. function [I,Q,F]=motif4funct_wei(W)
  2. %MOTIF4FUNCT_WEI Intensity and coherence of functional class-4 motifs
  3. %
  4. % [I,Q,F] = motif4funct_wei(W);
  5. %
  6. % *Structural motifs* are patterns of local connectivity in complex
  7. % networks. In contrast, *functional motifs* are all possible subsets of
  8. % patterns of local connectivity embedded within structural motifs. Such
  9. % patterns are particularly diverse in directed networks. The motif
  10. % frequency of occurrence around an individual node is known as the motif
  11. % fingerprint of that node. The motif intensity and coherence are
  12. % weighted generalizations of the motif frequency. The motif
  13. % intensity is equivalent to the geometric mean of weights of links
  14. % comprising each motif. The motif coherence is equivalent to the ratio
  15. % of geometric and arithmetic means of weights of links comprising each
  16. % motif.
  17. %
  18. % Input: W, weighted directed connection matrix
  19. % (all weights must be between 0 and 1)
  20. %
  21. % Output: I, node motif intensity fingerprint
  22. % Q, node motif coherence fingerprint
  23. % F, node motif frequency fingerprint
  24. %
  25. % Notes:
  26. % 1. The function find_motif34.m outputs the motif legend.
  27. % 2. Average intensity and coherence are given by I./F and Q./F
  28. % 3. All weights must be between 0 and 1. This may be achieved using
  29. % the weight_conversion.m function, as follows:
  30. % W_nrm = weight_conversion(W, 'normalize');
  31. % 4. There is a source of possible confusion in motif terminology.
  32. % Motifs ("structural" and "functional") are most frequently
  33. % considered only in the context of anatomical brain networks
  34. % (Sporns and Kötter, 2004). On the other hand, motifs are not
  35. % commonly studied in undirected networks, due to the paucity of
  36. % local undirected connectivity patterns.
  37. %
  38. % References: Onnela et al. (2005), Phys Rev E 71:065103
  39. % Milo et al. (2002) Science 298:824-827
  40. % Sporns O, Kötter R (2004) PLoS Biol 2: e369%
  41. %
  42. %
  43. % Mika Rubinov, UNSW/U Cambridge, 2007-2015
  44. % Modification History:
  45. % 2007: Original
  46. % 2015: Improved documentation
  47. persistent M4 ID4 N4
  48. if isempty(N4)
  49. load motif34lib M4 ID4 N4 %load motif data
  50. end
  51. n=length(W); %number of vertices in W
  52. I=zeros(199,n); %intensity
  53. Q=zeros(199,n); %coherence
  54. F=zeros(199,n); %frequency
  55. A=1*(W~=0); %adjacency matrix
  56. As=A|A.'; %symmetrized adjacency
  57. for u=1:n-3 %loop u 1:n-2
  58. V1=[false(1,u) As(u,u+1:n)]; %v1: neibs of u (>u)
  59. for v1=find(V1)
  60. V2=[false(1,u) As(v1,u+1:n)]; %v2: all neibs of v1 (>u)
  61. V2(V1)=0; %not already in V1
  62. V2=V2|([false(1,v1) As(u,v1+1:n)]); %and all neibs of u (>v1)
  63. for v2=find(V2)
  64. vz=max(v1,v2); %vz: largest rank node
  65. V3=([false(1,u) As(v2,u+1:n)]); %v3: all neibs of v2 (>u)
  66. V3(V2)=0; %not already in V1&V2
  67. V3=V3|([false(1,v2) As(v1,v2+1:n)]);%and all neibs of v1 (>v2)
  68. V3(V1)=0; %not already in V1
  69. V3=V3|([false(1,vz) As(u,vz+1:n)]); %and all neibs of u (>vz)
  70. for v3=find(V3)
  71. w=[W(v1,u) W(v2,u) W(v3,u) W(u,v1) W(v2,v1) W(v3,v1)...
  72. W(u,v2) W(v1,v2) W(v3,v2) W(u,v3) W(v1,v3) W(v2,v3)];
  73. a=[A(v1,u);A(v2,u);A(v3,u);A(u,v1);A(v2,v1);A(v3,v1);...
  74. A(u,v2);A(v1,v2);A(v3,v2);A(u,v3);A(v1,v3);A(v2,v3)];
  75. ind=(M4*a)==N4; %find all contained isomorphs
  76. m=sum(ind); %number of isomorphs
  77. M=M4(ind,:).*repmat(w,m,1);
  78. id=ID4(ind);
  79. l=N4(ind);
  80. x=sum(M,2)./l; %arithmetic mean
  81. M(M==0)=1; %enable geometric mean
  82. i=prod(M,2).^(1./l); %intensity
  83. q=i./x; %coherence
  84. [idu,j]=unique(id); %unique motif occurences
  85. j=[0;j]; %#ok<AGROW>
  86. mu=length(idu); %number of unique motifs
  87. i2=zeros(mu,1);
  88. q2=i2; f2=i2;
  89. for h=1:mu %for each unique motif
  90. i2(h)=sum(i(j(h)+1:j(h+1))); %sum all intensities,
  91. q2(h)=sum(q(j(h)+1:j(h+1))); %coherences
  92. f2(h)=j(h+1)-j(h); %and frequencies
  93. end
  94. %then add to cumulative count
  95. I(idu,[u v1 v2 v3])=I(idu,[u v1 v2 v3])+[i2 i2 i2 i2];
  96. Q(idu,[u v1 v2 v3])=Q(idu,[u v1 v2 v3])+[q2 q2 q2 q2];
  97. F(idu,[u v1 v2 v3])=F(idu,[u v1 v2 v3])+[f2 f2 f2 f2];
  98. end
  99. end
  100. end
  101. end