| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <p7_config.h> |
| 11 |
|
| 12 |
#include <stdlib.h> |
| 13 |
#include <string.h> |
| 14 |
#include <limits.h> |
| 15 |
|
| 16 |
#include "easel.h" |
| 17 |
#include "hmmer.h" |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
P7_TOPHITS * |
| 32 |
p7_tophits_Create(void) |
| 33 |
{ |
| 34 |
P7_TOPHITS *h = NULL; |
| 35 |
int default_nalloc = 256; |
| 36 |
int status; |
| 37 |
|
| 38 |
ESL_ALLOC(h, sizeof(P7_TOPHITS)); |
| 39 |
h->hit = NULL; |
| 40 |
h->unsrt = NULL; |
| 41 |
|
| 42 |
ESL_ALLOC(h->hit, sizeof(P7_HIT *) * default_nalloc); |
| 43 |
ESL_ALLOC(h->unsrt, sizeof(P7_HIT) * default_nalloc); |
| 44 |
h->Nalloc = default_nalloc; |
| 45 |
h->N = 0; |
| 46 |
h->nreported = 0; |
| 47 |
h->nincluded = 0; |
| 48 |
h->is_sorted_by_sortkey = TRUE; |
| 49 |
h->is_sorted_by_seqidx = FALSE; |
| 50 |
h->hit[0] = h->unsrt; |
| 51 |
return h; |
| 52 |
|
| 53 |
ERROR: |
| 54 |
p7_tophits_Destroy(h); |
| 55 |
return NULL; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
P7_TOPHITS * |
| 69 |
p7_tophits_Clone(const P7_TOPHITS *h) |
| 70 |
{ |
| 71 |
P7_TOPHITS *h2 = NULL; |
| 72 |
int i; |
| 73 |
int status; |
| 74 |
|
| 75 |
ESL_ALLOC(h2, sizeof(P7_TOPHITS)); |
| 76 |
|
| 77 |
h2->nreported = h->nreported; |
| 78 |
h2->nincluded = h->nincluded; |
| 79 |
h2->is_sorted_by_sortkey = h->is_sorted_by_sortkey; |
| 80 |
h2->is_sorted_by_seqidx = h->is_sorted_by_seqidx; |
| 81 |
|
| 82 |
h2->N = h->N; |
| 83 |
h2->Nalloc = h->N; |
| 84 |
|
| 85 |
h2->hit = NULL; |
| 86 |
h2->unsrt = NULL; |
| 87 |
|
| 88 |
ESL_ALLOC(h2->hit, sizeof(P7_HIT *) * h2->N); |
| 89 |
ESL_ALLOC(h2->unsrt, sizeof(P7_HIT) * h2->N); |
| 90 |
|
| 91 |
|
| 92 |
for (i = 0; i < h2->N; i++) { |
| 93 |
h2->unsrt[i].name = NULL; |
| 94 |
h2->unsrt[i].acc = NULL; |
| 95 |
h2->unsrt[i].desc = NULL; |
| 96 |
h2->unsrt[i].dcl = NULL; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
for (i = 0; i < h2->N; i++) { |
| 101 |
if ((status = p7_hit_Copy(&(h->unsrt[i]), &(h2->unsrt[i]))) != eslOK) goto ERROR; |
| 102 |
h2->hit[i] = h2->unsrt + (h->hit[i] - h->unsrt); |
| 103 |
} |
| 104 |
|
| 105 |
return h2; |
| 106 |
|
| 107 |
ERROR: |
| 108 |
p7_tophits_Destroy(h2); |
| 109 |
return NULL; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
int |
| 125 |
p7_tophits_Grow(P7_TOPHITS *h) |
| 126 |
{ |
| 127 |
void *p; |
| 128 |
P7_HIT *ori = h->unsrt; |
| 129 |
uint64_t Nalloc = h->Nalloc * 2; |
| 130 |
int i; |
| 131 |
int status; |
| 132 |
|
| 133 |
if (h->N < h->Nalloc) return eslOK; |
| 134 |
|
| 135 |
ESL_RALLOC(h->hit, p, sizeof(P7_HIT *) * Nalloc); |
| 136 |
ESL_RALLOC(h->unsrt, p, sizeof(P7_HIT) * Nalloc); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
if (h->is_sorted_by_seqidx || h->is_sorted_by_sortkey) |
| 142 |
{ |
| 143 |
for (i = 0; i < h->N; i++) |
| 144 |
h->hit[i] = h->unsrt + (h->hit[i] - ori); |
| 145 |
} |
| 146 |
|
| 147 |
h->Nalloc = Nalloc; |
| 148 |
return eslOK; |
| 149 |
|
| 150 |
ERROR: |
| 151 |
return eslEMEM; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
int |
| 169 |
p7_tophits_CreateNextHit(P7_TOPHITS *h, P7_HIT **ret_hit) |
| 170 |
{ |
| 171 |
P7_HIT *hit = NULL; |
| 172 |
int status; |
| 173 |
|
| 174 |
if ((status = p7_tophits_Grow(h)) != eslOK) goto ERROR; |
| 175 |
|
| 176 |
hit = &(h->unsrt[h->N]); |
| 177 |
h->N++; |
| 178 |
if (h->N >= 2) |
| 179 |
{ |
| 180 |
h->is_sorted_by_seqidx = FALSE; |
| 181 |
h->is_sorted_by_sortkey = FALSE; |
| 182 |
} |
| 183 |
|
| 184 |
hit->name = NULL; |
| 185 |
hit->acc = NULL; |
| 186 |
hit->desc = NULL; |
| 187 |
hit->sortkey = 0.0; |
| 188 |
|
| 189 |
hit->score = 0.0; |
| 190 |
hit->pre_score = 0.0; |
| 191 |
hit->sum_score = 0.0; |
| 192 |
|
| 193 |
hit->lnP = 0.0; |
| 194 |
hit->pre_lnP = 0.0; |
| 195 |
hit->sum_lnP = 0.0; |
| 196 |
|
| 197 |
hit->ndom = 0; |
| 198 |
hit->nexpected = 0.0; |
| 199 |
hit->nregions = 0; |
| 200 |
hit->nclustered = 0; |
| 201 |
hit->noverlaps = 0; |
| 202 |
hit->nenvelopes = 0; |
| 203 |
|
| 204 |
hit->flags = p7_HITFLAGS_DEFAULT; |
| 205 |
hit->nreported = 0; |
| 206 |
hit->nincluded = 0; |
| 207 |
hit->best_domain = -1; |
| 208 |
hit->dcl = NULL; |
| 209 |
hit->offset = 0; |
| 210 |
|
| 211 |
*ret_hit = hit; |
| 212 |
return eslOK; |
| 213 |
|
| 214 |
ERROR: |
| 215 |
*ret_hit = NULL; |
| 216 |
return status; |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
int |
| 265 |
p7_tophits_Add(P7_TOPHITS *h, |
| 266 |
char *name, char *acc, char *desc, |
| 267 |
double sortkey, |
| 268 |
float score, double lnP, |
| 269 |
float mothersc, double mother_lnP, |
| 270 |
int sqfrom, int sqto, int sqlen, |
| 271 |
int hmmfrom, int hmmto, int hmmlen, |
| 272 |
int domidx, int ndom, |
| 273 |
P7_ALIDISPLAY *ali) |
| 274 |
{ |
| 275 |
int status; |
| 276 |
|
| 277 |
if ((status = p7_tophits_Grow(h)) != eslOK) return status; |
| 278 |
if ((status = esl_strdup(name, -1, &(h->unsrt[h->N].name))) != eslOK) return status; |
| 279 |
if ((status = esl_strdup(acc, -1, &(h->unsrt[h->N].acc))) != eslOK) return status; |
| 280 |
if ((status = esl_strdup(desc, -1, &(h->unsrt[h->N].desc))) != eslOK) return status; |
| 281 |
h->unsrt[h->N].sortkey = sortkey; |
| 282 |
h->unsrt[h->N].score = score; |
| 283 |
h->unsrt[h->N].pre_score = 0.0; |
| 284 |
h->unsrt[h->N].sum_score = 0.0; |
| 285 |
h->unsrt[h->N].lnP = lnP; |
| 286 |
h->unsrt[h->N].pre_lnP = 0.0; |
| 287 |
h->unsrt[h->N].sum_lnP = 0.0; |
| 288 |
h->unsrt[h->N].nexpected = 0; |
| 289 |
h->unsrt[h->N].nregions = 0; |
| 290 |
h->unsrt[h->N].nclustered = 0; |
| 291 |
h->unsrt[h->N].noverlaps = 0; |
| 292 |
h->unsrt[h->N].nenvelopes = 0; |
| 293 |
h->unsrt[h->N].ndom = ndom; |
| 294 |
h->unsrt[h->N].flags = 0; |
| 295 |
h->unsrt[h->N].nreported = 0; |
| 296 |
h->unsrt[h->N].nincluded = 0; |
| 297 |
h->unsrt[h->N].best_domain= 0; |
| 298 |
h->unsrt[h->N].dcl = NULL; |
| 299 |
h->N++; |
| 300 |
|
| 301 |
if (h->N >= 2) { |
| 302 |
h->is_sorted_by_seqidx = FALSE; |
| 303 |
h->is_sorted_by_sortkey = FALSE; |
| 304 |
} |
| 305 |
return eslOK; |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
static int |
| 310 |
hit_sorter_by_sortkey(const void *vh1, const void *vh2) |
| 311 |
{ |
| 312 |
P7_HIT *h1 = *((P7_HIT **) vh1); |
| 313 |
P7_HIT *h2 = *((P7_HIT **) vh2); |
| 314 |
int c; |
| 315 |
|
| 316 |
if (h1->sortkey < h2->sortkey) return 1; |
| 317 |
else if (h1->sortkey > h2->sortkey) return -1; |
| 318 |
else { |
| 319 |
if ( (c = strcmp(h1->name, h2->name)) != 0) return c; |
| 320 |
|
| 321 |
|
| 322 |
int dir1 = (h1->dcl[0].iali < h1->dcl[0].jali ? 1 : -1); |
| 323 |
int dir2 = (h2->dcl[0].iali < h2->dcl[0].jali ? 1 : -1); |
| 324 |
if (dir1 != dir2) return dir2; |
| 325 |
else { |
| 326 |
if (h1->dcl[0].iali > h2->dcl[0].iali) return 1; |
| 327 |
else if(h1->dcl[0].iali < h2->dcl[0].iali) return -1; |
| 328 |
else return 0; |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
static int |
| 335 |
hit_sorter_by_seqidx_aliposition(const void *vh1, const void *vh2) |
| 336 |
{ |
| 337 |
P7_HIT *h1 = *((P7_HIT **) vh1); |
| 338 |
P7_HIT *h2 = *((P7_HIT **) vh2); |
| 339 |
int64_t s1, e1, s2, e2; |
| 340 |
int dir1, dir2; |
| 341 |
|
| 342 |
if (h1->seqidx > h2->seqidx) return 1; |
| 343 |
else if (h1->seqidx < h2->seqidx) return -1; |
| 344 |
|
| 345 |
|
| 346 |
s1 = h1->dcl[0].iali; e1 = h1->dcl[0].jali; if (s1 < e1) { dir1 = 1; } else { dir1 = -1; ESL_SWAP(s1, e1, int64_t); } |
| 347 |
s2 = h2->dcl[0].iali; e2 = h2->dcl[0].jali; if (s2 < e2) { dir2 = 1; } else { dir2 = -1; ESL_SWAP(s2, e2, int64_t); } |
| 348 |
|
| 349 |
if (dir1 != dir2) return dir2; |
| 350 |
|
| 351 |
if (s1 > s2) return 1; |
| 352 |
else if (s1 < s2) return -1; |
| 353 |
else if (e1 < e2) return 1; |
| 354 |
else if (e1 > e2) return -1; |
| 355 |
else return 0; |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
static int |
| 360 |
hit_sorter_by_modelname_aliposition(const void *vh1, const void *vh2) |
| 361 |
{ |
| 362 |
P7_HIT *h1 = *((P7_HIT **) vh1); |
| 363 |
P7_HIT *h2 = *((P7_HIT **) vh2); |
| 364 |
int64_t s1, e1, s2, e2; |
| 365 |
int dir1, dir2; |
| 366 |
int res; |
| 367 |
|
| 368 |
if ( ( res = esl_strcmp(h1->name, h2->name)) != 0 ) return res; |
| 369 |
|
| 370 |
s1 = h1->dcl[0].iali; e1 = h1->dcl[0].jali; if (s1 < e1) { dir1 = 1; } else { dir1 = -1; ESL_SWAP(s1, e1, int64_t); } |
| 371 |
s2 = h2->dcl[0].iali; e2 = h2->dcl[0].jali; if (s2 < e2) { dir2 = 1; } else { dir2 = -1; ESL_SWAP(s2, e2, int64_t); } |
| 372 |
|
| 373 |
if (dir1 != dir2) return dir2; |
| 374 |
|
| 375 |
if (s1 > s2) return 1; |
| 376 |
else if (s1 < s2) return -1; |
| 377 |
else if (e1 < e2) return 1; |
| 378 |
else if (e1 > e2) return -1; |
| 379 |
else return 0; |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
int |
| 393 |
p7_tophits_SortBySortkey(P7_TOPHITS *h) |
| 394 |
{ |
| 395 |
int i; |
| 396 |
|
| 397 |
if (h->is_sorted_by_sortkey) return eslOK; |
| 398 |
for (i = 0; i < h->N; i++) h->hit[i] = h->unsrt + i; |
| 399 |
if (h->N > 1) qsort(h->hit, h->N, sizeof(P7_HIT *), hit_sorter_by_sortkey); |
| 400 |
h->is_sorted_by_seqidx = FALSE; |
| 401 |
h->is_sorted_by_sortkey = TRUE; |
| 402 |
return eslOK; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
int |
| 426 |
p7_tophits_SortBySeqidxAndAlipos(P7_TOPHITS *h) |
| 427 |
{ |
| 428 |
int i; |
| 429 |
|
| 430 |
if (h->is_sorted_by_seqidx) return eslOK; |
| 431 |
for (i = 0; i < h->N; i++) h->hit[i] = h->unsrt + i; |
| 432 |
if (h->N > 1) qsort(h->hit, h->N, sizeof(P7_HIT *), hit_sorter_by_seqidx_aliposition); |
| 433 |
h->is_sorted_by_sortkey = FALSE; |
| 434 |
h->is_sorted_by_seqidx = TRUE; |
| 435 |
return eslOK; |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
int |
| 447 |
p7_tophits_SortByModelnameAndAlipos(P7_TOPHITS *h) |
| 448 |
{ |
| 449 |
int i; |
| 450 |
|
| 451 |
if (h->is_sorted_by_seqidx) return eslOK; |
| 452 |
for (i = 0; i < h->N; i++) h->hit[i] = h->unsrt + i; |
| 453 |
if (h->N > 1) qsort(h->hit, h->N, sizeof(P7_HIT *), hit_sorter_by_modelname_aliposition); |
| 454 |
h->is_sorted_by_sortkey = FALSE; |
| 455 |
h->is_sorted_by_seqidx = TRUE; |
| 456 |
return eslOK; |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
int |
| 475 |
p7_tophits_Merge(P7_TOPHITS *h1, P7_TOPHITS *h2) |
| 476 |
{ |
| 477 |
void *p; |
| 478 |
P7_HIT **new_hit = NULL; |
| 479 |
P7_HIT *ori1 = h1->unsrt; |
| 480 |
P7_HIT *new2; |
| 481 |
int i,j,k; |
| 482 |
uint64_t Nalloc = h1->N + h2->N; |
| 483 |
int status; |
| 484 |
|
| 485 |
if(h2->N <= 0) return eslOK; |
| 486 |
|
| 487 |
|
| 488 |
if ((status = p7_tophits_SortBySortkey(h1)) != eslOK) goto ERROR; |
| 489 |
if ((status = p7_tophits_SortBySortkey(h2)) != eslOK) goto ERROR; |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
ESL_RALLOC(h1->unsrt, p, sizeof(P7_HIT) * Nalloc); |
| 495 |
ESL_ALLOC (new_hit, sizeof(P7_HIT *) * Nalloc); |
| 496 |
for (i = 0; i < h1->N; i++) |
| 497 |
h1->hit[i] = h1->unsrt + (h1->hit[i] - ori1); |
| 498 |
|
| 499 |
|
| 500 |
new2 = h1->unsrt + h1->N; |
| 501 |
memcpy(new2, h2->unsrt, sizeof(P7_HIT) * h2->N); |
| 502 |
|
| 503 |
|
| 504 |
for (i=0,j=0,k=0; i < h1->N && j < h2->N ; k++) |
| 505 |
new_hit[k] = (hit_sorter_by_sortkey(&h1->hit[i], &h2->hit[j]) > 0) ? new2 + (h2->hit[j++] - h2->unsrt) : h1->hit[i++]; |
| 506 |
while (i < h1->N) new_hit[k++] = h1->hit[i++]; |
| 507 |
while (j < h2->N) new_hit[k++] = new2 + (h2->hit[j++] - h2->unsrt); |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
for (i = 0; i < h2->N; i++) |
| 512 |
{ |
| 513 |
h2->unsrt[i].name = NULL; |
| 514 |
h2->unsrt[i].acc = NULL; |
| 515 |
h2->unsrt[i].desc = NULL; |
| 516 |
h2->unsrt[i].dcl = NULL; |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
free(h1->hit); |
| 521 |
h1->hit = new_hit; |
| 522 |
h1->Nalloc = Nalloc; |
| 523 |
h1->N += h2->N; |
| 524 |
|
| 525 |
return eslOK; |
| 526 |
|
| 527 |
ERROR: |
| 528 |
if (new_hit != NULL) free(new_hit); |
| 529 |
return status; |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
int |
| 551 |
p7_tophits_GetMaxPositionLength(P7_TOPHITS *h) |
| 552 |
{ |
| 553 |
int64_t i; |
| 554 |
int max = 0; |
| 555 |
int n; |
| 556 |
char buffer [26]; |
| 557 |
|
| 558 |
|
| 559 |
for (i = 0; i < h->N; i++) { |
| 560 |
if (h->unsrt[i].dcl[0].iali > 0) { |
| 561 |
n = snprintf (buffer, 26, "%" PRId64 "", h->unsrt[i].dcl[0].iali); |
| 562 |
max = ESL_MAX(n, max); |
| 563 |
n = snprintf (buffer, 26, "%" PRId64 "", h->unsrt[i].dcl[0].jali); |
| 564 |
max = ESL_MAX(n, max); |
| 565 |
} |
| 566 |
} |
| 567 |
return max; |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
int |
| 586 |
p7_tophits_GetMaxNameLength(P7_TOPHITS *h) |
| 587 |
{ |
| 588 |
int i, max, n; |
| 589 |
for (max = 0, i = 0; i < h->N; i++) |
| 590 |
if (h->unsrt[i].name != NULL) { |
| 591 |
n = strlen(h->unsrt[i].name); |
| 592 |
max = ESL_MAX(n, max); |
| 593 |
} |
| 594 |
return max; |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
int |
| 605 |
p7_tophits_GetMaxAccessionLength(P7_TOPHITS *h) |
| 606 |
{ |
| 607 |
int i, max, n; |
| 608 |
for (max = 0, i = 0; i < h->N; i++) |
| 609 |
if (h->unsrt[i].acc != NULL) { |
| 610 |
n = strlen(h->unsrt[i].acc); |
| 611 |
max = ESL_MAX(n, max); |
| 612 |
} |
| 613 |
return max; |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
int |
| 627 |
p7_tophits_GetMaxShownLength(P7_TOPHITS *h) |
| 628 |
{ |
| 629 |
int i, max, n; |
| 630 |
for (max = 0, i = 0; i < h->N; i++) |
| 631 |
{ |
| 632 |
if (h->unsrt[i].acc != NULL && h->unsrt[i].acc[0] != '\0') |
| 633 |
{ |
| 634 |
n = strlen(h->unsrt[i].acc); |
| 635 |
max = ESL_MAX(n, max); |
| 636 |
} |
| 637 |
else if (h->unsrt[i].name != NULL) |
| 638 |
{ |
| 639 |
n = strlen(h->unsrt[i].name); |
| 640 |
max = ESL_MAX(n, max); |
| 641 |
} |
| 642 |
} |
| 643 |
return max; |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
int |
| 656 |
p7_tophits_Reuse(P7_TOPHITS *h) |
| 657 |
{ |
| 658 |
int i, j; |
| 659 |
|
| 660 |
if (h == NULL) return eslOK; |
| 661 |
if (h->unsrt != NULL) |
| 662 |
{ |
| 663 |
for (i = 0; i < h->N; i++) |
| 664 |
{ |
| 665 |
if (h->unsrt[i].name != NULL) free(h->unsrt[i].name); |
| 666 |
if (h->unsrt[i].acc != NULL) free(h->unsrt[i].acc); |
| 667 |
if (h->unsrt[i].desc != NULL) free(h->unsrt[i].desc); |
| 668 |
if (h->unsrt[i].dcl != NULL) { |
| 669 |
for (j = 0; j < h->unsrt[i].ndom; j++) |
| 670 |
if (h->unsrt[i].dcl[j].ad != NULL) p7_alidisplay_Destroy(h->unsrt[i].dcl[j].ad); |
| 671 |
free(h->unsrt[i].dcl); |
| 672 |
} |
| 673 |
} |
| 674 |
} |
| 675 |
h->N = 0; |
| 676 |
h->is_sorted_by_seqidx = FALSE; |
| 677 |
h->is_sorted_by_sortkey = TRUE; |
| 678 |
h->hit[0] = h->unsrt; |
| 679 |
return eslOK; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
void |
| 686 |
p7_tophits_Destroy(P7_TOPHITS *h) |
| 687 |
{ |
| 688 |
int i,j; |
| 689 |
if (h == NULL) return; |
| 690 |
if (h->hit != NULL) free(h->hit); |
| 691 |
if (h->unsrt != NULL) |
| 692 |
{ |
| 693 |
for (i = 0; i < h->N; i++) |
| 694 |
{ |
| 695 |
if (h->unsrt[i].name != NULL) free(h->unsrt[i].name); |
| 696 |
if (h->unsrt[i].acc != NULL) free(h->unsrt[i].acc); |
| 697 |
if (h->unsrt[i].desc != NULL) free(h->unsrt[i].desc); |
| 698 |
if (h->unsrt[i].dcl != NULL) { |
| 699 |
for (j = 0; j < h->unsrt[i].ndom; j++) { |
| 700 |
if (h->unsrt[i].dcl[j].ad != NULL) p7_alidisplay_Destroy(h->unsrt[i].dcl[j].ad); |
| 701 |
if (h->unsrt[i].dcl[j].scores_per_pos != NULL) free (h->unsrt[i].dcl->scores_per_pos); |
| 702 |
} |
| 703 |
free(h->unsrt[i].dcl); |
| 704 |
} |
| 705 |
} |
| 706 |
free(h->unsrt); |
| 707 |
} |
| 708 |
free(h); |
| 709 |
return; |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
static int |
| 756 |
workaround_bug_h74(P7_TOPHITS *th) |
| 757 |
{ |
| 758 |
int h; |
| 759 |
int d1, d2; |
| 760 |
int dremoved; |
| 761 |
|
| 762 |
for (h = 0; h < th->N; h++) |
| 763 |
if (th->hit[h]->noverlaps) |
| 764 |
{ |
| 765 |
for (d1 = 0; d1 < th->hit[h]->ndom; d1++) |
| 766 |
for (d2 = d1+1; d2 < th->hit[h]->ndom; d2++) |
| 767 |
if (th->hit[h]->dcl[d1].iali == th->hit[h]->dcl[d2].iali && |
| 768 |
th->hit[h]->dcl[d1].jali == th->hit[h]->dcl[d2].jali) |
| 769 |
{ |
| 770 |
dremoved = (th->hit[h]->dcl[d1].bitscore >= th->hit[h]->dcl[d2].bitscore) ? d2 : d1; |
| 771 |
if (th->hit[h]->dcl[dremoved].is_reported) { th->hit[h]->dcl[dremoved].is_reported = FALSE; th->hit[h]->nreported--; } |
| 772 |
if (th->hit[h]->dcl[dremoved].is_included) { th->hit[h]->dcl[dremoved].is_included = FALSE; th->hit[h]->nincluded--; } |
| 773 |
} |
| 774 |
} |
| 775 |
return eslOK; |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
int |
| 796 |
p7_tophits_ComputeNhmmerEvalues(P7_TOPHITS *th, double N, int W) |
| 797 |
{ |
| 798 |
int i; |
| 799 |
|
| 800 |
for (i = 0; i < th->N ; i++) |
| 801 |
{ |
| 802 |
th->unsrt[i].lnP += log((float)N / (float)W); |
| 803 |
th->unsrt[i].dcl[0].lnP = th->unsrt[i].lnP; |
| 804 |
th->unsrt[i].sortkey = -1.0 * th->unsrt[i].lnP; |
| 805 |
} |
| 806 |
return eslOK; |
| 807 |
} |
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
int |
| 823 |
p7_tophits_RemoveDuplicates(P7_TOPHITS *th, int using_bit_cutoffs) |
| 824 |
{ |
| 825 |
int i; |
| 826 |
int j; |
| 827 |
int s_i, s_j, e_i, e_j, dir_i, dir_j, len_i, len_j; |
| 828 |
int intersect_alistart, intersect_aliend, intersect_alilen; |
| 829 |
int intersect_hmmstart, intersect_hmmend, intersect_hmmlen; |
| 830 |
double p_i, p_j; |
| 831 |
int remove; |
| 832 |
|
| 833 |
if (th->N<2) return eslOK; |
| 834 |
|
| 835 |
j=0; |
| 836 |
for (i = 1; i < th->N; i++) |
| 837 |
{ |
| 838 |
p_j = th->hit[j]->lnP; |
| 839 |
s_j = th->hit[j]->dcl[0].iali; |
| 840 |
e_j = th->hit[j]->dcl[0].jali; |
| 841 |
dir_j = (s_j < e_j ? 1 : -1); |
| 842 |
if (dir_j == -1) ESL_SWAP(s_j, e_j, int); |
| 843 |
len_j = e_j - s_j + 1 ; |
| 844 |
|
| 845 |
p_i = th->hit[i]->lnP; |
| 846 |
s_i = th->hit[i]->dcl[0].iali; |
| 847 |
e_i = th->hit[i]->dcl[0].jali; |
| 848 |
dir_i = (s_i < e_i ? 1 : -1); |
| 849 |
if (dir_i == -1) ESL_SWAP(s_i, e_i, int); |
| 850 |
len_i = e_i - s_i + 1 ; |
| 851 |
|
| 852 |
|
| 853 |
intersect_alistart = s_i>s_j ? s_i : s_j; |
| 854 |
intersect_aliend = e_i<e_j ? e_i : e_j; |
| 855 |
intersect_alilen = intersect_aliend - intersect_alistart + 1; |
| 856 |
|
| 857 |
intersect_hmmstart = (th->hit[i]->dcl[0].ad->hmmfrom > th->hit[j]->dcl[0].ad->hmmfrom) ? th->hit[i]->dcl[0].ad->hmmfrom : th->hit[j]->dcl[0].ad->hmmfrom; |
| 858 |
intersect_hmmend = (th->hit[i]->dcl[0].ad->hmmto < th->hit[j]->dcl[0].ad->hmmto) ? th->hit[i]->dcl[0].ad->hmmto : th->hit[j]->dcl[0].ad->hmmto; |
| 859 |
intersect_hmmlen = intersect_hmmend - intersect_hmmstart + 1; |
| 860 |
|
| 861 |
if ( esl_strcmp(th->hit[i]->name, th->hit[i-1]->name) == 0 && |
| 862 |
th->hit[i]->seqidx == th->hit[i-1]->seqidx && |
| 863 |
dir_i == dir_j && |
| 864 |
intersect_hmmlen > 0 && |
| 865 |
( |
| 866 |
( s_i >= s_j-3 && s_i <= s_j+3) || |
| 867 |
( e_i >= e_j-3 && e_i <= e_j+3) || |
| 868 |
( intersect_alilen >= len_i * 0.95) || |
| 869 |
( intersect_alilen >= len_j * 0.95) |
| 870 |
)) |
| 871 |
{ |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
remove = p_i < p_j ? j : i; |
| 889 |
|
| 890 |
th->hit[remove]->flags |= p7_IS_DUPLICATE; |
| 891 |
if (using_bit_cutoffs) { |
| 892 |
th->hit[remove]->flags &= ~p7_IS_REPORTED; |
| 893 |
th->hit[remove]->flags &= ~p7_IS_INCLUDED; |
| 894 |
} |
| 895 |
|
| 896 |
j = (remove == j ? i : j); |
| 897 |
} |
| 898 |
else j = i; |
| 899 |
} |
| 900 |
return eslOK; |
| 901 |
} |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
int |
| 928 |
p7_tophits_Threshold(P7_TOPHITS *th, P7_PIPELINE *pli) |
| 929 |
{ |
| 930 |
int h, d; |
| 931 |
|
| 932 |
|
| 933 |
if (! pli->use_bit_cutoffs) |
| 934 |
{ |
| 935 |
for (h = 0; h < th->N; h++) |
| 936 |
{ |
| 937 |
|
| 938 |
if ( !(th->hit[h]->flags & p7_IS_DUPLICATE) && |
| 939 |
p7_pli_TargetReportable(pli, th->hit[h]->score, th->hit[h]->lnP)) |
| 940 |
{ |
| 941 |
th->hit[h]->flags |= p7_IS_REPORTED; |
| 942 |
if (p7_pli_TargetIncludable(pli, th->hit[h]->score, th->hit[h]->lnP)) |
| 943 |
th->hit[h]->flags |= p7_IS_INCLUDED; |
| 944 |
|
| 945 |
if (pli->long_targets) { |
| 946 |
th->hit[h]->dcl[0].is_reported = th->hit[h]->flags & p7_IS_REPORTED; |
| 947 |
th->hit[h]->dcl[0].is_included = th->hit[h]->flags & p7_IS_INCLUDED; |
| 948 |
} |
| 949 |
} |
| 950 |
} |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
th->nreported = 0; |
| 955 |
th->nincluded = 0; |
| 956 |
for (h = 0; h < th->N; h++) |
| 957 |
{ |
| 958 |
if (th->hit[h]->flags & p7_IS_REPORTED) th->nreported++; |
| 959 |
if (th->hit[h]->flags & p7_IS_INCLUDED) th->nincluded++; |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
if (pli->domZ_setby == p7_ZSETBY_NTARGETS) pli->domZ = (double) th->nreported; |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
if (! pli->use_bit_cutoffs && !pli->long_targets) |
| 973 |
{ |
| 974 |
for (h = 0; h < th->N; h++) |
| 975 |
{ |
| 976 |
if (th->hit[h]->flags & p7_IS_REPORTED) |
| 977 |
{ |
| 978 |
for (d = 0; d < th->hit[h]->ndom; d++) |
| 979 |
{ |
| 980 |
if (p7_pli_DomainReportable(pli, th->hit[h]->dcl[d].bitscore, th->hit[h]->dcl[d].lnP)) |
| 981 |
th->hit[h]->dcl[d].is_reported = TRUE; |
| 982 |
if ((th->hit[h]->flags & p7_IS_INCLUDED) && |
| 983 |
p7_pli_DomainIncludable(pli, th->hit[h]->dcl[d].bitscore, th->hit[h]->dcl[d].lnP)) |
| 984 |
th->hit[h]->dcl[d].is_included = TRUE; |
| 985 |
} |
| 986 |
} |
| 987 |
} |
| 988 |
} |
| 989 |
|
| 990 |
|
| 991 |
for (h = 0; h < th->N; h++) { |
| 992 |
th->hit[h]->nreported = 0; |
| 993 |
th->hit[h]->nincluded = 0; |
| 994 |
for (d = 0; d < th->hit[h]->ndom; d++) |
| 995 |
{ |
| 996 |
if (th->hit[h]->dcl[d].is_reported) th->hit[h]->nreported++; |
| 997 |
if (th->hit[h]->dcl[d].is_included) th->hit[h]->nincluded++; |
| 998 |
} |
| 999 |
} |
| 1000 |
|
| 1001 |
workaround_bug_h74(th); |
| 1002 |
|
| 1003 |
return eslOK; |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
int |
| 1059 |
p7_tophits_CompareRanking(P7_TOPHITS *th, ESL_KEYHASH *kh, int *opt_nnew) |
| 1060 |
{ |
| 1061 |
int nnew = 0; |
| 1062 |
int oldrank; |
| 1063 |
int h; |
| 1064 |
int status; |
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
for (h = 0; h < th->N; h++) |
| 1070 |
{ |
| 1071 |
esl_keyhash_Lookup(kh, th->hit[h]->name, -1, &oldrank); |
| 1072 |
|
| 1073 |
if (th->hit[h]->flags & p7_IS_INCLUDED) |
| 1074 |
{ |
| 1075 |
if (oldrank == -1) { th->hit[h]->flags |= p7_IS_NEW; nnew++; } |
| 1076 |
} |
| 1077 |
else |
| 1078 |
{ |
| 1079 |
if (oldrank >= 0) th->hit[h]->flags |= p7_IS_DROPPED; |
| 1080 |
} |
| 1081 |
} |
| 1082 |
|
| 1083 |
|
| 1084 |
esl_keyhash_Reuse(kh); |
| 1085 |
for (h = 0; h < th->N; h++) |
| 1086 |
{ |
| 1087 |
if (th->hit[h]->flags & p7_IS_INCLUDED) |
| 1088 |
{ |
| 1089 |
|
| 1090 |
status = esl_keyhash_Store(kh, th->hit[h]->name, -1, NULL); |
| 1091 |
if (status != eslOK && status != eslEDUP) goto ERROR; |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
if (opt_nnew != NULL) *opt_nnew = nnew; |
| 1096 |
return eslOK; |
| 1097 |
|
| 1098 |
ERROR: |
| 1099 |
if (opt_nnew != NULL) *opt_nnew = 0; |
| 1100 |
return status; |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
int |
| 1120 |
p7_tophits_Targets(FILE *ofp, P7_TOPHITS *th, P7_PIPELINE *pli, int textw) |
| 1121 |
{ |
| 1122 |
char newness; |
| 1123 |
int h; |
| 1124 |
int d; |
| 1125 |
int namew; |
| 1126 |
int posw; |
| 1127 |
int descw; |
| 1128 |
char *showname; |
| 1129 |
|
| 1130 |
int have_printed_incthresh = FALSE; |
| 1131 |
|
| 1132 |
|
| 1133 |
if (pli->show_accessions) namew = ESL_MAX(8, p7_tophits_GetMaxShownLength(th)); |
| 1134 |
else namew = ESL_MAX(8, p7_tophits_GetMaxNameLength(th)); |
| 1135 |
|
| 1136 |
|
| 1137 |
if (pli->long_targets) |
| 1138 |
{ |
| 1139 |
posw = ESL_MAX(6, p7_tophits_GetMaxPositionLength(th)); |
| 1140 |
|
| 1141 |
if (textw > 0) descw = ESL_MAX(32, textw - namew - 2*posw - 32); |
| 1142 |
else descw = 0; |
| 1143 |
|
| 1144 |
if (fprintf(ofp, "Scores for complete hit%s:\n", pli->mode == p7_SEARCH_SEQS ? "s" : "") < 0) |
| 1145 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1146 |
if (fprintf(ofp, " %9s %6s %5s %-*s %*s %*s %s\n", |
| 1147 |
"E-value", " score", " bias", namew, (pli->mode == p7_SEARCH_SEQS ? "Sequence":"Model"), posw, "start", posw, "end", "Description") < 0) |
| 1148 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1149 |
if (fprintf(ofp, " %9s %6s %5s %-*s %*s %*s %s\n", |
| 1150 |
"-------", "------", "-----", namew, "--------", posw, "-----", posw, "-----", "-----------") < 0) |
| 1151 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1152 |
} |
| 1153 |
else |
| 1154 |
{ |
| 1155 |
|
| 1156 |
if (textw > 0) descw = ESL_MAX(32, textw - namew - 61); |
| 1157 |
else descw = 0; |
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
if (fprintf(ofp, "Scores for complete sequence%s (score includes all domains):\n", pli->mode == p7_SEARCH_SEQS ? "s" : "") < 0) |
| 1162 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1163 |
if (fprintf(ofp, " %22s %22s %8s\n", " --- full sequence ---", " --- best 1 domain ---", "-#dom-") < 0) |
| 1164 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1165 |
if (fprintf(ofp, " %9s %6s %5s %9s %6s %5s %5s %2s %-*s %s\n", |
| 1166 |
"E-value", " score", " bias", "E-value", " score", " bias", " exp", "N", namew, (pli->mode == p7_SEARCH_SEQS ? "Sequence":"Model"), "Description") < 0) |
| 1167 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1168 |
if (fprintf(ofp, " %9s %6s %5s %9s %6s %5s %5s %2s %-*s %s\n", |
| 1169 |
"-------", "------", "-----", "-------", "------", "-----", " ----", "--", namew, "--------", "-----------") < 0) |
| 1170 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1171 |
} |
| 1172 |
|
| 1173 |
for (h = 0; h < th->N; h++) |
| 1174 |
{ |
| 1175 |
if (th->hit[h]->flags & p7_IS_REPORTED) |
| 1176 |
{ |
| 1177 |
d = th->hit[h]->best_domain; |
| 1178 |
|
| 1179 |
if (! (th->hit[h]->flags & p7_IS_INCLUDED) && ! have_printed_incthresh) |
| 1180 |
{ |
| 1181 |
if (fprintf(ofp, " ------ inclusion threshold ------\n") < 0) |
| 1182 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1183 |
have_printed_incthresh = TRUE; |
| 1184 |
} |
| 1185 |
|
| 1186 |
if (pli->show_accessions) |
| 1187 |
{ |
| 1188 |
if (th->hit[h]->acc != NULL && th->hit[h]->acc[0] != '\0') showname = th->hit[h]->acc; |
| 1189 |
else showname = th->hit[h]->name; |
| 1190 |
} |
| 1191 |
else |
| 1192 |
showname = th->hit[h]->name; |
| 1193 |
|
| 1194 |
if (th->hit[h]->flags & p7_IS_NEW) newness = '+'; |
| 1195 |
else if (th->hit[h]->flags & p7_IS_DROPPED) newness = '-'; |
| 1196 |
else newness = ' '; |
| 1197 |
|
| 1198 |
if (pli->long_targets) |
| 1199 |
{ |
| 1200 |
if (fprintf(ofp, "%c %9.2g %6.1f %5.1f %-*s %*" PRId64 " %*" PRId64 "", |
| 1201 |
newness, |
| 1202 |
exp(th->hit[h]->lnP), |
| 1203 |
th->hit[h]->score, |
| 1204 |
eslCONST_LOG2R * th->hit[h]->dcl[d].dombias, |
| 1205 |
namew, showname, |
| 1206 |
posw, th->hit[h]->dcl[d].iali, |
| 1207 |
posw, th->hit[h]->dcl[d].jali) < 0) |
| 1208 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1209 |
} |
| 1210 |
else |
| 1211 |
{ |
| 1212 |
if (fprintf(ofp, "%c %9.2g %6.1f %5.1f %9.2g %6.1f %5.1f %5.1f %2d %-*s ", |
| 1213 |
newness, |
| 1214 |
exp(th->hit[h]->lnP) * pli->Z, |
| 1215 |
th->hit[h]->score, |
| 1216 |
th->hit[h]->pre_score - th->hit[h]->score, |
| 1217 |
exp(th->hit[h]->dcl[d].lnP) * pli->Z, |
| 1218 |
th->hit[h]->dcl[d].bitscore, |
| 1219 |
eslCONST_LOG2R * th->hit[h]->dcl[d].dombias, |
| 1220 |
th->hit[h]->nexpected, |
| 1221 |
th->hit[h]->nreported, |
| 1222 |
namew, showname) < 0) |
| 1223 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1224 |
} |
| 1225 |
|
| 1226 |
if (textw > 0) |
| 1227 |
{ |
| 1228 |
if (fprintf(ofp, " %-.*s\n", descw, th->hit[h]->desc == NULL ? "" : th->hit[h]->desc) < 0) |
| 1229 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1230 |
} |
| 1231 |
else |
| 1232 |
{ |
| 1233 |
if (fprintf(ofp, " %s\n", th->hit[h]->desc == NULL ? "" : th->hit[h]->desc) < 0) |
| 1234 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1235 |
} |
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
} |
| 1241 |
} |
| 1242 |
|
| 1243 |
if (th->nreported == 0) |
| 1244 |
{ |
| 1245 |
if (fprintf(ofp, "\n [No hits detected that satisfy reporting thresholds]\n") < 0) |
| 1246 |
ESL_EXCEPTION_SYS(eslEWRITE, "per-sequence hit list: write failed"); |
| 1247 |
} |
| 1248 |
return eslOK; |
| 1249 |
} |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
int |
| 1267 |
p7_tophits_Domains(FILE *ofp, P7_TOPHITS *th, P7_PIPELINE *pli, int textw) |
| 1268 |
{ |
| 1269 |
int h, d; |
| 1270 |
int nd; |
| 1271 |
int namew, descw; |
| 1272 |
char *showname; |
| 1273 |
int status; |
| 1274 |
|
| 1275 |
if (pli->long_targets) |
| 1276 |
{ |
| 1277 |
if (fprintf(ofp, "Annotation for each hit %s:\n", |
| 1278 |
pli->show_alignments ? " (and alignments)" : "") < 0) |
| 1279 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1280 |
} |
| 1281 |
else |
| 1282 |
{ |
| 1283 |
if (fprintf(ofp, "Domain annotation for each %s%s:\n", |
| 1284 |
pli->mode == p7_SEARCH_SEQS ? "sequence" : "model", |
| 1285 |
pli->show_alignments ? " (and alignments)" : "") < 0) |
| 1286 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1287 |
} |
| 1288 |
|
| 1289 |
for (h = 0; h < th->N; h++) |
| 1290 |
if (th->hit[h]->flags & p7_IS_REPORTED) |
| 1291 |
{ |
| 1292 |
if (pli->show_accessions && th->hit[h]->acc != NULL && th->hit[h]->acc[0] != '\0') |
| 1293 |
{ |
| 1294 |
showname = th->hit[h]->acc; |
| 1295 |
namew = strlen(th->hit[h]->acc); |
| 1296 |
} |
| 1297 |
else |
| 1298 |
{ |
| 1299 |
showname = th->hit[h]->name; |
| 1300 |
namew = strlen(th->hit[h]->name); |
| 1301 |
} |
| 1302 |
|
| 1303 |
if (textw > 0) |
| 1304 |
{ |
| 1305 |
descw = ESL_MAX(32, textw - namew - 5); |
| 1306 |
if (fprintf(ofp, ">> %s %-.*s\n", showname, descw, (th->hit[h]->desc == NULL ? "" : th->hit[h]->desc)) < 0) |
| 1307 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1308 |
} |
| 1309 |
else |
| 1310 |
{ |
| 1311 |
if (fprintf(ofp, ">> %s %s\n", showname, (th->hit[h]->desc == NULL ? "" : th->hit[h]->desc)) < 0) |
| 1312 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1313 |
} |
| 1314 |
|
| 1315 |
if (th->hit[h]->nreported == 0) |
| 1316 |
{ |
| 1317 |
if (fprintf(ofp," [No individual domains that satisfy reporting thresholds (although complete target did)]\n\n") < 0) |
| 1318 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1319 |
continue; |
| 1320 |
} |
| 1321 |
|
| 1322 |
|
| 1323 |
if (pli->long_targets) |
| 1324 |
{ |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
if (fprintf(ofp, " %6s %5s %9s %9s %9s %2s %9s %9s %2s %9s %9s %9s %2s %4s\n", "score", "bias", " Evalue", "hmmfrom", "hmm to", " ", " alifrom ", " ali to ", " ", " envfrom ", " env to ", (pli->mode == p7_SEARCH_SEQS ? " sq len " : " mod len "), " ", "acc") < 0) |
| 1331 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1332 |
if (fprintf(ofp, " %6s %5s %9s %9s %9s %2s %9s %9s %2s %9s %9s %9s %2s %4s\n", "------", "-----", "---------", "-------", "-------", " ", "---------", "---------", " ", "---------", "---------", "---------", " ", "----") < 0) |
| 1333 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1334 |
} |
| 1335 |
else |
| 1336 |
{ |
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
if (fprintf(ofp, " %3s %6s %5s %9s %9s %7s %7s %2s %7s %7s %2s %7s %7s %2s %4s\n", "#", "score", "bias", "c-Evalue", "i-Evalue", "hmmfrom", "hmm to", " ", "alifrom", "ali to", " ", "envfrom", "env to", " ", "acc") < 0) |
| 1344 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1345 |
if (fprintf(ofp, " %3s %6s %5s %9s %9s %7s %7s %2s %7s %7s %2s %7s %7s %2s %4s\n", "---", "------", "-----", "---------", "---------", "-------", "-------", " ", "-------", "-------", " ", "-------", "-------", " ", "----") < 0) |
| 1346 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1347 |
} |
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
nd = 0; |
| 1352 |
for (d = 0; d < th->hit[h]->ndom; d++) |
| 1353 |
{ |
| 1354 |
if (th->hit[h]->dcl[d].is_reported) |
| 1355 |
{ |
| 1356 |
nd++; |
| 1357 |
if (pli->long_targets) |
| 1358 |
{ |
| 1359 |
if (fprintf(ofp, " %c %6.1f %5.1f %9.2g %9d %9d %c%c %9" PRId64 " %9" PRId64 " %c%c %9" PRId64 " %9" PRId64 " %c%c %9" PRId64 " %4.2f\n", |
| 1360 |
|
| 1361 |
th->hit[h]->dcl[d].is_included ? '!' : '?', |
| 1362 |
th->hit[h]->dcl[d].bitscore, |
| 1363 |
th->hit[h]->dcl[d].dombias * eslCONST_LOG2R, |
| 1364 |
exp(th->hit[h]->dcl[d].lnP), |
| 1365 |
th->hit[h]->dcl[d].ad->hmmfrom, |
| 1366 |
th->hit[h]->dcl[d].ad->hmmto, |
| 1367 |
(th->hit[h]->dcl[d].ad->hmmfrom == 1) ? '[' : '.', |
| 1368 |
(th->hit[h]->dcl[d].ad->hmmto == th->hit[h]->dcl[d].ad->M) ? ']' : '.', |
| 1369 |
th->hit[h]->dcl[d].ad->sqfrom, |
| 1370 |
th->hit[h]->dcl[d].ad->sqto, |
| 1371 |
(th->hit[h]->dcl[d].ad->sqfrom == 1) ? '[' : '.', |
| 1372 |
(th->hit[h]->dcl[d].ad->sqto == th->hit[h]->dcl[d].ad->L) ? ']' : '.', |
| 1373 |
th->hit[h]->dcl[d].ienv, |
| 1374 |
th->hit[h]->dcl[d].jenv, |
| 1375 |
(th->hit[h]->dcl[d].ienv == 1) ? '[' : '.', |
| 1376 |
(th->hit[h]->dcl[d].jenv == th->hit[h]->dcl[d].ad->L) ? ']' : '.', |
| 1377 |
th->hit[h]->dcl[d].ad->L, |
| 1378 |
(th->hit[h]->dcl[d].oasc / (1.0 + fabs((float) (th->hit[h]->dcl[d].jenv - th->hit[h]->dcl[d].ienv))))) < 0) |
| 1379 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1380 |
} |
| 1381 |
else |
| 1382 |
{ |
| 1383 |
if (fprintf(ofp, " %3d %c %6.1f %5.1f %9.2g %9.2g %7d %7d %c%c", |
| 1384 |
nd, |
| 1385 |
th->hit[h]->dcl[d].is_included ? '!' : '?', |
| 1386 |
th->hit[h]->dcl[d].bitscore, |
| 1387 |
th->hit[h]->dcl[d].dombias * eslCONST_LOG2R, |
| 1388 |
exp(th->hit[h]->dcl[d].lnP) * pli->domZ, |
| 1389 |
exp(th->hit[h]->dcl[d].lnP) * pli->Z, |
| 1390 |
th->hit[h]->dcl[d].ad->hmmfrom, |
| 1391 |
th->hit[h]->dcl[d].ad->hmmto, |
| 1392 |
(th->hit[h]->dcl[d].ad->hmmfrom == 1) ? '[' : '.', |
| 1393 |
(th->hit[h]->dcl[d].ad->hmmto == th->hit[h]->dcl[d].ad->M ) ? ']' : '.') < 0) |
| 1394 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1395 |
|
| 1396 |
if (fprintf(ofp, " %7" PRId64 " %7" PRId64 " %c%c", |
| 1397 |
th->hit[h]->dcl[d].ad->sqfrom, |
| 1398 |
th->hit[h]->dcl[d].ad->sqto, |
| 1399 |
(th->hit[h]->dcl[d].ad->sqfrom == 1) ? '[' : '.', |
| 1400 |
(th->hit[h]->dcl[d].ad->sqto == th->hit[h]->dcl[d].ad->L) ? ']' : '.') < 0) |
| 1401 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1402 |
|
| 1403 |
if (fprintf(ofp, " %7" PRId64 " %7" PRId64 " %c%c", |
| 1404 |
th->hit[h]->dcl[d].ienv, |
| 1405 |
th->hit[h]->dcl[d].jenv, |
| 1406 |
(th->hit[h]->dcl[d].ienv == 1) ? '[' : '.', |
| 1407 |
(th->hit[h]->dcl[d].jenv == th->hit[h]->dcl[d].ad->L) ? ']' : '.') < 0) |
| 1408 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1409 |
|
| 1410 |
if (fprintf(ofp, " %4.2f\n", |
| 1411 |
(th->hit[h]->dcl[d].oasc / (1.0 + fabs((float) (th->hit[h]->dcl[d].jenv - th->hit[h]->dcl[d].ienv))))) < 0) |
| 1412 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1413 |
} |
| 1414 |
|
| 1415 |
} |
| 1416 |
} |
| 1417 |
|
| 1418 |
|
| 1419 |
if (pli->show_alignments) |
| 1420 |
{ |
| 1421 |
if (pli->long_targets) |
| 1422 |
{ |
| 1423 |
if (fprintf(ofp, "\n Alignment:\n") < 0) |
| 1424 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1425 |
} |
| 1426 |
else |
| 1427 |
{ |
| 1428 |
if (fprintf(ofp, "\n Alignments for each domain:\n") < 0) |
| 1429 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1430 |
nd = 0; |
| 1431 |
} |
| 1432 |
|
| 1433 |
for (d = 0; d < th->hit[h]->ndom; d++) |
| 1434 |
if (th->hit[h]->dcl[d].is_reported) |
| 1435 |
{ |
| 1436 |
nd++; |
| 1437 |
if (!pli->long_targets) |
| 1438 |
{ |
| 1439 |
if (fprintf(ofp, " == domain %d", nd ) < 0) |
| 1440 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1441 |
} |
| 1442 |
if (fprintf(ofp, " score: %.1f bits", th->hit[h]->dcl[d].bitscore) < 0) |
| 1443 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1444 |
if (!pli->long_targets) |
| 1445 |
{ |
| 1446 |
if (fprintf(ofp, "; conditional E-value: %.2g\n", exp(th->hit[h]->dcl[d].lnP) * pli->domZ) < 0) |
| 1447 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1448 |
} |
| 1449 |
else |
| 1450 |
{ |
| 1451 |
if (fprintf(ofp, "\n") < 0) |
| 1452 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1453 |
} |
| 1454 |
|
| 1455 |
if ((status = p7_alidisplay_Print(ofp, th->hit[h]->dcl[d].ad, 40, textw, pli)) != eslOK) return status; |
| 1456 |
|
| 1457 |
if (fprintf(ofp, "\n") < 0) |
| 1458 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1459 |
} |
| 1460 |
} |
| 1461 |
else |
| 1462 |
{ |
| 1463 |
if (fprintf(ofp, "\n") < 0) |
| 1464 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1465 |
} |
| 1466 |
|
| 1467 |
} |
| 1468 |
|
| 1469 |
if (th->nreported == 0) |
| 1470 |
{ |
| 1471 |
if (fprintf(ofp, "\n [No targets detected that satisfy reporting thresholds]\n") < 0) |
| 1472 |
ESL_EXCEPTION_SYS(eslEWRITE, "domain hit list: write failed"); |
| 1473 |
} |
| 1474 |
return eslOK; |
| 1475 |
} |
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
int |
| 1509 |
p7_tophits_Alignment(const P7_TOPHITS *th, const ESL_ALPHABET *abc, |
| 1510 |
ESL_SQ **inc_sqarr, P7_TRACE **inc_trarr, int inc_n, |
| 1511 |
int optflags, ESL_MSA **ret_msa) |
| 1512 |
{ |
| 1513 |
ESL_SQ **sqarr = NULL; |
| 1514 |
P7_TRACE **trarr = NULL; |
| 1515 |
ESL_MSA *msa = NULL; |
| 1516 |
int ndom = 0; |
| 1517 |
int M = 0; |
| 1518 |
int h, d, y; |
| 1519 |
int status; |
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
for (h = 0; h < th->N; h++) |
| 1529 |
if (th->hit[h]->flags & p7_IS_INCLUDED) |
| 1530 |
for (d = 0; d < th->hit[h]->ndom; d++) |
| 1531 |
if (th->hit[h]->dcl[d].is_included) |
| 1532 |
{ |
| 1533 |
if (M == 0) M = th->hit[h]->dcl[d].ad->M; |
| 1534 |
ndom++; |
| 1535 |
} |
| 1536 |
|
| 1537 |
if (inc_n) |
| 1538 |
{ |
| 1539 |
if (M == 0) M = inc_trarr[0]->M; |
| 1540 |
else if (M != inc_trarr[0]->M) |
| 1541 |
ESL_XEXCEPTION(eslECORRUPT, "top hits and included trace(s) have different profile lengths"); |
| 1542 |
} |
| 1543 |
if (inc_n+ndom == 0) { status = eslFAIL; goto ERROR; } |
| 1544 |
|
| 1545 |
|
| 1546 |
ESL_ALLOC(sqarr, sizeof(ESL_SQ *) * (ndom + inc_n)); |
| 1547 |
ESL_ALLOC(trarr, sizeof(P7_TRACE *) * (ndom + inc_n)); |
| 1548 |
|
| 1549 |
for (y = 0; y < inc_n; y++) { sqarr[y] = inc_sqarr[y]; trarr[y] = inc_trarr[y]; } |
| 1550 |
for (; y < (ndom+inc_n); y++) { sqarr[y] = NULL; trarr[y] = NULL; } |
| 1551 |
|
| 1552 |
|
| 1553 |
y = inc_n; |
| 1554 |
for (h = 0; h < th->N; h++) |
| 1555 |
if (th->hit[h]->flags & p7_IS_INCLUDED) |
| 1556 |
{ |
| 1557 |
for (d = 0; d < th->hit[h]->ndom; d++) |
| 1558 |
if (th->hit[h]->dcl[d].is_included) |
| 1559 |
{ |
| 1560 |
if ((status = p7_alidisplay_Backconvert(th->hit[h]->dcl[d].ad, abc, &(sqarr[y]), &(trarr[y]))) != eslOK) goto ERROR; |
| 1561 |
y++; |
| 1562 |
} |
| 1563 |
} |
| 1564 |
|
| 1565 |
|
| 1566 |
if ((status = p7_tracealign_Seqs(sqarr, trarr, inc_n+ndom, M, optflags, NULL, &msa)) != eslOK) goto ERROR; |
| 1567 |
|
| 1568 |
|
| 1569 |
for (y = inc_n; y < ndom+inc_n; y++) esl_sq_Destroy(sqarr[y]); |
| 1570 |
for (y = inc_n; y < ndom+inc_n; y++) p7_trace_Destroy(trarr[y]); |
| 1571 |
free(sqarr); |
| 1572 |
free(trarr); |
| 1573 |
*ret_msa = msa; |
| 1574 |
return eslOK; |
| 1575 |
|
| 1576 |
ERROR: |
| 1577 |
if (sqarr != NULL) { for (y = inc_n; y < ndom+inc_n; y++) if (sqarr[y] != NULL) esl_sq_Destroy(sqarr[y]); free(sqarr); } |
| 1578 |
if (trarr != NULL) { for (y = inc_n; y < ndom+inc_n; y++) if (trarr[y] != NULL) p7_trace_Destroy(trarr[y]); free(trarr); } |
| 1579 |
if (msa != NULL) esl_msa_Destroy(msa); |
| 1580 |
*ret_msa = NULL; |
| 1581 |
return status; |
| 1582 |
} |
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
int |
| 1610 |
p7_tophits_TabularTargets(FILE *ofp, char *qname, char *qacc, P7_TOPHITS *th, P7_PIPELINE *pli, int show_header) |
| 1611 |
{ |
| 1612 |
int qnamew = ESL_MAX(20, strlen(qname)); |
| 1613 |
int tnamew = ESL_MAX(20, p7_tophits_GetMaxNameLength(th)); |
| 1614 |
int qaccw = ((qacc != NULL) ? ESL_MAX(10, strlen(qacc)) : 10); |
| 1615 |
int taccw = ESL_MAX(10, p7_tophits_GetMaxAccessionLength(th)); |
| 1616 |
int posw = (pli->long_targets ? ESL_MAX(7, p7_tophits_GetMaxPositionLength(th)) : 0); |
| 1617 |
int h,d; |
| 1618 |
|
| 1619 |
if (show_header) |
| 1620 |
{ |
| 1621 |
if (pli->long_targets) |
| 1622 |
{ |
| 1623 |
if (fprintf(ofp, "#%-*s %-*s %-*s %-*s %s %s %*s %*s %*s %*s %*s %6s %9s %6s %5s %s\n", |
| 1624 |
tnamew-1, " target name", taccw, "accession", qnamew, "query name", qaccw, "accession", "hmmfrom", "hmm to", posw, "alifrom", posw, "ali to", posw, "envfrom", posw, "env to", posw, ( pli->mode == p7_SCAN_MODELS ? "modlen" : "sq len" ), "strand", " E-value", " score", " bias", "description of target") < 0) |
| 1625 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-sequence hit list: write failed"); |
| 1626 |
if (fprintf(ofp, "#%*s %*s %*s %*s %s %s %*s %*s %*s %*s %*s %6s %9s %6s %5s %s\n", |
| 1627 |
tnamew-1, "-------------------", taccw, "----------", qnamew, "--------------------", qaccw, "----------", "-------", "-------", posw, "-------", posw, "-------", posw, "-------", posw, "-------", posw, "-------", "------", "---------", "------", "-----", "---------------------") < 0) |
| 1628 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-per-sequence hit list: write failed"); |
| 1629 |
} |
| 1630 |
else |
| 1631 |
{ |
| 1632 |
if (fprintf(ofp, "#%*s %22s %22s %33s\n", tnamew+qnamew+taccw+qaccw+2, "", "--- full sequence ----", "--- best 1 domain ----", "--- domain number estimation ----") < 0) |
| 1633 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-sequence hit list: write failed"); |
| 1634 |
if (fprintf(ofp, "#%-*s %-*s %-*s %-*s %9s %6s %5s %9s %6s %5s %5s %3s %3s %3s %3s %3s %3s %3s %s\n", |
| 1635 |
tnamew-1, " target name", taccw, "accession", qnamew, "query name", qaccw, "accession", " E-value", " score", " bias", " E-value", " score", " bias", "exp", "reg", "clu", " ov", "env", "dom", "rep", "inc", "description of target") < 0) |
| 1636 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-sequence hit list: write failed"); |
| 1637 |
if (fprintf(ofp, "#%*s %*s %*s %*s %9s %6s %5s %9s %6s %5s %5s %3s %3s %3s %3s %3s %3s %3s %s\n", |
| 1638 |
tnamew-1, "-------------------", taccw, "----------", qnamew, "--------------------", qaccw, "----------", "---------", "------", "-----", "---------", "------", "-----", "---", "---", "---", "---", "---", "---", "---", "---", "---------------------") < 0) |
| 1639 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-sequence hit list: write failed"); |
| 1640 |
} |
| 1641 |
} |
| 1642 |
|
| 1643 |
for (h = 0; h < th->N; h++) |
| 1644 |
if (th->hit[h]->flags & p7_IS_REPORTED) |
| 1645 |
{ |
| 1646 |
d = th->hit[h]->best_domain; |
| 1647 |
if (pli->long_targets) |
| 1648 |
{ |
| 1649 |
if (fprintf(ofp, "%-*s %-*s %-*s %-*s %7d %7d %*" PRId64 " %*" PRId64 " %*" PRId64 " %*" PRId64 " %*" PRId64 " %6s %9.2g %6.1f %5.1f %s\n", |
| 1650 |
tnamew, th->hit[h]->name, |
| 1651 |
taccw, th->hit[h]->acc ? th->hit[h]->acc : "-", |
| 1652 |
qnamew, qname, |
| 1653 |
qaccw, ( (qacc != NULL && qacc[0] != '\0') ? qacc : "-"), |
| 1654 |
th->hit[h]->dcl[d].ad->hmmfrom, |
| 1655 |
th->hit[h]->dcl[d].ad->hmmto, |
| 1656 |
posw, th->hit[h]->dcl[d].iali, |
| 1657 |
posw, th->hit[h]->dcl[d].jali, |
| 1658 |
posw, th->hit[h]->dcl[d].ienv, |
| 1659 |
posw, th->hit[h]->dcl[d].jenv, |
| 1660 |
posw, th->hit[h]->dcl[0].ad->L, |
| 1661 |
(th->hit[h]->dcl[d].iali < th->hit[h]->dcl[d].jali ? " + " : " - "), |
| 1662 |
exp(th->hit[h]->lnP), |
| 1663 |
th->hit[h]->score, |
| 1664 |
th->hit[h]->dcl[d].dombias * eslCONST_LOG2R, |
| 1665 |
th->hit[h]->desc == NULL ? "-" : th->hit[h]->desc ) < 0) |
| 1666 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-sequence hit list: write failed"); |
| 1667 |
} |
| 1668 |
else |
| 1669 |
{ |
| 1670 |
if (fprintf(ofp, "%-*s %-*s %-*s %-*s %9.2g %6.1f %5.1f %9.2g %6.1f %5.1f %5.1f %3d %3d %3d %3d %3d %3d %3d %s\n", |
| 1671 |
tnamew, th->hit[h]->name, |
| 1672 |
taccw, th->hit[h]->acc ? th->hit[h]->acc : "-", |
| 1673 |
qnamew, qname, |
| 1674 |
qaccw, ( (qacc != NULL && qacc[0] != '\0') ? qacc : "-"), |
| 1675 |
exp(th->hit[h]->lnP) * pli->Z, |
| 1676 |
th->hit[h]->score, |
| 1677 |
th->hit[h]->pre_score - th->hit[h]->score, |
| 1678 |
exp(th->hit[h]->dcl[d].lnP) * pli->Z, |
| 1679 |
th->hit[h]->dcl[d].bitscore, |
| 1680 |
th->hit[h]->dcl[d].dombias * eslCONST_LOG2R, |
| 1681 |
th->hit[h]->nexpected, |
| 1682 |
th->hit[h]->nregions, |
| 1683 |
th->hit[h]->nclustered, |
| 1684 |
th->hit[h]->noverlaps, |
| 1685 |
th->hit[h]->nenvelopes, |
| 1686 |
th->hit[h]->ndom, |
| 1687 |
th->hit[h]->nreported, |
| 1688 |
th->hit[h]->nincluded, |
| 1689 |
(th->hit[h]->desc == NULL ? "-" : th->hit[h]->desc)) < 0) |
| 1690 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-sequence hit list: write failed"); |
| 1691 |
} |
| 1692 |
} |
| 1693 |
return eslOK; |
| 1694 |
} |
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
int |
| 1714 |
p7_tophits_TabularDomains(FILE *ofp, char *qname, char *qacc, P7_TOPHITS *th, P7_PIPELINE *pli, int show_header) |
| 1715 |
{ |
| 1716 |
|
| 1717 |
int qnamew = ESL_MAX(20, strlen(qname)); |
| 1718 |
int tnamew = ESL_MAX(20, p7_tophits_GetMaxNameLength(th)); |
| 1719 |
int qaccw = (qacc ? ESL_MAX(10, strlen(qacc)) : 10); |
| 1720 |
int taccw = ESL_MAX(10, p7_tophits_GetMaxAccessionLength(th)); |
| 1721 |
int tlen, qlen; |
| 1722 |
int h,d,nd; |
| 1723 |
|
| 1724 |
if (show_header) |
| 1725 |
{ |
| 1726 |
if (fprintf(ofp, "#%*s %22s %40s %11s %11s %11s\n", tnamew+qnamew-1+15+taccw+qaccw, "", "--- full sequence ---", "-------------- this domain -------------", "hmm coord", "ali coord", "env coord") < 0) |
| 1727 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-domain hit list: write failed"); |
| 1728 |
if (fprintf(ofp, "#%-*s %-*s %5s %-*s %-*s %5s %9s %6s %5s %3s %3s %9s %9s %6s %5s %5s %5s %5s %5s %5s %5s %4s %s\n", |
| 1729 |
tnamew-1, " target name", taccw, "accession", "tlen", qnamew, "query name", qaccw, "accession", "qlen", "E-value", "score", "bias", "#", "of", "c-Evalue", "i-Evalue", "score", "bias", "from", "to", "from", "to", "from", "to", "acc", "description of target") < 0) |
| 1730 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-domain hit list: write failed"); |
| 1731 |
if (fprintf(ofp, "#%*s %*s %5s %*s %*s %5s %9s %6s %5s %3s %3s %9s %9s %6s %5s %5s %5s %5s %5s %5s %5s %4s %s\n", |
| 1732 |
tnamew-1, "-------------------", taccw, "----------", "-----", qnamew, "--------------------", qaccw, "----------", "-----", "---------", "------", "-----", "---", "---", "---------", "---------", "------", "-----", "-----", "-----", "-----", "-----", "-----", "-----", "----", "---------------------") < 0) |
| 1733 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-domain hit list: write failed"); |
| 1734 |
} |
| 1735 |
|
| 1736 |
for (h = 0; h < th->N; h++) |
| 1737 |
if (th->hit[h]->flags & p7_IS_REPORTED) |
| 1738 |
{ |
| 1739 |
nd = 0; |
| 1740 |
for (d = 0; d < th->hit[h]->ndom; d++) |
| 1741 |
if (th->hit[h]->dcl[d].is_reported) |
| 1742 |
{ |
| 1743 |
nd++; |
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
if (pli->mode == p7_SEARCH_SEQS) { qlen = th->hit[h]->dcl[d].ad->M; tlen = th->hit[h]->dcl[d].ad->L; } |
| 1751 |
else { qlen = th->hit[h]->dcl[d].ad->L; tlen = th->hit[h]->dcl[d].ad->M; } |
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
if (fprintf(ofp, "%-*s %-*s %5d %-*s %-*s %5d %9.2g %6.1f %5.1f %3d %3d %9.2g %9.2g %6.1f %5.1f %5d %5d %5" PRId64 " %5" PRId64 " %5" PRId64 " %5" PRId64 " %4.2f %s\n", |
| 1756 |
tnamew, th->hit[h]->name, |
| 1757 |
taccw, th->hit[h]->acc ? th->hit[h]->acc : "-", |
| 1758 |
tlen, |
| 1759 |
qnamew, qname, |
| 1760 |
qaccw, ( (qacc != NULL && qacc[0] != '\0') ? qacc : "-"), |
| 1761 |
qlen, |
| 1762 |
exp(th->hit[h]->lnP) * pli->Z, |
| 1763 |
th->hit[h]->score, |
| 1764 |
th->hit[h]->pre_score - th->hit[h]->score, |
| 1765 |
nd, |
| 1766 |
th->hit[h]->nreported, |
| 1767 |
exp(th->hit[h]->dcl[d].lnP) * pli->domZ, |
| 1768 |
exp(th->hit[h]->dcl[d].lnP) * pli->Z, |
| 1769 |
th->hit[h]->dcl[d].bitscore, |
| 1770 |
th->hit[h]->dcl[d].dombias * eslCONST_LOG2R, |
| 1771 |
th->hit[h]->dcl[d].ad->hmmfrom, |
| 1772 |
th->hit[h]->dcl[d].ad->hmmto, |
| 1773 |
th->hit[h]->dcl[d].ad->sqfrom, |
| 1774 |
th->hit[h]->dcl[d].ad->sqto, |
| 1775 |
th->hit[h]->dcl[d].ienv, |
| 1776 |
th->hit[h]->dcl[d].jenv, |
| 1777 |
(th->hit[h]->dcl[d].oasc / (1.0 + fabs((float) (th->hit[h]->dcl[d].jenv - th->hit[h]->dcl[d].ienv)))), |
| 1778 |
(th->hit[h]->desc ? th->hit[h]->desc : "-")) < 0) |
| 1779 |
ESL_EXCEPTION_SYS(eslEWRITE, "tabular per-domain hit list: write failed"); |
| 1780 |
|
| 1781 |
} |
| 1782 |
} |
| 1783 |
return eslOK; |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
int |
| 1815 |
p7_tophits_TabularXfam(FILE *ofp, char *qname, char *qacc, P7_TOPHITS *th, P7_PIPELINE *pli) |
| 1816 |
{ |
| 1817 |
P7_TOPHITS *domHitlist = NULL; |
| 1818 |
P7_HIT *domhit = NULL; |
| 1819 |
int tnamew = ESL_MAX(20, p7_tophits_GetMaxNameLength(th)); |
| 1820 |
int taccw = ESL_MAX(20, p7_tophits_GetMaxAccessionLength(th)); |
| 1821 |
int qnamew = ESL_MAX(20, strlen(qname)); |
| 1822 |
int posw = (pli->long_targets ? ESL_MAX(7, p7_tophits_GetMaxPositionLength(th)) : 0); |
| 1823 |
int h,d; |
| 1824 |
int status; |
| 1825 |
|
| 1826 |
|
| 1827 |
if (pli->long_targets) |
| 1828 |
{ |
| 1829 |
if (fprintf(ofp, "# hit scores\n# ----------\n#\n") < 0) |
| 1830 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1831 |
if (fprintf(ofp, "# %-*s %-*s %-*s %6s %9s %5s %s %s %6s %*s %*s %*s %*s %*s %s\n", |
| 1832 |
tnamew-1, "target name", taccw, "acc", qnamew, "query name", "bits", " e-value", " bias", "hmm-st", "hmm-en", "strand", posw, "ali-st", posw, "ali-en", posw, "env-st", posw, "env-en", posw, ( pli->mode == p7_SCAN_MODELS ? "modlen" : "sq-len" ), "description of target") < 0) |
| 1833 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1834 |
if (fprintf(ofp, "# %-*s %-*s %-*s %6s %9s %5s %s %s %6s %*s %*s %*s %*s %*s %s\n", |
| 1835 |
tnamew-1, "-------------------", taccw, "-------------------", qnamew, "-------------------", "------", "---------", "-----", "-------", "-------", "------", posw, "-------", posw, "-------", posw, "-------", posw, "-------", posw, "-------", "---------------------") < 0) |
| 1836 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1837 |
|
| 1838 |
for (h = 0; h < th->N; h++) |
| 1839 |
if (th->hit[h]->flags & p7_IS_REPORTED) |
| 1840 |
{ |
| 1841 |
|
| 1842 |
if (fprintf(ofp, "%-*s %-*s %-*s %6.1f %9.2g %5.1f %7d %7d %s %*" PRId64 " %*" PRId64 " %*" PRId64 " %*" PRId64 " %*" PRId64 " %s\n", |
| 1843 |
tnamew, th->hit[h]->name, |
| 1844 |
taccw, ( pli->mode == p7_SCAN_MODELS ? (th->hit[h]->acc ? th->hit[h]->acc : "-") : ((qacc && qacc[0] != '\0') ? qacc : "-")), |
| 1845 |
qnamew, qname, |
| 1846 |
th->hit[h]->score, |
| 1847 |
exp(th->hit[h]->lnP), |
| 1848 |
th->hit[h]->dcl[0].dombias * eslCONST_LOG2R, |
| 1849 |
th->hit[h]->dcl[0].ad->hmmfrom, |
| 1850 |
th->hit[h]->dcl[0].ad->hmmto, |
| 1851 |
(th->hit[h]->dcl[0].iali < th->hit[h]->dcl[0].jali ? " + " : " - "), |
| 1852 |
posw, th->hit[h]->dcl[0].iali, |
| 1853 |
posw, th->hit[h]->dcl[0].jali, |
| 1854 |
posw, th->hit[h]->dcl[0].ienv, |
| 1855 |
posw, th->hit[h]->dcl[0].jenv, |
| 1856 |
posw, th->hit[h]->dcl[0].ad->L, |
| 1857 |
th->hit[h]->desc == NULL ? "-" : th->hit[h]->desc) < 0) |
| 1858 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1859 |
} |
| 1860 |
} |
| 1861 |
else |
| 1862 |
{ |
| 1863 |
if (fprintf(ofp, "# Sequence scores\n# ---------------\n#\n") < 0) |
| 1864 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1865 |
if (fprintf(ofp, "# %-*s %6s %9s %3s %5s %5s %s\n", |
| 1866 |
tnamew-1, "name", " bits", " E-value", "n", "exp", " bias", "description") < 0) |
| 1867 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1868 |
if (fprintf(ofp, "# %*s %6s %9s %3s %5s %5s %s\n", |
| 1869 |
tnamew-1, "-------------------", "------", "---------","---", "-----", "-----", "---------------------") < 0) |
| 1870 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1871 |
|
| 1872 |
for (h = 0; h < th->N; h++) |
| 1873 |
{ |
| 1874 |
if (th->hit[h]->flags & p7_IS_REPORTED) |
| 1875 |
{ |
| 1876 |
if (fprintf(ofp, "%-*s %6.1f %9.2g %3d %5.1f %5.1f %s\n", |
| 1877 |
tnamew, th->hit[h]->name, |
| 1878 |
th->hit[h]->score, |
| 1879 |
exp(th->hit[h]->lnP) * pli->Z, |
| 1880 |
th->hit[h]->ndom, |
| 1881 |
th->hit[h]->nexpected, |
| 1882 |
th->hit[h]->pre_score - th->hit[h]->score, |
| 1883 |
(th->hit[h]->desc == NULL ? "-" : th->hit[h]->desc)) < 0) |
| 1884 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1885 |
} |
| 1886 |
} |
| 1887 |
if (fprintf(ofp, "\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
if ((domHitlist = p7_tophits_Create()) == NULL) return eslEMEM; |
| 1893 |
for (h = 0; h < th->N; h++) |
| 1894 |
{ |
| 1895 |
if (th->hit[h]->flags & p7_IS_REPORTED) |
| 1896 |
{ |
| 1897 |
int ndomReported = 0; |
| 1898 |
for (d = 0; d < th->hit[h]->ndom; d++) |
| 1899 |
{ |
| 1900 |
if (th->hit[h]->dcl[d].is_reported) |
| 1901 |
{ |
| 1902 |
p7_tophits_CreateNextHit(domHitlist, &domhit); |
| 1903 |
ndomReported++; |
| 1904 |
ESL_ALLOC(domhit->dcl, sizeof(P7_DOMAIN) ); |
| 1905 |
|
| 1906 |
domhit->ndom = ndomReported; |
| 1907 |
domhit->name = th->hit[h]->name; |
| 1908 |
domhit->desc = th->hit[h]->desc; |
| 1909 |
domhit->dcl[0] = th->hit[h]->dcl[d]; |
| 1910 |
domhit->sortkey = pli->inc_by_E ? -1.0 * th->hit[h]->dcl[d].lnP : th->hit[h]->dcl[d].bitscore; |
| 1911 |
} |
| 1912 |
} |
| 1913 |
} |
| 1914 |
} |
| 1915 |
p7_tophits_SortBySortkey(domHitlist); |
| 1916 |
|
| 1917 |
|
| 1918 |
if (fprintf(ofp, "# Domain scores\n# -------------\n#\n") < 0) |
| 1919 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1920 |
if (fprintf(ofp, "# %-*s %6s %9s %5s %5s %6s %6s %6s %6s %6s %6s %s\n", |
| 1921 |
tnamew-1, " name", "bits", "E-value", "hit", "bias", "env-st", "env-en", "ali-st", "ali-en", "hmm-st", "hmm-en", "description") < 0) |
| 1922 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1923 |
if (fprintf(ofp, "# %*s %6s %9s %5s %5s %6s %6s %6s %6s %6s %6s %s\n", |
| 1924 |
tnamew-1, "-------------------", "------", "---------", "-----", "-----", "------", "------", "------", "------", "------", "------", "---------------------") < 0) |
| 1925 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1926 |
|
| 1927 |
for (h = 0; h < domHitlist->N; h++) |
| 1928 |
{ |
| 1929 |
domhit = domHitlist->hit[h]; |
| 1930 |
|
| 1931 |
if (fprintf(ofp, "%-*s %6.1f %9.2g %5d %5.1f %6" PRId64 " %6" PRId64 " %6" PRId64 " %6" PRId64 " %6d %6d %s\n", |
| 1932 |
tnamew, domHitlist->hit[h]->name, |
| 1933 |
domhit->dcl[0].bitscore, |
| 1934 |
exp(domhit->dcl[0].lnP) * pli->Z, |
| 1935 |
domhit->ndom, |
| 1936 |
domhit->dcl[0].dombias * eslCONST_LOG2R, |
| 1937 |
domhit->dcl[0].ienv, |
| 1938 |
domhit->dcl[0].jenv, |
| 1939 |
domhit->dcl[0].ad->sqfrom, |
| 1940 |
domhit->dcl[0].ad->sqto, |
| 1941 |
domhit->dcl[0].ad->hmmfrom, |
| 1942 |
domhit->dcl[0].ad->hmmto, |
| 1943 |
(domhit->desc ? domhit->desc : "-")) < 0) |
| 1944 |
ESL_XEXCEPTION_SYS(eslEWRITE, "xfam tabular output: write failed"); |
| 1945 |
} |
| 1946 |
free (domHitlist->unsrt); |
| 1947 |
free (domHitlist->hit); |
| 1948 |
free (domHitlist); |
| 1949 |
} |
| 1950 |
return eslOK; |
| 1951 |
|
| 1952 |
ERROR: |
| 1953 |
if (domHitlist) |
| 1954 |
{ |
| 1955 |
free (domHitlist->unsrt); |
| 1956 |
free (domHitlist->hit); |
| 1957 |
free (domHitlist); |
| 1958 |
} |
| 1959 |
return status; |
| 1960 |
} |
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
int |
| 1974 |
p7_tophits_AliScores(FILE *ofp, char *qname, P7_TOPHITS *th ) |
| 1975 |
{ |
| 1976 |
P7_HIT *hit; |
| 1977 |
int h, i; |
| 1978 |
float *scores; |
| 1979 |
|
| 1980 |
for (h = 0; h < th->N; h++) { |
| 1981 |
hit = th->hit[h]; |
| 1982 |
if (hit->flags & p7_IS_REPORTED) |
| 1983 |
{ |
| 1984 |
fprintf (ofp, "%s %s %" PRId64 " %" PRId64 " :", qname, hit->name, hit->dcl[0].iali, hit->dcl[0].jali); |
| 1985 |
|
| 1986 |
scores = hit->dcl[0].scores_per_pos; |
| 1987 |
for (i=0; i<hit->dcl[0].ad->N; i++) { |
| 1988 |
if (scores[i] == -eslINFINITY) |
| 1989 |
fprintf (ofp, " >"); |
| 1990 |
else |
| 1991 |
fprintf (ofp, " %.3f", scores[i] * eslCONST_LOG2R); |
| 1992 |
|
| 1993 |
} |
| 1994 |
fprintf (ofp, "\n"); |
| 1995 |
} |
| 1996 |
|
| 1997 |
} |
| 1998 |
return eslOK; |
| 1999 |
|
| 2000 |
} |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| •2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
int |
| 2031 |
p7_tophits_TabularTail(FILE *ofp, const char *progname, enum p7_pipemodes_e pipemode, const char *qfile, const char *tfile, const ESL_GETOPTS *go) |
| 2032 |
{ |
| 2033 |
time_t date = time(NULL); |
| 2034 |
char *spoof_cmd = NULL; |
| 2035 |
char *cwd = NULL; |
| 2036 |
char timestamp[32]; |
| 2037 |
char modestamp[16]; |
| 2038 |
int status; |
| 2039 |
|
| 2040 |
|
| 2041 |
if ((status = esl_opt_SpoofCmdline(go, &spoof_cmd)) != eslOK) goto ERROR; |
| 2042 |
if (date == -1) ESL_XEXCEPTION(eslESYS, "time() failed"); |
| 2043 |
if ((ctime_r(&date, timestamp)) == NULL) ESL_XEXCEPTION(eslESYS, "ctime_r() failed"); |
| 2044 |
switch (pipemode) { |
| 2045 |
case p7_SEARCH_SEQS: strcpy(modestamp, "SEARCH"); break; |
| 2046 |
case p7_SCAN_MODELS: strcpy(modestamp, "SCAN"); break; |
| 2047 |
default: ESL_EXCEPTION(eslEINCONCEIVABLE, "wait, what? no such pipemode"); |
| 2048 |
} |
| 2049 |
esl_getcwd(&cwd); |
| 2050 |
|
| 2051 |
if (fprintf(ofp, "#\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2052 |
if (fprintf(ofp, "# Program: %s\n", (progname == NULL) ? "[none]" : progname) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2053 |
if (fprintf(ofp, "# Version: %s (%s)\n", HMMER_VERSION, HMMER_DATE) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2054 |
if (fprintf(ofp, "# Pipeline mode: %s\n", modestamp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2055 |
if (fprintf(ofp, "# Query file: %s\n", (qfile == NULL) ? "[none]" : qfile) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2056 |
if (fprintf(ofp, "# Target file: %s\n", (tfile == NULL) ? "[none]" : tfile) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2057 |
if (fprintf(ofp, "# Option settings: %s\n", spoof_cmd) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2058 |
if (getenv("SOURCE_DATE_EPOCH") != NULL) { |
| 2059 |
if (fprintf(ofp, "# Current dir: %s\n", (cwd == NULL) ? "[unknown]" : cwd) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2060 |
if (fprintf(ofp, "# Date: %s", timestamp) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2061 |
} |
| 2062 |
if (fprintf(ofp, "# [ok]\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "tabular output tail, write failed"); |
| 2063 |
|
| 2064 |
free(spoof_cmd); |
| 2065 |
if (cwd) free(cwd); |
| 2066 |
return eslOK; |
| 2067 |
|
| 2068 |
ERROR: |
| 2069 |
if (spoof_cmd) free(spoof_cmd); |
| 2070 |
if (cwd) free(cwd); |
| 2071 |
return status; |
| 2072 |
} |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
#ifdef p7TOPHITS_BENCHMARK |
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
#include <p7_config.h> |
| 2092 |
|
| 2093 |
#include "easel.h" |
| 2094 |
#include "esl_getopts.h" |
| 2095 |
#include "esl_stopwatch.h" |
| 2096 |
#include "esl_random.h" |
| 2097 |
|
| 2098 |
#include "hmmer.h" |
| 2099 |
|
| 2100 |
static ESL_OPTIONS options[] = { |
| 2101 |
|
| 2102 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 2103 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 2104 |
{ "-M", eslARG_INT, "10", NULL, NULL, NULL, NULL, NULL, "number of top hits lists to simulate and merge", 0 }, |
| 2105 |
{ "-N", eslARG_INT, "10000", NULL, NULL, NULL, NULL, NULL, "number of top hits to simulate", 0 }, |
| 2106 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 2107 |
}; |
| 2108 |
static char usage[] = "[-options]"; |
| 2109 |
static char banner[] = "benchmark driver for P7_TOPHITS"; |
| 2110 |
|
| 2111 |
int |
| 2112 |
main(int argc, char **argv) |
| 2113 |
{ |
| 2114 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 2115 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 2116 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 2117 |
int N = esl_opt_GetInteger(go, "-N"); |
| 2118 |
int M = esl_opt_GetInteger(go, "-M"); |
| 2119 |
P7_TOPHITS **h = NULL; |
| 2120 |
double *sortkeys = NULL; |
| 2121 |
char name[] = "not_unique_name"; |
| 2122 |
char acc[] = "not_unique_acc"; |
| 2123 |
char desc[] = "Test description for the purposes of making the benchmark allocate space"; |
| 2124 |
int i,j; |
| 2125 |
int status; |
| 2126 |
|
| 2127 |
|
| 2128 |
ESL_ALLOC(h, sizeof(P7_TOPHITS *) * M); |
| 2129 |
ESL_ALLOC(sortkeys, sizeof(double) * N * M); |
| 2130 |
for (i = 0; i < N*M; i++) sortkeys[i] = esl_random(r); |
| 2131 |
|
| 2132 |
esl_stopwatch_Start(w); |
| 2133 |
|
| 2134 |
|
| 2135 |
for (j = 0; j < M; j++) |
| 2136 |
{ |
| 2137 |
h[j] = p7_tophits_Create(); |
| 2138 |
for (i = 0; i < N; i++) |
| 2139 |
p7_tophits_Add(h[j], name, acc, desc, sortkeys[j*N + i], |
| 2140 |
(float) sortkeys[j*N+i], sortkeys[j*N+i], |
| 2141 |
(float) sortkeys[j*N+i], sortkeys[j*N+i], |
| 2142 |
i, i, N, |
| 2143 |
i, i, N, |
| 2144 |
i, N, NULL); |
| 2145 |
p7_tophits_SortBySortkey(h[j]); |
| 2146 |
} |
| 2147 |
|
| 2148 |
for (j = 1; j < M; j++) |
| 2149 |
{ |
| 2150 |
p7_tophits_Merge(h[0], h[j]); |
| 2151 |
p7_tophits_Destroy(h[j]); |
| 2152 |
} |
| 2153 |
|
| 2154 |
esl_stopwatch_Stop(w); |
| 2155 |
|
| 2156 |
p7_tophits_Destroy(h[0]); |
| 2157 |
status = eslOK; |
| 2158 |
ERROR: |
| 2159 |
esl_getopts_Destroy(go); |
| 2160 |
esl_stopwatch_Destroy(w); |
| 2161 |
esl_randomness_Destroy(r); |
| 2162 |
if (sortkeys != NULL) free(sortkeys); |
| 2163 |
if (h != NULL) free(h); |
| 2164 |
return status; |
| 2165 |
} |
| 2166 |
#endif |
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
#ifdef p7TOPHITS_TESTDRIVE |
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
#include <p7_config.h> |
| 2179 |
|
| 2180 |
#include "easel.h" |
| 2181 |
#include "esl_getopts.h" |
| 2182 |
#include "esl_stopwatch.h" |
| 2183 |
#include "esl_random.h" |
| 2184 |
|
| 2185 |
#include "hmmer.h" |
| 2186 |
|
| 2187 |
static ESL_OPTIONS options[] = { |
| 2188 |
|
| 2189 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 2190 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 2191 |
{ "-N", eslARG_INT, "100", NULL, NULL, NULL, NULL, NULL, "number of top hits to simulate", 0 }, |
| 2192 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 2193 |
}; |
| 2194 |
|
| 2195 |
static char usage[] = "[-options]"; |
| 2196 |
static char banner[] = "test driver for P7_TOPHITS"; |
| 2197 |
|
| 2198 |
int |
| 2199 |
main(int argc, char **argv) |
| 2200 |
{ |
| 2201 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 2202 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 2203 |
int N = esl_opt_GetInteger(go, "-N"); |
| 2204 |
P7_TOPHITS *h1 = NULL; |
| 2205 |
P7_TOPHITS *h2 = NULL; |
| 2206 |
P7_TOPHITS *h3 = NULL; |
| 2207 |
char name[] = "not_unique_name"; |
| 2208 |
char acc[] = "not_unique_acc"; |
| 2209 |
char desc[] = "Test description for the purposes of making the test driver allocate space"; |
| 2210 |
double key; |
| 2211 |
int i; |
| 2212 |
|
| 2213 |
h1 = p7_tophits_Create(); |
| 2214 |
h2 = p7_tophits_Create(); |
| 2215 |
h3 = p7_tophits_Create(); |
| 2216 |
|
| 2217 |
for (i = 0; i < N; i++) |
| 2218 |
{ |
| 2219 |
key = esl_random(r); |
| 2220 |
p7_tophits_Add(h1, name, acc, desc, key, (float) key, key, (float) key, key, i, i, N, i, i, N, 1, 1, NULL); |
| 2221 |
key = 10.0 * esl_random(r); |
| 2222 |
p7_tophits_Add(h2, name, acc, desc, key, (float) key, key, (float) key, key, i, i, N, i, i, N, 2, 2, NULL); |
| 2223 |
key = 0.1 * esl_random(r); |
| 2224 |
p7_tophits_Add(h3, name, acc, desc, key, (float) key, key, (float) key, key, i, i, N, i, i, N, 3, 3, NULL); |
| 2225 |
} |
| 2226 |
p7_tophits_Add(h1, "last", NULL, NULL, -1.0, (float) key, key, (float) key, key, i, i, N, i, i, N, 1, 1, NULL); |
| 2227 |
p7_tophits_Add(h1, "first", NULL, NULL, 20.0, (float) key, key, (float) key, key, i, i, N, i, i, N, 1, 1, NULL); |
| 2228 |
|
| 2229 |
p7_tophits_SortBySortkey(h1); |
| 2230 |
if (strcmp(h1->hit[0]->name, "first") != 0) esl_fatal("sort failed (top is %s = %f)", h1->hit[0]->name, h1->hit[0]->sortkey); |
| 2231 |
if (strcmp(h1->hit[N+1]->name, "last") != 0) esl_fatal("sort failed (last is %s = %f)", h1->hit[N+1]->name, h1->hit[N+1]->sortkey); |
| 2232 |
|
| 2233 |
p7_tophits_Merge(h1, h2); |
| 2234 |
if (strcmp(h1->hit[0]->name, "first") != 0) esl_fatal("after merge 1, sort failed (top is %s = %f)", h1->hit[0]->name, h1->hit[0]->sortkey); |
| 2235 |
if (strcmp(h1->hit[2*N+1]->name, "last") != 0) esl_fatal("after merge 1, sort failed (last is %s = %f)", h1->hit[2*N+1]->name, h1->hit[2*N+1]->sortkey); |
| 2236 |
|
| 2237 |
p7_tophits_Merge(h3, h1); |
| 2238 |
if (strcmp(h3->hit[0]->name, "first") != 0) esl_fatal("after merge 2, sort failed (top is %s = %f)", h3->hit[0]->name, h3->hit[0]->sortkey); |
| 2239 |
if (strcmp(h3->hit[3*N+1]->name, "last") != 0) esl_fatal("after merge 2, sort failed (last is %s = %f)", h3->hit[3*N+1]->name, h3->hit[3*N+1]->sortkey); |
| 2240 |
|
| 2241 |
if (p7_tophits_GetMaxNameLength(h3) != strlen(name)) esl_fatal("GetMaxNameLength() failed"); |
| 2242 |
|
| 2243 |
p7_tophits_Destroy(h1); |
| 2244 |
p7_tophits_Destroy(h2); |
| 2245 |
p7_tophits_Destroy(h3); |
| 2246 |
esl_randomness_Destroy(r); |
| 2247 |
esl_getopts_Destroy(go); |
| 2248 |
return eslOK; |
| 2249 |
} |
| 2250 |
#endif |
| 2251 |
|
| 2252 |
|
| 2253 |
|