7 #include "likelihood.h"
11 #include "compute_like.h"
12 #include "interface.h"
15 void average_score_over_coils2(Sequence seq,
16 double scores[MAXSEQLEN][POSNUM+1],
17 double PreprocLike[MAXSEQLEN][POSNUM+1],
18 int CoilDiffMethod, int offset_to_use,
19 char offsets[MAXSEQLEN],
20 int start_at_reg_shift)
23 int start_coil[POSNUM+1];
24 double total_coil_score[POSNUM+1];
25 double avg_coil_score[POSNUM+1];
28 double total_coil_length[POSNUM +1]; /* A weighted length. */
30 for (j=0; j<POSNUM+1; j++) {
32 total_coil_score[j]=0;
34 total_coil_length[j]=0;
37 if (offset_to_use == -1 ) offset_to_use = 7; /* Adjust "all" offset */
38 /* to max offset locally. */
40 while (i<=seq.seqlen) {
41 for (k=0; k<=POSNUM; k++) {
42 if (k!=7) regist = (i+k)%POSNUM;
45 /* Consider < 1/10 percent to be zero */
46 if ( ( PreprocLike[i][regist] < .001) || (i==seq.seqlen) ||
47 ( (i>0) && (offsets[i] != offsets[i-1]) && start_at_reg_shift &&
48 (PreprocLike[i-1][7]>= .001) ) ) {
49 /** If not in a coil (value of -HUGE_VAL signals not in coil). */
50 if (start_coil[k] != -1) { /* Ended coil at i-1. */
51 avg_coil_score[k] = total_coil_score[k]/total_coil_length[k];
52 for (j=start_coil[k]; j<i; j++) {
54 scores[j][(j+k)%POSNUM]= avg_coil_score[k];
56 scores[j][7]= avg_coil_score[k];
60 total_coil_score[k] =0;
61 void average_score_over_coils2(Sequence seq,
62 double scores[MAXSEQLEN][POSNUM+1],
63 double PreprocLike[MAXSEQLEN][POSNUM+1],
64 int CoilDiffMethod, int offset_to_use,
65 char offsets[MAXSEQLEN],
66 int start_at_reg_shift)
69 int start_coil[POSNUM+1];
70 double total_coil_score[POSNUM+1];
71 double avg_coil_score[POSNUM+1];
74 double total_coil_length[POSNUM +1]; /* A weighted length. */
76 for (j=0; j<POSNUM+1; j++) {
78 total_coil_score[j]=0;
80 total_coil_length[j]=0;
83 if (offset_to_use == -1 ) offset_to_use = 7; /* Adjust "all" offset */
84 /* to max offset locally. */
86 while (i<=seq.seqlen) {
87 for (k=0; k<=POSNUM; k++) {
88 if (k!=7) regist = (i+k)%POSNUM;
91 /* Consider < 1/10 percent to be zero */
92 if ( ( PreprocLike[i][regist] < .001) || (i==seq.seqlen) ||
93 ( (i>0) && (offsets[i] != offsets[i-1]) && start_at_reg_shift &&
94 (PreprocLike[i-1][7]>= .001) ) ) {
95 /** If not in a coil (value of -HUGE_VAL signals not in coil). */
96 if (start_coil[k] != -1) { /* Ended coil at i-1. */
97 avg_coil_score[k] = total_coil_score[k]/total_coil_length[k];
98 for (j=start_coil[k]; j<i; j++) {
100 scores[j][(j+k)%POSNUM]= avg_coil_score[k];
102 scores[j][7]= avg_coil_score[k];
106 total_coil_score[k] =0;
107 if (i != seq.seqlen) /* Consider < 1/10 percent to be 0 */
108 if ( PreprocLike[i][regist] < .001) { /* Not in coil anymore. */
111 total_coil_length[k] =0;
113 else { /* Changing registers. */
115 if (CoilDiffMethod==0) {
116 total_coil_length[k] = 1;
117 total_coil_score[k] = scores[i][regist];
119 else if (CoilDiffMethod ==1) {
120 total_coil_length[k]= PreprocLike[i][regist];
121 total_coil_score[k] = scores[i][regist]*
122 PreprocLike[i][regist];
125 } /** Ends if ending a coil. **/
127 else { /* If in a coil. */
128 if (CoilDiffMethod ==0) { /* Average scores over coil residues. */
129 total_coil_score[k] += scores[i][regist];
131 total_coil_length[k] += 1;
133 else if (CoilDiffMethod == 1) { /* Weighted average scores. */
134 total_coil_score[k] += scores[i][regist]*
135 PreprocLike[i][regist];
136 total_coil_length[k] += PreprocLike[i][regist];
138 if (start_coil[k] == -1)
146 /* Need the following hack to get the correct register in max off method.*/
147 if ( (offset_to_use == 7) && (!start_at_reg_shift))
148 for (i=0; i<seq.seqlen; i++) {
149 for (j=0; j<POSNUM; j++)
150 scores[i][j]= -HUGE_VAL;
151 scores[i][(i+offsets[i]) %POSNUM] = scores[i][7];
157 /*******************************************************************/
159 void PairCoilDiffer(int mode, Sequence sequence, char lib[MAXFUNCTNUM],
160 double *maxscore,char offsets[MAXSEQLEN],
161 double preproc_like[MAXSEQLEN][POSNUM+1],
162 int offset_to_use, int table,
163 double scores[MAXSEQLEN][POSNUM+1],
164 int Avg_Coil_Score, int CoilDiffMethod,
165 int start_coil_at_reg_shift)
169 double sc2scores[MAXSEQLEN][POSNUM];
170 char diff_offsets[MAXSEQLEN];
171 double total_coilscore[POSNUM+1];
172 int coil_length[POSNUM +1];
175 extern long pfreqs[MAX_TABLE_NUMBER][AANUM][POSNUM];
176 extern long ptotals[MAX_TABLE_NUMBER][POSNUM];
177 extern long pfreqp[MAX_TABLE_NUMBER][AANUM][AANUM][POSNUM][POSNUM];
178 extern long ptotalp[MAX_TABLE_NUMBER][POSNUM][POSNUM];
181 int ProlineFreeWindow= mode & PROLINE_FREE_MODE;
183 if (table ==0) like2or3= 2;
186 for (i=0; i<=POSNUM; i++) {
188 total_coilscore[i] =0;
193 /* score the sequence using sc2seq */
195 sequence.seq, sequence.seqlen,
198 maxscore, mode, 1); /* Get differentiator score.*/
204 /* *maxscore= exp(*maxscore); */
208 for (i=0; i<sequence.seqlen; ++i) {
209 /* Do the most probabable register if offset_to_use is -1 or 7. */
210 if ((offset_to_use == -1) || (offset_to_use ==7))
212 scores[i][7] = 1 - exp(sc2scores[i][offsets[i]]);
214 scores[i][7] = exp(sc2scores[i][offsets[i]]);
216 else /* Offset to use is 0-6. */
218 scores[i][7] = 1 - exp(sc2scores[i][offset_to_use]);
220 scores[i][7] = exp(sc2scores[i][offset_to_use]);
221 /*****Trimer like is 1 - dimerlike ***/
223 if (preproc_like[i][7] <.001) /* Consider < 1/10 percent to be 0 */
224 scores[i][7]=0; /* Don't score non-coiled regions. */
228 for (j=0; j<7; ++j) { /** sc2scores[i][j] is the score for position
230 if (preproc_like[i][(i+j)%POSNUM]> 0) {
232 scores[i][(i+j)%POSNUM] = 1 - exp(sc2scores[i][j]);
234 scores[i][(i+j)%POSNUM] = exp(sc2scores[i][j]);
237 scores[i][(i+j)%POSNUM]= 0;
244 average_score_over_coils2(sequence, scores, preproc_like,
245 CoilDiffMethod, offset_to_use,offsets,
246 start_coil_at_reg_shift);
250 for (i=0; i<sequence.seqlen; i++)
251 if (scores[i][7] > *maxscore) *maxscore = scores[i][7];