| 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 |
#include <esl_config.h> |
| 29 |
|
| 30 |
#include <math.h> |
| 31 |
#include <string.h> |
| 32 |
#include <ctype.h> |
| 33 |
|
| 34 |
#include "easel.h" |
| 35 |
#include "esl_alphabet.h" |
| 36 |
#include "esl_distance.h" |
| 37 |
#include "esl_dmatrix.h" |
| 38 |
#include "esl_matrixops.h" |
| 39 |
#include "esl_msa.h" |
| 40 |
#include "esl_msacluster.h" |
| 41 |
#include "esl_quicksort.h" |
| 42 |
#include "esl_tree.h" |
| 43 |
#include "esl_vectorops.h" |
| 44 |
|
| 45 |
#include "esl_msaweight.h" |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
static int consensus_by_rf (const ESL_MSA *msa, int *conscols, int *ret_ncons, ESL_MSAWEIGHT_DAT *dat); |
| 60 |
static int consensus_by_sample(const ESL_MSAWEIGHT_CFG *cfg, const ESL_MSA *msa, int **ct, int *conscols, int *ret_ncons, ESL_MSAWEIGHT_DAT *dat); |
| 61 |
static int consensus_by_all (const ESL_MSAWEIGHT_CFG *cfg, const ESL_MSA *msa, int **ct, int *conscols, int *ret_ncons, ESL_MSAWEIGHT_DAT *dat); |
| 62 |
static int collect_counts (const ESL_MSAWEIGHT_CFG *cfg, const ESL_MSA *msa, const int *conscols, int ncons, int **ct, ESL_MSAWEIGHT_DAT *dat); |
| 63 |
static int msaweight_PB_txt(ESL_MSA *msa); |
| 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 |
int |
| 155 |
esl_msaweight_PB(ESL_MSA *msa) |
| 156 |
{ |
| 157 |
if (msa->flags & eslMSA_DIGITAL) return esl_msaweight_PB_adv(NULL, msa, NULL); |
| 158 |
else return msaweight_PB_txt(msa); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
int |
| 183 |
esl_msaweight_PB_adv(const ESL_MSAWEIGHT_CFG *cfg, ESL_MSA *msa, ESL_MSAWEIGHT_DAT *dat) |
| 184 |
{ |
| 185 |
int ignore_rf = (cfg? cfg->ignore_rf : eslMSAWEIGHT_IGNORE_RF); |
| 186 |
int allow_samp = (cfg? cfg->allow_samp : eslMSAWEIGHT_ALLOW_SAMP); |
| 187 |
int sampthresh = (cfg? cfg->sampthresh : eslMSAWEIGHT_SAMPTHRESH); |
| 188 |
int **ct = NULL; |
| 189 |
int *r = NULL; |
| 190 |
int *conscols = NULL; |
| 191 |
int ncons = 0; |
| 192 |
int idx, apos, j, a; |
| 193 |
int rlen; |
| 194 |
int status = eslOK; |
| 195 |
|
| 196 |
|
| 197 |
ESL_DASSERT1(( msa->nseq >= 1 && msa->alen >= 1)); |
| 198 |
ESL_DASSERT1(( msa->flags & eslMSA_DIGITAL )); |
| 199 |
if (msa->nseq == 1) { msa->wgt[0] = 1.0; return eslOK; } |
| 200 |
|
| 201 |
|
| 202 |
ct = esl_mat_ICreate( msa->alen+1, msa->abc->Kp ); |
| 203 |
ESL_ALLOC(conscols, sizeof(int) * msa->alen); |
| 204 |
|
| 205 |
|
| 206 |
if (! ignore_rf && msa->rf) consensus_by_rf(msa, conscols, &ncons, dat); |
| 207 |
else if (allow_samp && msa->nseq > sampthresh) consensus_by_sample(cfg, msa, ct, conscols, &ncons, dat); |
| 208 |
|
| 209 |
|
| 210 |
collect_counts(cfg, msa, conscols, ncons, ct, dat); |
| 211 |
|
| 212 |
|
| 213 |
if (! ncons) consensus_by_all(cfg, msa, ct, conscols, &ncons, dat); |
| 214 |
|
| 215 |
|
| 216 |
if (! ncons) |
| 217 |
{ |
| 218 |
for (apos = 1; apos <= msa->alen; apos++) conscols[apos-1] = apos; |
| 219 |
ncons = msa->alen; |
| 220 |
if (dat) dat->cons_allcols = TRUE; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
ESL_ALLOC(r, sizeof(int) * ncons); |
| 225 |
esl_vec_ISet(r, ncons, 0); |
| 226 |
for (j = 0; j < ncons; j++) |
| 227 |
{ |
| 228 |
apos = conscols[j]; |
| 229 |
for (a = 0; a < msa->abc->K; a++) |
| 230 |
if (ct[apos][a] > 0) r[j]++; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
esl_vec_DSet(msa->wgt, msa->nseq, 0.0); |
| 235 |
for (idx = 0; idx < msa->nseq; idx++) |
| 236 |
{ |
| 237 |
rlen = 0; |
| 238 |
for (j = 0; j < ncons; j++) |
| 239 |
{ |
| 240 |
apos = conscols[j]; |
| 241 |
a = msa->ax[idx][apos]; |
| 242 |
msa->wgt[idx] += (a >= msa->abc->K ? 0. : 1. / (double) (r[j] * ct[apos][a])); |
| 243 |
rlen += (a >= msa->abc->K ? 0 : 1); |
| 244 |
} |
| 245 |
if (rlen > 0) msa->wgt[idx] /= (double) rlen; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
esl_vec_DNorm(msa->wgt, msa->nseq); |
| 250 |
esl_vec_DScale(msa->wgt, msa->nseq, (double) msa->nseq); |
| 251 |
msa->flags |= eslMSA_HASWGTS; |
| 252 |
|
| 253 |
ERROR: |
| 254 |
esl_mat_IDestroy(ct); |
| 255 |
free(r); |
| 256 |
if (dat) dat->ncons = ncons; |
| 257 |
if (dat) dat->conscols = conscols; else free(conscols); |
| 258 |
return status; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
static int |
| 272 |
consensus_by_rf(const ESL_MSA *msa, int *conscols, int *ret_ncons, ESL_MSAWEIGHT_DAT *dat) |
| 273 |
{ |
| 274 |
int ncons = 0; |
| 275 |
int apos; |
| 276 |
|
| 277 |
for (apos = 1; apos <= msa->alen; apos++) |
| 278 |
{ |
| 279 |
if (esl_abc_CIsGap(msa->abc, msa->rf[apos-1])) continue; |
| 280 |
conscols[ncons] = apos; |
| 281 |
ncons++; |
| 282 |
} |
| 283 |
if (dat) dat->cons_by_rf = TRUE; |
| 284 |
*ret_ncons = ncons; |
| 285 |
return eslOK; |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
static int |
| 322 |
consensus_by_sample(const ESL_MSAWEIGHT_CFG *cfg, const ESL_MSA *msa, int **ct, int *conscols, int *ret_ncons, ESL_MSAWEIGHT_DAT *dat) |
| 323 |
{ |
| 324 |
float fragthresh = (cfg? cfg->fragthresh : eslMSAWEIGHT_FRAGTHRESH); |
| 325 |
float symfrac = (cfg? cfg->symfrac : eslMSAWEIGHT_SYMFRAC); |
| 326 |
int nsamp = (cfg? cfg->nsamp : eslMSAWEIGHT_NSAMP); |
| 327 |
int maxfrag = (cfg? cfg->maxfrag : eslMSAWEIGHT_MAXFRAG); |
| 328 |
ESL_RAND64 *rng = (cfg? esl_rand64_Create(cfg->seed) : esl_rand64_Create(eslMSAWEIGHT_RNGSEED)); |
| 329 |
int64_t *sampidx = NULL; |
| 330 |
int nfrag = 0; |
| 331 |
int ncons = 0; |
| 332 |
int tot; |
| 333 |
int minspan; |
| 334 |
int apos, a; |
| 335 |
int lpos, rpos; |
| 336 |
int i, idx; |
| 337 |
int status = eslOK; |
| 338 |
|
| 339 |
ESL_ALLOC(sampidx, sizeof(int64_t) * nsamp); |
| 340 |
esl_mat_ISet(ct, msa->alen+1, msa->abc->Kp, 0); |
| 341 |
if (dat) dat->seed = esl_rand64_GetSeed(rng); |
| 342 |
|
| 343 |
esl_rand64_Deal(rng, nsamp, (int64_t) msa->nseq, sampidx); |
| 344 |
|
| 345 |
minspan = (int) ceil( fragthresh * (float) msa->alen ); |
| 346 |
for (i = 0; i < nsamp; i++) |
| 347 |
{ |
| 348 |
idx = (int) sampidx[i]; |
| 349 |
|
| 350 |
for (lpos = 1; lpos <= msa->alen; lpos++) if (esl_abc_XIsResidue(msa->abc, msa->ax[idx][lpos])) break; |
| 351 |
for (rpos = msa->alen; rpos >= 1; rpos--) if (esl_abc_XIsResidue(msa->abc, msa->ax[idx][rpos])) break; |
| 352 |
if (rpos - lpos + 1 < minspan) nfrag++; else { lpos = 1; rpos = msa->alen; } |
| 353 |
|
| 354 |
for (apos = lpos; apos <= rpos; apos++) |
| 355 |
ct[apos][msa->ax[idx][apos]]++; |
| 356 |
} |
| 357 |
|
| 358 |
if (dat) dat->samp_nfrag = nfrag; |
| 359 |
|
| 360 |
if (nfrag <= maxfrag) |
| 361 |
{ |
| 362 |
for (apos = 1; apos <= msa->alen; apos++) |
| 363 |
{ |
| 364 |
for (tot = 0, a = 0; a < msa->abc->Kp-2; a++) tot += ct[apos][a]; |
| 365 |
if ( ((float) ct[apos][msa->abc->K] / (float) tot) < symfrac) |
| 366 |
conscols[ncons++] = apos; |
| 367 |
} |
| 368 |
if (dat) dat->cons_by_sample = TRUE; |
| 369 |
} |
| 370 |
else |
| 371 |
{ |
| 372 |
if (dat) dat->rejected_sample = TRUE; |
| 373 |
status = eslFAIL; |
| 374 |
} |
| 375 |
|
| 376 |
ERROR: |
| 377 |
free(sampidx); |
| 378 |
esl_rand64_Destroy(rng); |
| 379 |
*ret_ncons = ncons; |
| 380 |
return status; |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
static int |
| 401 |
consensus_by_all(const ESL_MSAWEIGHT_CFG *cfg, const ESL_MSA *msa, int **ct, int *conscols, int *ret_ncons, ESL_MSAWEIGHT_DAT *dat) |
| 402 |
{ |
| 403 |
float symfrac = (cfg? cfg->symfrac : eslMSAWEIGHT_SYMFRAC); |
| 404 |
int ncons = 0; |
| 405 |
int apos; |
| 406 |
int tot; |
| 407 |
int a; |
| 408 |
|
| 409 |
for (apos = 1; apos <= msa->alen; apos++) |
| 410 |
{ |
| 411 |
tot = 0; |
| 412 |
for (a = 0; a < msa->abc->Kp-2; a++) |
| 413 |
tot += ct[apos][a]; |
| 414 |
if ( ((float) ct[apos][msa->abc->K] / (float) tot) < symfrac) |
| 415 |
conscols[ncons++] = apos; |
| 416 |
} |
| 417 |
if (dat) dat->cons_by_all = TRUE; |
| 418 |
*ret_ncons = ncons; |
| 419 |
return eslOK; |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
static int |
| 435 |
collect_counts(const ESL_MSAWEIGHT_CFG *cfg, const ESL_MSA *msa, const int *conscols, int ncons, int **ct, ESL_MSAWEIGHT_DAT *dat) |
| 436 |
{ |
| 437 |
float fragthresh = (cfg? cfg->fragthresh : eslMSAWEIGHT_FRAGTHRESH); |
| 438 |
int minspan = (int) ceil( fragthresh * (float) msa->alen ); |
| 439 |
int lpos, rpos; |
| 440 |
int idx, apos, j; |
| 441 |
|
| 442 |
|
| 443 |
esl_mat_ISet(ct, msa->alen+1, msa->abc->Kp, 0); |
| 444 |
for (idx = 0; idx < msa->nseq; idx++) |
| 445 |
{ |
| 446 |
|
| 447 |
for (lpos = 1; lpos <= msa->alen; lpos++) if (esl_abc_XIsResidue(msa->abc, msa->ax[idx][lpos])) break; |
| 448 |
for (rpos = msa->alen; rpos >= 1; rpos--) if (esl_abc_XIsResidue(msa->abc, msa->ax[idx][rpos])) break; |
| 449 |
|
| 450 |
if (rpos - lpos + 1 >= minspan) { lpos = 1; rpos = msa->alen; } else if (dat) dat->all_nfrag++; |
| 451 |
|
| 452 |
if (ncons) |
| 453 |
{ |
| 454 |
for (j = 0; j < ncons && conscols[j] <= rpos; j++) |
| 455 |
{ |
| 456 |
apos = conscols[j]; |
| 457 |
if (apos < lpos) continue; |
| 458 |
ct[apos][msa->ax[idx][apos]]++; |
| 459 |
} |
| 460 |
} |
| 461 |
else |
| 462 |
{ |
| 463 |
for (apos = lpos; apos <= rpos; apos++) |
| 464 |
ct[apos][msa->ax[idx][apos]]++; |
| 465 |
} |
| 466 |
} |
| 467 |
return eslOK; |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
static int |
| 487 |
msaweight_PB_txt(ESL_MSA *msa) |
| 488 |
{ |
| 489 |
int *ct = NULL; |
| 490 |
int K = 26; |
| 491 |
int r; |
| 492 |
int idx, apos, a, rlen; |
| 493 |
int status = eslOK; |
| 494 |
|
| 495 |
ESL_DASSERT1( (msa->nseq >= 1) ); |
| 496 |
ESL_DASSERT1( (msa->alen >= 1) ); |
| 497 |
ESL_DASSERT1( (! (msa->flags & eslMSA_DIGITAL ))); |
| 498 |
if (msa->nseq == 1) { msa->wgt[0] = 1.0; return eslOK; } |
| 499 |
|
| 500 |
ESL_ALLOC(ct, sizeof(int) * K); |
| 501 |
esl_vec_DSet(msa->wgt, msa->nseq, 0.0); |
| 502 |
|
| 503 |
for (apos = 0; apos < msa->alen; apos++) |
| 504 |
{ |
| 505 |
|
| 506 |
esl_vec_ISet(ct, K, 0.); |
| 507 |
for (idx = 0; idx < msa->nseq; idx++) |
| 508 |
if (isalpha((int) msa->aseq[idx][apos])) |
| 509 |
ct[toupper((int) msa->aseq[idx][apos]) - 'A'] ++; |
| 510 |
for (r = 0, a = 0; a < K; a++) if (ct[a] > 0) r++; |
| 511 |
|
| 512 |
|
| 513 |
if (r > 0) { |
| 514 |
for (idx = 0; idx < msa->nseq; idx++) { |
| 515 |
if (isalpha((int) msa->aseq[idx][apos])) |
| 516 |
msa->wgt[idx] += 1. / |
| 517 |
(double) (r * ct[toupper((int) msa->aseq[idx][apos]) - 'A'] ); |
| 518 |
} |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
for (idx = 0; idx < msa->nseq; idx++) { |
| 524 |
for (rlen = 0, apos = 0; apos < msa->alen; apos++) |
| 525 |
if (isalpha((int) msa->aseq[idx][apos])) rlen++; |
| 526 |
if (rlen > 0) msa->wgt[idx] /= (double) rlen; |
| 527 |
|
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
esl_vec_DNorm(msa->wgt, msa->nseq); |
| 535 |
esl_vec_DScale(msa->wgt, msa->nseq, (double) msa->nseq); |
| 536 |
msa->flags |= eslMSA_HASWGTS; |
| 537 |
|
| 538 |
ERROR: |
| 539 |
free(ct); |
| 540 |
return status; |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
ESL_MSAWEIGHT_CFG * |
| 556 |
esl_msaweight_cfg_Create(void) |
| 557 |
{ |
| 558 |
ESL_MSAWEIGHT_CFG *cfg = NULL; |
| 559 |
int status; |
| 560 |
|
| 561 |
ESL_ALLOC(cfg, sizeof(ESL_MSAWEIGHT_CFG)); |
| 562 |
|
| 563 |
cfg->fragthresh = eslMSAWEIGHT_FRAGTHRESH; |
| 564 |
cfg->symfrac = eslMSAWEIGHT_SYMFRAC; |
| 565 |
cfg->ignore_rf = eslMSAWEIGHT_IGNORE_RF; |
| 566 |
cfg->allow_samp = eslMSAWEIGHT_ALLOW_SAMP; |
| 567 |
cfg->sampthresh = eslMSAWEIGHT_SAMPTHRESH; |
| 568 |
cfg->nsamp = eslMSAWEIGHT_NSAMP; |
| 569 |
cfg->maxfrag = eslMSAWEIGHT_MAXFRAG; |
| 570 |
cfg->seed = eslMSAWEIGHT_RNGSEED; |
| 571 |
cfg->filterpref = eslMSAWEIGHT_FILT_CONSCOVER; |
| 572 |
|
| 573 |
ERROR: |
| 574 |
return cfg; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
void |
| 581 |
esl_msaweight_cfg_Destroy(ESL_MSAWEIGHT_CFG *cfg) |
| 582 |
{ |
| 583 |
free(cfg); |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
ESL_MSAWEIGHT_DAT * |
| 592 |
esl_msaweight_dat_Create(void) |
| 593 |
{ |
| 594 |
ESL_MSAWEIGHT_DAT *dat = NULL; |
| 595 |
int status; |
| 596 |
|
| 597 |
ESL_ALLOC(dat, sizeof(ESL_MSAWEIGHT_DAT)); |
| 598 |
|
| 599 |
dat->seed = eslMSAWEIGHT_RNGSEED; |
| 600 |
|
| 601 |
dat->cons_by_rf = FALSE; |
| 602 |
dat->cons_by_sample = FALSE; |
| 603 |
dat->cons_by_all = FALSE; |
| 604 |
dat->cons_allcols = FALSE; |
| 605 |
dat->rejected_sample = FALSE; |
| 606 |
|
| 607 |
dat->ncons = 0; |
| 608 |
dat->conscols = NULL; |
| 609 |
|
| 610 |
dat->all_nfrag = 0; |
| 611 |
dat->samp_nfrag = 0; |
| 612 |
|
| 613 |
ERROR: |
| 614 |
return dat; |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
int |
| 621 |
esl_msaweight_dat_Reuse(ESL_MSAWEIGHT_DAT *dat) |
| 622 |
{ |
| 623 |
if (dat->conscols) { free(dat->conscols); } |
| 624 |
dat->seed = eslMSAWEIGHT_RNGSEED; |
| 625 |
dat->cons_by_rf = FALSE; |
| 626 |
dat->cons_by_sample = FALSE; |
| 627 |
dat->cons_by_all = FALSE; |
| 628 |
dat->cons_allcols = FALSE; |
| 629 |
dat->rejected_sample = FALSE; |
| 630 |
dat->ncons = 0; |
| 631 |
dat->conscols = NULL; |
| 632 |
dat->all_nfrag = 0; |
| 633 |
dat->samp_nfrag = 0; |
| 634 |
return eslOK; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
void |
| 642 |
esl_msaweight_dat_Destroy(ESL_MSAWEIGHT_DAT *dat) |
| 643 |
{ |
| 644 |
if (dat) |
| 645 |
{ |
| 646 |
if (dat->conscols) free(dat->conscols); |
| 647 |
free(dat); |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
int |
| 712 |
esl_msaweight_GSC(ESL_MSA *msa) |
| 713 |
{ |
| 714 |
ESL_DMATRIX *D = NULL; |
| 715 |
ESL_TREE *T = NULL; |
| 716 |
double *x = NULL; |
| 717 |
double lw, rw; |
| 718 |
double lx, rx; |
| 719 |
int i; |
| 720 |
int status; |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
ESL_DASSERT1( (msa != NULL) ); |
| 725 |
ESL_DASSERT1( (msa->nseq >= 1) ); |
| 726 |
ESL_DASSERT1( (msa->alen >= 1) ); |
| 727 |
ESL_DASSERT1( (msa->wgt != NULL) ); |
| 728 |
if (msa->nseq == 1) { msa->wgt[0] = 1.0; return eslOK; } |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
if (! (msa->flags & eslMSA_DIGITAL)) |
| 734 |
{ |
| 735 |
if ((status = esl_dst_CDiffMx(msa->aseq, msa->nseq, &D)) != eslOK) goto ERROR; |
| 736 |
} |
| 737 |
else |
| 738 |
{ |
| 739 |
if ((status = esl_dst_XDiffMx(msa->abc, msa->ax, msa->nseq, &D)) != eslOK) goto ERROR; |
| 740 |
} |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
#ifdef eslMSAWEIGHT_REGRESSION |
| 746 |
if ((status = esl_tree_SingleLinkage(D, &T)) != eslOK) goto ERROR; |
| 747 |
#else |
| 748 |
if ((status = esl_tree_UPGMA(D, &T)) != eslOK) goto ERROR; |
| 749 |
#endif |
| 750 |
esl_tree_SetCladesizes(T); |
| 751 |
|
| 752 |
ESL_ALLOC(x, sizeof(double) * (T->N-1)); |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
for (i = T->N-2; i >= 0; i--) |
| 759 |
{ |
| 760 |
x[i] = T->ld[i] + T->rd[i]; |
| 761 |
if (T->left[i] > 0) x[i] += x[T->left[i]]; |
| 762 |
if (T->right[i] > 0) x[i] += x[T->right[i]]; |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
x[0] = 0; |
| 776 |
for (i = 0; i <= T->N-2; i++) |
| 777 |
{ |
| 778 |
lw = T->ld[i]; if (T->left[i] > 0) lw += x[T->left[i]]; |
| 779 |
rw = T->rd[i]; if (T->right[i] > 0) rw += x[T->right[i]]; |
| 780 |
|
| 781 |
if (lw+rw == 0.) |
| 782 |
{ |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
if (T->left[i] > 0) lx = x[i] * ((double) T->cladesize[T->left[i]] / (double) T->cladesize[i]); |
| 788 |
else lx = x[i] / (double) T->cladesize[i]; |
| 789 |
|
| 790 |
if (T->right[i] > 0) rx = x[i] * ((double) T->cladesize[T->right[i]] / (double) T->cladesize[i]); |
| 791 |
else rx = x[i] / (double) T->cladesize[i]; |
| 792 |
} |
| 793 |
else |
| 794 |
{ |
| 795 |
lx = x[i] * lw/(lw+rw); |
| 796 |
rx = x[i] * rw/(lw+rw); |
| 797 |
} |
| 798 |
|
| 799 |
if (T->left[i] <= 0) msa->wgt[-(T->left[i])] = lx + T->ld[i]; |
| 800 |
else x[T->left[i]] = lx + T->ld[i]; |
| 801 |
|
| 802 |
if (T->right[i] <= 0) msa->wgt[-(T->right[i])] = rx + T->rd[i]; |
| 803 |
else x[T->right[i]] = rx + T->rd[i]; |
| 804 |
} |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
esl_vec_DNorm(msa->wgt, msa->nseq); |
| 809 |
esl_vec_DScale(msa->wgt, msa->nseq, (double) msa->nseq); |
| 810 |
msa->flags |= eslMSA_HASWGTS; |
| 811 |
|
| 812 |
free(x); |
| 813 |
esl_tree_Destroy(T); |
| 814 |
esl_dmatrix_Destroy(D); |
| 815 |
return eslOK; |
| 816 |
|
| 817 |
ERROR: |
| 818 |
if (x != NULL) free(x); |
| 819 |
if (T != NULL) esl_tree_Destroy(T); |
| 820 |
if (D != NULL) esl_dmatrix_Destroy(D); |
| 821 |
return status; |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
int |
| 861 |
esl_msaweight_BLOSUM(ESL_MSA *msa, double maxid) |
| 862 |
{ |
| 863 |
int *c = NULL; |
| 864 |
int *nmem = NULL; |
| 865 |
int nc; |
| 866 |
int i; |
| 867 |
int status; |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
ESL_DASSERT1( (maxid >= 0. && maxid <= 1.) ); |
| 872 |
ESL_DASSERT1( (msa->nseq >= 1) ); |
| 873 |
ESL_DASSERT1( (msa->alen >= 1) ); |
| 874 |
if (msa->nseq == 1) { msa->wgt[0] = 1.0; return eslOK; } |
| 875 |
|
| 876 |
if ((status = esl_msacluster_SingleLinkage(msa, maxid, &c, NULL, &nc)) != eslOK) goto ERROR; |
| 877 |
ESL_ALLOC(nmem, sizeof(int) * nc); |
| 878 |
esl_vec_ISet(nmem, nc, 0); |
| 879 |
for (i = 0; i < msa->nseq; i++) nmem[c[i]]++; |
| 880 |
for (i = 0; i < msa->nseq; i++) msa->wgt[i] = 1. / (double) nmem[c[i]]; |
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
esl_vec_DNorm(msa->wgt, msa->nseq); |
| 885 |
esl_vec_DScale(msa->wgt, msa->nseq, (double) msa->nseq); |
| 886 |
msa->flags |= eslMSA_HASWGTS; |
| 887 |
|
| 888 |
free(nmem); |
| 889 |
free(c); |
| 890 |
return eslOK; |
| 891 |
|
| 892 |
ERROR: |
| 893 |
if (c != NULL) free(c); |
| 894 |
if (nmem != NULL) free(nmem); |
| 895 |
return status; |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
static int sort_doubles_decreasing(const void *data, int e1, int e2); |
| 911 |
static int set_preference_conscover(const ESL_MSA *msa, const int *conscols, int ncons, double *sortwgt); |
| 912 |
static int set_preference_randomly(const ESL_MSAWEIGHT_CFG *cfg, int nseq, double *sortwgt); |
| 913 |
static int set_preference_origorder(int nseq, double *sortwgt); |
| 914 |
static int msaweight_IDFilter_txt(const ESL_MSA *msa, double maxid, ESL_MSA **ret_newmsa); |
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
int |
| 961 |
esl_msaweight_IDFilter(const ESL_MSA *msa, double maxid, ESL_MSA **ret_newmsa) |
| 962 |
{ |
| 963 |
if (msa->flags & eslMSA_DIGITAL) return esl_msaweight_IDFilter_adv(NULL, msa, maxid, ret_newmsa); |
| 964 |
else return msaweight_IDFilter_txt ( msa, maxid, ret_newmsa); |
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
int |
| 986 |
esl_msaweight_IDFilter_adv(const ESL_MSAWEIGHT_CFG *cfg, const ESL_MSA *msa, double maxid, ESL_MSA **ret_newmsa) |
| 987 |
{ |
| 988 |
int ignore_rf = (cfg? cfg->ignore_rf : eslMSAWEIGHT_IGNORE_RF); |
| 989 |
int allow_samp = (cfg? cfg->allow_samp : eslMSAWEIGHT_ALLOW_SAMP); |
| 990 |
int sampthresh = (cfg? cfg->sampthresh : eslMSAWEIGHT_SAMPTHRESH); |
| 991 |
int filterpref = (cfg? cfg->filterpref : eslMSAWEIGHT_FILT_CONSCOVER); |
| 992 |
int **ct = NULL; |
| 993 |
int *conscols = NULL; |
| 994 |
double *sortwgt = NULL; |
| 995 |
int *ranked_at = NULL; |
| 996 |
int *list = NULL; |
| 997 |
int *useme = NULL; |
| 998 |
int ncons = 0; |
| 999 |
int nnew = 0; |
| 1000 |
int apos, r, i; |
| 1001 |
double ident; |
| 1002 |
int status = eslOK; |
| 1003 |
|
| 1004 |
ESL_DASSERT1(( msa->nseq >= 1 && msa->alen >= 1)); |
| 1005 |
ESL_DASSERT1(( msa->flags & eslMSA_DIGITAL )); |
| 1006 |
|
| 1007 |
|
| 1008 |
ESL_ALLOC(sortwgt, sizeof(double) * msa->nseq); |
| 1009 |
ESL_ALLOC(ranked_at, sizeof(double) * msa->nseq); |
| 1010 |
ESL_ALLOC(list, sizeof(int) * msa->nseq); |
| 1011 |
ESL_ALLOC(useme, sizeof(int) * msa->nseq); |
| 1012 |
esl_vec_ISet(useme, msa->nseq, 0); |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
if (filterpref == eslMSAWEIGHT_FILT_CONSCOVER) |
| 1027 |
{ |
| 1028 |
|
| 1029 |
ct = esl_mat_ICreate( msa->alen+1, msa->abc->Kp ); |
| 1030 |
ESL_ALLOC(conscols, sizeof(int) * msa->alen); |
| 1031 |
|
| 1032 |
if (! ignore_rf && msa->rf) consensus_by_rf(msa, conscols, &ncons, NULL); |
| 1033 |
else if (allow_samp && msa->nseq > sampthresh) consensus_by_sample(cfg, msa, ct, conscols, &ncons, NULL); |
| 1034 |
else { |
| 1035 |
collect_counts(cfg, msa, conscols, ncons, ct, NULL); |
| 1036 |
consensus_by_all(cfg, msa, ct, conscols, &ncons, NULL); |
| 1037 |
} |
| 1038 |
if (!ncons) { |
| 1039 |
for (apos = 1; apos <= msa->alen; apos++) conscols[apos-1] = apos; |
| 1040 |
ncons = msa->alen; |
| 1041 |
} |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
if (filterpref == eslMSAWEIGHT_FILT_CONSCOVER) set_preference_conscover(msa, conscols, ncons, sortwgt); |
| 1048 |
else if (filterpref == eslMSAWEIGHT_FILT_RANDOM) set_preference_randomly (cfg, msa->nseq, sortwgt); |
| 1049 |
else if (filterpref == eslMSAWEIGHT_FILT_ORIGORDER) set_preference_origorder( msa->nseq, sortwgt); |
| 1050 |
else esl_fatal("bad filterpref"); |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
esl_quicksort(sortwgt, msa->nseq, sort_doubles_decreasing, ranked_at); |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
for (r = 0; r < msa->nseq; r++) |
| 1060 |
{ |
| 1061 |
for (i = 0; i < nnew; i++) |
| 1062 |
{ |
| 1063 |
if ((status = esl_dst_XPairId(msa->abc, msa->ax[ranked_at[r]], msa->ax[list[i]], &ident, NULL, NULL)) != eslOK) goto ERROR; |
| 1064 |
if (ident >= maxid) break; |
| 1065 |
} |
| 1066 |
|
| 1067 |
if (i == nnew) |
| 1068 |
{ |
| 1069 |
list[nnew++] = ranked_at[r]; |
| 1070 |
useme[ranked_at[r]] = TRUE; |
| 1071 |
} |
| 1072 |
} |
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
if ((status = esl_msa_SequenceSubset(msa, useme, ret_newmsa)) != eslOK) goto ERROR; |
| 1077 |
|
| 1078 |
ERROR: |
| 1079 |
free(useme); |
| 1080 |
free(list); |
| 1081 |
free(ranked_at); |
| 1082 |
free(sortwgt); |
| 1083 |
free(conscols); |
| 1084 |
esl_mat_IDestroy(ct); |
| 1085 |
return status; |
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
static int |
| 1095 |
sort_doubles_decreasing(const void *data, int e1, int e2) |
| 1096 |
{ |
| 1097 |
double *sortwgt = (double *) data; |
| 1098 |
if (sortwgt[e1] > sortwgt[e2]) return -1; |
| 1099 |
if (sortwgt[e1] < sortwgt[e2]) return 1; |
| 1100 |
return 0; |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
static int |
| 1116 |
set_preference_conscover(const ESL_MSA *msa, const int *conscols, int ncons, double *sortwgt) |
| 1117 |
{ |
| 1118 |
int idx, apos, lpos, rpos, j; |
| 1119 |
|
| 1120 |
for (idx = 0; idx < msa->nseq; idx++) |
| 1121 |
{ |
| 1122 |
for (lpos = 1; lpos <= msa->alen; lpos++) if (esl_abc_XIsResidue(msa->abc, msa->ax[idx][lpos])) break; |
| 1123 |
for (rpos = msa->alen; rpos >= 1; rpos--) if (esl_abc_XIsResidue(msa->abc, msa->ax[idx][rpos])) break; |
| 1124 |
|
| 1125 |
sortwgt[idx] = 0.; |
| 1126 |
for (j = 0; j < ncons && conscols[j] <= rpos; j++) |
| 1127 |
{ |
| 1128 |
apos = conscols[j]; |
| 1129 |
if (apos < lpos) continue; |
| 1130 |
sortwgt[idx] += 1.; |
| 1131 |
} |
| 1132 |
} |
| 1133 |
return eslOK; |
| 1134 |
} |
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
static int |
| 1139 |
set_preference_randomly(const ESL_MSAWEIGHT_CFG *cfg, int nseq, double *sortwgt) |
| 1140 |
{ |
| 1141 |
ESL_RAND64 *rng = (cfg? esl_rand64_Create(cfg->seed) : esl_rand64_Create(eslMSAWEIGHT_RNGSEED)); |
| 1142 |
int idx; |
| 1143 |
|
| 1144 |
for (idx = 0; idx < nseq; idx++) |
| 1145 |
sortwgt[idx] = esl_rand64_double(rng); |
| 1146 |
|
| 1147 |
esl_rand64_Destroy(rng); |
| 1148 |
return eslOK; |
| 1149 |
} |
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
static int |
| 1155 |
set_preference_origorder(int nseq, double *sortwgt) |
| 1156 |
{ |
| 1157 |
int idx; |
| 1158 |
|
| 1159 |
for (idx = 0; idx < nseq; idx++) |
| 1160 |
sortwgt[idx] = (double) (nseq - idx); |
| 1161 |
return eslOK; |
| 1162 |
} |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
static int |
| 1169 |
msaweight_IDFilter_txt(const ESL_MSA *msa, double maxid, ESL_MSA **ret_newmsa) |
| 1170 |
{ |
| 1171 |
int *list = NULL; |
| 1172 |
int *useme = NULL; |
| 1173 |
int nnew; |
| 1174 |
double ident; |
| 1175 |
int i,j; |
| 1176 |
int remove; |
| 1177 |
int status; |
| 1178 |
|
| 1179 |
ESL_DASSERT1(( msa )); |
| 1180 |
ESL_DASSERT1(( msa->nseq >= 1 )); |
| 1181 |
ESL_DASSERT1(( msa->alen >= 1 )); |
| 1182 |
ESL_DASSERT1(( ! (msa->flags & eslMSA_DIGITAL ))); |
| 1183 |
|
| 1184 |
|
| 1185 |
ESL_ALLOC(list, sizeof(int) * msa->nseq); |
| 1186 |
ESL_ALLOC(useme, sizeof(int) * msa->nseq); |
| 1187 |
esl_vec_ISet(useme, msa->nseq, 0); |
| 1188 |
|
| 1189 |
|
| 1190 |
nnew = 0; |
| 1191 |
for (i = 0; i < msa->nseq; i++) |
| 1192 |
{ |
| 1193 |
remove = FALSE; |
| 1194 |
for (j = 0; j < nnew; j++) |
| 1195 |
{ |
| 1196 |
if (! (msa->flags & eslMSA_DIGITAL)) { |
| 1197 |
if ((status = esl_dst_CPairId(msa->aseq[i], msa->aseq[list[j]], &ident, NULL, NULL)) != eslOK) goto ERROR; |
| 1198 |
} |
| 1199 |
else { |
| 1200 |
if ((status = esl_dst_XPairId(msa->abc, msa->ax[i], msa->ax[list[j]], &ident, NULL, NULL)) != eslOK) goto ERROR; |
| 1201 |
} |
| 1202 |
|
| 1203 |
if (ident >= maxid) |
| 1204 |
{ |
| 1205 |
remove = TRUE; |
| 1206 |
break; |
| 1207 |
} |
| 1208 |
} |
| 1209 |
if (remove == FALSE) { |
| 1210 |
list[nnew++] = i; |
| 1211 |
useme[i] = TRUE; |
| 1212 |
} |
| 1213 |
} |
| 1214 |
if ((status = esl_msa_SequenceSubset(msa, useme, ret_newmsa)) != eslOK) goto ERROR; |
| 1215 |
|
| 1216 |
free(list); |
| 1217 |
free(useme); |
| 1218 |
return eslOK; |
| 1219 |
|
| 1220 |
ERROR: |
| 1221 |
if (list != NULL) free(list); |
| 1222 |
if (useme != NULL) free(useme); |
| 1223 |
return status; |
| 1224 |
} |
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
#ifdef eslMSAWEIGHT_BENCHMARK |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
#include "easel.h" |
| 1241 |
#include "esl_getopts.h" |
| 1242 |
#include "esl_msa.h" |
| 1243 |
#include "esl_msafile.h" |
| 1244 |
#include "esl_msaweight.h" |
| 1245 |
#include "esl_vectorops.h" |
| 1246 |
#include "esl_stopwatch.h" |
| 1247 |
|
| 1248 |
#define WGROUP "--blosum,--gsc,--pb" |
| 1249 |
|
| 1250 |
static ESL_OPTIONS options[] = { |
| 1251 |
|
| 1252 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show help and usage", 0 }, |
| 1253 |
{ "--blosum", eslARG_NONE, FALSE, NULL, NULL, WGROUP, NULL, NULL, "use BLOSUM weights", 0 }, |
| 1254 |
{ "--gsc", eslARG_NONE,"default",NULL,NULL, WGROUP, NULL, NULL, "use GSC weights", 0 }, |
| 1255 |
{ "--pb", eslARG_NONE, FALSE, NULL, NULL, WGROUP, NULL, NULL, "use position-based weights", 0 }, |
| 1256 |
{ "--id", eslARG_REAL, "0.62", NULL,"0<=x<=1",NULL,"--blosum",NULL, "id threshold for --blosum", 0 }, |
| 1257 |
{ "--maxN", eslARG_INT, "0", NULL,"n>=0", NULL, NULL, NULL, "skip alignments w/ > <n> seqs", 0 }, |
| 1258 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1259 |
}; |
| 1260 |
|
| 1261 |
static char usage[] = "Usage: ./benchmark [-options] <msa_file>"; |
| 1262 |
|
| 1263 |
int |
| 1264 |
main(int argc, char **argv) |
| 1265 |
{ |
| 1266 |
ESL_STOPWATCH *w; |
| 1267 |
ESL_GETOPTS *go; |
| 1268 |
char *msafile; |
| 1269 |
ESL_MSAFILE *afp; |
| 1270 |
ESL_MSA *msa; |
| 1271 |
int do_gsc; |
| 1272 |
int do_pb; |
| 1273 |
int do_blosum; |
| 1274 |
int maxN; |
| 1275 |
double maxid; |
| 1276 |
double cpu; |
| 1277 |
int status; |
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
go = esl_getopts_Create(options); |
| 1282 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK) esl_fatal("failed to parse cmd line: %s", go->errbuf); |
| 1283 |
if (esl_opt_VerifyConfig(go) != eslOK) esl_fatal("failed to parse cmd line: %s", go->errbuf); |
| 1284 |
if (esl_opt_GetBoolean(go, "-h") == TRUE) { |
| 1285 |
puts(usage); |
| 1286 |
puts("\n where options are:"); |
| 1287 |
esl_opt_DisplayHelp(stdout, go, 0, 2, 80); |
| 1288 |
return 0; |
| 1289 |
} |
| 1290 |
do_blosum = esl_opt_GetBoolean(go, "--blosum"); |
| 1291 |
do_gsc = esl_opt_GetBoolean(go, "--gsc"); |
| 1292 |
do_pb = esl_opt_GetBoolean(go, "--pb"); |
| 1293 |
maxid = esl_opt_GetReal (go, "--id"); |
| 1294 |
maxN = esl_opt_GetInteger(go, "--maxN"); |
| 1295 |
if (esl_opt_ArgNumber(go) != 1) { |
| 1296 |
puts("Incorrect number of command line arguments."); |
| 1297 |
puts(usage); |
| 1298 |
return 1; |
| 1299 |
} |
| 1300 |
if ((msafile = esl_opt_GetArg(go, 1)) == NULL) esl_fatal("failed to parse cmd line: %s", go->errbuf); |
| 1301 |
esl_getopts_Destroy(go); |
| 1302 |
|
| 1303 |
w = esl_stopwatch_Create(); |
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
if ((status = esl_msafile_Open(NULL, msafile, NULL, eslMSAFILE_UNKNOWN, NULL, &afp)) != eslOK) |
| 1308 |
esl_msafile_OpenFailure(afp, status); |
| 1309 |
|
| 1310 |
while ( (status = esl_msafile_Read(afp, &msa)) != eslEOF) |
| 1311 |
{ |
| 1312 |
if (status != eslOK) esl_msafile_ReadFailure(afp, status); |
| 1313 |
if (maxN > 0 && msa->nseq > maxN) { esl_msa_Destroy(msa); continue; } |
| 1314 |
|
| 1315 |
esl_stopwatch_Start(w); |
| 1316 |
|
| 1317 |
if (do_gsc) esl_msaweight_GSC(msa); |
| 1318 |
else if (do_pb) esl_msaweight_PB(msa); |
| 1319 |
else if (do_blosum) esl_msaweight_BLOSUM(msa, maxid); |
| 1320 |
|
| 1321 |
esl_stopwatch_Stop(w); |
| 1322 |
cpu = w->user; |
| 1323 |
printf("%-20s %6d %6d %.3f\n", msa->name, msa->alen, msa->nseq, cpu); |
| 1324 |
esl_msa_Destroy(msa); |
| 1325 |
} |
| 1326 |
esl_msafile_Close(afp); |
| 1327 |
|
| 1328 |
esl_stopwatch_Destroy(w); |
| 1329 |
return eslOK; |
| 1330 |
} |
| 1331 |
#endif |
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
#ifdef eslMSAWEIGHT_STATS |
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
#include "easel.h" |
| 1349 |
#include "esl_getopts.h" |
| 1350 |
#include "esl_msa.h" |
| 1351 |
#include "esl_msafile.h" |
| 1352 |
#include "esl_msaweight.h" |
| 1353 |
#include "esl_vectorops.h" |
| 1354 |
|
| 1355 |
#define WGROUP "--blosum,--gsc,--pb" |
| 1356 |
|
| 1357 |
static ESL_OPTIONS options[] = { |
| 1358 |
|
| 1359 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show help and usage", 0 }, |
| 1360 |
{ "--blosum", eslARG_NONE, FALSE, NULL, NULL, WGROUP, NULL, NULL, "use BLOSUM weights", 0 }, |
| 1361 |
{ "--gsc", eslARG_NONE,"default",NULL,NULL, WGROUP, NULL, NULL, "use GSC weights", 0 }, |
| 1362 |
{ "--pb", eslARG_NONE, FALSE, NULL, NULL, WGROUP, NULL, NULL, "use position-based weights", 0 }, |
| 1363 |
{ "--id", eslARG_REAL, "0.62", NULL,"0<=x<=1",NULL,"--blosum",NULL, "id threshold for --blosum", 0 }, |
| 1364 |
{ "--maxN", eslARG_INT, "0", NULL,"n>=0", NULL, NULL, NULL, "skip alignments w/ > <n> seqs", 0 }, |
| 1365 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1366 |
}; |
| 1367 |
|
| 1368 |
static char usage[] = "Usage: ./stats [-options] <msa_file>"; |
| 1369 |
|
| 1370 |
int |
| 1371 |
main(int argc, char **argv) |
| 1372 |
{ |
| 1373 |
ESL_GETOPTS *go; |
| 1374 |
char *msafile; |
| 1375 |
ESL_MSAFILE *afp; |
| 1376 |
ESL_MSA *msa; |
| 1377 |
int do_gsc; |
| 1378 |
int do_pb; |
| 1379 |
int do_blosum; |
| 1380 |
int maxN; |
| 1381 |
double maxid; |
| 1382 |
int nsmall, nbig; |
| 1383 |
int i; |
| 1384 |
int status; |
| 1385 |
|
| 1386 |
|
| 1387 |
go = esl_getopts_Create(options); |
| 1388 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK) esl_fatal("%s", go->errbuf); |
| 1389 |
if (esl_opt_VerifyConfig(go) != eslOK) esl_fatal("%s", go->errbuf); |
| 1390 |
if (esl_opt_GetBoolean(go, "-h") == TRUE){ |
| 1391 |
puts(usage); |
| 1392 |
puts("\n where options are:"); |
| 1393 |
esl_opt_DisplayHelp(stdout, go, 0, 2, 80); |
| 1394 |
return 0; |
| 1395 |
} |
| 1396 |
do_blosum = esl_opt_GetBoolean(go, "--blosum"); |
| 1397 |
do_gsc = esl_opt_GetBoolean(go, "--gsc"); |
| 1398 |
do_pb = esl_opt_GetBoolean(go, "--pb"); |
| 1399 |
maxid = esl_opt_GetReal (go, "--id"); |
| 1400 |
maxN = esl_opt_GetInteger(go, "--maxN"); |
| 1401 |
if (esl_opt_ArgNumber(go) != 1) { |
| 1402 |
puts("Incorrect number of command line arguments."); |
| 1403 |
puts(usage); |
| 1404 |
return 1; |
| 1405 |
} |
| 1406 |
if ((msafile = esl_opt_GetArg(go, 1)) == NULL) esl_fatal("%s", go->errbuf); |
| 1407 |
esl_getopts_Destroy(go); |
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
if ((status = esl_msafile_Open(NULL, msafile, NULL, eslMSAFILE_UNKNOWN, NULL, &afp)) != eslOK) |
| 1412 |
esl_msafile_OpenFailure(afp, status); |
| 1413 |
|
| 1414 |
while ( (status = esl_msafile_Read(afp, &msa)) != eslEOF) |
| 1415 |
{ |
| 1416 |
if (status != eslOK) esl_msafile_ReadFailure(afp, status); |
| 1417 |
if (maxN > 0 && msa->nseq > maxN) { esl_msa_Destroy(msa); continue; } |
| 1418 |
|
| 1419 |
if (do_gsc) esl_msaweight_GSC(msa); |
| 1420 |
else if (do_pb) esl_msaweight_PB(msa); |
| 1421 |
else if (do_blosum) esl_msaweight_BLOSUM(msa, maxid); |
| 1422 |
|
| 1423 |
for (nsmall = 0, nbig = 0, i = 0; i < msa->nseq; i++) { |
| 1424 |
if (msa->wgt[i] < 0.2) nsmall++; |
| 1425 |
if (msa->wgt[i] > 5.0) nbig++; |
| 1426 |
} |
| 1427 |
|
| 1428 |
printf("%-20s %5d %5d %8.4f %8.4f %5d %5d\n", |
| 1429 |
msa->name, |
| 1430 |
msa->nseq, |
| 1431 |
msa->alen, |
| 1432 |
esl_vec_DMin(msa->wgt, msa->nseq), |
| 1433 |
esl_vec_DMax(msa->wgt, msa->nseq), |
| 1434 |
nsmall, |
| 1435 |
nbig); |
| 1436 |
esl_msa_Destroy(msa); |
| 1437 |
} |
| 1438 |
esl_msafile_Close(afp); |
| 1439 |
return eslOK; |
| 1440 |
} |
| 1441 |
#endif |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
#ifdef eslMSAWEIGHT_TESTDRIVE |
| 1451 |
|
| 1452 |
#include "esl_msafile.h" |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
static void |
| 1463 |
do_GSC(ESL_ALPHABET *abc, ESL_MSA *msa, double *expect, char *msg) |
| 1464 |
{ |
| 1465 |
|
| 1466 |
if (esl_msaweight_GSC(msa) != eslOK) esl_fatal(msg); |
| 1467 |
if (esl_vec_DCompare(msa->wgt, expect, msa->nseq, 0.001) != eslOK) esl_fatal(msg); |
| 1468 |
|
| 1469 |
|
| 1470 |
if (abc) |
| 1471 |
{ |
| 1472 |
if (esl_msa_Digitize(abc, msa, NULL) != eslOK) esl_fatal(msg); |
| 1473 |
if (esl_msaweight_GSC(msa) != eslOK) esl_fatal(msg); |
| 1474 |
if (esl_vec_DCompare(msa->wgt, expect, msa->nseq, 0.001) != eslOK) esl_fatal(msg); |
| 1475 |
if (esl_msa_Textize(msa) != eslOK) esl_fatal(msg); |
| 1476 |
} |
| 1477 |
} |
| 1478 |
|
| 1479 |
|
| 1480 |
static void |
| 1481 |
do_PB(ESL_ALPHABET *abc, ESL_MSA *msa, double *expect, char *msg) |
| 1482 |
{ |
| 1483 |
if (esl_msaweight_PB(msa) != eslOK) esl_fatal(msg); |
| 1484 |
if (esl_vec_DCompare(msa->wgt, expect, msa->nseq, 0.001) != eslOK) esl_fatal(msg); |
| 1485 |
|
| 1486 |
if (abc) |
| 1487 |
{ |
| 1488 |
if (esl_msa_Digitize(abc, msa, NULL) != eslOK) esl_fatal(msg); |
| 1489 |
if (esl_msaweight_PB(msa) != eslOK) esl_fatal(msg); |
| 1490 |
if (esl_vec_DCompare(msa->wgt, expect, msa->nseq, 0.001) != eslOK) esl_fatal(msg); |
| 1491 |
if (esl_msa_Textize(msa) != eslOK) esl_fatal(msg); |
| 1492 |
} |
| 1493 |
} |
| 1494 |
|
| 1495 |
|
| 1496 |
static void |
| 1497 |
do_BLOSUM(ESL_ALPHABET *abc, ESL_MSA *msa, double maxid, double *expect, char *msg) |
| 1498 |
{ |
| 1499 |
if (esl_msaweight_BLOSUM(msa, maxid) != eslOK) esl_fatal(msg); |
| 1500 |
if (esl_vec_DCompare(msa->wgt, expect, msa->nseq, 0.001) != eslOK) esl_fatal(msg); |
| 1501 |
|
| 1502 |
if (abc) |
| 1503 |
{ |
| 1504 |
if (esl_msa_Digitize(abc, msa, NULL) != eslOK) esl_fatal(msg); |
| 1505 |
if (esl_msaweight_BLOSUM(msa, maxid) != eslOK) esl_fatal(msg); |
| 1506 |
if (esl_vec_DCompare(msa->wgt, expect, msa->nseq, 0.001) != eslOK) esl_fatal(msg); |
| 1507 |
if (esl_msa_Textize(msa) != eslOK) esl_fatal(msg); |
| 1508 |
} |
| 1509 |
} |
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
static void |
| 1515 |
utest_identical_seqs(void) |
| 1516 |
{ |
| 1517 |
char msg[] = "identical_seqs test failed"; |
| 1518 |
ESL_MSA *msa = esl_msa_CreateFromString("# STOCKHOLM 1.0\n\nseq1 AAAAA\nseq2 AAAAA\nseq3 AAAAA\nseq4 AAAAA\nseq5 AAAAA\n//\n", eslMSAFILE_STOCKHOLM); |
| 1519 |
ESL_ALPHABET *aa_abc = esl_alphabet_Create(eslAMINO); |
| 1520 |
ESL_ALPHABET *nt_abc = esl_alphabet_Create(eslDNA); |
| 1521 |
double uniform[5] = { 1.0, 1.0, 1.0, 1.0, 1.0 }; |
| 1522 |
|
| 1523 |
do_GSC (aa_abc, msa, uniform, msg); |
| 1524 |
do_GSC (nt_abc, msa, uniform, msg); |
| 1525 |
do_PB (aa_abc, msa, uniform, msg); |
| 1526 |
do_PB (nt_abc, msa, uniform, msg); |
| 1527 |
do_BLOSUM(aa_abc, msa, 0.62, uniform, msg); |
| 1528 |
do_BLOSUM(nt_abc, msa, 0.62, uniform, msg); |
| 1529 |
|
| 1530 |
esl_alphabet_Destroy(nt_abc); |
| 1531 |
esl_alphabet_Destroy(aa_abc); |
| 1532 |
esl_msa_Destroy(msa); |
| 1533 |
} |
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
static void |
| 1540 |
utest_henikoff_contrived(void) |
| 1541 |
{ |
| 1542 |
char msg[] = "henikoff_contrived test failed"; |
| 1543 |
ESL_MSA *msa = esl_msa_CreateFromString("# STOCKHOLM 1.0\n\nseq1 AAAAA\nseq2 AAAAA\nseq3 CCCCC\nseq4 CCCCC\nseq5 TTTTT\n//\n", eslMSAFILE_STOCKHOLM); |
| 1544 |
ESL_ALPHABET *aa_abc = esl_alphabet_Create(eslAMINO); |
| 1545 |
ESL_ALPHABET *nt_abc = esl_alphabet_Create(eslDNA); |
| 1546 |
double ewgt[5] = { 0.833333, 0.833333, 0.833333, 0.833333, 1.66667 }; |
| 1547 |
|
| 1548 |
do_GSC (aa_abc, msa, ewgt, msg); |
| 1549 |
do_GSC (nt_abc, msa, ewgt, msg); |
| 1550 |
do_PB (aa_abc, msa, ewgt, msg); |
| 1551 |
do_PB (nt_abc, msa, ewgt, msg); |
| 1552 |
do_BLOSUM(aa_abc, msa, 0.62, ewgt, msg); |
| 1553 |
do_BLOSUM(nt_abc, msa, 0.62, ewgt, msg); |
| 1554 |
|
| 1555 |
esl_alphabet_Destroy(nt_abc); |
| 1556 |
esl_alphabet_Destroy(aa_abc); |
| 1557 |
esl_msa_Destroy(msa); |
| 1558 |
} |
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
static void |
| 1564 |
utest_nitrogenase(void) |
| 1565 |
{ |
| 1566 |
char msg[] = "nitrogenase test failed"; |
| 1567 |
ESL_MSA *msa = esl_msa_CreateFromString("# STOCKHOLM 1.0\n\nNIFE_CLOPA GYVGS\nNIFD_AZOVI GFDGF\nNIFD_BRAJA GYDGF\nNIFK_ANASP GYQGG\n//\n", eslMSAFILE_STOCKHOLM); |
| 1568 |
ESL_ALPHABET *aa_abc = esl_alphabet_Create(eslAMINO); |
| 1569 |
double egsc[4] = { 1.125000, 0.875000, 0.875000, 1.125000 }; |
| 1570 |
double epb[4] = { 1.066667, 1.066667, 0.800000, 1.066667 }; |
| 1571 |
double eblo[4] = { 1.333333, 0.666667, 0.666667, 1.333333 }; |
| 1572 |
|
| 1573 |
do_GSC (aa_abc, msa, egsc, msg); |
| 1574 |
do_PB (aa_abc, msa, epb, msg); |
| 1575 |
do_BLOSUM(aa_abc, msa, 0.62, eblo, msg); |
| 1576 |
|
| 1577 |
esl_alphabet_Destroy(aa_abc); |
| 1578 |
esl_msa_Destroy(msa); |
| 1579 |
} |
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
static void |
| 1585 |
utest_gerstein4(void) |
| 1586 |
{ |
| 1587 |
char msg[] = "gerstein4 test failed"; |
| 1588 |
ESL_MSA *msa = esl_msa_CreateFromString("# STOCKHOLM 1.0\n\nA AAAAAAAAAA\nB TTAAAAAAAA\nC ATAAAACCCC\nD GGGAAGGGGG\n//\n", eslMSAFILE_STOCKHOLM); |
| 1589 |
ESL_ALPHABET *aa_abc = esl_alphabet_Create(eslAMINO); |
| 1590 |
ESL_ALPHABET *nt_abc = esl_alphabet_Create(eslDNA); |
| 1591 |
double egsc[4] = { 0.760870, 0.760870, 1.086957, 1.391304 }; |
| 1592 |
double epb[4] = { 0.800000, 0.800000, 1.000000, 1.400000 }; |
| 1593 |
double eblo[4] = { 0.666667, 0.666667, 1.333333, 1.333333 }; |
| 1594 |
double uni[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 1595 |
|
| 1596 |
do_GSC (aa_abc, msa, egsc, msg); |
| 1597 |
do_GSC (nt_abc, msa, egsc, msg); |
| 1598 |
do_PB (aa_abc, msa, epb, msg); |
| 1599 |
do_PB (nt_abc, msa, epb, msg); |
| 1600 |
do_BLOSUM(aa_abc, msa, 0.62, eblo, msg); |
| 1601 |
do_BLOSUM(nt_abc, msa, 0.62, eblo, msg); |
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
do_BLOSUM(aa_abc, msa, 0.0, uni, msg); |
| 1607 |
do_BLOSUM(aa_abc, msa, 1.0, uni, msg); |
| 1608 |
|
| 1609 |
esl_alphabet_Destroy(nt_abc); |
| 1610 |
esl_alphabet_Destroy(aa_abc); |
| 1611 |
esl_msa_Destroy(msa); |
| 1612 |
} |
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
static void |
| 1619 |
utest_pathologs(void) |
| 1620 |
{ |
| 1621 |
char msg[] = "pathologs test failed"; |
| 1622 |
ESL_MSA *msa = esl_msa_CreateFromString("# STOCKHOLM 1.0\n\nA A----\nB -C---\nC --G--\nD ---T-\nE ----T\n//\n", eslMSAFILE_STOCKHOLM); |
| 1623 |
ESL_ALPHABET *aa_abc = esl_alphabet_Create(eslAMINO); |
| 1624 |
ESL_ALPHABET *nt_abc = esl_alphabet_Create(eslDNA); |
| 1625 |
double uni[5] = { 1.0, 1.0, 1.0, 1.0, 1.0 }; |
| 1626 |
|
| 1627 |
do_GSC (aa_abc, msa, uni, msg); |
| 1628 |
do_GSC (nt_abc, msa, uni, msg); |
| 1629 |
do_PB (aa_abc, msa, uni, msg); |
| 1630 |
do_PB (nt_abc, msa, uni, msg); |
| 1631 |
do_BLOSUM(aa_abc, msa, 0.62, uni, msg); |
| 1632 |
do_BLOSUM(nt_abc, msa, 0.62, uni, msg); |
| 1633 |
|
| 1634 |
esl_alphabet_Destroy(nt_abc); |
| 1635 |
esl_alphabet_Destroy(aa_abc); |
| 1636 |
esl_msa_Destroy(msa); |
| 1637 |
} |
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
static void |
| 1647 |
utest_idfilter(void) |
| 1648 |
{ |
| 1649 |
char msg[] = "idfilter test failed"; |
| 1650 |
ESL_MSAWEIGHT_CFG *cfg = esl_msaweight_cfg_Create(); |
| 1651 |
ESL_ALPHABET *abc = esl_alphabet_Create(eslAMINO); |
| 1652 |
ESL_MSA *msa = esl_msa_CreateFromString("# STOCKHOLM 1.0\n\nseq1 ..AAAAAAAA\nseq2 AAAAAAAAAA\nseq3 CCCCCCCCCC\nseq4 GGGGGGGGGG\n//\n", eslMSAFILE_STOCKHOLM); |
| 1653 |
ESL_MSA *msa2 = NULL; |
| 1654 |
|
| 1655 |
|
| 1656 |
if (esl_msaweight_IDFilter(msa, 1.0, &msa2) != eslOK) esl_fatal(msg); |
| 1657 |
if (msa2->nseq != 3 || strcmp(msa2->sqname[0], "seq1") != 0) esl_fatal(msg); |
| 1658 |
esl_msa_Destroy(msa2); |
| 1659 |
|
| 1660 |
|
| 1661 |
if (esl_msa_Digitize(abc, msa, NULL) != eslOK) esl_fatal(msg); |
| 1662 |
if (esl_msaweight_IDFilter(msa, 1.0, &msa2) != eslOK) esl_fatal(msg); |
| 1663 |
if (msa2->nseq != 3 || strcmp(msa2->sqname[0], "seq2") != 0) esl_fatal(msg); |
| 1664 |
esl_msa_Destroy(msa2); |
| 1665 |
|
| 1666 |
|
| 1667 |
if (esl_msaweight_IDFilter_adv(cfg, msa, 1.0, &msa2) != eslOK) esl_fatal(msg); |
| 1668 |
if (msa2->nseq != 3 || strcmp(msa2->sqname[0], "seq2") != 0) esl_fatal(msg); |
| 1669 |
esl_msa_Destroy(msa2); |
| 1670 |
|
| 1671 |
|
| 1672 |
cfg->filterpref = eslMSAWEIGHT_FILT_ORIGORDER; |
| 1673 |
if (esl_msaweight_IDFilter_adv(cfg, msa, 1.0, &msa2) != eslOK) esl_fatal(msg); |
| 1674 |
if (msa2->nseq != 3 || strcmp(msa2->sqname[0], "seq1") != 0) esl_fatal(msg); |
| 1675 |
esl_msa_Destroy(msa2); |
| 1676 |
|
| 1677 |
|
| 1678 |
cfg->filterpref = eslMSAWEIGHT_FILT_RANDOM; |
| 1679 |
if (esl_msaweight_IDFilter_adv(cfg, msa, 1.0, &msa2) != eslOK) esl_fatal(msg); |
| 1680 |
if (msa2->nseq != 3) esl_fatal(msg); |
| 1681 |
if (strcmp(msa2->sqname[0], "seq1") != 0 && strcmp(msa2->sqname[0], "seq2") != 0) esl_fatal(msg); |
| 1682 |
esl_msa_Destroy(msa2); |
| 1683 |
|
| 1684 |
esl_msaweight_cfg_Destroy(cfg); |
| 1685 |
esl_alphabet_Destroy(abc); |
| 1686 |
esl_msa_Destroy(msa); |
| 1687 |
} |
| 1688 |
|
| 1689 |
#endif |
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
#ifdef eslMSAWEIGHT_TESTDRIVE |
| 1698 |
|
| 1699 |
#include "easel.h" |
| 1700 |
#include "esl_getopts.h" |
| 1701 |
#include "esl_msa.h" |
| 1702 |
#include "esl_msafile.h" |
| 1703 |
#include "esl_msaweight.h" |
| 1704 |
|
| 1705 |
static ESL_OPTIONS options[] = { |
| 1706 |
|
| 1707 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 1708 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1709 |
}; |
| 1710 |
static char usage[] = "[-options]"; |
| 1711 |
static char banner[] = "test driver for msaweight module"; |
| 1712 |
|
| 1713 |
int |
| 1714 |
main(int argc, char **argv) |
| 1715 |
{ |
| 1716 |
ESL_GETOPTS *go = esl_getopts_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 1717 |
|
| 1718 |
fprintf(stderr, "## %s\n", argv[0]); |
| 1719 |
|
| 1720 |
utest_identical_seqs(); |
| 1721 |
utest_henikoff_contrived(); |
| 1722 |
utest_nitrogenase(); |
| 1723 |
utest_gerstein4(); |
| 1724 |
utest_pathologs(); |
| 1725 |
|
| 1726 |
utest_idfilter(); |
| 1727 |
|
| 1728 |
fprintf(stderr, "# status = ok\n"); |
| 1729 |
|
| 1730 |
esl_getopts_Destroy(go); |
| 1731 |
exit(0); |
| 1732 |
} |
| 1733 |
#endif |
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
#ifdef eslMSAWEIGHT_EXAMPLE |
| 1744 |
|
| 1745 |
#include "easel.h" |
| 1746 |
#include "esl_getopts.h" |
| 1747 |
#include "esl_msa.h" |
| 1748 |
#include "esl_msafile.h" |
| 1749 |
#include "esl_msaweight.h" |
| 1750 |
|
| 1751 |
static ESL_OPTIONS options[] = { |
| 1752 |
|
| 1753 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 1 }, |
| 1754 |
{ "--informat", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, NULL, "specify the input MSA file is in format <s>", 1 }, |
| 1755 |
{ "--dna", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use DNA alphabet", 1 }, |
| 1756 |
{ "--rna", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use RNA alphabet", 1 }, |
| 1757 |
{ "--amino", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use protein alphabet", 1 }, |
| 1758 |
|
| 1759 |
{ "--ignore-rf", eslARG_NONE, eslMSAWEIGHT_IGNORE_RF, NULL, NULL, NULL, NULL, NULL, "ignore any RF line; always determine our own consensus", 2 }, |
| 1760 |
{ "--fragthresh", eslARG_REAL, ESL_STR(eslMSAWEIGHT_FRAGTHRESH), NULL, "0<=x<=1", NULL, NULL, NULL, "seq is fragment if aspan/alen < fragthresh", 2 }, |
| 1761 |
{ "--symfrac", eslARG_REAL, ESL_STR(eslMSAWEIGHT_SYMFRAC), NULL, "0<=x<=1", NULL, NULL, NULL, "col is consensus if nres/(nres+ngap) >= symfrac", 2 }, |
| 1762 |
|
| 1763 |
{ "--no-sampling", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "never use subsampling to determine consensus", 3 }, |
| 1764 |
{ "--nsamp", eslARG_INT, ESL_STR(eslMSAWEIGHT_NSAMP), NULL, "n>=0", NULL, NULL, "--no-sampling", "number of seqs to sample (if using sampling)", 3 }, |
| 1765 |
{ "--sampthresh", eslARG_INT, ESL_STR(eslMSAWEIGHT_SAMPTHRESH), NULL, "n>=0", NULL, NULL, "--no-sampling", "switch to using sampling when nseq > nsamp", 3 }, |
| 1766 |
{ "--maxfrag", eslARG_INT, ESL_STR(eslMSAWEIGHT_MAXFRAG), NULL, "n>=0", NULL, NULL, "--no-sampling", "if sample has > maxfrag fragments, don't use sample", 3 }, |
| 1767 |
{ "-s", eslARG_INT, ESL_STR(eslMSAWEIGHT_RNGSEED), NULL, "n>=0", NULL, NULL, NULL, "set random number seed to <n>", 3 }, |
| 1768 |
|
| 1769 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1770 |
}; |
| 1771 |
|
| 1772 |
static char usage[] = "[-options] <msafile>"; |
| 1773 |
static char banner[] = "esl_msaweight example"; |
| 1774 |
|
| 1775 |
int |
| 1776 |
main(int argc, char **argv) |
| 1777 |
{ |
| 1778 |
ESL_GETOPTS *go = esl_getopts_Create(options); |
| 1779 |
char *msafile = NULL; |
| 1780 |
int infmt = eslMSAFILE_UNKNOWN; |
| 1781 |
ESL_MSAWEIGHT_CFG *cfg = esl_msaweight_cfg_Create(); |
| 1782 |
ESL_MSAWEIGHT_DAT *dat = esl_msaweight_dat_Create(); |
| 1783 |
ESL_ALPHABET *abc = NULL; |
| 1784 |
ESL_MSAFILE *afp = NULL; |
| 1785 |
ESL_MSA *msa = NULL; |
| 1786 |
int nali = 0; |
| 1787 |
int idx; |
| 1788 |
int status; |
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK || |
| 1793 |
esl_opt_VerifyConfig(go) != eslOK) |
| 1794 |
esl_fatal("Failed to parse command line: %s\n", go->errbuf); |
| 1795 |
if (esl_opt_GetBoolean(go, "-h") == TRUE) |
| 1796 |
{ |
| 1797 |
esl_banner(stdout, argv[0], banner); |
| 1798 |
esl_usage (stdout, argv[0], usage); |
| 1799 |
puts("\noptions:"); |
| 1800 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 1801 |
puts("\noptions for deriving consensus:"); |
| 1802 |
esl_opt_DisplayHelp(stdout, go, 2, 2, 80); |
| 1803 |
puts("\noptions for deriving consensus by sampling (on deep MSAs):"); |
| 1804 |
esl_opt_DisplayHelp(stdout, go, 3, 2, 80); |
| 1805 |
return 0; |
| 1806 |
} |
| 1807 |
|
| 1808 |
if (esl_opt_ArgNumber(go) != 1) esl_fatal("Incorrect number of command line arguments.\n%s\n", usage); |
| 1809 |
msafile = esl_opt_GetArg(go, 1); |
| 1810 |
|
| 1811 |
if (esl_opt_GetBoolean(go, "--rna")) abc = esl_alphabet_Create(eslRNA); |
| 1812 |
else if (esl_opt_GetBoolean(go, "--dna")) abc = esl_alphabet_Create(eslDNA); |
| 1813 |
else if (esl_opt_GetBoolean(go, "--amino")) abc = esl_alphabet_Create(eslAMINO); |
| 1814 |
|
| 1815 |
if (esl_opt_IsOn(go, "--informat") && |
| 1816 |
(infmt = esl_msafile_EncodeFormat(esl_opt_GetString(go, "--informat"))) == eslMSAFILE_UNKNOWN) |
| 1817 |
esl_fatal("%s is not a valid MSA file format for --informat", esl_opt_GetString(go, "--informat")); |
| 1818 |
|
| 1819 |
cfg->fragthresh = esl_opt_GetReal (go, "--fragthresh"); |
| 1820 |
cfg->symfrac = esl_opt_GetReal (go, "--symfrac"); |
| 1821 |
cfg->ignore_rf = esl_opt_GetBoolean(go, "--ignore-rf"); |
| 1822 |
cfg->allow_samp = !esl_opt_GetBoolean(go, "--no-sampling"); |
| 1823 |
cfg->sampthresh = esl_opt_GetInteger(go, "--sampthresh"); |
| 1824 |
cfg->nsamp = esl_opt_GetInteger(go, "--nsamp"); |
| 1825 |
cfg->maxfrag = esl_opt_GetInteger(go, "--maxfrag"); |
| 1826 |
cfg->seed = esl_opt_GetInteger(go, "-s"); |
| 1827 |
|
| 1828 |
if ((status = esl_msafile_Open(&abc, msafile, NULL, infmt, NULL, &afp)) != eslOK) |
| 1829 |
esl_msafile_OpenFailure(afp, status); |
| 1830 |
|
| 1831 |
while ((status = esl_msafile_Read(afp, &msa)) == eslOK) |
| 1832 |
{ |
| 1833 |
nali++; |
| 1834 |
|
| 1835 |
if ((status = esl_msaweight_PB_adv(cfg, msa, dat)) != eslOK) |
| 1836 |
esl_fatal("weighting failed"); |
| 1837 |
|
| 1838 |
for (idx = 0; idx < msa->nseq; idx++) |
| 1839 |
printf("%-25s %.4f\n", msa->sqname[idx], msa->wgt[idx]); |
| 1840 |
|
| 1841 |
|
| 1842 |
if (dat->cons_by_rf) printf("# consensus by: RF annotation\n"); |
| 1843 |
else if (dat->cons_by_sample) printf("# consensus by: subsampling\n"); |
| 1844 |
else if (dat->cons_by_all) printf("# consensus by: standard rules\n"); |
| 1845 |
else if (dat->cons_allcols) printf("# consensus by: all columns\n"); |
| 1846 |
|
| 1847 |
if (dat->rejected_sample) printf("# (attempted sampling but rejected, too many frags\n"); |
| 1848 |
printf("# sampling allowed? %s\n", cfg->allow_samp ? "yes" : "NO"); |
| 1849 |
|
| 1850 |
printf("# fragthresh: %.4f\n", cfg->fragthresh); |
| 1851 |
printf("# symfrac: %.4f\n", cfg->symfrac); |
| 1852 |
if (dat->cons_by_sample) |
| 1853 |
{ |
| 1854 |
printf("# Info on sampling:\n"); |
| 1855 |
printf("# RNG seed: %" PRIu64 "\n", dat->seed); |
| 1856 |
printf("# Sample size: %d\n", cfg->nsamp); |
| 1857 |
printf("# Fragments: %d (<= maxfrag of %d)\n", dat->samp_nfrag, cfg->maxfrag); |
| 1858 |
} |
| 1859 |
|
| 1860 |
printf("# number of consensus cols: %d out of %d\n", dat->ncons, (int) msa->alen); |
| 1861 |
printf("# number of fragments: %d out of %d\n", dat->all_nfrag, msa->nseq); |
| 1862 |
|
| 1863 |
esl_msa_Destroy(msa); |
| 1864 |
} |
| 1865 |
if (nali == 0 || status != eslEOF) esl_msafile_ReadFailure(afp, status); |
| 1866 |
|
| 1867 |
esl_msaweight_cfg_Destroy(cfg); |
| 1868 |
esl_msaweight_dat_Destroy(dat); |
| 1869 |
esl_alphabet_Destroy(abc); |
| 1870 |
esl_msafile_Close(afp); |
| 1871 |
esl_getopts_Destroy(go); |
| 1872 |
exit(0); |
| 1873 |
} |
| 1874 |
#endif |