-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathse.h
191 lines (178 loc) · 5.58 KB
/
se.h
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "TMalign.h"
/* entry function for se
* outfmt_opt>=2 should not parse sequence alignment */
int se_main(
double **xa, double **ya, const char *seqx, const char *seqy,
double &TM1, double &TM2, double &TM3, double &TM4, double &TM5,
double &d0_0, double &TM_0,
double &d0A, double &d0B, double &d0u, double &d0a, double &d0_out,
string &seqM, string &seqxA, string &seqyA,
double &rmsd0, int &L_ali, double &Liden,
double &TM_ali, double &rmsd_ali, int &n_ali, int &n_ali8,
const int xlen, const int ylen, const vector<string> &sequence,
const double Lnorm_ass, const double d0_scale, const bool i_opt,
const bool a_opt, const bool u_opt, const bool d_opt, const int mol_type,
const int outfmt_opt, int *invmap)
{
double D0_MIN; //for d0
double Lnorm; //normalization length
double score_d8,d0,d0_search,dcu0;//for TMscore search
double **score; // Input score table for dynamic programming
bool **path; // for dynamic programming
double **val; // for dynamic programming
int *m1=NULL;
int *m2=NULL;
double d;
if (outfmt_opt<2)
{
m1=new int[xlen]; //alignd index in x
m2=new int[ylen]; //alignd index in y
}
/***********************/
/* allocate memory */
/***********************/
NewArray(&score, xlen+1, ylen+1);
NewArray(&path, xlen+1, ylen+1);
NewArray(&val, xlen+1, ylen+1);
//int *invmap = new int[ylen+1];
/* set d0 */
parameter_set4search(xlen, ylen, D0_MIN, Lnorm,
score_d8, d0, d0_search, dcu0); // set score_d8
parameter_set4final(xlen, D0_MIN, Lnorm,
d0B, d0_search, mol_type); // set d0B
parameter_set4final(ylen, D0_MIN, Lnorm,
d0A, d0_search, mol_type); // set d0A
if (a_opt)
parameter_set4final((xlen+ylen)*0.5, D0_MIN, Lnorm,
d0a, d0_search, mol_type); // set d0a
if (u_opt)
parameter_set4final(Lnorm_ass, D0_MIN, Lnorm,
d0u, d0_search, mol_type); // set d0u
/* perform alignment */
for(int j=0; j<ylen; j++) invmap[j]=-1;
if (!i_opt) NWDP_SE(path, val, xa, ya, xlen, ylen, d0*d0, 0, invmap);
else
{
int i1 = -1;// in C version, index starts from zero, not from one
int i2 = -1;
int L1 = sequence[0].size();
int L2 = sequence[1].size();
int L = min(L1, L2);// Get positions for aligned residues
for (int kk1 = 0; kk1 < L; kk1++)
{
if (sequence[0][kk1] != '-') i1++;
if (sequence[1][kk1] != '-')
{
i2++;
if (i2 >= ylen || i1 >= xlen) kk1 = L;
else if (sequence[0][kk1] != '-') invmap[i2] = i1;
}
}
}
rmsd0=TM1=TM2=TM3=TM4=TM5=0;
int k=0;
n_ali=0;
n_ali8=0;
for(int i=0,j=0; j<ylen; j++)
{
i=invmap[j];
if(i>=0)//aligned
{
n_ali++;
d=sqrt(dist(&xa[i][0], &ya[j][0]));
if (d <= score_d8 || i_opt)
{
if (outfmt_opt<2)
{
m1[k]=i;
m2[k]=j;
}
k++;
TM2+=1/(1+(d/d0B)*(d/d0B)); // chain_1
TM1+=1/(1+(d/d0A)*(d/d0A)); // chain_2
if (a_opt) TM3+=1/(1+(d/d0a)*(d/d0a)); // -a
if (u_opt) TM4+=1/(1+(d/d0u)*(d/d0u)); // -u
if (d_opt) TM5+=1/(1+(d/d0_scale)*(d/d0_scale)); // -d
rmsd0+=d*d;
}
}
}
n_ali8=k;
TM2/=xlen;
TM1/=ylen;
TM3/=(xlen+ylen)*0.5;
TM4/=Lnorm_ass;
TM5/=ylen;
if (n_ali8) rmsd0=sqrt(rmsd0/n_ali8);
if (outfmt_opt>=2)
{
DeleteArray(&score, xlen+1);
DeleteArray(&path, xlen+1);
DeleteArray(&val, xlen+1);
return 0;
}
/* extract aligned sequence */
int ali_len=xlen+ylen; //maximum length of alignment
seqxA.assign(ali_len,'-');
seqM.assign( ali_len,' ');
seqyA.assign(ali_len,'-');
int kk=0, i_old=0, j_old=0;
d=0;
Liden=0;
for(int k=0; k<n_ali8; k++)
{
for(int i=i_old; i<m1[k]; i++)
{
//align x to gap
seqxA[kk]=seqx[i];
seqyA[kk]='-';
seqM[kk]=' ';
kk++;
}
for(int j=j_old; j<m2[k]; j++)
{
//align y to gap
seqxA[kk]='-';
seqyA[kk]=seqy[j];
seqM[kk]=' ';
kk++;
}
seqxA[kk]=seqx[m1[k]];
seqyA[kk]=seqy[m2[k]];
Liden+=(seqxA[kk]==seqyA[kk]);
d=sqrt(dist(&xa[m1[k]][0], &ya[m2[k]][0]));
if(d<d0_out) seqM[kk]=':';
else seqM[kk]='.';
kk++;
i_old=m1[k]+1;
j_old=m2[k]+1;
}
//tail
for(int i=i_old; i<xlen; i++)
{
//align x to gap
seqxA[kk]=seqx[i];
seqyA[kk]='-';
seqM[kk]=' ';
kk++;
}
for(int j=j_old; j<ylen; j++)
{
//align y to gap
seqxA[kk]='-';
seqyA[kk]=seqy[j];
seqM[kk]=' ';
kk++;
}
seqxA=seqxA.substr(0,kk);
seqyA=seqyA.substr(0,kk);
seqM =seqM.substr(0,kk);
/* free memory */
//delete [] invmap;
delete [] m1;
delete [] m2;
DeleteArray(&score, xlen+1);
DeleteArray(&path, xlen+1);
DeleteArray(&val, xlen+1);
return 0; // zero for no exception
}