-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_motif34.cpp
105 lines (85 loc) · 2.39 KB
/
find_motif34.cpp
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
#include "bct.h"
/*
* Returns all motif isomorphs for a given motif ID and size.
*/
std::vector<MATRIX_T*> BCT_NAMESPACE::find_motif34(int m, int n) {
// if n==3
if (n == 3) {
// load motif34lib M3 ID3
VECTOR_T* ID3;
MATRIX_T* M3 = motif3generate(&ID3);
// ind=find(ID3==m).';
VECTOR_T* ID3_eq_m = compare_elements(ID3, fp_equal, (FP_T)m);
VECTOR_ID(free)(ID3);
VECTOR_T* ind = find(ID3_eq_m);
VECTOR_ID(free)(ID3_eq_m);
// M=zeros(3,3,length(ind));
std::vector<MATRIX_T*> M(length(ind));
int i_nondiag[] = { 1, 2, 3, 5, 6, 7 };
// for i=1:length(ind)
for (int i = 0; i < length(ind); i++) {
// M(:,:,i)=reshape([0 M3(ind(i),1:3) 0 M3(ind(i),4:6) 0],3,3);
M[i] = MATRIX_ID(calloc)(3, 3);
int ind_i = (int)VECTOR_ID(get)(ind, i);
for (int j = 0; j < 6; j++) {
ordinal_index_assign(M[i], i_nondiag[j], MATRIX_ID(get)(M3, ind_i, j));
}
}
MATRIX_ID(free)(M3);
VECTOR_ID(free)(ind);
return M;
// elseif n==4
} else if (n == 4) {
// load motif34lib M4 ID4;
VECTOR_T* ID4;
MATRIX_T* M4 = motif4generate(&ID4);
// ind=find(ID4==m).';
VECTOR_T* ID4_eq_m = compare_elements(ID4, fp_equal, (FP_T)m);
VECTOR_ID(free)(ID4);
VECTOR_T* ind = find(ID4_eq_m);
VECTOR_ID(free)(ID4_eq_m);
// M=zeros(4,4,length(ind));
std::vector<MATRIX_T*> M(length(ind));
int i_nondiag[] = { 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14 };
// for i=1:length(ind)
for (int i = 0; i < length(ind); i++) {
// M(:,:,i)=reshape([0 M4(ind(i),1:4) 0 M4(ind(i),5:8) 0 M4(ind(i),9:12) 0],4,4);
M[i] = MATRIX_ID(calloc)(4, 4);
int ind_i = (int)VECTOR_ID(get)(ind, i);
for (int j = 0; j < 12; j++) {
ordinal_index_assign(M[i], i_nondiag[j], MATRIX_ID(get)(M4, ind_i, j));
}
}
MATRIX_ID(free)(M4);
VECTOR_ID(free)(ind);
return M;
} else {
return std::vector<MATRIX_T*>();
}
}
/*
* Returns the motif ID for a given matrix.
*/
int BCT_NAMESPACE::find_motif34(const MATRIX_T* m) {
if (safe_mode) check_status(m, SQUARE, "find_motif34");
// n=size(m,1);
int n = m->size1;
// M=eval(['find(motif' int2str(n) 'struct_bin(m))']);
VECTOR_T* f;
if (n == 3) {
f = motif3struct_bin(m);
} else if (n == 4) {
f = motif4struct_bin(m);
} else {
return 0;
}
VECTOR_T* M_v = find(f);
VECTOR_ID(free)(f);
if (M_v != NULL) {
int M = (int)VECTOR_ID(get)(M_v, 0);
VECTOR_ID(free)(M_v);
return M + 1;
} else {
return 0;
}
}