| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <esl_config.h> |
| 11 |
|
| 12 |
#include "easel.h" |
| 13 |
#include "esl_composition.h" |
| 14 |
#include "esl_scorematrix.h" |
| 15 |
|
| 16 |
#define eslSWAT_PROHIBIT -999999999 |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
int |
| 39 |
esl_swat_Score(ESL_DSQ *x, int L, ESL_DSQ *y, int M, ESL_SCOREMATRIX *S, int gop, int gex, int *ret_sc) |
| 40 |
{ |
| 41 |
int status; |
| 42 |
int i,j; |
| 43 |
int **rowmem = NULL; |
| 44 |
int *mc, *mp, *ixc, *ixp, *iyc, *iyp; |
| 45 |
int maxsc; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
ESL_ALLOC(rowmem, sizeof(int *) * 6); |
| 56 |
rowmem[0] = NULL; |
| 57 |
ESL_ALLOC(rowmem[0], sizeof(int) * 6 * (L+1)); |
| 58 |
for (i = 1; i < 6; i++) rowmem[i] = rowmem[0] + i*(L+1); |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
rowmem[1][0] = 0; |
| 63 |
rowmem[3][0] = eslSWAT_PROHIBIT; |
| 64 |
rowmem[5][0] = eslSWAT_PROHIBIT; |
| 65 |
for (j = 0; j <= L; j++) { |
| 66 |
rowmem[0][j] = 0; |
| 67 |
rowmem[2][j] = eslSWAT_PROHIBIT; |
| 68 |
rowmem[4][j] = eslSWAT_PROHIBIT; |
| 69 |
} |
| 70 |
|
| 71 |
maxsc = 0; |
| 72 |
for (i = 1; i <= M; i++) |
| 73 |
{ |
| 74 |
if (i%2) { mp = rowmem[0]; mc = rowmem[1]; ixp = rowmem[2]; ixc = rowmem[3]; iyp = rowmem[4]; iyc = rowmem[5]; } |
| 75 |
else { mc = rowmem[0]; mp = rowmem[1]; ixc = rowmem[2]; ixp = rowmem[3]; iyc = rowmem[4]; iyp = rowmem[5]; } |
| 76 |
|
| 77 |
for (j = 1; j <= L; j++) |
| 78 |
{ |
| 79 |
|
| 80 |
mc[j] = 0; |
| 81 |
if (mp[j-1] > mc[j]) mc[j] = mp[j-1]; |
| 82 |
if (ixp[j-1] > mc[j]) mc[j] = ixp[j-1]; |
| 83 |
if (iyp[j-1] > mc[j]) mc[j] = iyp[j-1]; |
| 84 |
mc[j] += S->s[x[j]][y[i]]; |
| 85 |
|
| 86 |
if (mc[j] > maxsc) maxsc = mc[j]; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
ixc[j] = mc[j-1] + gop; |
| 92 |
if (ixc[j-1] + gex > ixc[j]) ixc[j] = ixc[j-1] + gex; |
| 93 |
|
| 94 |
|
| 95 |
iyc[j] = mp[j] + gop; |
| 96 |
if (iyp[j] + gex > iyc[j]) iyc[j] = iyp[j] + gex; |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
*ret_sc = maxsc; |
| 101 |
free(rowmem[0]); |
| 102 |
free(rowmem); |
| 103 |
return eslOK; |
| 104 |
|
| 105 |
ERROR: |
| 106 |
*ret_sc = 0; |
| 107 |
if (rowmem != NULL) { |
| 108 |
if (rowmem[0] != NULL) free(rowmem[0]); |
| 109 |
free(rowmem); |
| 110 |
} |
| 111 |
return status; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
#ifdef eslSWAT_STATS |
| 124 |
|
| 125 |
#include "easel.h" |
| 126 |
#include "esl_getopts.h" |
| 127 |
#include "esl_fileparser.h" |
| 128 |
#include "esl_scorematrix.h" |
| 129 |
#include "esl_random.h" |
| 130 |
#include "esl_randomseq.h" |
| 131 |
#include "esl_histogram.h" |
| 132 |
|
| 133 |
int |
| 134 |
main(int argc, char **argv) |
| 135 |
{ |
| 136 |
int status; |
| 137 |
ESL_RANDOMNESS *r = esl_randomness_Create(0); |
| 138 |
ESL_ALPHABET *abc = esl_alphabet_Create(eslAMINO); |
| 139 |
ESL_SCOREMATRIX *S = NULL; |
| 140 |
ESL_DSQ *x = NULL; |
| 141 |
ESL_DSQ *y = NULL; |
| 142 |
double lambda; |
| 143 |
double bg[20]; |
| 144 |
int L; |
| 145 |
int M; |
| 146 |
int nseq; |
| 147 |
int i; |
| 148 |
int gop; |
| 149 |
int gex; |
| 150 |
char *mxfile = "PMX"; |
| 151 |
int raw_sc; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
L = 400; |
| 156 |
M = 400; |
| 157 |
nseq = 50000; |
| 158 |
gop = -11; |
| 159 |
gex = -1; |
| 160 |
lambda = 0.3207; |
| 161 |
|
| 162 |
ESL_ALLOC(x, sizeof(ESL_DSQ) * (L+2)); |
| 163 |
ESL_ALLOC(y, sizeof(ESL_DSQ) * (M+2)); |
| 164 |
|
| 165 |
|
| 166 |
if (mxfile != NULL) { |
| 167 |
ESL_FILEPARSER *efp = NULL; |
| 168 |
if ( esl_fileparser_Open(mxfile, NULL, &efp) != eslOK) esl_fatal("failed to open score file %s", mxfile); |
| 169 |
if ( esl_scorematrix_Read(efp, abc, &S) != eslOK) esl_fatal("failed to read matrix from %s", mxfile); |
| 170 |
esl_fileparser_Close(efp); |
| 171 |
} else { |
| 172 |
S = esl_scorematrix_Create(abc); |
| 173 |
esl_scorematrix_Set("BLOSUM62", S); |
| 174 |
} |
| 175 |
esl_composition_BL62(bg); |
| 176 |
|
| 177 |
esl_rsq_xIID(r, bg, 20, L, x); |
| 178 |
|
| 179 |
for (i = 0; i < nseq; i++) |
| 180 |
{ |
| 181 |
esl_rsq_xIID(r, bg, 20, M, y); |
| 182 |
esl_swat_Score(x, L, y, M, S, gop, gex, &raw_sc); |
| 183 |
printf("%d\n", raw_sc); |
| 184 |
} |
| 185 |
|
| 186 |
free(x); |
| 187 |
free(y); |
| 188 |
esl_scorematrix_Destroy(S); |
| 189 |
esl_alphabet_Destroy(abc); |
| 190 |
esl_randomness_Destroy(r); |
| 191 |
exit(0); |
| 192 |
|
| 193 |
ERROR: |
| 194 |
exit(status); |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
#endif |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
void |
| 210 |
utest_Score(char *s1, char *s2, ESL_SCOREMATRIX *S, int gop, int gex, int expect_score) |
| 211 |
{ |
| 212 |
|
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|