motif3funct_bin.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. function [f,F]=motif3funct_bin(A)
  2. %MOTIF3FUNCT_BIN Frequency of functional class-3 motifs
  3. %
  4. % [f,F] = motif3funct_bin(A);
  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 total motif frequency of occurrence in
  12. % the whole network is correspondingly known as the motif fingerprint of
  13. % the network.
  14. %
  15. % Input: A, binary directed connection matrix
  16. %
  17. % Output: F, node motif frequency fingerprint
  18. % f, network motif frequency fingerprint
  19. %
  20. % Notes:
  21. % 1. The function find_motif34.m outputs the motif legend.
  22. % 2. There is a source of possible confusion in motif terminology.
  23. % Motifs ("structural" and "functional") are most frequently
  24. % considered only in the context of anatomical brain networks
  25. % (Sporns and Kötter, 2004). On the other hand, motifs are not
  26. % commonly studied in undirected networks, due to the paucity of
  27. % local undirected connectivity patterns.
  28. %
  29. % References: Milo et al. (2002) Science 298:824-827
  30. % Sporns O, Kötter R (2004) PLoS Biol 2: e369
  31. %
  32. %
  33. % Mika Rubinov, UNSW/U Cambridge, 2007-2015
  34. % Modification History:
  35. % 2007: Original
  36. % 2015: Improved documentation
  37. persistent M3 ID3 N3
  38. if isempty(N3)
  39. load motif34lib M3 ID3 N3 %load motif data
  40. end
  41. n=length(A); %number of vertices in A
  42. f=zeros(13,1); %motif count for whole graph
  43. F=zeros(13,n); %frequency
  44. A=1*(A~=0); %adjacency matrix
  45. As=A|A.'; %symmetrized adjacency
  46. for u=1:n-2 %loop u 1:n-2
  47. V1=[false(1,u) As(u,u+1:n)]; %v1: neibs of u (>u)
  48. for v1=find(V1)
  49. V2=[false(1,u) As(v1,u+1:n)]; %v2: all neibs of v1 (>u)
  50. V2(V1)=0; %not already in V1
  51. V2=([false(1,v1) As(u,v1+1:n)])|V2; %and all neibs of u (>v1)
  52. for v2=find(V2)
  53. a=[A(v1,u);A(v2,u);A(u,v1);A(v2,v1);A(u,v2);A(v1,v2)];
  54. ind=(M3*a)==N3; %find all contained isomorphs
  55. id=ID3(ind);
  56. [idu,j]=unique(id); %unique motif occurences
  57. j=[0;j]; %#ok<AGROW>
  58. mu=length(idu); %number of unique motifs
  59. f2=zeros(mu,1);
  60. for h=1:mu %for each unique motif
  61. f2(h)=j(h+1)-j(h); %and frequencies
  62. end
  63. %then add to cumulative count
  64. f(idu)=f(idu)+f2;
  65. if nargout==2
  66. F(idu,[u v1 v2])=F(idu,[u v1 v2])+[f2 f2 f2];
  67. end
  68. end
  69. end
  70. end