| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include <p7_config.h> |
| 14 |
|
| 15 |
#include <stdlib.h> |
| 16 |
#include <stdio.h> |
| 17 |
#include <string.h> |
| 18 |
#include <ctype.h> |
| 19 |
#include <string.h> |
| 20 |
|
| 21 |
#include "easel.h" |
| 22 |
#include "hmmer.h" |
| 23 |
|
| 24 |
|
| 25 |
#define RFLINE_PRESENT (1 << 0) |
| 26 |
#define MMLINE_PRESENT (1 << 1) |
| 27 |
#define CSLINE_PRESENT (1 << 2) |
| 28 |
#define PPLINE_PRESENT (1 << 3) |
| 29 |
#define ASEQ_PRESENT (1 << 4) |
| 30 |
#define NTSEQ_PRESENT (1 << 5) |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
P7_ALIDISPLAY * |
| 92 |
p7_alidisplay_Create(const P7_TRACE *tr, int which, const P7_OPROFILE *om, const ESL_SQ *sq, const ESL_SQ *ntsq) |
| 93 |
{ |
| 94 |
P7_ALIDISPLAY *ad = NULL; |
| 95 |
char *Alphabet = om->abc->sym; |
| 96 |
int n, pos, z; |
| 97 |
int z1,z2; |
| 98 |
int k,x,i,s; |
| 99 |
int hmm_namelen, hmm_acclen, hmm_desclen; |
| 100 |
int sq_namelen, sq_acclen, sq_desclen; |
| 101 |
int status; |
| 102 |
ESL_SQ *ntorfseqtxt = NULL; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
if (tr->ndom > 0) { |
| 108 |
for (z1 = tr->tfrom[which]; z1 < tr->N; z1++) if (tr->st[z1] == p7T_M) break; |
| 109 |
if (z1 == tr->N) return NULL; |
| 110 |
for (z2 = tr->tto[which]; z2 >= 0 ; z2--) if (tr->st[z2] == p7T_M) break; |
| 111 |
if (z2 == -1) return NULL; |
| 112 |
} else { |
| 113 |
for (z1 = 0; which >= 0 && z1 < tr->N; z1++) if (tr->st[z1] == p7T_B) which--; |
| 114 |
if (z1 == tr->N) return NULL; |
| 115 |
for (; z1 < tr->N; z1++) if (tr->st[z1] == p7T_M) break; |
| 116 |
if (z1 == tr->N) return NULL; |
| 117 |
for (z2 = z1; z2 < tr->N; z2++) if (tr->st[z2] == p7T_E) break; |
| 118 |
for (; z2 >= 0; z2--) if (tr->st[z2] == p7T_M) break; |
| 119 |
if (z2 == -1) return NULL; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
n = (z2-z1+2) * 3; |
| 134 |
|
| 135 |
if (om->rf[0] != 0) n += z2-z1+2; |
| 136 |
if (om->mm[0] != 0) n += z2-z1+2; |
| 137 |
if (om->cs[0] != 0) n += z2-z1+2; |
| 138 |
if (tr->pp != NULL) n += z2-z1+2; |
| 139 |
hmm_namelen = strlen(om->name); n += hmm_namelen + 1; |
| 140 |
hmm_acclen = (om->acc != NULL ? strlen(om->acc) : 0); n += hmm_acclen + 1; |
| 141 |
hmm_desclen = (om->desc != NULL ? strlen(om->desc) : 0); n += hmm_desclen + 1; |
| 142 |
|
| 143 |
sq_namelen = strlen(sq->name); n += sq_namelen + 1; |
| 144 |
sq_acclen = strlen(sq->acc); n += sq_acclen + 1; |
| 145 |
sq_desclen = strlen(sq->desc); n += sq_desclen + 1; |
| 146 |
|
| 147 |
ESL_ALLOC(ad, sizeof(P7_ALIDISPLAY)); |
| 148 |
ad->mem = NULL; |
| 149 |
|
| 150 |
pos = 0; |
| 151 |
ad->memsize = sizeof(char) * n; |
| 152 |
ESL_ALLOC(ad->mem, ad->memsize); |
| 153 |
if (om->rf[0] != 0) { ad->rfline = ad->mem + pos; pos += z2-z1+2; } else { ad->rfline = NULL; } |
| 154 |
|
| 155 |
ad->mmline = NULL; |
| 156 |
if (om->cs[0] != 0) { ad->csline = ad->mem + pos; pos += z2-z1+2; } else { ad->csline = NULL; } |
| 157 |
ad->model = ad->mem + pos; pos += z2-z1+2; |
| 158 |
ad->mline = ad->mem + pos; pos += z2-z1+2; |
| 159 |
ad->aseq = ad->mem + pos; pos += z2-z1+2; |
| 160 |
|
| 161 |
if (tr->pp != NULL) { ad->ppline = ad->mem + pos; pos += z2-z1+2;} else { ad->ppline = NULL; } |
| 162 |
ad->hmmname = ad->mem + pos; pos += hmm_namelen +1; |
| 163 |
ad->hmmacc = ad->mem + pos; pos += hmm_acclen +1; |
| 164 |
ad->hmmdesc = ad->mem + pos; pos += hmm_desclen +1; |
| 165 |
ad->sqname = ad->mem + pos; pos += sq_namelen +1; |
| 166 |
ad->sqacc = ad->mem + pos; pos += sq_acclen +1; |
| 167 |
ad->sqdesc = ad->mem + pos; pos += sq_desclen +1; |
| 168 |
|
| 169 |
strcpy(ad->hmmname, om->name); |
| 170 |
if (om->acc != NULL) strcpy(ad->hmmacc, om->acc); else ad->hmmacc[0] = 0; |
| 171 |
if (om->desc != NULL) strcpy(ad->hmmdesc, om->desc); else ad->hmmdesc[0] = 0; |
| 172 |
|
| 173 |
strcpy(ad->sqname, sq->name); |
| 174 |
strcpy(ad->sqacc, sq->acc); |
| 175 |
strcpy(ad->sqdesc, sq->desc); |
| 176 |
|
| 177 |
|
| 178 |
ad->hmmfrom = tr->k[z1]; |
| 179 |
ad->hmmto = tr->k[z2]; |
| 180 |
ad->M = om->M; |
| 181 |
|
| 182 |
ad->sqfrom = tr->i[z1]; |
| 183 |
ad->sqto = tr->i[z2]; |
| 184 |
ad->L = sq->n; |
| 185 |
|
| 186 |
|
| 187 |
if (ad->rfline != NULL) { |
| 188 |
for (z = z1; z <= z2; z++) ad->rfline[z-z1] = ((tr->st[z] == p7T_I) ? '.' : om->rf[tr->k[z]]); |
| 189 |
ad->rfline[z-z1] = '\0'; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
if (ad->mmline != NULL) { |
| 194 |
for (z = z1; z <= z2; z++) ad->mmline[z-z1] = ((tr->st[z] == p7T_I) ? '.' : om->mm[tr->k[z]]); |
| 195 |
ad->mmline[z-z1] = '\0'; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
if (ad->csline != NULL) { |
| 200 |
for (z = z1; z <= z2; z++) ad->csline[z-z1] = ((tr->st[z] == p7T_I) ? '.' : om->cs[tr->k[z]]); |
| 201 |
ad->csline[z-z1] = '\0'; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
if (ad->ppline != NULL) { |
| 206 |
for (z = z1; z <= z2; z++) ad->ppline[z-z1] = ( (tr->st[z] == p7T_D) ? '.' : p7_alidisplay_EncodePostProb(tr->pp[z])); |
| 207 |
ad->ppline[z-z1] = '\0'; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
for (z = z1; z <= z2; z++) |
| 213 |
{ |
| 214 |
k = tr->k[z]; |
| 215 |
i = tr->i[z]; |
| 216 |
x = sq->dsq[i]; |
| 217 |
s = tr->st[z]; |
| 218 |
|
| 219 |
switch (s) { |
| 220 |
case p7T_M: |
| 221 |
ad->model[z-z1] = om->consensus[k]; |
| 222 |
if (x == esl_abc_DigitizeSymbol(om->abc, om->consensus[k])) ad->mline[z-z1] = ad->model[z-z1]; |
| 223 |
else if (p7_oprofile_FGetEmission(om, k, x) > 1.0) ad->mline[z-z1] = '+'; |
| 224 |
else ad->mline[z-z1] = ' '; |
| 225 |
ad->aseq [z-z1] = toupper(Alphabet[x]); |
| 226 |
break; |
| 227 |
|
| 228 |
case p7T_I: |
| 229 |
ad->model [z-z1] = '.'; |
| 230 |
ad->mline [z-z1] = ' '; |
| 231 |
ad->aseq [z-z1] = tolower(Alphabet[x]); |
| 232 |
break; |
| 233 |
|
| 234 |
case p7T_D: |
| 235 |
ad->model [z-z1] = om->consensus[k]; |
| 236 |
ad->mline [z-z1] = ' '; |
| 237 |
ad->aseq [z-z1] = '-'; |
| 238 |
|
| 239 |
break; |
| 240 |
|
| 241 |
default: ESL_XEXCEPTION(eslEINVAL, "invalid state in trace: not M,D,I"); |
| 242 |
} |
| 243 |
} |
| 244 |
ad->model [z2-z1+1] = '\0'; |
| 245 |
ad->mline [z2-z1+1] = '\0'; |
| 246 |
ad->aseq [z2-z1+1] = '\0'; |
| 247 |
ad->N = z2-z1+1; |
| 248 |
ad->ntseq = NULL; |
| 249 |
|
| 250 |
esl_sq_Destroy(ntorfseqtxt); |
| 251 |
|
| 252 |
|
| 253 |
return ad; |
| 254 |
|
| 255 |
ERROR: |
| 256 |
p7_alidisplay_Destroy(ad); |
| 257 |
return NULL; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
extern P7_ALIDISPLAY *p7_alidisplay_Create_empty() |
| 273 |
{ |
| 274 |
P7_ALIDISPLAY *new_obj; |
| 275 |
int status; |
| 276 |
|
| 277 |
ESL_ALLOC(new_obj, sizeof(P7_ALIDISPLAY)); |
| 278 |
|
| 279 |
|
| 280 |
new_obj->rfline = NULL; |
| 281 |
new_obj->mmline = NULL; |
| 282 |
new_obj->csline = NULL; |
| 283 |
new_obj->model = NULL; |
| 284 |
new_obj->mline = NULL; |
| 285 |
new_obj->aseq = NULL; |
| 286 |
new_obj->ntseq = NULL; |
| 287 |
new_obj->ppline = NULL; |
| 288 |
new_obj->N = 0; |
| 289 |
|
| 290 |
new_obj->hmmname = NULL; |
| 291 |
new_obj->hmmacc = NULL; |
| 292 |
new_obj->hmmdesc = NULL; |
| 293 |
new_obj->hmmfrom = 0; |
| 294 |
new_obj->hmmto = 0; |
| 295 |
new_obj->M = 0; |
| 296 |
|
| 297 |
new_obj->sqname = NULL; |
| 298 |
new_obj->sqacc = NULL; |
| 299 |
new_obj->sqdesc = NULL; |
| 300 |
new_obj->sqfrom = 0; |
| 301 |
new_obj->sqto = 0; |
| 302 |
new_obj->L = 0; |
| 303 |
|
| 304 |
new_obj->memsize = 0; |
| 305 |
new_obj->mem = NULL; |
| 306 |
|
| 307 |
return new_obj; |
| 308 |
|
| 309 |
ERROR: |
| 310 |
return NULL; |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
P7_ALIDISPLAY * |
| 324 |
p7_alidisplay_Clone(const P7_ALIDISPLAY *ad) |
| 325 |
{ |
| 326 |
P7_ALIDISPLAY *ad2 = NULL; |
| 327 |
int status; |
| 328 |
|
| 329 |
ESL_ALLOC(ad2, sizeof(P7_ALIDISPLAY)); |
| 330 |
ad2->rfline = ad2->mmline = ad2->csline = ad2->model = ad2->mline = ad2->aseq = ad2->ntseq = ad2->ppline = NULL; |
| 331 |
ad2->hmmname = ad2->hmmacc = ad2->hmmdesc = NULL; |
| 332 |
ad2->sqname = ad2->sqacc = ad2->sqdesc = NULL; |
| 333 |
ad2->mem = NULL; |
| 334 |
ad2->memsize = 0; |
| 335 |
|
| 336 |
if (ad->memsize) |
| 337 |
{ |
| 338 |
ESL_ALLOC(ad2->mem, sizeof(char) * ad->memsize); |
| 339 |
ad2->memsize = ad->memsize; |
| 340 |
memcpy(ad2->mem, ad->mem, ad->memsize); |
| 341 |
|
| 342 |
ad2->rfline = (ad->rfline ? ad2->mem + (ad->rfline - ad->mem) : NULL ); |
| 343 |
ad2->mmline = (ad->mmline ? ad2->mem + (ad->mmline - ad->mem) : NULL ); |
| 344 |
ad2->csline = (ad->csline ? ad2->mem + (ad->csline - ad->mem) : NULL ); |
| 345 |
ad2->model = ad2->mem + (ad->model - ad->mem); |
| 346 |
ad2->mline = ad2->mem + (ad->mline - ad->mem); |
| 347 |
ad2->aseq = ad2->mem + (ad->aseq - ad->mem); |
| 348 |
ad2->ntseq = (ad->ntseq ? ad2->mem + (ad->ntseq - ad->mem) : NULL ); |
| 349 |
ad2->ppline = (ad->ppline ? ad2->mem + (ad->ppline - ad->mem) : NULL ); |
| 350 |
ad2->N = ad->N; |
| 351 |
|
| 352 |
ad2->hmmname = ad2->mem + (ad->hmmname - ad->mem); |
| 353 |
ad2->hmmacc = ad2->mem + (ad->hmmacc - ad->mem); |
| 354 |
ad2->hmmdesc = ad2->mem + (ad->hmmdesc - ad->mem); |
| 355 |
ad2->hmmfrom = ad->hmmfrom; |
| 356 |
ad2->hmmto = ad->hmmto; |
| 357 |
ad2->M = ad->M; |
| 358 |
|
| 359 |
ad2->sqname = ad2->mem + (ad->sqname - ad->mem); |
| 360 |
ad2->sqacc = ad2->mem + (ad->sqacc - ad->mem); |
| 361 |
ad2->sqdesc = ad2->mem + (ad->sqdesc - ad->mem); |
| 362 |
ad2->sqfrom = ad->sqfrom; |
| 363 |
ad2->sqto = ad->sqto; |
| 364 |
ad2->L = ad->L; |
| 365 |
} |
| 366 |
else |
| 367 |
{ |
| 368 |
if ( esl_strdup(ad->rfline, -1, &(ad2->rfline)) != eslOK) goto ERROR; |
| 369 |
if ( esl_strdup(ad->mmline, -1, &(ad2->mmline)) != eslOK) goto ERROR; |
| 370 |
if ( esl_strdup(ad->csline, -1, &(ad2->csline)) != eslOK) goto ERROR; |
| 371 |
if ( esl_strdup(ad->model, -1, &(ad2->model)) != eslOK) goto ERROR; |
| 372 |
if ( esl_strdup(ad->mline, -1, &(ad2->mline)) != eslOK) goto ERROR; |
| 373 |
if ( esl_strdup(ad->aseq, -1, &(ad2->aseq)) != eslOK) goto ERROR; |
| 374 |
if ( esl_strdup(ad->ntseq, -1, &(ad2->ntseq)) != eslOK) goto ERROR; |
| 375 |
if ( esl_strdup(ad->ppline, -1, &(ad2->ppline)) != eslOK) goto ERROR; |
| 376 |
ad2->N = ad->N; |
| 377 |
|
| 378 |
if ( esl_strdup(ad->hmmname, -1, &(ad2->hmmname)) != eslOK) goto ERROR; |
| 379 |
if ( esl_strdup(ad->hmmacc, -1, &(ad2->hmmacc)) != eslOK) goto ERROR; |
| 380 |
if ( esl_strdup(ad->hmmdesc, -1, &(ad2->hmmdesc)) != eslOK) goto ERROR; |
| 381 |
ad2->hmmfrom = ad->hmmfrom; |
| 382 |
ad2->hmmto = ad->hmmto; |
| 383 |
ad2->M = ad->M; |
| 384 |
|
| 385 |
if ( esl_strdup(ad->sqname, -1, &(ad2->sqname)) != eslOK) goto ERROR; |
| 386 |
if ( esl_strdup(ad->sqacc, -1, &(ad2->sqacc)) != eslOK) goto ERROR; |
| 387 |
if ( esl_strdup(ad->sqdesc, -1, &(ad2->sqdesc)) != eslOK) goto ERROR; |
| 388 |
ad2->sqfrom = ad->sqfrom; |
| 389 |
ad2->sqto = ad->sqto; |
| 390 |
ad2->L = ad->L; |
| 391 |
} |
| 392 |
|
| 393 |
return ad2; |
| 394 |
|
| 395 |
ERROR: |
| 396 |
if (ad2) p7_alidisplay_Destroy(ad2); |
| 397 |
return NULL; |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
size_t |
| 415 |
p7_alidisplay_Sizeof(const P7_ALIDISPLAY *ad) |
| 416 |
{ |
| 417 |
size_t n = sizeof(P7_ALIDISPLAY); |
| 418 |
|
| 419 |
if (ad->rfline) n += ad->N+1; |
| 420 |
if (ad->mmline) n += ad->N+1; |
| 421 |
if (ad->csline) n += ad->N+1; |
| 422 |
if (ad->ppline) n += ad->N+1; |
| 423 |
n += 3 * (ad->N+1); |
| 424 |
if (ad->ntseq) n += (3 * ad->N) + 1; |
| 425 |
n += 1 + strlen(ad->hmmname); |
| 426 |
n += 1 + strlen(ad->hmmacc); |
| 427 |
n += 1 + strlen(ad->hmmdesc); |
| 428 |
n += 1 + strlen(ad->sqname); |
| 429 |
n += 1 + strlen(ad->sqacc); |
| 430 |
n += 1 + strlen(ad->sqdesc); |
| 431 |
|
| 432 |
return n; |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
#define SER_BASE_SIZE ((5 * sizeof(int)) + (3 * sizeof(int64_t)) +1) // Total size of the fixed-length fields in a |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
int p7_alidisplay_Serialize(const P7_ALIDISPLAY *obj, uint8_t **buf, uint32_t *n, uint32_t *nalloc){ |
| 465 |
|
| 466 |
int status; |
| 467 |
uint32_t ser_size; |
| 468 |
uint8_t *ptr; |
| 469 |
uint32_t network_32bit; |
| 470 |
uint64_t network_64bit; |
| 471 |
uint8_t presence_flags = 0; |
| 472 |
uint32_t hmmname_length, hmmacc_length, hmmdesc_length, sqname_length, sqacc_length, sqdesc_length; |
| 473 |
|
| 474 |
|
| 475 |
if(obj == NULL || buf == NULL || n == NULL){ |
| 476 |
return(eslEINVAL); |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
ser_size = SER_BASE_SIZE; |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
if (obj->rfline){ |
| 492 |
presence_flags += RFLINE_PRESENT; |
| 493 |
ser_size += obj->N+1; |
| 494 |
} |
| 495 |
|
| 496 |
if (obj->mmline) { |
| 497 |
presence_flags += MMLINE_PRESENT; |
| 498 |
ser_size += obj->N+1; |
| 499 |
} |
| 500 |
|
| 501 |
if (obj->csline){ |
| 502 |
presence_flags += CSLINE_PRESENT; |
| 503 |
ser_size += obj->N+1; |
| 504 |
} |
| 505 |
|
| 506 |
ser_size += 2 * (obj->N+1); |
| 507 |
|
| 508 |
if (obj->aseq){ |
| 509 |
presence_flags += ASEQ_PRESENT; |
| 510 |
ser_size += obj->N+1; |
| 511 |
} |
| 512 |
|
| 513 |
if (obj->ntseq){ |
| 514 |
presence_flags += NTSEQ_PRESENT; |
| 515 |
ser_size += (3 * obj->N) + 1; |
| 516 |
} |
| 517 |
|
| 518 |
if (obj->ppline){ |
| 519 |
presence_flags += PPLINE_PRESENT; |
| 520 |
ser_size += obj->N+1; |
| 521 |
} |
| 522 |
|
| 523 |
hmmname_length = strlen(obj->hmmname); |
| 524 |
ser_size += 1 + hmmname_length; |
| 525 |
|
| 526 |
hmmacc_length = strlen(obj->hmmacc); |
| 527 |
ser_size += 1 + hmmacc_length; |
| 528 |
|
| 529 |
hmmdesc_length = strlen(obj->hmmdesc); |
| 530 |
ser_size += 1 + hmmdesc_length; |
| 531 |
|
| 532 |
sqname_length = strlen(obj->sqname); |
| 533 |
ser_size += 1 + sqname_length; |
| 534 |
|
| 535 |
sqacc_length = strlen(obj->sqacc); |
| 536 |
ser_size += 1 + sqacc_length; |
| 537 |
|
| 538 |
sqdesc_length = strlen(obj->sqdesc); |
| 539 |
ser_size += 1 + sqdesc_length; |
| 540 |
|
| 541 |
|
| 542 |
if(*buf == NULL){ |
| 543 |
ESL_ALLOC(*buf, ser_size); |
| 544 |
*nalloc = ser_size; |
| 545 |
} |
| 546 |
|
| 547 |
if((*n + ser_size) > *nalloc){ |
| 548 |
ESL_REALLOC(*buf, (*n + ser_size)); |
| 549 |
*nalloc = *n + ser_size; |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
ptr = *buf + *n; |
| 556 |
|
| 557 |
network_32bit = esl_hton32(ser_size); |
| 558 |
memcpy(ptr, &network_32bit, sizeof(uint32_t)); |
| 559 |
ptr += sizeof(uint32_t); |
| 560 |
|
| 561 |
|
| 562 |
network_32bit = esl_hton32(obj->N); |
| 563 |
memcpy(ptr, &network_32bit, sizeof(uint32_t)); |
| 564 |
ptr += sizeof(uint32_t); |
| 565 |
|
| 566 |
|
| 567 |
network_32bit = esl_hton32(obj->hmmfrom); |
| 568 |
memcpy(ptr, &network_32bit, sizeof(uint32_t)); |
| 569 |
ptr += sizeof(uint32_t); |
| 570 |
|
| 571 |
|
| 572 |
network_32bit = esl_hton32(obj->hmmto); |
| 573 |
memcpy(ptr, &network_32bit, sizeof(uint32_t)); |
| 574 |
ptr += sizeof(uint32_t); |
| 575 |
|
| 576 |
|
| 577 |
network_32bit = esl_hton32(obj->M); |
| 578 |
memcpy(ptr, &network_32bit, sizeof(uint32_t)); |
| 579 |
ptr += sizeof(uint32_t); |
| 580 |
|
| 581 |
|
| 582 |
network_64bit = esl_hton64(obj->sqfrom); |
| 583 |
memcpy(ptr, &network_64bit, sizeof(int64_t)); |
| 584 |
ptr += sizeof(int64_t); |
| 585 |
|
| 586 |
|
| 587 |
network_64bit = esl_hton64(obj->sqto); |
| 588 |
memcpy(ptr, &network_64bit, sizeof(int64_t)); |
| 589 |
ptr += sizeof(int64_t); |
| 590 |
|
| 591 |
|
| 592 |
network_64bit = esl_hton64(obj->L); |
| 593 |
memcpy(ptr, &network_64bit, sizeof(int64_t)); |
| 594 |
ptr += sizeof(int64_t); |
| 595 |
|
| 596 |
|
| 597 |
memcpy(ptr, &presence_flags, sizeof(uint8_t)); |
| 598 |
ptr += sizeof(uint8_t); |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
if(presence_flags & RFLINE_PRESENT){ |
| 605 |
strcpy((char *) ptr, obj->rfline); |
| 606 |
ptr += obj->N + 1; |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
if(presence_flags & MMLINE_PRESENT){ |
| 611 |
strcpy((char *) ptr, obj->mmline); |
| 612 |
ptr += obj->N + 1; |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
if(presence_flags & CSLINE_PRESENT){ |
| 617 |
strcpy((char *) ptr, obj->csline); |
| 618 |
ptr += obj->N + 1; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
strcpy((char *) ptr, obj->model); |
| 623 |
ptr += obj->N + 1; |
| 624 |
|
| 625 |
|
| 626 |
strcpy((char *) ptr, obj->mline); |
| 627 |
ptr += obj->N + 1; |
| 628 |
|
| 629 |
|
| 630 |
if(presence_flags & ASEQ_PRESENT){ |
| 631 |
strcpy((char *) ptr, obj->aseq); |
| 632 |
ptr += obj->N + 1; |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
if(presence_flags & NTSEQ_PRESENT){ |
| 637 |
strcpy((char *) ptr, obj->ntseq); |
| 638 |
ptr += (3 * obj->N) + 1; |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
if(presence_flags & PPLINE_PRESENT){ |
| 643 |
strcpy((char *) ptr, obj->ppline); |
| 644 |
ptr += obj->N + 1; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
strcpy((char *) ptr, obj->hmmname); |
| 649 |
ptr += hmmname_length + 1; |
| 650 |
|
| 651 |
|
| 652 |
strcpy((char *) ptr, obj->hmmacc); |
| 653 |
ptr += hmmacc_length + 1; |
| 654 |
|
| 655 |
|
| 656 |
strcpy((char *) ptr, obj->hmmdesc); |
| 657 |
ptr += hmmdesc_length + 1; |
| 658 |
|
| 659 |
|
| 660 |
strcpy((char *) ptr, obj->sqname); |
| 661 |
ptr += sqname_length +1; |
| 662 |
|
| 663 |
|
| 664 |
strcpy((char *) ptr, obj->sqacc); |
| 665 |
ptr += sqacc_length +1 ; |
| 666 |
|
| 667 |
|
| 668 |
strcpy((char *) ptr, obj->sqdesc); |
| 669 |
ptr += sqdesc_length +1 ; |
| 670 |
|
| 671 |
|
| 672 |
if(ptr != *buf + *n + ser_size){ |
| 673 |
ESL_EXCEPTION(eslFAIL, "Serialized object length did not match computed length in p7_alidisplay_Serialize"); |
| 674 |
} |
| 675 |
|
| 676 |
*n = ptr - *buf; |
| 677 |
return eslOK; |
| 678 |
|
| 679 |
ERROR: |
| 680 |
return eslEMEM; |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
extern int p7_alidisplay_Deserialize(const uint8_t *buf, uint32_t *n, P7_ALIDISPLAY *ret_obj){ |
| 703 |
int status; |
| 704 |
|
| 705 |
uint8_t *ptr; |
| 706 |
char *mem_ptr; |
| 707 |
uint64_t network_64bit; |
| 708 |
uint32_t network_32bit; |
| 709 |
uint32_t obj_size; |
| 710 |
uint8_t presence_flags; |
| 711 |
int string_length; |
| 712 |
|
| 713 |
if ((buf == NULL) || (ret_obj == NULL) || (n == NULL)){ |
| 714 |
return(eslEINVAL); |
| 715 |
} |
| 716 |
|
| 717 |
mem_ptr = NULL; |
| 718 |
ptr = (uint8_t *) buf + *n; |
| 719 |
|
| 720 |
|
| 721 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 722 |
obj_size = esl_ntoh32(network_32bit); |
| 723 |
ptr += sizeof(uint32_t); |
| 724 |
|
| 725 |
if(ret_obj->memsize < (obj_size - SER_BASE_SIZE)){ |
| 726 |
if(ret_obj->mem != NULL){ |
| 727 |
ESL_REALLOC(ret_obj->mem, (obj_size - SER_BASE_SIZE)); |
| 728 |
} |
| 729 |
else{ |
| 730 |
ESL_ALLOC(ret_obj->mem, (obj_size - SER_BASE_SIZE)); |
| 731 |
} |
| 732 |
ret_obj->memsize = obj_size - SER_BASE_SIZE; |
| 733 |
} |
| 734 |
|
| 735 |
|
| 736 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 737 |
ret_obj->N = esl_ntoh32(network_32bit); |
| 738 |
ptr += sizeof(uint32_t); |
| 739 |
|
| 740 |
|
| 741 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 742 |
ret_obj->hmmfrom = esl_ntoh32(network_32bit); |
| 743 |
ptr += sizeof(uint32_t); |
| 744 |
|
| 745 |
|
| 746 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 747 |
ret_obj->hmmto = esl_ntoh32(network_32bit); |
| 748 |
ptr += sizeof(uint32_t); |
| 749 |
|
| 750 |
|
| 751 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 752 |
ret_obj->M = esl_ntoh32(network_32bit); |
| 753 |
ptr += sizeof(uint32_t); |
| 754 |
|
| 755 |
|
| 756 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 757 |
ret_obj->sqfrom = esl_ntoh64(network_64bit); |
| 758 |
ptr += sizeof(uint64_t); |
| 759 |
|
| 760 |
|
| 761 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 762 |
ret_obj->sqto = esl_ntoh64(network_64bit); |
| 763 |
ptr += sizeof(uint64_t); |
| 764 |
|
| 765 |
|
| 766 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 767 |
ret_obj->L = esl_ntoh64(network_64bit); |
| 768 |
ptr += sizeof(uint64_t); |
| 769 |
|
| 770 |
|
| 771 |
presence_flags = *ptr; |
| 772 |
ptr += sizeof(uint8_t); |
| 773 |
|
| 774 |
|
| 775 |
memcpy(ret_obj->mem, ptr, (obj_size - SER_BASE_SIZE)); |
| 776 |
mem_ptr = ret_obj->mem; |
| 777 |
ptr += (obj_size - SER_BASE_SIZE); |
| 778 |
|
| 779 |
|
| 780 |
if(ptr != buf + *n + obj_size){ |
| 781 |
ESL_EXCEPTION(eslFAIL, "In p7_alidisplay_Deserialize, found object (ptr) to be of size %ld, expected %u.\n", (long int) (ptr - (buf + *n)), obj_size); |
| 782 |
} |
| 783 |
|
| 784 |
if(presence_flags & RFLINE_PRESENT){ |
| 785 |
ret_obj->rfline = mem_ptr; |
| 786 |
string_length = strlen(ret_obj->rfline); |
| 787 |
mem_ptr+= string_length +1; |
| 788 |
} |
| 789 |
else{ |
| 790 |
ret_obj->rfline = NULL; |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
if(presence_flags & MMLINE_PRESENT){ |
| 795 |
ret_obj->mmline = mem_ptr; |
| 796 |
string_length = strlen(ret_obj->mmline); |
| 797 |
mem_ptr+= string_length + 1; |
| 798 |
} |
| 799 |
else{ |
| 800 |
ret_obj->mmline = NULL; |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
if(presence_flags & CSLINE_PRESENT){ |
| 805 |
ret_obj->csline = mem_ptr; |
| 806 |
string_length = strlen(ret_obj->csline); |
| 807 |
mem_ptr+= string_length + 1; |
| 808 |
} |
| 809 |
else{ |
| 810 |
ret_obj->csline = NULL; |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
ret_obj->model = mem_ptr; |
| 816 |
string_length = strlen(ret_obj->model); |
| 817 |
mem_ptr+= string_length + 1; |
| 818 |
|
| 819 |
|
| 820 |
ret_obj->mline = mem_ptr; |
| 821 |
string_length = strlen(ret_obj->mline); |
| 822 |
mem_ptr+= string_length + 1; |
| 823 |
|
| 824 |
|
| 825 |
if(presence_flags & ASEQ_PRESENT){ |
| 826 |
ret_obj->aseq = mem_ptr; |
| 827 |
string_length = strlen(ret_obj->aseq); |
| 828 |
mem_ptr+= string_length + 1; |
| 829 |
} |
| 830 |
else{ |
| 831 |
ret_obj->aseq = NULL; |
| 832 |
} |
| 833 |
|
| 834 |
|
| 835 |
if(presence_flags & NTSEQ_PRESENT){ |
| 836 |
ret_obj->ntseq = mem_ptr; |
| 837 |
string_length = strlen(ret_obj->ntseq); |
| 838 |
mem_ptr+= string_length + 1; |
| 839 |
} |
| 840 |
else{ |
| 841 |
ret_obj->ntseq = NULL; |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
if(presence_flags & PPLINE_PRESENT){ |
| 846 |
ret_obj->ppline = mem_ptr; |
| 847 |
string_length = strlen(ret_obj->ppline); |
| 848 |
mem_ptr+= string_length + 1; |
| 849 |
} |
| 850 |
else{ |
| 851 |
ret_obj->ppline = NULL; |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
ret_obj->hmmname = mem_ptr; |
| 856 |
string_length = strlen(ret_obj->hmmname); |
| 857 |
mem_ptr+= string_length + 1; |
| 858 |
|
| 859 |
|
| 860 |
ret_obj->hmmacc = mem_ptr; |
| 861 |
string_length = strlen(ret_obj->hmmacc); |
| 862 |
mem_ptr+= string_length + 1; |
| 863 |
|
| 864 |
|
| 865 |
ret_obj->hmmdesc = mem_ptr; |
| 866 |
string_length = strlen(ret_obj->hmmdesc); |
| 867 |
mem_ptr+= string_length + 1; |
| 868 |
|
| 869 |
|
| 870 |
ret_obj->sqname = mem_ptr; |
| 871 |
string_length = strlen(ret_obj->sqname); |
| 872 |
mem_ptr+= string_length + 1; |
| 873 |
|
| 874 |
|
| 875 |
ret_obj->sqacc = mem_ptr; |
| 876 |
string_length = strlen(ret_obj->sqacc); |
| 877 |
mem_ptr+= string_length + 1; |
| 878 |
|
| 879 |
|
| 880 |
ret_obj->sqdesc = mem_ptr; |
| 881 |
string_length = strlen(ret_obj->sqdesc); |
| 882 |
mem_ptr+= string_length +1; |
| 883 |
|
| 884 |
|
| 885 |
if(mem_ptr - ret_obj->mem != (obj_size - SER_BASE_SIZE)){ |
| 886 |
ESL_EXCEPTION(eslFAIL, "At end of p7_alidisplay_Deserialize, found strings to be of size %ld, expected %ld.\n", (long)(mem_ptr - ret_obj->mem), (long)(obj_size - SER_BASE_SIZE)); |
| 887 |
} |
| 888 |
*n += obj_size; |
| 889 |
return eslOK; |
| 890 |
|
| 891 |
ERROR: |
| 892 |
return eslEMEM; |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
int |
| 913 |
p7_alidisplay_Serialize_old(P7_ALIDISPLAY *ad) |
| 914 |
{ |
| 915 |
int pos; |
| 916 |
int n; |
| 917 |
int status; |
| 918 |
|
| 919 |
if (ad->mem) return eslOK; |
| 920 |
ad->memsize = p7_alidisplay_Sizeof(ad) - sizeof(P7_ALIDISPLAY); |
| 921 |
ESL_ALLOC(ad->mem, ad->memsize); |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
pos = 0; |
| 926 |
if (ad->rfline) { memcpy(ad->mem+pos, ad->rfline, ad->N+1); free(ad->rfline); ad->rfline = ad->mem+pos; pos += ad->N+1; } |
| 927 |
if (ad->mmline) { memcpy(ad->mem+pos, ad->mmline, ad->N+1); free(ad->mmline); ad->mmline = ad->mem+pos; pos += ad->N+1; } |
| 928 |
if (ad->csline) { memcpy(ad->mem+pos, ad->csline, ad->N+1); free(ad->csline); ad->csline = ad->mem+pos; pos += ad->N+1; } |
| 929 |
memcpy(ad->mem+pos, ad->model, ad->N+1); free(ad->model); ad->model = ad->mem+pos; pos += ad->N+1; |
| 930 |
memcpy(ad->mem+pos, ad->mline, ad->N+1); free(ad->mline); ad->mline = ad->mem+pos; pos += ad->N+1; |
| 931 |
memcpy(ad->mem+pos, ad->aseq, ad->N+1); free(ad->aseq); ad->aseq = ad->mem+pos; pos += ad->N+1; |
| 932 |
if (ad->ntseq) { memcpy(ad->mem+pos, ad->ntseq, (3*ad->N)+1); free(ad->ntseq); ad->ntseq = ad->mem+pos; pos += (3*ad->N)+1; } |
| 933 |
if (ad->ppline) { memcpy(ad->mem+pos, ad->ppline, ad->N+1); free(ad->ppline); ad->ppline = ad->mem+pos; pos += ad->N+1; } |
| 934 |
n = 1 + strlen(ad->hmmname); memcpy(ad->mem + pos, ad->hmmname, n); free(ad->hmmname); ad->hmmname = ad->mem+pos; pos += n; |
| 935 |
n = 1 + strlen(ad->hmmacc); memcpy(ad->mem + pos, ad->hmmacc, n); free(ad->hmmacc); ad->hmmacc = ad->mem+pos; pos += n; |
| 936 |
n = 1 + strlen(ad->hmmdesc); memcpy(ad->mem + pos, ad->hmmdesc, n); free(ad->hmmdesc); ad->hmmdesc = ad->mem+pos; pos += n; |
| 937 |
n = 1 + strlen(ad->sqname); memcpy(ad->mem + pos, ad->sqname, n); free(ad->sqname); ad->sqname = ad->mem+pos; pos += n; |
| 938 |
n = 1 + strlen(ad->sqacc); memcpy(ad->mem + pos, ad->sqacc, n); free(ad->sqacc); ad->sqacc = ad->mem+pos; pos += n; |
| 939 |
n = 1 + strlen(ad->sqdesc); memcpy(ad->mem + pos, ad->sqdesc, n); free(ad->sqdesc); ad->sqdesc = ad->mem+pos; pos += n; |
| 940 |
|
| 941 |
return eslOK; |
| 942 |
|
| 943 |
ERROR: |
| 944 |
if (ad->mem) { free(ad->mem); ad->mem = NULL; } |
| 945 |
return status; |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
int |
| 966 |
p7_alidisplay_Deserialize_old(P7_ALIDISPLAY *ad) |
| 967 |
{ |
| 968 |
int pos; |
| 969 |
int n; |
| 970 |
int status; |
| 971 |
|
| 972 |
if (ad->mem == NULL) return eslOK; |
| 973 |
|
| 974 |
pos = 0; |
| 975 |
if (ad->rfline) { ESL_ALLOC(ad->rfline, sizeof(char) * ad->N+1); memcpy(ad->rfline, ad->mem+pos, ad->N+1); pos += ad->N+1; } |
| 976 |
if (ad->mmline) { ESL_ALLOC(ad->mmline, sizeof(char) * ad->N+1); memcpy(ad->mmline, ad->mem+pos, ad->N+1); pos += ad->N+1; } |
| 977 |
if (ad->csline) { ESL_ALLOC(ad->csline, sizeof(char) * ad->N+1); memcpy(ad->csline, ad->mem+pos, ad->N+1); pos += ad->N+1; } |
| 978 |
ESL_ALLOC(ad->model, sizeof(char) * ad->N+1); memcpy(ad->model, ad->mem+pos, ad->N+1); pos += ad->N+1; |
| 979 |
ESL_ALLOC(ad->mline, sizeof(char) * ad->N+1); memcpy(ad->mline, ad->mem+pos, ad->N+1); pos += ad->N+1; |
| 980 |
ESL_ALLOC(ad->aseq, sizeof(char) * ad->N+1); memcpy(ad->aseq, ad->mem+pos, ad->N+1); pos += ad->N+1; |
| 981 |
if (ad->ntseq) { ESL_ALLOC(ad->ntseq, sizeof(char) * (3*ad->N)+1); memcpy(ad->ntseq, ad->mem+pos, (3*ad->N)+1); pos += (3*ad->N)+1; } |
| 982 |
if (ad->ppline) { ESL_ALLOC(ad->ppline, sizeof(char) * ad->N+1); memcpy(ad->ppline, ad->mem+pos, ad->N+1); pos += ad->N+1; } |
| 983 |
n = 1 + strlen(ad->mem+pos); ESL_ALLOC(ad->hmmname, sizeof(char) * n); memcpy(ad->hmmname, ad->mem+pos, n); pos += n; |
| 984 |
n = 1 + strlen(ad->mem+pos); ESL_ALLOC(ad->hmmacc, sizeof(char) * n); memcpy(ad->hmmacc, ad->mem+pos, n); pos += n; |
| 985 |
n = 1 + strlen(ad->mem+pos); ESL_ALLOC(ad->hmmdesc, sizeof(char) * n); memcpy(ad->hmmdesc, ad->mem+pos, n); pos += n; |
| 986 |
n = 1 + strlen(ad->mem+pos); ESL_ALLOC(ad->sqname, sizeof(char) * n); memcpy(ad->sqname, ad->mem+pos, n); pos += n; |
| 987 |
n = 1 + strlen(ad->mem+pos); ESL_ALLOC(ad->sqacc, sizeof(char) * n); memcpy(ad->sqacc, ad->mem+pos, n); pos += n; |
| 988 |
n = 1 + strlen(ad->mem+pos); ESL_ALLOC(ad->sqdesc, sizeof(char) * n); memcpy(ad->sqdesc, ad->mem+pos, n); pos += n; |
| 989 |
|
| 990 |
free(ad->mem); |
| 991 |
ad->mem = NULL; |
| 992 |
ad->memsize = 0; |
| 993 |
return eslOK; |
| 994 |
|
| 995 |
ERROR: |
| 996 |
|
| 997 |
|
| 998 |
pos = 0; |
| 999 |
if (ad->rfline) { if (ad->rfline != ad->mem+pos) { free(ad->rfline); ad->rfline = ad->mem+pos; } pos += ad->N+1; } |
| 1000 |
if (ad->mmline) { if (ad->mmline != ad->mem+pos) { free(ad->mmline); ad->mmline = ad->mem+pos; } pos += ad->N+1; } |
| 1001 |
if (ad->csline) { if (ad->csline != ad->mem+pos) { free(ad->csline); ad->csline = ad->mem+pos; } pos += ad->N+1; } |
| 1002 |
if (ad->model != ad->mem+pos) { free(ad->model); ad->model = ad->mem+pos; } pos += ad->N+1; |
| 1003 |
if (ad->mline != ad->mem+pos) { free(ad->mline); ad->mline = ad->mem+pos; } pos += ad->N+1; |
| 1004 |
if (ad->aseq != ad->mem+pos) { free(ad->aseq); ad->aseq = ad->mem+pos; } pos += ad->N+1; |
| 1005 |
if (ad->ntseq) { if (ad->ntseq != ad->mem+pos) { free(ad->ntseq); ad->ntseq = ad->mem+pos; } pos += (3*ad->N)+1; } |
| 1006 |
if (ad->ppline) { if (ad->ppline != ad->mem+pos) { free(ad->ppline); ad->ppline = ad->mem+pos; } pos += ad->N+1; } |
| 1007 |
|
| 1008 |
n = 1 + strlen(ad->hmmname); if (ad->hmmname != ad->mem+pos) { free(ad->hmmname); ad->hmmname = ad->mem+pos; } pos += n; |
| 1009 |
n = 1 + strlen(ad->hmmacc); if (ad->hmmacc != ad->mem+pos) { free(ad->hmmacc); ad->hmmacc = ad->mem+pos; } pos += n; |
| 1010 |
n = 1 + strlen(ad->hmmname); if (ad->hmmdesc != ad->mem+pos) { free(ad->hmmdesc); ad->hmmdesc = ad->mem+pos; } pos += n; |
| 1011 |
n = 1 + strlen(ad->sqname); if (ad->sqname != ad->mem+pos) { free(ad->sqname); ad->sqname = ad->mem+pos; } pos += n; |
| 1012 |
n = 1 + strlen(ad->sqacc); if (ad->sqacc != ad->mem+pos) { free(ad->sqacc); ad->sqacc = ad->mem+pos; } pos += n; |
| 1013 |
n = 1 + strlen(ad->sqname); if (ad->sqdesc != ad->mem+pos) { free(ad->sqdesc); ad->sqdesc = ad->mem+pos; } pos += n; |
| 1014 |
return status; |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
void |
| 1022 |
p7_alidisplay_Destroy(P7_ALIDISPLAY *ad) |
| 1023 |
{ |
| 1024 |
if (ad == NULL) return; |
| 1025 |
if (ad->mem) |
| 1026 |
{ |
| 1027 |
free(ad->mem); |
| 1028 |
} |
| 1029 |
else |
| 1030 |
{ |
| 1031 |
if (ad->rfline) free(ad->rfline); |
| 1032 |
if (ad->mmline) free(ad->mmline); |
| 1033 |
if (ad->csline) free(ad->csline); |
| 1034 |
if (ad->model) free(ad->model); |
| 1035 |
if (ad->mline) free(ad->mline); |
| 1036 |
if (ad->aseq) free(ad->aseq); |
| 1037 |
if (ad->ntseq) free(ad->ntseq); |
| 1038 |
if (ad->ppline) free(ad->ppline); |
| 1039 |
if (ad->hmmname) free(ad->hmmname); |
| 1040 |
if (ad->hmmacc) free(ad->hmmacc); |
| 1041 |
if (ad->hmmdesc) free(ad->hmmdesc); |
| 1042 |
if (ad->sqname) free(ad->sqname); |
| 1043 |
if (ad->sqacc) free(ad->sqacc); |
| 1044 |
if (ad->sqdesc) free(ad->sqdesc); |
| 1045 |
} |
| 1046 |
free(ad); |
| 1047 |
} |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
static int |
| 1057 |
integer_textwidth(long n) |
| 1058 |
{ |
| 1059 |
int w = (n < 0)? 1 : 0; |
| 1060 |
while (n != 0) { n /= 10; w++; } |
| 1061 |
return w; |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
char |
| 1083 |
p7_alidisplay_EncodePostProb(float p) |
| 1084 |
{ |
| 1085 |
return (p + 0.05 >= 1.0) ? '*' : (char) ((p + 0.05) * 10.0) + '0'; |
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
float |
| 1103 |
p7_alidisplay_DecodePostProb(char pc) |
| 1104 |
{ |
| 1105 |
if (pc == '0') return 0.01; |
| 1106 |
else if (pc == '*') return 1.0; |
| 1107 |
else if (pc == '.') return 0.0; |
| 1108 |
else return ((float) (pc - '0') / 10.); |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
int |
| 1133 |
p7_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, P7_PIPELINE *pli) |
| 1134 |
{ |
| 1135 |
int status; |
| 1136 |
if ((status = p7_nontranslated_alidisplay_Print(fp, ad, min_aliwidth, linewidth, pli->show_accessions)) != eslOK) return status; |
| 1137 |
|
| 1138 |
return status; |
| 1139 |
} |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
int |
| 1162 |
p7_nontranslated_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, int show_accessions) |
| 1163 |
{ |
| 1164 |
char *buf = NULL; |
| 1165 |
char *show_hmmname = NULL; |
| 1166 |
char *show_seqname = NULL; |
| 1167 |
int namewidth, coordwidth, aliwidth; |
| 1168 |
int pos; |
| 1169 |
int status; |
| 1170 |
int ni, nk; |
| 1171 |
int z; |
| 1172 |
long i1,i2; |
| 1173 |
int k1,k2; |
| 1174 |
|
| 1175 |
|
| 1176 |
show_hmmname = (show_accessions && ad->hmmacc[0] != '\0') ? ad->hmmacc : ad->hmmname; |
| 1177 |
show_seqname = (show_accessions && ad->sqacc[0] != '\0') ? ad->sqacc : ad->sqname; |
| 1178 |
|
| 1179 |
|
| 1180 |
namewidth = ESL_MAX(strlen(show_hmmname), strlen(show_seqname)); |
| 1181 |
coordwidth = ESL_MAX(ESL_MAX(integer_textwidth(ad->hmmfrom), |
| 1182 |
integer_textwidth(ad->hmmto)), |
| 1183 |
ESL_MAX(integer_textwidth(ad->sqfrom), |
| 1184 |
integer_textwidth(ad->sqto))); |
| 1185 |
|
| 1186 |
aliwidth = (linewidth > 0) ? linewidth - namewidth - 2*coordwidth - 5 : ad->N; |
| 1187 |
if (aliwidth < ad->N && aliwidth < min_aliwidth) aliwidth = min_aliwidth; |
| 1188 |
ESL_ALLOC(buf, sizeof(char) * (aliwidth+1)); |
| 1189 |
buf[aliwidth] = 0; |
| 1190 |
|
| 1191 |
|
| 1192 |
i1 = ad->sqfrom; |
| 1193 |
k1 = ad->hmmfrom; |
| 1194 |
for (pos = 0; pos < ad->N; pos += aliwidth) |
| 1195 |
{ |
| 1196 |
if (pos > 0) { if (fprintf(fp, "\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "alignment display write failed"); } |
| 1197 |
|
| 1198 |
ni = nk = 0; |
| 1199 |
for (z = pos; z < pos + aliwidth && z < ad->N; z++) { |
| 1200 |
if (ad->model[z] != '.') nk++; |
| 1201 |
if (ad->aseq[z] != '-') ni++; |
| 1202 |
} |
| 1203 |
|
| 1204 |
k2 = k1+nk-1; |
| 1205 |
if (ad->sqfrom < ad->sqto) i2 = i1+ni-1; |
| 1206 |
else i2 = i1-ni+1; |
| 1207 |
|
| 1208 |
if (ad->csline != NULL) { strncpy(buf, ad->csline+pos, aliwidth); if (fprintf(fp, " %*s %s CS\n", namewidth+coordwidth+1, "", buf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "alignment display write failed"); } |
| 1209 |
if (ad->rfline != NULL) { strncpy(buf, ad->rfline+pos, aliwidth); if (fprintf(fp, " %*s %s RF\n", namewidth+coordwidth+1, "", buf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "alignment display write failed"); } |
| 1210 |
if (ad->mmline != NULL) { strncpy(buf, ad->mmline+pos, aliwidth); if (fprintf(fp, " %*s %s MM\n", namewidth+coordwidth+1, "", buf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "alignment display write failed"); } |
| 1211 |
|
| 1212 |
strncpy(buf, ad->model+pos, aliwidth); if (fprintf(fp, " %*s %*d %s %-*d\n", namewidth, show_hmmname, coordwidth, k1, buf, coordwidth, k2) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "alignment display write failed"); |
| 1213 |
strncpy(buf, ad->mline+pos, aliwidth); if (fprintf(fp, " %*s %s\n", namewidth+coordwidth+1, " ", buf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "alignment display write failed"); |
| 1214 |
|
| 1215 |
if (ni > 0) { strncpy(buf, ad->aseq+pos, aliwidth); if (fprintf(fp, " %*s %*ld %s %-*ld\n", namewidth, show_seqname, coordwidth, i1, buf, coordwidth, i2) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "alignment display write failed"); } |
| 1216 |
else { strncpy(buf, ad->aseq+pos, aliwidth); if (fprintf(fp, " %*s %*s %s %*s\n", namewidth, show_seqname, coordwidth, "-", buf, coordwidth, "-") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "alignment display write failed"); } |
| 1217 |
|
| 1218 |
if (ad->ppline != NULL) { strncpy(buf, ad->ppline+pos, aliwidth); if (fprintf(fp, " %*s %s PP\n", namewidth+coordwidth+1, "", buf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "alignment display write failed"); } |
| 1219 |
|
| 1220 |
k1 += nk; |
| 1221 |
if (ad->sqfrom < ad->sqto) i1 += ni; |
| 1222 |
else i1 -= ni; |
| 1223 |
} |
| 1224 |
fflush(fp); |
| 1225 |
free(buf); |
| 1226 |
return eslOK; |
| 1227 |
|
| 1228 |
ERROR: |
| 1229 |
if (buf) free(buf); |
| 1230 |
return status; |
| 1231 |
} |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
int |
| 1262 |
p7_alidisplay_Backconvert(const P7_ALIDISPLAY *ad, const ESL_ALPHABET *abc, ESL_SQ **ret_sq, P7_TRACE **ret_tr) |
| 1263 |
{ |
| 1264 |
ESL_SQ *sq = NULL; |
| 1265 |
P7_TRACE *tr = NULL; |
| 1266 |
int subL = 0; |
| 1267 |
int a, i, k; |
| 1268 |
char s; |
| 1269 |
int status; |
| 1270 |
|
| 1271 |
|
| 1272 |
for (a = 0; a < ad->N; a++) |
| 1273 |
if (! esl_abc_CIsGap(abc, ad->aseq[a])) subL++; |
| 1274 |
|
| 1275 |
|
| 1276 |
if ((sq = esl_sq_CreateDigital(abc)) == NULL) { status = eslEMEM; goto ERROR; } |
| 1277 |
if ((status = esl_sq_GrowTo(sq, subL)) != eslOK) goto ERROR; |
| 1278 |
|
| 1279 |
if ((tr = (ad->ppline == NULL) ? p7_trace_Create() : p7_trace_CreateWithPP()) == NULL) { status = eslEMEM; goto ERROR; } |
| 1280 |
if ((status = p7_trace_GrowTo(tr, subL+6)) != eslOK) goto ERROR; |
| 1281 |
|
| 1282 |
|
| 1283 |
sq->dsq[0] = eslDSQ_SENTINEL; |
| 1284 |
if ((status = ((ad->ppline == NULL) ? p7_trace_Append(tr, p7T_S, 0, 0) : p7_trace_AppendWithPP(tr, p7T_S, 0, 0, 0.0))) != eslOK) goto ERROR; |
| 1285 |
if ((status = ((ad->ppline == NULL) ? p7_trace_Append(tr, p7T_N, 0, 0) : p7_trace_AppendWithPP(tr, p7T_N, 0, 0, 0.0))) != eslOK) goto ERROR; |
| 1286 |
if ((status = ((ad->ppline == NULL) ? p7_trace_Append(tr, p7T_B, 0, 0) : p7_trace_AppendWithPP(tr, p7T_B, 0, 0, 0.0))) != eslOK) goto ERROR; |
| 1287 |
k = ad->hmmfrom - 1; |
| 1288 |
i = 1; |
| 1289 |
for (a = 0; a < ad->N; a++) |
| 1290 |
{ |
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
if (! esl_abc_CIsGap(abc, ad->model[a])) { k++; s = (! esl_abc_CIsGap(abc, ad->aseq[a]) ? p7T_M : p7T_D); } |
| 1298 |
else s = p7T_I; |
| 1299 |
|
| 1300 |
if ((status = ((ad->ppline == NULL) ? p7_trace_Append(tr, s, k, i) : p7_trace_AppendWithPP(tr, s, k, i, p7_alidisplay_DecodePostProb(ad->ppline[a])))) != eslOK) goto ERROR; |
| 1301 |
|
| 1302 |
switch (s) { |
| 1303 |
case p7T_M: sq->dsq[i] = esl_abc_DigitizeSymbol(abc, ad->aseq[a]); i++; break; |
| 1304 |
case p7T_I: sq->dsq[i] = esl_abc_DigitizeSymbol(abc, ad->aseq[a]); i++; break; |
| 1305 |
case p7T_D: break; |
| 1306 |
} |
| 1307 |
} |
| 1308 |
if ((status = ((ad->ppline == NULL) ? p7_trace_Append(tr, p7T_E, 0, 0) : p7_trace_AppendWithPP(tr, p7T_E, 0, 0, 0.0))) != eslOK) goto ERROR; |
| 1309 |
if ((status = ((ad->ppline == NULL) ? p7_trace_Append(tr, p7T_C, 0, 0) : p7_trace_AppendWithPP(tr, p7T_C, 0, 0, 0.0))) != eslOK) goto ERROR; |
| 1310 |
if ((status = ((ad->ppline == NULL) ? p7_trace_Append(tr, p7T_T, 0, 0) : p7_trace_AppendWithPP(tr, p7T_T, 0, 0, 0.0))) != eslOK) goto ERROR; |
| 1311 |
sq->dsq[i] = eslDSQ_SENTINEL; |
| 1312 |
|
| 1313 |
|
| 1314 |
if (tr->N != ad->N + 6) ESL_XEXCEPTION(eslECORRUPT, "backconverted trace ended up with unexpected size (%s/%s)", ad->sqname, ad->hmmname); |
| 1315 |
if (k != ad->hmmto) ESL_XEXCEPTION(eslECORRUPT, "backconverted trace didn't end at expected place on model (%s/%s)", ad->sqname, ad->hmmname); |
| 1316 |
if (i != subL+1) ESL_XEXCEPTION(eslECORRUPT, "backconverted subseq didn't end at expected length (%s/%s)", ad->sqname, ad->hmmname); |
| 1317 |
|
| 1318 |
|
| 1319 |
if ((status = esl_sq_FormatName(sq, "%s/%" PRId64 "-%" PRId64 "", ad->sqname, ad->sqfrom, ad->sqto)) != eslOK) goto ERROR; |
| 1320 |
if ((status = esl_sq_FormatDesc(sq, "[subseq from] %s", ad->sqdesc[0] != '\0' ? ad->sqdesc : ad->sqname)) != eslOK) goto ERROR; |
| 1321 |
if ((status = esl_sq_SetSource (sq, ad->sqname)) != eslOK) goto ERROR; |
| 1322 |
if (ad->sqacc[0] != '\0') { if ((status = esl_sq_SetAccession (sq, ad->sqacc)) != eslOK) goto ERROR; } |
| 1323 |
sq->n = subL; |
| 1324 |
sq->start = ad->sqfrom; |
| 1325 |
sq->end = ad->sqto; |
| 1326 |
sq->C = 0; |
| 1327 |
sq->W = subL; |
| 1328 |
sq->L = ad->L; |
| 1329 |
|
| 1330 |
tr->M = ad->M; |
| 1331 |
tr->L = ad->L; |
| 1332 |
|
| 1333 |
*ret_sq = sq; |
| 1334 |
*ret_tr = tr; |
| 1335 |
return eslOK; |
| 1336 |
|
| 1337 |
ERROR: |
| 1338 |
if (sq != NULL) esl_sq_Destroy(sq); |
| 1339 |
if (tr != NULL) p7_trace_Destroy(tr); |
| 1340 |
*ret_sq = NULL; |
| 1341 |
*ret_tr = NULL; |
| 1342 |
return status; |
| 1343 |
} |
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
int |
| 1373 |
p7_alidisplay_Sample(ESL_RANDOMNESS *rng, int N, P7_ALIDISPLAY **ret_ad) |
| 1374 |
{ |
| 1375 |
P7_ALIDISPLAY *ad = NULL; |
| 1376 |
char *guidestring = NULL; |
| 1377 |
int nM = 0; |
| 1378 |
int nD = 0; |
| 1379 |
int nI = 0; |
| 1380 |
enum p7t_statetype_e last_st; |
| 1381 |
int pos; |
| 1382 |
int status; |
| 1383 |
|
| 1384 |
ESL_ALLOC(guidestring, sizeof(char) * (N+1)); |
| 1385 |
|
| 1386 |
guidestring[0] = 'M'; nM++; last_st = p7T_M; |
| 1387 |
for (pos = 1; pos < N-1; pos++) |
| 1388 |
{ |
| 1389 |
switch (last_st) |
| 1390 |
{ |
| 1391 |
case p7T_M: |
| 1392 |
switch (esl_rnd_Roll(rng, 3)) |
| 1393 |
{ |
| 1394 |
case 0: guidestring[pos] = 'M'; nM++; last_st = p7T_M; break; |
| 1395 |
case 1: guidestring[pos] = 'D'; nD++; last_st = p7T_D; break; |
| 1396 |
case 2: guidestring[pos] = 'I'; nI++; last_st = p7T_I; break; |
| 1397 |
} |
| 1398 |
break; |
| 1399 |
|
| 1400 |
case p7T_I: |
| 1401 |
switch (esl_rnd_Roll(rng, 2)) |
| 1402 |
{ |
| 1403 |
case 0: guidestring[pos] = 'M'; nM++; last_st = p7T_M; break; |
| 1404 |
case 1: guidestring[pos] = 'I'; nI++; last_st = p7T_I; break; |
| 1405 |
} |
| 1406 |
break; |
| 1407 |
|
| 1408 |
case p7T_D: |
| 1409 |
switch (esl_rnd_Roll(rng, 2)) |
| 1410 |
{ |
| 1411 |
case 0: guidestring[pos] = 'M'; nM++; last_st = p7T_M; break; |
| 1412 |
case 1: guidestring[pos] = 'D'; nD++; last_st = p7T_D; break; |
| 1413 |
} |
| 1414 |
break; |
| 1415 |
|
| 1416 |
default: |
| 1417 |
break; |
| 1418 |
} |
| 1419 |
} |
| 1420 |
|
| 1421 |
switch (last_st) { |
| 1422 |
case p7T_I: |
| 1423 |
guidestring[N-1] = 'M'; nM++; break; |
| 1424 |
default: |
| 1425 |
switch (esl_rnd_Roll(rng, 2)) { |
| 1426 |
case 0: guidestring[N-1] = 'M'; nM++; break; |
| 1427 |
case 1: guidestring[N-1] = 'D'; nD++; break; |
| 1428 |
} |
| 1429 |
break; |
| 1430 |
} |
| 1431 |
guidestring[N] = '\0'; |
| 1432 |
|
| 1433 |
ESL_ALLOC(ad, sizeof(P7_ALIDISPLAY)); |
| 1434 |
ad->rfline = ad->mmline = ad->csline = ad->model = ad->mline = ad->aseq = ad->ntseq = ad->ppline = NULL; |
| 1435 |
ad->hmmname = ad->hmmacc = ad->hmmdesc = NULL; |
| 1436 |
ad->sqname = ad->sqacc = ad->sqdesc = NULL; |
| 1437 |
ad->mem = NULL; |
| 1438 |
ad->memsize = 0; |
| 1439 |
|
| 1440 |
|
| 1441 |
if (esl_rnd_Roll(rng, 2) == 0) ESL_ALLOC(ad->rfline, sizeof(char) * (N+1)); |
| 1442 |
if (esl_rnd_Roll(rng, 2) == 0) ESL_ALLOC(ad->mmline, sizeof(char) * (N+1)); |
| 1443 |
if (esl_rnd_Roll(rng, 2) == 0) ESL_ALLOC(ad->csline, sizeof(char) * (N+1)); |
| 1444 |
if (esl_rnd_Roll(rng, 2) == 0) ESL_ALLOC(ad->ppline, sizeof(char) * (N+1)); |
| 1445 |
ESL_ALLOC(ad->model, sizeof(char) * (N+1)); |
| 1446 |
ESL_ALLOC(ad->mline, sizeof(char) * (N+1)); |
| 1447 |
ESL_ALLOC(ad->aseq, sizeof(char) * (N+1)); |
| 1448 |
ad->N = N; |
| 1449 |
|
| 1450 |
esl_strdup("my_hmm", -1, &(ad->hmmname)); |
| 1451 |
if (esl_rnd_Roll(rng, 2) == 0) esl_strdup("PF000007", -1, &(ad->hmmacc)); else esl_strdup("", -1, &(ad->hmmacc)); |
| 1452 |
if (esl_rnd_Roll(rng, 2) == 0) esl_strdup("(hmm description)", -1, &(ad->hmmdesc)); else esl_strdup("", -1, &(ad->hmmdesc)); |
| 1453 |
|
| 1454 |
esl_strdup("my_seq", -1, &(ad->sqname)); |
| 1455 |
if (esl_rnd_Roll(rng, 2) == 0) esl_strdup("ABC000001.42", -1, &(ad->sqacc)); else esl_strdup("", -1, &(ad->sqacc)); |
| 1456 |
if (esl_rnd_Roll(rng, 2) == 0) esl_strdup("(sequence description)", -1, &(ad->sqdesc)); else esl_strdup("", -1, &(ad->sqdesc)); |
| 1457 |
|
| 1458 |
|
| 1459 |
ad->hmmfrom = 100; |
| 1460 |
ad->hmmto = ad->hmmfrom + nM + nD - 1; |
| 1461 |
ad->M = ad->hmmto + esl_rnd_Roll(rng, 2); |
| 1462 |
|
| 1463 |
ad->sqfrom = 1000; |
| 1464 |
ad->sqto = ad->sqfrom + nM + nI - 1; |
| 1465 |
ad->L = ad->sqto + esl_rnd_Roll(rng, 2); |
| 1466 |
|
| 1467 |
|
| 1468 |
if (ad->rfline) { |
| 1469 |
for (pos = 0; pos < N; pos++) |
| 1470 |
ad->rfline[pos] = (guidestring[pos] == 'I' ? '.' : 'x'); |
| 1471 |
ad->rfline[pos] = '\0'; |
| 1472 |
} |
| 1473 |
|
| 1474 |
|
| 1475 |
if (ad->mmline) { |
| 1476 |
for (pos = 0; pos < N; pos++) |
| 1477 |
ad->mmline[pos] = (guidestring[pos] == 'I' ? '.' : '.'); |
| 1478 |
ad->mmline[pos] = '\0'; |
| 1479 |
} |
| 1480 |
|
| 1481 |
|
| 1482 |
if (ad->csline) { |
| 1483 |
for (pos = 0; pos < N; pos++) |
| 1484 |
ad->csline[pos] = (guidestring[pos] == 'I' ? '.' : 'X'); |
| 1485 |
ad->csline[pos] = '\0'; |
| 1486 |
} |
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
for (pos = 0; pos < N; pos++) |
| 1496 |
{ |
| 1497 |
switch (guidestring[pos]) { |
| 1498 |
case 'M': |
| 1499 |
ad->model[pos] = 'X'; |
| 1500 |
switch (esl_rnd_Roll(rng, 3)) { |
| 1501 |
case 0: ad->mline[pos] = 'A'; |
| 1502 |
case 1: ad->mline[pos] = '+'; |
| 1503 |
case 2: ad->mline[pos] = ' '; |
| 1504 |
} |
| 1505 |
if (ad->mline[pos] == ' ' && esl_rnd_Roll(rng, 50) == 0) ad->aseq[pos] = '*'; |
| 1506 |
else ad->aseq[pos] = 'A'; |
| 1507 |
break; |
| 1508 |
|
| 1509 |
case 'D': |
| 1510 |
ad->model[pos] = 'X'; |
| 1511 |
ad->mline[pos] = ' '; |
| 1512 |
ad->aseq[pos] = '-'; |
| 1513 |
break; |
| 1514 |
|
| 1515 |
case 'I': |
| 1516 |
ad->model[pos] = '.'; |
| 1517 |
ad->mline[pos] = ' '; |
| 1518 |
ad->aseq[pos] = 'a'; |
| 1519 |
break; |
| 1520 |
} |
| 1521 |
} |
| 1522 |
ad->model[pos] = '\0'; |
| 1523 |
ad->mline[pos] = '\0'; |
| 1524 |
ad->aseq[pos] = '\0'; |
| 1525 |
|
| 1526 |
|
| 1527 |
if (ad->ppline) { |
| 1528 |
for (pos = 0; pos < N; pos++) |
| 1529 |
ad->ppline[pos] = (guidestring[pos] == 'D' ? '.' : p7_alidisplay_EncodePostProb(esl_random(rng))); |
| 1530 |
ad->ppline[pos] = '\0'; |
| 1531 |
} |
| 1532 |
|
| 1533 |
free(guidestring); |
| 1534 |
*ret_ad = ad; |
| 1535 |
return eslOK; |
| 1536 |
|
| 1537 |
ERROR: |
| 1538 |
if (guidestring) free(guidestring); |
| 1539 |
if (ad) p7_alidisplay_Destroy(ad); |
| 1540 |
*ret_ad = NULL; |
| 1541 |
return status; |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
int |
| 1558 |
p7_alidisplay_Dump(FILE *fp, const P7_ALIDISPLAY *ad) |
| 1559 |
{ |
| 1560 |
fprintf(fp, "P7_ALIDISPLAY dump\n"); |
| 1561 |
fprintf(fp, "------------------\n"); |
| 1562 |
|
| 1563 |
fprintf(fp, "rfline = %s\n", ad->rfline ? ad->rfline : "[none]"); |
| 1564 |
fprintf(fp, "mmline = %s\n", ad->mmline ? ad->mmline : "[none]"); |
| 1565 |
fprintf(fp, "csline = %s\n", ad->csline ? ad->csline : "[none]"); |
| 1566 |
fprintf(fp, "model = %s\n", ad->model); |
| 1567 |
fprintf(fp, "mline = %s\n", ad->mline); |
| 1568 |
fprintf(fp, "aseq = %s\n", ad->aseq); |
| 1569 |
fprintf(fp, "N = %d\n", ad->N); |
| 1570 |
fprintf(fp, "\n"); |
| 1571 |
|
| 1572 |
fprintf(fp, "hmmname = %s\n", ad->hmmname); |
| 1573 |
fprintf(fp, "hmmacc = %s\n", ad->hmmacc[0] == '\0' ? "[none]" : ad->hmmacc); |
| 1574 |
fprintf(fp, "hmmdesc = %s\n", ad->hmmdesc[0] == '\0' ? "[none]" : ad->hmmdesc); |
| 1575 |
fprintf(fp, "hmmfrom = %d\n", ad->hmmfrom); |
| 1576 |
fprintf(fp, "hmmto = %d\n", ad->hmmto); |
| 1577 |
fprintf(fp, "M = %d\n", ad->M); |
| 1578 |
fprintf(fp, "\n"); |
| 1579 |
|
| 1580 |
fprintf(fp, "sqname = %s\n", ad->sqname); |
| 1581 |
fprintf(fp, "sqacc = %s\n", ad->sqacc[0] == '\0' ? "[none]" : ad->sqacc); |
| 1582 |
fprintf(fp, "sqdesc = %s\n", ad->sqdesc[0] == '\0' ? "[none]" : ad->sqdesc); |
| 1583 |
fprintf(fp, "sqfrom = %" PRId64 "\n", ad->sqfrom); |
| 1584 |
fprintf(fp, "sqto = %" PRId64 "\n", ad->sqto); |
| 1585 |
fprintf(fp, "L = %" PRId64 "\n", ad->L); |
| 1586 |
fprintf(fp, "\n"); |
| 1587 |
|
| 1588 |
fprintf(fp, "size = %d bytes\n", (int) p7_alidisplay_Sizeof(ad)); |
| 1589 |
fprintf(fp, "%s\n", ad->mem ? "serialized" : "not serialized"); |
| 1590 |
return eslOK; |
| 1591 |
} |
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
int |
| 1605 |
p7_alidisplay_Compare(const P7_ALIDISPLAY *ad1, const P7_ALIDISPLAY *ad2) |
| 1606 |
{ |
| 1607 |
if (ad1->mem && ad2->mem) |
| 1608 |
{ |
| 1609 |
if (ad1->memsize != ad2->memsize) return eslFAIL; |
| 1610 |
if (memcmp(ad1->mem, ad2->mem, ad1->memsize) != 0) return eslFAIL; |
| 1611 |
} |
| 1612 |
|
| 1613 |
if (esl_strcmp(ad1->rfline, ad2->rfline) != eslOK) return eslFAIL; |
| 1614 |
if (esl_strcmp(ad1->mmline, ad2->mmline) != eslOK) return eslFAIL; |
| 1615 |
if (esl_strcmp(ad1->csline, ad2->csline) != eslOK) return eslFAIL; |
| 1616 |
if (esl_strcmp(ad1->model, ad2->model) != eslOK) return eslFAIL; |
| 1617 |
if (esl_strcmp(ad1->mline, ad2->mline) != eslOK) return eslFAIL; |
| 1618 |
if (esl_strcmp(ad1->aseq, ad2->aseq) != eslOK) return eslFAIL; |
| 1619 |
if (esl_strcmp(ad1->ntseq, ad2->ntseq) != eslOK) return eslFAIL; |
| 1620 |
if (esl_strcmp(ad1->ppline, ad2->ppline) != eslOK) return eslFAIL; |
| 1621 |
if (ad1->N != ad2->N) return eslFAIL; |
| 1622 |
|
| 1623 |
if (esl_strcmp(ad1->hmmname, ad2->hmmname) != eslOK) return eslFAIL; |
| 1624 |
if (esl_strcmp(ad1->hmmacc, ad2->hmmacc) != eslOK) return eslFAIL; |
| 1625 |
if (esl_strcmp(ad1->hmmdesc, ad2->hmmdesc) != eslOK) return eslFAIL; |
| 1626 |
if (ad1->hmmfrom != ad2->hmmfrom) return eslFAIL; |
| 1627 |
if (ad1->hmmto != ad2->hmmto) return eslFAIL; |
| 1628 |
if (ad1->M != ad2->M) return eslFAIL; |
| 1629 |
|
| 1630 |
if (esl_strcmp(ad1->sqname, ad2->sqname) != eslOK) return eslFAIL; |
| 1631 |
if (esl_strcmp(ad1->sqacc, ad2->sqacc) != eslOK) return eslFAIL; |
| 1632 |
if (esl_strcmp(ad1->sqdesc, ad2->sqdesc) != eslOK) return eslFAIL; |
| 1633 |
if (ad1->sqfrom != ad2->sqfrom) return eslFAIL; |
| 1634 |
if (ad1->sqto != ad2->sqto) return eslFAIL; |
| 1635 |
if (ad1->M != ad2->M) return eslFAIL; |
| 1636 |
|
| 1637 |
return eslOK; |
| 1638 |
} |
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
#ifdef p7ALIDISPLAY_BENCHMARK |
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
#include <p7_config.h> |
| 1656 |
|
| 1657 |
#include "easel.h" |
| 1658 |
#include "esl_alphabet.h" |
| 1659 |
#include "esl_getopts.h" |
| 1660 |
#include "esl_random.h" |
| 1661 |
#include "esl_stopwatch.h" |
| 1662 |
|
| 1663 |
#include "hmmer.h" |
| 1664 |
|
| 1665 |
static ESL_OPTIONS options[] = { |
| 1666 |
|
| 1667 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 1668 |
{ "-b", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "baseline timing", 0 }, |
| 1669 |
{ "-p", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "include fake PP line, just to see how it looks", 0 }, |
| 1670 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 1671 |
{ "-N", eslARG_INT, "50000", NULL, "n>0", NULL, NULL, NULL, "number of traces to generate", 0 }, |
| 1672 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1673 |
}; |
| 1674 |
static char usage[] = "[-options] <hmmfile>"; |
| 1675 |
static char banner[] = "benchmark driver for P7_ALIDISPLAY"; |
| 1676 |
|
| 1677 |
int |
| 1678 |
main(int argc, char **argv) |
| 1679 |
{ |
| 1680 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 1681 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 1682 |
int N = esl_opt_GetInteger(go, "-N"); |
| 1683 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 1684 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 1685 |
ESL_ALPHABET *abc = NULL; |
| 1686 |
P7_HMMFILE *hfp = NULL; |
| 1687 |
P7_HMM *hmm = NULL; |
| 1688 |
P7_BG *bg = NULL; |
| 1689 |
P7_PROFILE *gm = NULL; |
| 1690 |
P7_OPROFILE *om = NULL; |
| 1691 |
P7_TRACE *tr = NULL; |
| 1692 |
ESL_SQ *sq = NULL; |
| 1693 |
P7_ALIDISPLAY *ad = NULL; |
| 1694 |
int i,z; |
| 1695 |
|
| 1696 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 1697 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 1698 |
p7_hmmfile_Close(hfp); |
| 1699 |
|
| 1700 |
|
| 1701 |
bg = p7_bg_Create(abc); |
| 1702 |
p7_bg_SetLength(bg, 0); |
| 1703 |
gm = p7_profile_Create(hmm->M, abc); |
| 1704 |
p7_ProfileConfig(hmm, bg, gm, 0, p7_UNIGLOCAL); |
| 1705 |
om = p7_oprofile_Create(gm->M, abc); |
| 1706 |
p7_oprofile_Convert(gm, om); |
| 1707 |
|
| 1708 |
if (esl_opt_GetBoolean(go, "-p")) tr = p7_trace_CreateWithPP(); |
| 1709 |
else tr = p7_trace_Create(); |
| 1710 |
|
| 1711 |
sq = esl_sq_CreateDigital(abc); |
| 1712 |
|
| 1713 |
esl_stopwatch_Start(w); |
| 1714 |
for (i = 0; i < N; i++) |
| 1715 |
{ |
| 1716 |
p7_ProfileEmit(r, hmm, gm, bg, sq, tr); |
| 1717 |
esl_sq_SetName(sq, "random"); |
| 1718 |
|
| 1719 |
if (! esl_opt_GetBoolean(go, "-b")) |
| 1720 |
{ |
| 1721 |
if (esl_opt_GetBoolean(go, "-p")) |
| 1722 |
for (z = 0; z < tr->N; z++) |
| 1723 |
if (tr->i[z] > 0) tr->pp[z] = esl_random(r); |
| 1724 |
|
| 1725 |
ad = p7_alidisplay_Create(tr, 0, om, sq, NULL); |
| 1726 |
p7_alidisplay_Print(stdout, ad, 40, 80, FALSE); |
| 1727 |
p7_alidisplay_Destroy(ad); |
| 1728 |
} |
| 1729 |
p7_trace_Reuse(tr); |
| 1730 |
esl_sq_Reuse(sq); |
| 1731 |
} |
| 1732 |
esl_stopwatch_Stop(w); |
| 1733 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 1734 |
|
| 1735 |
esl_sq_Destroy(sq); |
| 1736 |
p7_trace_Destroy(tr); |
| 1737 |
p7_oprofile_Destroy(om); |
| 1738 |
p7_profile_Destroy(gm); |
| 1739 |
p7_bg_Destroy(bg); |
| 1740 |
p7_hmm_Destroy(hmm); |
| 1741 |
esl_alphabet_Destroy(abc); |
| 1742 |
esl_randomness_Destroy(r); |
| 1743 |
esl_stopwatch_Destroy(w); |
| 1744 |
esl_getopts_Destroy(go); |
| 1745 |
return 0; |
| 1746 |
} |
| 1747 |
#endif |
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
#ifdef p7ALIDISPLAY_TESTDRIVE |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
static int |
| 1761 |
alidisplay_SampleFake_ntseq(ESL_RANDOMNESS *rng, int N, P7_ALIDISPLAY **ret_ad) |
| 1762 |
{ |
| 1763 |
P7_ALIDISPLAY *ad = NULL; |
| 1764 |
char *guidestring = NULL; |
| 1765 |
int nM = 0; |
| 1766 |
int nD = 0; |
| 1767 |
int nI = 0; |
| 1768 |
enum p7t_statetype_e last_st; |
| 1769 |
int pos; |
| 1770 |
int status; |
| 1771 |
|
| 1772 |
ESL_ALLOC(guidestring, sizeof(char) * (N+1)); |
| 1773 |
|
| 1774 |
guidestring[0] = 'M'; nM++; last_st = p7T_M; |
| 1775 |
for (pos = 1; pos < N-1; pos++) |
| 1776 |
{ |
| 1777 |
switch (last_st) |
| 1778 |
{ |
| 1779 |
case p7T_M: |
| 1780 |
switch (esl_rnd_Roll(rng, 3)) |
| 1781 |
{ |
| 1782 |
case 0: guidestring[pos] = 'M'; nM++; last_st = p7T_M; break; |
| 1783 |
case 1: guidestring[pos] = 'D'; nD++; last_st = p7T_D; break; |
| 1784 |
case 2: guidestring[pos] = 'I'; nI++; last_st = p7T_I; break; |
| 1785 |
} |
| 1786 |
break; |
| 1787 |
|
| 1788 |
case p7T_I: |
| 1789 |
switch (esl_rnd_Roll(rng, 2)) |
| 1790 |
{ |
| 1791 |
case 0: guidestring[pos] = 'M'; nM++; last_st = p7T_M; break; |
| 1792 |
case 1: guidestring[pos] = 'I'; nI++; last_st = p7T_I; break; |
| 1793 |
} |
| 1794 |
break; |
| 1795 |
|
| 1796 |
case p7T_D: |
| 1797 |
switch (esl_rnd_Roll(rng, 2)) |
| 1798 |
{ |
| 1799 |
case 0: guidestring[pos] = 'M'; nM++; last_st = p7T_M; break; |
| 1800 |
case 1: guidestring[pos] = 'D'; nD++; last_st = p7T_D; break; |
| 1801 |
} |
| 1802 |
break; |
| 1803 |
|
| 1804 |
default: |
| 1805 |
break; |
| 1806 |
} |
| 1807 |
} |
| 1808 |
|
| 1809 |
switch (last_st) { |
| 1810 |
case p7T_I: |
| 1811 |
guidestring[N-1] = 'M'; nM++; break; |
| 1812 |
default: |
| 1813 |
switch (esl_rnd_Roll(rng, 2)) { |
| 1814 |
case 0: guidestring[N-1] = 'M'; nM++; break; |
| 1815 |
case 1: guidestring[N-1] = 'D'; nD++; break; |
| 1816 |
} |
| 1817 |
break; |
| 1818 |
} |
| 1819 |
guidestring[N] = '\0'; |
| 1820 |
|
| 1821 |
ESL_ALLOC(ad, sizeof(P7_ALIDISPLAY)); |
| 1822 |
ad->rfline = ad->mmline = ad->csline = ad->model = ad->mline = ad->aseq = ad->ntseq = ad->ppline = NULL; |
| 1823 |
ad->hmmname = ad->hmmacc = ad->hmmdesc = NULL; |
| 1824 |
ad->sqname = ad->sqacc = ad->sqdesc = NULL; |
| 1825 |
ad->mem = NULL; |
| 1826 |
ad->memsize = 0; |
| 1827 |
|
| 1828 |
|
| 1829 |
if (esl_rnd_Roll(rng, 2) == 0) ESL_ALLOC(ad->rfline, sizeof(char) * (N+1)); |
| 1830 |
if (esl_rnd_Roll(rng, 2) == 0) ESL_ALLOC(ad->mmline, sizeof(char) * (N+1)); |
| 1831 |
if (esl_rnd_Roll(rng, 2) == 0) ESL_ALLOC(ad->csline, sizeof(char) * (N+1)); |
| 1832 |
if (esl_rnd_Roll(rng, 2) == 0) ESL_ALLOC(ad->ppline, sizeof(char) * (N+1)); |
| 1833 |
ESL_ALLOC(ad->model, sizeof(char) * (N+1)); |
| 1834 |
ESL_ALLOC(ad->mline, sizeof(char) * (N+1)); |
| 1835 |
ESL_ALLOC(ad->ntseq, sizeof(char) * ((3 *N)+1)); |
| 1836 |
ad->N = N; |
| 1837 |
|
| 1838 |
esl_strdup("my_hmm", -1, &(ad->hmmname)); |
| 1839 |
if (esl_rnd_Roll(rng, 2) == 0) esl_strdup("PF000007", -1, &(ad->hmmacc)); else esl_strdup("", -1, &(ad->hmmacc)); |
| 1840 |
if (esl_rnd_Roll(rng, 2) == 0) esl_strdup("(hmm description)", -1, &(ad->hmmdesc)); else esl_strdup("", -1, &(ad->hmmdesc)); |
| 1841 |
|
| 1842 |
esl_strdup("my_seq", -1, &(ad->sqname)); |
| 1843 |
if (esl_rnd_Roll(rng, 2) == 0) esl_strdup("ABC000001.42", -1, &(ad->sqacc)); else esl_strdup("", -1, &(ad->sqacc)); |
| 1844 |
if (esl_rnd_Roll(rng, 2) == 0) esl_strdup("(sequence description)", -1, &(ad->sqdesc)); else esl_strdup("", -1, &(ad->sqdesc)); |
| 1845 |
|
| 1846 |
|
| 1847 |
ad->hmmfrom = 100; |
| 1848 |
ad->hmmto = ad->hmmfrom + nM + nD - 1; |
| 1849 |
ad->M = ad->hmmto + esl_rnd_Roll(rng, 2); |
| 1850 |
|
| 1851 |
ad->sqfrom = 1000; |
| 1852 |
ad->sqto = ad->sqfrom + nM + nI - 1; |
| 1853 |
ad->L = ad->sqto + esl_rnd_Roll(rng, 2); |
| 1854 |
|
| 1855 |
|
| 1856 |
if (ad->rfline) { |
| 1857 |
for (pos = 0; pos < N; pos++) |
| 1858 |
ad->rfline[pos] = (guidestring[pos] == 'I' ? '.' : 'x'); |
| 1859 |
ad->rfline[pos] = '\0'; |
| 1860 |
} |
| 1861 |
|
| 1862 |
|
| 1863 |
if (ad->mmline) { |
| 1864 |
for (pos = 0; pos < N; pos++) |
| 1865 |
ad->mmline[pos] = (guidestring[pos] == 'I' ? '.' : '.'); |
| 1866 |
ad->mmline[pos] = '\0'; |
| 1867 |
} |
| 1868 |
|
| 1869 |
|
| 1870 |
if (ad->csline) { |
| 1871 |
for (pos = 0; pos < N; pos++) |
| 1872 |
ad->csline[pos] = (guidestring[pos] == 'I' ? '.' : 'X'); |
| 1873 |
ad->csline[pos] = '\0'; |
| 1874 |
} |
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
for (pos = 0; pos < N; pos++) |
| 1884 |
{ |
| 1885 |
switch (guidestring[pos]) { |
| 1886 |
case 'M': |
| 1887 |
ad->model[pos] = 'X'; |
| 1888 |
switch (esl_rnd_Roll(rng, 3)) { |
| 1889 |
case 0: ad->mline[pos] = 'A'; |
| 1890 |
case 1: ad->mline[pos] = '+'; |
| 1891 |
case 2: ad->mline[pos] = ' '; |
| 1892 |
} |
| 1893 |
if (ad->mline[pos] == ' ' && esl_rnd_Roll(rng, 50) == 0) ad->ntseq[pos] = '*'; |
| 1894 |
else ad->ntseq[pos] = 'A'; |
| 1895 |
break; |
| 1896 |
|
| 1897 |
case 'D': |
| 1898 |
ad->model[pos] = 'X'; |
| 1899 |
ad->mline[pos] = ' '; |
| 1900 |
ad->ntseq[pos] = '-'; |
| 1901 |
break; |
| 1902 |
|
| 1903 |
case 'I': |
| 1904 |
ad->model[pos] = '.'; |
| 1905 |
ad->mline[pos] = ' '; |
| 1906 |
ad->ntseq[pos] = 'a'; |
| 1907 |
break; |
| 1908 |
} |
| 1909 |
} |
| 1910 |
ad->model[pos] = '\0'; |
| 1911 |
ad->mline[pos] = '\0'; |
| 1912 |
|
| 1913 |
|
| 1914 |
for (pos = N; pos < (3 * N); pos++){ |
| 1915 |
if(esl_rnd_Roll(rng, 50) == 0) ad->ntseq[pos] = '*'; |
| 1916 |
else ad->ntseq[pos] = 'A'; |
| 1917 |
} |
| 1918 |
ad->ntseq[pos] = '\0'; |
| 1919 |
|
| 1920 |
|
| 1921 |
if (ad->ppline) { |
| 1922 |
for (pos = 0; pos < N; pos++) |
| 1923 |
ad->ppline[pos] = (guidestring[pos] == 'D' ? '.' : p7_alidisplay_EncodePostProb(esl_random(rng))); |
| 1924 |
ad->ppline[pos] = '\0'; |
| 1925 |
} |
| 1926 |
|
| 1927 |
free(guidestring); |
| 1928 |
*ret_ad = ad; |
| 1929 |
return eslOK; |
| 1930 |
|
| 1931 |
ERROR: |
| 1932 |
if (guidestring) free(guidestring); |
| 1933 |
if (ad) p7_alidisplay_Destroy(ad); |
| 1934 |
*ret_ad = NULL; |
| 1935 |
return status; |
| 1936 |
} |
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
static void |
| 1942 |
utest_Serialize(ESL_RANDOMNESS *rng, int ntrials) |
| 1943 |
{ |
| 1944 |
char msg[] = "utest_Serialize failed"; |
| 1945 |
P7_ALIDISPLAY **serial = malloc(ntrials * sizeof(P7_ALIDISPLAY *)); |
| 1946 |
P7_ALIDISPLAY **deserial = malloc(ntrials * sizeof(P7_ALIDISPLAY *)); |
| 1947 |
uint8_t **buf = malloc(sizeof(uint8_t *)); |
| 1948 |
uint32_t n = 0; |
| 1949 |
uint32_t nalloc = 0; |
| 1950 |
int alignment_length; |
| 1951 |
int i; |
| 1952 |
|
| 1953 |
*buf = NULL; |
| 1954 |
for (i = 0; i < ntrials; i++) |
| 1955 |
{ |
| 1956 |
|
| 1957 |
alignment_length = (esl_random_uint32(rng) %300) + 50; |
| 1958 |
if (esl_rnd_Roll(rng, 2) == 0) |
| 1959 |
{ |
| 1960 |
if (p7_alidisplay_Sample(rng, alignment_length, &(serial[i])) != eslOK) esl_fatal(msg); |
| 1961 |
} |
| 1962 |
else |
| 1963 |
{ |
| 1964 |
if (alidisplay_SampleFake_ntseq(rng, alignment_length, &(serial[i])) != eslOK) esl_fatal(msg); |
| 1965 |
} |
| 1966 |
if (p7_alidisplay_Serialize(serial[i], buf, &n, &nalloc) != eslOK) esl_fatal(msg); |
| 1967 |
} |
| 1968 |
|
| 1969 |
n = 0; |
| 1970 |
for (i = 0; i < ntrials; i++) |
| 1971 |
{ |
| 1972 |
if ((deserial[i] = p7_alidisplay_Create_empty()) == NULL) esl_fatal(msg); |
| 1973 |
if( p7_alidisplay_Deserialize(*buf, &n, deserial[i]) != eslOK) esl_fatal(msg); |
| 1974 |
} |
| 1975 |
|
| 1976 |
|
| 1977 |
free(*buf); |
| 1978 |
free(buf); |
| 1979 |
for (i = 0; i < ntrials; i++) |
| 1980 |
if (p7_alidisplay_Compare(serial[i], deserial[i]) != eslOK) esl_fatal(msg); |
| 1981 |
|
| 1982 |
|
| 1983 |
for (i = 0; i < ntrials; i++) { |
| 1984 |
p7_alidisplay_Destroy(serial[i]); |
| 1985 |
p7_alidisplay_Destroy(deserial[i]); |
| 1986 |
} |
| 1987 |
free(serial); |
| 1988 |
free(deserial); |
| 1989 |
return; |
| 1990 |
} |
| 1991 |
|
| 1992 |
|
| 1993 |
static void |
| 1994 |
utest_serialize_error_conditions(ESL_RANDOMNESS *rng) |
| 1995 |
{ |
| 1996 |
char msg[] = "utest_serialize_error_conditions failed"; |
| 1997 |
P7_ALIDISPLAY *foo = NULL; |
| 1998 |
uint8_t **buf = malloc(sizeof(uint8_t *)); |
| 1999 |
uint32_t n = 0; |
| 2000 |
uint32_t nalloc = 0; |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
*buf = NULL; |
| 2005 |
if ( p7_alidisplay_Sample(rng, 100, &foo) != eslOK) esl_fatal(msg); |
| 2006 |
if ( p7_alidisplay_Serialize(foo, NULL, &n, &nalloc) != eslEINVAL) esl_fatal(msg); |
| 2007 |
if ( p7_alidisplay_Serialize(foo, buf, NULL, &nalloc) != eslEINVAL) esl_fatal(msg); |
| 2008 |
if ( p7_alidisplay_Serialize(NULL, buf, &n, &nalloc) != eslEINVAL) esl_fatal(msg); |
| 2009 |
|
| 2010 |
if (buf) { free(*buf); free(buf); } |
| 2011 |
p7_alidisplay_Destroy(foo); |
| 2012 |
return; |
| 2013 |
} |
| 2014 |
|
| 2015 |
static void |
| 2016 |
utest_deserialize_error_conditions(ESL_RANDOMNESS *rng) |
| 2017 |
{ |
| 2018 |
char msg[] = "utest_deserialize_error_conditions failed"; |
| 2019 |
P7_ALIDISPLAY *sampled = NULL; |
| 2020 |
P7_ALIDISPLAY *deserial = NULL; |
| 2021 |
uint8_t *buf = NULL; |
| 2022 |
uint32_t n = 0, nalloc = 0; |
| 2023 |
|
| 2024 |
if ((deserial = p7_alidisplay_Create_empty()) == NULL) esl_fatal(msg); |
| 2025 |
if ( p7_alidisplay_Sample(rng, 100, &sampled) != eslOK) esl_fatal(msg); |
| 2026 |
if ( p7_alidisplay_Serialize(sampled, &buf, &n, &nalloc) != eslOK) esl_fatal(msg); |
| 2027 |
|
| 2028 |
|
| 2029 |
if ( p7_alidisplay_Deserialize(NULL, &n, deserial) != eslEINVAL) esl_fatal(msg); |
| 2030 |
if ( p7_alidisplay_Deserialize(buf, NULL, deserial) != eslEINVAL) esl_fatal(msg); |
| 2031 |
if ( p7_alidisplay_Deserialize(buf, &n, NULL) != eslEINVAL) esl_fatal(msg); |
| 2032 |
|
| 2033 |
free(buf); |
| 2034 |
p7_alidisplay_Destroy(deserial); |
| 2035 |
p7_alidisplay_Destroy(sampled); |
| 2036 |
return; |
| 2037 |
} |
| 2038 |
|
| 2039 |
|
| 2040 |
static void |
| 2041 |
utest_Backconvert(int be_verbose, ESL_RANDOMNESS *rng, ESL_ALPHABET *abc, int ntrials, int N) |
| 2042 |
{ |
| 2043 |
char msg[] = "utest_Backconvert failed"; |
| 2044 |
P7_ALIDISPLAY *ad = NULL; |
| 2045 |
ESL_SQ *sq = NULL; |
| 2046 |
P7_TRACE *tr = NULL; |
| 2047 |
int trial; |
| 2048 |
|
| 2049 |
for (trial = 0; trial < ntrials; trial++) |
| 2050 |
{ |
| 2051 |
if ( p7_alidisplay_Sample(rng, N, &ad) != eslOK) esl_fatal(msg); |
| 2052 |
if ( p7_alidisplay_Serialize_old(ad) != eslOK) esl_fatal(msg); |
| 2053 |
if (be_verbose && p7_alidisplay_Dump(stdout, ad) != eslOK) esl_fatal(msg); |
| 2054 |
if ( p7_alidisplay_Backconvert(ad, abc, &sq, &tr) != eslOK) esl_fatal(msg); |
| 2055 |
if (be_verbose && p7_trace_Dump(stdout, tr, NULL, sq->dsq) != eslOK) esl_fatal(msg); |
| 2056 |
if ( p7_trace_Validate(tr, abc, sq->dsq, NULL) != eslOK) esl_fatal(msg); |
| 2057 |
|
| 2058 |
p7_alidisplay_Destroy(ad); |
| 2059 |
esl_sq_Destroy(sq); |
| 2060 |
p7_trace_Destroy(tr); |
| 2061 |
} |
| 2062 |
return; |
| 2063 |
} |
| 2064 |
|
| 2065 |
|
| 2066 |
#endif |
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
#ifdef p7ALIDISPLAY_TESTDRIVE |
| 2073 |
|
| 2074 |
#include <stdlib.h> |
| 2075 |
#include <string.h> |
| 2076 |
|
| 2077 |
#include "easel.h" |
| 2078 |
#include "esl_getopts.h" |
| 2079 |
#include "esl_random.h" |
| 2080 |
|
| 2081 |
#include "hmmer.h" |
| 2082 |
|
| 2083 |
static ESL_OPTIONS options[] = { |
| 2084 |
|
| 2085 |
{"-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show help and usage", 0}, |
| 2086 |
{"-N", eslARG_INT, "10", NULL, NULL, NULL, NULL, NULL, "number of random-sampled alidisplays to test", 0}, |
| 2087 |
{"-L", eslARG_INT, "20", NULL, NULL, NULL, NULL, NULL, "length of random-sampled alidisplays to test", 0}, |
| 2088 |
{"-s", eslARG_INT, "0", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0}, |
| 2089 |
{"-v", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show verbose commentary/output", 0}, |
| 2090 |
{ 0,0,0,0,0,0,0,0,0,0}, |
| 2091 |
}; |
| 2092 |
static char usage[] = "[-options]"; |
| 2093 |
static char banner[] = "test driver for p7_alidisplay.c"; |
| 2094 |
|
| 2095 |
int |
| 2096 |
main(int argc, char **argv) |
| 2097 |
{ |
| 2098 |
ESL_GETOPTS *go = esl_getopts_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 2099 |
ESL_RANDOMNESS *rng = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 2100 |
ESL_ALPHABET *abc = esl_alphabet_Create(eslAMINO); |
| 2101 |
int N = esl_opt_GetInteger(go, "-N"); |
| 2102 |
int L = esl_opt_GetInteger(go, "-L"); |
| 2103 |
int be_verbose = esl_opt_GetBoolean(go, "-v"); |
| 2104 |
|
| 2105 |
|
| 2106 |
utest_Serialize(rng, 100); |
| 2107 |
utest_Backconvert(be_verbose, rng, abc, N, L); |
| 2108 |
utest_serialize_error_conditions(rng); |
| 2109 |
utest_deserialize_error_conditions(rng); |
| 2110 |
|
| 2111 |
esl_alphabet_Destroy(abc); |
| 2112 |
esl_randomness_Destroy(rng); |
| 2113 |
esl_getopts_Destroy(go); |
| 2114 |
return 0; |
| 2115 |
} |
| 2116 |
#endif |
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
#ifdef p7ALIDISPLAY_EXAMPLE |
| 2127 |
#include <p7_config.h> |
| 2128 |
|
| 2129 |
#include "easel.h" |
| 2130 |
#include "esl_alphabet.h" |
| 2131 |
#include "esl_getopts.h" |
| 2132 |
#include "esl_sq.h" |
| 2133 |
#include "esl_sqio.h" |
| 2134 |
|
| 2135 |
#include "hmmer.h" |
| 2136 |
|
| 2137 |
static ESL_OPTIONS options[] = { |
| 2138 |
|
| 2139 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 2140 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 2141 |
}; |
| 2142 |
static char usage[] = "[-options] <hmmfile> <seqfile>"; |
| 2143 |
static char banner[] = "example driver for P7_ALIDISPLAY"; |
| 2144 |
|
| 2145 |
int |
| 2146 |
main(int argc, char **argv) |
| 2147 |
{ |
| 2148 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 2, argc, argv, banner, usage); |
| 2149 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 2150 |
char *seqfile = esl_opt_GetArg(go, 2); |
| 2151 |
ESL_ALPHABET *abc = NULL; |
| 2152 |
P7_HMMFILE *hfp = NULL; |
| 2153 |
P7_HMM *hmm = NULL; |
| 2154 |
P7_BG *bg = NULL; |
| 2155 |
P7_PROFILE *gm = NULL; |
| 2156 |
P7_OPROFILE *om = NULL; |
| 2157 |
P7_TRACE *tr1 = NULL; |
| 2158 |
P7_TRACE *tr2 = NULL; |
| 2159 |
ESL_SQFILE *sqfp = NULL; |
| 2160 |
ESL_SQ *sq = NULL; |
| 2161 |
ESL_SQ *sq2 = NULL; |
| 2162 |
P7_ALIDISPLAY *ad = NULL; |
| 2163 |
P7_PIPELINE *pli = NULL; |
| 2164 |
P7_TOPHITS *hitlist = NULL; |
| 2165 |
|
| 2166 |
p7_FLogsumInit(); |
| 2167 |
|
| 2168 |
|
| 2169 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 2170 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 2171 |
p7_hmmfile_Close(hfp); |
| 2172 |
|
| 2173 |
|
| 2174 |
if (esl_sqfile_Open(seqfile, eslSQFILE_UNKNOWN, NULL, &sqfp) != eslOK) p7_Fail("Failed to open sequence file %s", seqfile); |
| 2175 |
sq = esl_sq_CreateDigital(abc); |
| 2176 |
if (esl_sqio_Read(sqfp, sq) != eslOK) p7_Fail("Failed to read sequence"); |
| 2177 |
|
| 2178 |
|
| 2179 |
bg = p7_bg_Create(abc); |
| 2180 |
p7_bg_SetLength(bg, 0); |
| 2181 |
gm = p7_profile_Create(hmm->M, abc); |
| 2182 |
p7_ProfileConfig(hmm, bg, gm, 0, p7_UNILOCAL); |
| 2183 |
om = p7_oprofile_Create(gm->M, abc); |
| 2184 |
p7_oprofile_Convert(gm, om); |
| 2185 |
|
| 2186 |
|
| 2187 |
pli = p7_pipeline_Create(NULL, hmm->M, 400, FALSE, p7_SEARCH_SEQS); |
| 2188 |
hitlist = p7_tophits_Create(); |
| 2189 |
|
| 2190 |
|
| 2191 |
p7_pli_NewSeq(pli, sq); |
| 2192 |
p7_bg_SetLength(bg, sq->n); |
| 2193 |
p7_oprofile_ReconfigLength(om, sq->n); |
| 2194 |
p7_Pipeline(pli, om, bg, sq, NULL, hitlist); |
| 2195 |
|
| 2196 |
if (hitlist->N == 0) { p7_Fail("target sequence doesn't hit"); } |
| 2197 |
|
| 2198 |
if (p7_alidisplay_Backconvert(hitlist->hit[0]->dcl[0].ad, abc, &sq2, &tr2) != eslOK) p7_Fail("backconvert failed"); |
| 2199 |
|
| 2200 |
p7_trace_Dump(stdout, tr2, gm, sq2->dsq); |
| 2201 |
|
| 2202 |
p7_tophits_Destroy(hitlist); |
| 2203 |
p7_alidisplay_Destroy(ad); |
| 2204 |
esl_sq_Destroy(sq); |
| 2205 |
esl_sq_Destroy(sq2); |
| 2206 |
p7_trace_Destroy(tr2); |
| 2207 |
p7_trace_Destroy(tr1); |
| 2208 |
p7_oprofile_Destroy(om); |
| 2209 |
p7_profile_Destroy(gm); |
| 2210 |
p7_bg_Destroy(bg); |
| 2211 |
p7_hmm_Destroy(hmm); |
| 2212 |
esl_alphabet_Destroy(abc); |
| 2213 |
esl_getopts_Destroy(go); |
| 2214 |
return 0; |
| 2215 |
} |
| 2216 |
#endif |
| 2217 |
|
| 2218 |
|