motif4struct_bin.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. function [f,F]=motif4struct_bin(A)
  2. %MOTIF4STRUCT_BIN Frequency of structural class-4 motifs
  3. %
  4. % [f,F] = motif4struct_bin(A);
  5. %
  6. % Structural motifs are patterns of local connectivity in complex
  7. % networks. Such patterns are particularly diverse in directed networks.
  8. % The motif frequency of occurrence around an individual node is known as
  9. % the motif fingerprint of that node. The total motif frequency of
  10. % occurrence in the whole network is correspondingly known as the
  11. % motif fingerprint of the network.
  12. %
  13. % Input: A, binary directed connection matrix
  14. %
  15. % Output: F, node motif frequency fingerprint
  16. % f, network motif frequency fingerprint
  17. %
  18. % Note: The function find_motif34.m outputs the motif legend.
  19. %
  20. % References: Milo et al. (2002) Science 298:824-827
  21. % Sporns O, Kötter R (2004) PLoS Biol 2: e369
  22. %
  23. %
  24. % Mika Rubinov, UNSW/U Cambridge, 2007-2015
  25. % Modification History:
  26. % 2007: Original
  27. % 2015: Improved documentation
  28. persistent M4n ID4
  29. if isempty(ID4)
  30. load motif34lib M4n ID4 %load motif data
  31. end
  32. n=length(A); %number of vertices in A
  33. F=zeros(199,n); %motif count of each vertex
  34. f=zeros(199,1); %motif count for whole graph
  35. As=A|A.'; %symmetric adjacency matrix
  36. for u=1:n-3 %loop u 1:n-2
  37. V1=[false(1,u) As(u,u+1:n)]; %v1: neibs of u (>u)
  38. for v1=find(V1)
  39. V2=[false(1,u) As(v1,u+1:n)]; %v2: all neibs of v1 (>u)
  40. V2(V1)=0; %not already in V1
  41. V2=V2|([false(1,v1) As(u,v1+1:n)]); %and all neibs of u (>v1)
  42. for v2=find(V2)
  43. vz=max(v1,v2); %vz: largest rank node
  44. V3=([false(1,u) As(v2,u+1:n)]); %v3: all neibs of v2 (>u)
  45. V3(V2)=0; %not already in V1&V2
  46. V3=V3|([false(1,v2) As(v1,v2+1:n)]);%and all neibs of v1 (>v2)
  47. V3(V1)=0; %not already in V1
  48. V3=V3|([false(1,vz) As(u,vz+1:n)]); %and all neibs of u (>vz)
  49. for v3=find(V3)
  50. s=uint64(sum(10.^(11:-1:0).*[A(v1,u) A(v2,u) A(v3,u)...
  51. A(u,v1) A(v2,v1) A(v3,v1) A(u,v2) A(v1,v2)...
  52. A(v3,v2) A(u,v3) A(v1,v3) A(v2,v3)]));
  53. ind=ID4(s==M4n);
  54. if nargout==2; F(ind,[u v1 v2 v3])=F(ind,[u v1 v2 v3])+1; end
  55. f(ind)=f(ind)+1;
  56. end
  57. end
  58. end
  59. end