| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <p7_config.h> |
| 8 |
|
| 9 |
#include <stdlib.h> |
| 10 |
#include <stdio.h> |
| 11 |
#include <string.h> |
| 12 |
#include <ctype.h> |
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
#include "easel.h" |
| 16 |
#include "esl_vectorops.h" |
| 17 |
|
| 18 |
#include "hmmer.h" |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
extern P7_DOMAIN *p7_domain_Create_empty(){ |
| 33 |
P7_DOMAIN *the_domain; |
| 34 |
int status; |
| 35 |
|
| 36 |
ESL_ALLOC(the_domain, sizeof(P7_DOMAIN)); |
| 37 |
|
| 38 |
the_domain->ienv = 0; |
| 39 |
the_domain->jenv = 0; |
| 40 |
the_domain->iali = 0; |
| 41 |
the_domain->jali = 0; |
| 42 |
the_domain->iorf = 0; |
| 43 |
the_domain->jorf = 0; |
| 44 |
the_domain->envsc = 0.0; |
| 45 |
the_domain->domcorrection = 0.0; |
| 46 |
the_domain->dombias = 0.0; |
| 47 |
the_domain->oasc = 0.0; |
| 48 |
the_domain->bitscore = 0.0; |
| 49 |
the_domain->lnP = 0.0; |
| 50 |
the_domain->is_reported = 0; |
| 51 |
the_domain->is_included = 0; |
| 52 |
the_domain->scores_per_pos = NULL; |
| 53 |
the_domain->ad = NULL; |
| 54 |
|
| 55 |
return the_domain; |
| 56 |
|
| 57 |
ERROR: |
| 58 |
return NULL; |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
extern void p7_domain_Destroy(P7_DOMAIN *obj){ |
| 76 |
if(obj == NULL){ |
| 77 |
return; |
| 78 |
} |
| 79 |
if(obj->scores_per_pos != NULL){ |
| 80 |
free(obj->scores_per_pos); |
| 81 |
} |
| 82 |
if(obj->ad != NULL){ |
| 83 |
p7_alidisplay_Destroy(obj->ad); |
| 84 |
} |
| 85 |
free(obj); |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
extern int p7_domain_Copy(const P7_DOMAIN *src, P7_DOMAIN *dst){ |
| 100 |
int status = eslOK; |
| 101 |
P7_ALIDISPLAY* ad = NULL; |
| 102 |
float* scores_per_pos = NULL; |
| 103 |
|
| 104 |
|
| 105 |
if (src->ad != NULL) { |
| 106 |
if ((ad = p7_alidisplay_Clone(src->ad)) == NULL) ESL_XEXCEPTION(eslEMEM, "allocation failure"); |
| 107 |
if (src->scores_per_pos != NULL) { |
| 108 |
ESL_ALLOC(scores_per_pos, sizeof(float) * src->ad->N); |
| 109 |
esl_vec_FCopy(src->scores_per_pos, src->ad->N, scores_per_pos); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
memcpy(dst, src, sizeof(P7_DOMAIN)); |
| 115 |
dst->ad = ad; |
| 116 |
dst->scores_per_pos = scores_per_pos; |
| 117 |
return status; |
| 118 |
|
| 119 |
ERROR: |
| 120 |
free(ad); |
| 121 |
free(scores_per_pos); |
| 122 |
return status; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
#define SER_BASE_SIZE (4 * sizeof(int)) + (6 * sizeof(int64_t)) + (5 * sizeof(float)) + (sizeof(double)) |
| 155 |
|
| 156 |
extern int p7_domain_Serialize(const P7_DOMAIN *obj, uint8_t **buf, uint32_t *n, uint32_t *nalloc){ |
| 157 |
|
| 158 |
int status; |
| 159 |
uint32_t ser_size; |
| 160 |
uint8_t *ptr; |
| 161 |
uint32_t network_32bit; |
| 162 |
uint64_t network_64bit; |
| 163 |
int i; |
| 164 |
|
| 165 |
if(obj == NULL || buf == NULL || n == NULL){ |
| 166 |
return(eslEINVAL); |
| 167 |
} |
| 168 |
|
| 169 |
if(obj->scores_per_pos != NULL){ |
| 170 |
ser_size = SER_BASE_SIZE + (obj->ad->N * sizeof(float)); |
| 171 |
} |
| 172 |
else{ |
| 173 |
ser_size = SER_BASE_SIZE; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
if(*buf == NULL){ |
| 178 |
if((*n != 0) || (*nalloc != 0)){ |
| 179 |
return eslEINVAL; |
| 180 |
} |
| 181 |
ESL_ALLOC(*buf, ser_size); |
| 182 |
*nalloc = ser_size; |
| 183 |
} |
| 184 |
|
| 185 |
if((*n + ser_size) > *nalloc){ |
| 186 |
ESL_REALLOC(*buf, (*n + ser_size)); |
| 187 |
*nalloc = *n + ser_size; |
| 188 |
} |
| 189 |
|
| 190 |
ptr = *buf + *n; |
| 191 |
|
| 192 |
|
| 193 |
network_32bit = esl_hton32(ser_size); |
| 194 |
memcpy(ptr, &network_32bit, sizeof(int32_t)); |
| 195 |
ptr += sizeof(int32_t); |
| 196 |
|
| 197 |
|
| 198 |
network_64bit = esl_hton64(obj->ienv); |
| 199 |
memcpy(ptr, &network_64bit, sizeof(int64_t)); |
| 200 |
ptr += sizeof(int64_t); |
| 201 |
|
| 202 |
|
| 203 |
network_64bit = esl_hton64(obj->jenv); |
| 204 |
memcpy(ptr, &network_64bit, sizeof(int64_t)); |
| 205 |
ptr += sizeof(int64_t); |
| 206 |
|
| 207 |
|
| 208 |
network_64bit = esl_hton64(obj->iali); |
| 209 |
memcpy(ptr, &network_64bit, sizeof(int64_t)); |
| 210 |
ptr += sizeof(int64_t); |
| 211 |
|
| 212 |
|
| 213 |
network_64bit = esl_hton64(obj->jali); |
| 214 |
memcpy(ptr, &network_64bit, sizeof(int64_t)); |
| 215 |
ptr += sizeof(int64_t); |
| 216 |
|
| 217 |
|
| 218 |
network_64bit = esl_hton64(obj->iorf); |
| 219 |
memcpy(ptr, &network_64bit, sizeof(int64_t)); |
| 220 |
ptr += sizeof(int64_t); |
| 221 |
|
| 222 |
|
| 223 |
network_64bit = esl_hton64(obj->jorf); |
| 224 |
memcpy(ptr, &network_64bit, sizeof(int64_t)); |
| 225 |
ptr += sizeof(int64_t); |
| 226 |
|
| 227 |
|
| 228 |
network_32bit = esl_hton32(*((uint32_t *) &(obj->envsc))); |
| 229 |
|
| 230 |
|
| 231 |
memcpy((void *) ptr, (void *) &network_32bit, sizeof(obj->envsc)); |
| 232 |
ptr += sizeof(obj->envsc); |
| 233 |
|
| 234 |
|
| 235 |
network_32bit = esl_hton32(*((uint32_t *) &(obj->domcorrection))); |
| 236 |
memcpy((void *) ptr, (void *) &network_32bit, sizeof(obj->domcorrection)); |
| 237 |
ptr += sizeof(obj->domcorrection); |
| 238 |
|
| 239 |
|
| 240 |
network_32bit = esl_hton32(*((uint32_t *) &(obj->dombias))); |
| 241 |
memcpy((void *) ptr, (void *) &network_32bit, sizeof(obj->dombias)); |
| 242 |
ptr += sizeof(obj->dombias); |
| 243 |
|
| 244 |
|
| 245 |
network_32bit = esl_hton32(*((uint32_t *) &(obj->oasc))); |
| 246 |
memcpy((void *) ptr, (void *) &network_32bit, sizeof(obj->oasc)); |
| 247 |
ptr += sizeof(obj->oasc); |
| 248 |
|
| 249 |
|
| 250 |
network_32bit = esl_hton32(*((uint32_t *) &(obj->bitscore))); |
| 251 |
memcpy((void *) ptr, (void *) &network_32bit, sizeof(obj->bitscore)); |
| 252 |
ptr += sizeof(obj->bitscore); |
| 253 |
|
| 254 |
|
| 255 |
network_64bit = esl_hton64(*((uint64_t *) &(obj->lnP))); |
| 256 |
memcpy((void *) ptr, (void *) &network_64bit, sizeof(obj->lnP)); |
| 257 |
ptr += sizeof(obj->lnP); |
| 258 |
|
| 259 |
|
| 260 |
network_32bit = esl_hton32(obj->is_reported); |
| 261 |
memcpy(ptr, &network_32bit, sizeof(int32_t)); |
| 262 |
ptr += sizeof(int32_t); |
| 263 |
|
| 264 |
|
| 265 |
network_32bit = esl_hton32(obj->is_included); |
| 266 |
memcpy(ptr, &network_32bit, sizeof(int32_t)); |
| 267 |
ptr += sizeof(int32_t); |
| 268 |
|
| 269 |
|
| 270 |
if(obj->scores_per_pos == NULL){ |
| 271 |
network_32bit = esl_hton32(0); |
| 272 |
memcpy(ptr, &network_32bit, sizeof(int32_t)); |
| 273 |
ptr += sizeof(int32_t); |
| 274 |
} |
| 275 |
else{ |
| 276 |
int scores_per_pos_length = obj->ad->N; |
| 277 |
|
| 278 |
network_32bit = esl_hton32(scores_per_pos_length); |
| 279 |
memcpy(ptr, &network_32bit, sizeof(int32_t)); |
| 280 |
ptr += sizeof(int32_t); |
| 281 |
|
| 282 |
for(i = 0; i < scores_per_pos_length; i++){ |
| 283 |
network_32bit = esl_hton32(*((uint32_t *) &(obj->scores_per_pos[i]))); |
| 284 |
memcpy(ptr, &network_32bit, sizeof(int32_t)); |
| 285 |
ptr += sizeof(int32_t); |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
if (ser_size != ptr - (*buf + *n)){ |
| 291 |
ESL_EXCEPTION(eslFAIL,"Unexpected serialized object length found in p7_domain_Serialize\n"); |
| 292 |
} |
| 293 |
|
| 294 |
*n = ptr - *buf; |
| 295 |
|
| 296 |
int ser_return = p7_alidisplay_Serialize(obj->ad, buf, n, nalloc); |
| 297 |
|
| 298 |
return ser_return; |
| 299 |
|
| 300 |
|
| 301 |
ERROR: |
| 302 |
return eslEMEM; |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
extern int p7_domain_Deserialize(const uint8_t *buf, uint32_t *n, P7_DOMAIN *ret_obj){ |
| 324 |
|
| 325 |
uint8_t *ptr; |
| 326 |
uint64_t network_64bit; |
| 327 |
uint64_t host_64bit; |
| 328 |
uint32_t network_32bit; |
| 329 |
uint32_t host_32bit; |
| 330 |
uint32_t obj_size; |
| 331 |
int status; |
| 332 |
int i; |
| 333 |
|
| 334 |
if(ret_obj == NULL || buf == NULL || n == NULL){ |
| 335 |
return eslEINVAL; |
| 336 |
} |
| 337 |
|
| 338 |
ptr = (uint8_t *) buf + *n; |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 343 |
obj_size = esl_ntoh32(network_32bit); |
| 344 |
ptr += sizeof(uint32_t); |
| 345 |
|
| 346 |
|
| 347 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 348 |
ret_obj->ienv = esl_ntoh64(network_64bit); |
| 349 |
ptr += sizeof(uint64_t); |
| 350 |
|
| 351 |
|
| 352 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 353 |
ret_obj->jenv = esl_ntoh64(network_64bit); |
| 354 |
ptr += sizeof(uint64_t); |
| 355 |
|
| 356 |
|
| 357 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 358 |
ret_obj->iali = esl_ntoh64(network_64bit); |
| 359 |
ptr += sizeof(uint64_t); |
| 360 |
|
| 361 |
|
| 362 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 363 |
ret_obj->jali = esl_ntoh64(network_64bit); |
| 364 |
ptr += sizeof(uint64_t); |
| 365 |
|
| 366 |
|
| 367 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 368 |
ret_obj->iorf = esl_ntoh64(network_64bit); |
| 369 |
ptr += sizeof(uint64_t); |
| 370 |
|
| 371 |
|
| 372 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 373 |
ret_obj->jorf = esl_ntoh64(network_64bit); |
| 374 |
ptr += sizeof(uint64_t); |
| 375 |
|
| 376 |
|
| 377 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 378 |
host_32bit = esl_ntoh32(network_32bit); |
| 379 |
ret_obj->envsc = *((float *) &host_32bit); |
| 380 |
ptr += sizeof(uint32_t); |
| 381 |
|
| 382 |
|
| 383 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 384 |
host_32bit = esl_ntoh32(network_32bit); |
| 385 |
ret_obj->domcorrection = *((float *) &host_32bit); |
| 386 |
ptr += sizeof(uint32_t); |
| 387 |
|
| 388 |
|
| 389 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 390 |
host_32bit = esl_ntoh32(network_32bit); |
| 391 |
ret_obj->dombias = *((float *) &host_32bit); |
| 392 |
ptr += sizeof(uint32_t); |
| 393 |
|
| 394 |
|
| 395 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 396 |
host_32bit = esl_ntoh32(network_32bit); |
| 397 |
ret_obj->oasc = *((float *) &host_32bit); |
| 398 |
ptr += sizeof(uint32_t); |
| 399 |
|
| 400 |
|
| 401 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 402 |
host_32bit = esl_ntoh32(network_32bit); |
| 403 |
ret_obj->bitscore = *((float *) &host_32bit); |
| 404 |
ptr += sizeof(uint32_t); |
| 405 |
|
| 406 |
|
| 407 |
memcpy(&network_64bit, ptr, sizeof(uint64_t)); |
| 408 |
host_64bit = esl_ntoh64(network_64bit); |
| 409 |
ret_obj->lnP = *((double *) &host_64bit); |
| 410 |
ptr += sizeof(uint64_t); |
| 411 |
|
| 412 |
|
| 413 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 414 |
ret_obj->is_reported = esl_ntoh32(network_32bit); |
| 415 |
ptr += sizeof(uint32_t); |
| 416 |
|
| 417 |
|
| 418 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 419 |
ret_obj->is_included = esl_ntoh32(network_32bit); |
| 420 |
ptr += sizeof(uint32_t); |
| 421 |
|
| 422 |
|
| 423 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 424 |
int scores_per_pos_length = esl_ntoh32(network_32bit); |
| 425 |
ptr += sizeof(uint32_t); |
| 426 |
|
| 427 |
if(scores_per_pos_length > 0){ |
| 428 |
if(ret_obj->scores_per_pos != NULL){ |
| 429 |
free(ret_obj->scores_per_pos); |
| 430 |
} |
| 431 |
ESL_ALLOC(ret_obj->scores_per_pos, scores_per_pos_length * sizeof(float)); |
| 432 |
|
| 433 |
for(i = 0; i < scores_per_pos_length; i++){ |
| 434 |
memcpy(&network_32bit, ptr, sizeof(uint32_t)); |
| 435 |
host_32bit = esl_ntoh32(network_32bit); |
| 436 |
ret_obj->scores_per_pos[i] = *((float *) &host_32bit); |
| 437 |
ptr += sizeof(uint32_t); |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
if(ptr - (buf + *n) != obj_size){ |
| 443 |
ESL_EXCEPTION(eslFAIL, "Deserialized object size didn't match expected length in p7_domain_Deserialize\n"); |
| 444 |
} |
| 445 |
|
| 446 |
*n = ptr - buf; |
| 447 |
|
| 448 |
|
| 449 |
if(ret_obj->ad == NULL){ |
| 450 |
ret_obj->ad =p7_alidisplay_Create_empty(); |
| 451 |
} |
| 452 |
return p7_alidisplay_Deserialize(buf, n, ret_obj->ad); |
| 453 |
|
| 454 |
|
| 455 |
ERROR: |
| 456 |
return eslEMEM; |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
extern int p7_domain_TestSample(ESL_RAND64 *rng, P7_DOMAIN **ret_obj){ |
| 476 |
int status; |
| 477 |
int i; |
| 478 |
if (ret_obj == NULL) |
| 479 |
{ |
| 480 |
return eslEINVAL; |
| 481 |
} |
| 482 |
if(*ret_obj == NULL){ |
| 483 |
ESL_ALLOC(*ret_obj, sizeof(P7_DOMAIN)); |
| 484 |
} |
| 485 |
|
| 486 |
P7_DOMAIN *the_domain = *ret_obj; |
| 487 |
|
| 488 |
|
| 489 |
the_domain->ienv = esl_rand64(rng); |
| 490 |
the_domain->jenv = esl_rand64(rng); |
| 491 |
the_domain->iali = esl_rand64(rng); |
| 492 |
the_domain->jali = esl_rand64(rng); |
| 493 |
the_domain->iorf = esl_rand64(rng); |
| 494 |
the_domain->jorf = esl_rand64(rng); |
| 495 |
the_domain->envsc = (float) esl_rand64_double(rng); |
| 496 |
the_domain->domcorrection = (float) esl_rand64_double(rng); |
| 497 |
the_domain->dombias = (float) esl_rand64_double(rng); |
| 498 |
the_domain->oasc = (float) esl_rand64_double(rng); |
| 499 |
the_domain->bitscore = (float) esl_rand64_double(rng); |
| 500 |
the_domain->lnP = esl_rand64_double(rng); |
| 501 |
the_domain->is_reported = esl_rand64_Roll(rng, 1); |
| 502 |
the_domain->is_included = esl_rand64_Roll(rng, 1); |
| 503 |
|
| 504 |
|
| 505 |
ESL_RANDOMNESS *rng2 = esl_randomness_Create((uint32_t) esl_rand64(rng)); |
| 506 |
|
| 507 |
if(p7_alidisplay_Sample(rng2, esl_rand64_Roll(rng, 300) + 50, &(the_domain->ad)) != eslOK){ |
| 508 |
return eslFAIL; |
| 509 |
} |
| 510 |
esl_randomness_Destroy(rng2); |
| 511 |
|
| 512 |
if(esl_rand64_Roll(rng, 1)){ |
| 513 |
ESL_ALLOC(the_domain->scores_per_pos, the_domain->ad->N * sizeof(float)); |
| 514 |
for(i = 0; i < the_domain->ad->N; i++){ |
| 515 |
the_domain->scores_per_pos[i] = esl_rand64_double(rng); |
| 516 |
} |
| 517 |
} |
| 518 |
else{ |
| 519 |
the_domain->scores_per_pos = NULL; |
| 520 |
} |
| 521 |
|
| 522 |
return eslOK; |
| 523 |
|
| 524 |
ERROR: |
| 525 |
return eslEMEM; |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
extern int p7_domain_Compare(P7_DOMAIN *first, P7_DOMAIN *second, double atol, double rtol){ |
| 545 |
int i; |
| 546 |
|
| 547 |
if(first->ienv != second->ienv){ |
| 548 |
return eslFAIL; |
| 549 |
} |
| 550 |
if(first->jenv != second->jenv){ |
| 551 |
return eslFAIL; |
| 552 |
} |
| 553 |
if(first->iali != second->iali){ |
| 554 |
return eslFAIL; |
| 555 |
} |
| 556 |
if(first->jali != second->jali){ |
| 557 |
return eslFAIL; |
| 558 |
} |
| 559 |
if(first->iorf != second->iorf){ |
| 560 |
return eslFAIL; |
| 561 |
} |
| 562 |
if(first->jorf != second->jorf){ |
| 563 |
return eslFAIL; |
| 564 |
} |
| 565 |
if(esl_FCompare(first->envsc, second->envsc, (float) atol, (float) rtol) != eslOK){ |
| 566 |
return eslFAIL; |
| 567 |
} |
| 568 |
if(esl_FCompare(first->domcorrection, second->domcorrection, (float) atol, (float) rtol) != eslOK){ |
| 569 |
return eslFAIL; |
| 570 |
} |
| 571 |
if(esl_FCompare(first->dombias, second->dombias, (float) atol, (float) rtol) != eslOK){ |
| 572 |
return eslFAIL; |
| 573 |
} |
| 574 |
if(esl_FCompare(first->oasc, second->oasc, (float) atol, (float) rtol) != eslOK){ |
| 575 |
return eslFAIL; |
| 576 |
} |
| 577 |
if(esl_FCompare(first->bitscore, second->bitscore, (float) atol, (float) rtol) != eslOK){ |
| 578 |
return eslFAIL; |
| 579 |
} |
| 580 |
if(esl_DCompare(first->lnP, second->lnP, atol, rtol) != eslOK){ |
| 581 |
return eslFAIL; |
| 582 |
} |
| 583 |
if(first->lnP != second->lnP){ |
| 584 |
return eslFAIL; |
| 585 |
} |
| 586 |
if(first->is_reported != second->is_reported){ |
| 587 |
return eslFAIL; |
| 588 |
} |
| 589 |
if(first->is_included != second->is_included){ |
| 590 |
return eslFAIL; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
if((first->scores_per_pos == NULL && second->scores_per_pos != NULL) || |
| 595 |
(first-> scores_per_pos != NULL && second->scores_per_pos == NULL)){ |
| 596 |
return eslFAIL; |
| 597 |
} |
| 598 |
|
| 599 |
if((first->scores_per_pos != NULL) && (second->scores_per_pos != NULL)){ |
| 600 |
|
| 601 |
if(first->ad->N != second->ad->N){ |
| 602 |
return eslFAIL; |
| 603 |
} |
| 604 |
|
| 605 |
for(i = 0; i < first->ad->N; i++){ |
| 606 |
if(esl_FCompare(first->scores_per_pos[i], second->scores_per_pos[i], (float) atol, (float) rtol) != eslOK){ |
| 607 |
return eslFAIL; |
| 608 |
} |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
return p7_alidisplay_Compare(first->ad, second->ad); |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
#ifdef p7DOMAIN_TESTDRIVE |
| 623 |
|
| 624 |
|
| 625 |
static void utest_Serialize_error_conditions(){ |
| 626 |
int status; |
| 627 |
P7_DOMAIN *foo = NULL; |
| 628 |
uint8_t **buf = NULL; |
| 629 |
uint32_t n; |
| 630 |
uint32_t nalloc; |
| 631 |
ESL_RAND64 *rng= NULL; |
| 632 |
rng = esl_rand64_Create(0); |
| 633 |
|
| 634 |
char msg[] = "utest_Serialize_error_conditions failed"; |
| 635 |
|
| 636 |
n = 0; |
| 637 |
nalloc = 0; |
| 638 |
|
| 639 |
if(p7_domain_TestSample(rng, &foo) != eslOK){ |
| 640 |
esl_fatal(msg); |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
buf = NULL; |
| 645 |
|
| 646 |
if(p7_domain_Serialize(foo, buf, &n, &nalloc) != eslEINVAL){ |
| 647 |
esl_fatal(msg); |
| 648 |
} |
| 649 |
else{ |
| 650 |
|
| 651 |
} |
| 652 |
|
| 653 |
ESL_ALLOC(buf, sizeof(uint8_t *)); |
| 654 |
*buf = NULL; |
| 655 |
|
| 656 |
|
| 657 |
if(p7_domain_Serialize(foo, buf, NULL, &nalloc) != eslEINVAL){ |
| 658 |
esl_fatal(msg); |
| 659 |
} |
| 660 |
else{ |
| 661 |
|
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
if(p7_domain_Serialize(NULL, buf, &n, &nalloc) != eslEINVAL){ |
| 666 |
esl_fatal(msg); |
| 667 |
} |
| 668 |
else{ |
| 669 |
|
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
n = 3; |
| 674 |
if(p7_domain_Serialize(foo, buf, &n, &nalloc) != eslEINVAL){ |
| 675 |
esl_fatal(msg); |
| 676 |
} |
| 677 |
else{ |
| 678 |
|
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
n = 0; |
| 683 |
nalloc = 10; |
| 684 |
if(p7_domain_Serialize(foo, buf, &n, &nalloc) != eslEINVAL){ |
| 685 |
esl_fatal(msg); |
| 686 |
} |
| 687 |
else{ |
| 688 |
|
| 689 |
} |
| 690 |
|
| 691 |
if(buf !=NULL && *buf != NULL){ |
| 692 |
free(*buf); |
| 693 |
} |
| 694 |
if(buf != NULL){ |
| 695 |
free(buf); |
| 696 |
} |
| 697 |
|
| 698 |
esl_rand64_Destroy(rng); |
| 699 |
p7_domain_Destroy(foo); |
| 700 |
|
| 701 |
return; |
| 702 |
|
| 703 |
ERROR: |
| 704 |
if (rng != NULL){ |
| 705 |
esl_rand64_Destroy(rng); |
| 706 |
} |
| 707 |
|
| 708 |
if(foo != NULL){ |
| 709 |
p7_domain_Destroy(foo); |
| 710 |
} |
| 711 |
|
| 712 |
if(buf !=NULL && *buf != NULL){ |
| 713 |
free(*buf); |
| 714 |
} |
| 715 |
if(buf != NULL){ |
| 716 |
free(buf); |
| 717 |
} |
| 718 |
esl_fatal(msg); |
| 719 |
} |
| 720 |
|
| 721 |
static void utest_Deserialize_error_conditions(){ |
| 722 |
P7_DOMAIN *sampled = NULL; |
| 723 |
P7_DOMAIN *deserial = NULL; |
| 724 |
char msg[]="utest_Deserialize_error_conditions failed"; |
| 725 |
uint8_t *buf = NULL; |
| 726 |
uint32_t n = 0, nalloc = 0; |
| 727 |
|
| 728 |
deserial = p7_domain_Create_empty(); |
| 729 |
if(deserial == NULL){ |
| 730 |
esl_fatal(msg); |
| 731 |
} |
| 732 |
|
| 733 |
ESL_RAND64 *rng = esl_rand64_Create(0); |
| 734 |
if(p7_domain_TestSample(rng, &sampled) != eslOK){ |
| 735 |
esl_fatal(msg); |
| 736 |
} |
| 737 |
esl_rand64_Destroy(rng); |
| 738 |
|
| 739 |
if(p7_domain_Serialize(sampled, &buf, &n, &nalloc) != eslOK){ |
| 740 |
esl_fatal(msg); |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
if(p7_domain_Deserialize(NULL, &n, deserial) != eslEINVAL){ |
| 745 |
esl_fatal(msg); |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
if(p7_domain_Deserialize(buf, NULL, deserial) != eslEINVAL){ |
| 751 |
esl_fatal(msg); |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
if(p7_domain_Deserialize(buf, &n, NULL) != eslEINVAL){ |
| 757 |
esl_fatal(msg); |
| 758 |
} |
| 759 |
|
| 760 |
free(buf); |
| 761 |
p7_domain_Destroy(deserial); |
| 762 |
p7_domain_Destroy(sampled); |
| 763 |
return; |
| 764 |
} |
| 765 |
|
| 766 |
static void utest_Serialize(int ntrials){ |
| 767 |
int i; |
| 768 |
uint8_t **buf=NULL; |
| 769 |
uint32_t n; |
| 770 |
uint32_t nalloc; |
| 771 |
P7_DOMAIN **serial=NULL, *deserial=NULL; |
| 772 |
int status; |
| 773 |
char msg[] = "utest_Serialize failed"; |
| 774 |
|
| 775 |
ESL_ALLOC(buf, sizeof(uint8_t *)); |
| 776 |
*buf = NULL; |
| 777 |
n = 0; |
| 778 |
nalloc = 0; |
| 779 |
|
| 780 |
ESL_ALLOC(serial, ntrials * sizeof(P7_DOMAIN *)); |
| 781 |
for(i = 0; i< ntrials; i++){ |
| 782 |
serial[i] = NULL; |
| 783 |
} |
| 784 |
|
| 785 |
ESL_RAND64 *rng = esl_rand64_Create(0); |
| 786 |
|
| 787 |
for(i = 0; i < ntrials; i++){ |
| 788 |
if(p7_domain_TestSample(rng, &(serial[i])) != eslOK){ |
| 789 |
esl_fatal(msg); |
| 790 |
} |
| 791 |
if(p7_domain_Serialize(serial[i], buf, &n, &nalloc) != eslOK){ |
| 792 |
esl_fatal(msg); |
| 793 |
} |
| 794 |
} |
| 795 |
|
| 796 |
n = 0; |
| 797 |
|
| 798 |
deserial = p7_domain_Create_empty(); |
| 799 |
if(deserial == NULL){ |
| 800 |
esl_fatal(msg); |
| 801 |
} |
| 802 |
|
| 803 |
for(i = 0; i < ntrials; i++){ |
| 804 |
if(p7_domain_Deserialize(*buf, &n, deserial) != eslOK){ |
| 805 |
esl_fatal(msg); |
| 806 |
} |
| 807 |
if(p7_domain_Compare(serial[i], deserial, 1e-4, 1e-4) != eslOK){ |
| 808 |
esl_fatal(msg); |
| 809 |
} |
| 810 |
p7_domain_Destroy(deserial); |
| 811 |
deserial = p7_domain_Create_empty(); |
| 812 |
} |
| 813 |
|
| 814 |
free(*buf); |
| 815 |
free(buf); |
| 816 |
for(i = 0; i < ntrials; i++){ |
| 817 |
p7_domain_Destroy(serial[i]); |
| 818 |
} |
| 819 |
free(serial); |
| 820 |
p7_domain_Destroy(deserial); |
| 821 |
esl_rand64_Destroy(rng); |
| 822 |
|
| 823 |
return; |
| 824 |
|
| 825 |
ERROR: |
| 826 |
if(buf != NULL){ |
| 827 |
if(*buf != NULL){ |
| 828 |
free(*buf); |
| 829 |
} |
| 830 |
free(buf); |
| 831 |
} |
| 832 |
|
| 833 |
if(serial != NULL){ |
| 834 |
for(i = 0; i < ntrials; i++){ |
| 835 |
if(serial[i] != NULL){ |
| 836 |
p7_domain_Destroy(serial[i]); |
| 837 |
} |
| 838 |
} |
| 839 |
free(serial); |
| 840 |
} |
| 841 |
|
| 842 |
if(deserial != NULL){ |
| 843 |
p7_domain_Destroy(deserial); |
| 844 |
} |
| 845 |
|
| 846 |
esl_fatal(msg); |
| 847 |
|
| 848 |
} |
| 849 |
|
| 850 |
#endif |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
#ifdef p7DOMAIN_TESTDRIVE |
| 857 |
|
| 858 |
#include "esl_getopts.h" |
| 859 |
|
| 860 |
int |
| 861 |
main(int argc, char **argv) |
| 862 |
{ |
| 863 |
|
| 864 |
utest_Serialize_error_conditions(); |
| 865 |
utest_Deserialize_error_conditions(); |
| 866 |
utest_Serialize(100); |
| 867 |
return eslOK; |
| 868 |
} |
| 869 |
#endif |