| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <esl_config.h> |
| 20 |
#include <p7_config.h> |
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include <stdio.h> |
| 24 |
#include <stdlib.h> |
| 25 |
#include <string.h> |
| 26 |
#include <math.h> |
| 27 |
|
| 28 |
#include "easel.h" |
| 29 |
#include "esl_alphabet.h" |
| 30 |
#include "esl_random.h" |
| 31 |
#include "esl_stack.h" |
| 32 |
#include "esl_vectorops.h" |
| 33 |
#include "esl_wuss.h" |
| 34 |
|
| 35 |
#include "hmmer.h" |
| 36 |
|
| 37 |
#include "infernal.h" |
| 38 |
|
| 39 |
static void map_orig2sub_cm(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, int print_flag); |
| 40 |
static int map_orig2sub_cm_helper(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, int orig_v, int sub_v); |
| 41 |
static int cm2sub_cm_check_id_next_node(CM_t *orig_cm, CM_t *sub_cm, int orig_nd, int sub_nd, |
| 42 |
CMSubMap_t *submap, CP9Map_t *orig_cp9map, CP9Map_t *sub_cp9map, |
| 43 |
int print_flag); |
| 44 |
static void cm2sub_cm_emit_probs(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, int v_s, int v_o1, int v_o2, |
| 45 |
CMSubMap_t *submap); |
| 46 |
static void cm2sub_cm_trans_probs(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, char ***tmap, int v_s, |
| 47 |
CMSubMap_t *submap); |
| 48 |
static void cm2sub_cm_trans_probs_S(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, char ***tmap, int v_start, |
| 49 |
CMSubMap_t *submap); |
| 50 |
static void cm2sub_cm_trans_probs_B_E(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, char ***tmap, int v_end, |
| 51 |
CMSubMap_t *submap, int print_flag); |
| 52 |
static void cm2sub_cm_add_single_trans(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, int orig_v, int orig_y, |
| 53 |
int sub_v, int yoffset, double *orig_psi, char ***tmap); |
| 54 |
static float cm2sub_cm_sum_subpaths(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, int start, int end, |
| 55 |
int init_sub_start, char ***tmap, double *orig_psi); |
| 56 |
static int cm_trans_check(CM_t *cm, int a, int b); |
| 57 |
static void cm2sub_cm_subtract_root_subpaths(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, char ***tmap, |
| 58 |
CMSubMap_t *submap, int print_flag); |
| 59 |
static void cm2sub_cm_find_impossible_misc_cases(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, CMSubInfo_t *subinfo, |
| 60 |
CP9Map_t *orig_cp9map, CP9Map_t *sub_cp9map, int print_flag); |
| 61 |
static void cm2sub_cm_find_impossible_matr_cases(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, CMSubInfo_t *subinfo, |
| 62 |
CP9Map_t *orig_cp9map, CP9Map_t *sub_cp9map, int print_flag); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
CMSubMap_t * |
| 83 |
AllocSubMap(CM_t *sub_cm, CM_t *orig_cm, int sstruct, int estruct) |
| 84 |
{ |
| 85 |
CMSubMap_t *submap; |
| 86 |
int v; |
| 87 |
int status; |
| 88 |
|
| 89 |
ESL_ALLOC(submap, sizeof(struct submap_s)); |
| 90 |
|
| 91 |
submap->sub_M = sub_cm->M; |
| 92 |
submap->orig_M = orig_cm->M; |
| 93 |
|
| 94 |
submap->orig_clen = 0; |
| 95 |
for(v = 0; v <= orig_cm->M; v++) |
| 96 |
{ |
| 97 |
if(orig_cm->stid[v] == MATP_MP) |
| 98 |
submap->orig_clen += 2; |
| 99 |
else if(orig_cm->stid[v] == MATL_ML || orig_cm->stid[v] == MATR_MR) |
| 100 |
submap->orig_clen++; |
| 101 |
} |
| 102 |
submap->sstruct = sstruct; |
| 103 |
submap->estruct = estruct; |
| 104 |
submap->sub_clen = (submap->estruct-submap->sstruct+1); |
| 105 |
submap->spos = submap->sstruct; |
| 106 |
submap->epos = submap->estruct; |
| 107 |
|
| 108 |
|
| 109 |
ESL_ALLOC(submap->s2o_id, sizeof(int) * (sub_cm->M+1)); |
| 110 |
ESL_ALLOC(submap->s2o_smap, sizeof(int *) * (sub_cm->M+1)); |
| 111 |
for(v = 0; v <= sub_cm->M; v++) |
| 112 |
{ |
| 113 |
submap->s2o_id[v] = FALSE; |
| 114 |
ESL_ALLOC(submap->s2o_smap[v], sizeof(int) * 2); |
| 115 |
submap->s2o_smap[v][0] = -1; |
| 116 |
submap->s2o_smap[v][1] = -1; |
| 117 |
} |
| 118 |
|
| 119 |
ESL_ALLOC(submap->o2s_smap, sizeof(int *) * (orig_cm->M+1)); |
| 120 |
for(v = 0; v <= orig_cm->M; v++) |
| 121 |
{ |
| 122 |
ESL_ALLOC(submap->o2s_smap[v], sizeof(int) * 2); |
| 123 |
submap->o2s_smap[v][0] = -1; |
| 124 |
submap->o2s_smap[v][1] = -1; |
| 125 |
} |
| 126 |
return submap; |
| 127 |
|
| 128 |
ERROR: |
| 129 |
cm_Fail("Memory allocation error."); |
| 130 |
return NULL; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
void |
| 138 |
FreeSubMap(CMSubMap_t *submap) |
| 139 |
{ |
| 140 |
int v; |
| 141 |
for(v = 0; v <= submap->sub_M; v++) |
| 142 |
free(submap->s2o_smap[v]); |
| 143 |
free(submap->s2o_smap); |
| 144 |
for(v = 0; v <= submap->orig_M; v++) |
| 145 |
free(submap->o2s_smap[v]); |
| 146 |
free(submap->o2s_smap); |
| 147 |
free(submap->s2o_id); |
| 148 |
free(submap); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
CMSubInfo_t * |
| 164 |
AllocSubInfo(int clen) |
| 165 |
{ |
| 166 |
int status; |
| 167 |
CMSubInfo_t *subinfo; |
| 168 |
int i; |
| 169 |
int ncases; |
| 170 |
|
| 171 |
ESL_ALLOC(subinfo, sizeof(struct subinfo_s)); |
| 172 |
|
| 173 |
ESL_ALLOC(subinfo->imp_cc, sizeof(int) * (clen + 2)); |
| 174 |
for(i = 0; i <= clen+1; i++) |
| 175 |
subinfo->imp_cc[i] = FALSE; |
| 176 |
|
| 177 |
|
| 178 |
ncases = 6; |
| 179 |
ESL_ALLOC(subinfo->apredict_ct, sizeof(int) * (ncases+1)); |
| 180 |
ESL_ALLOC(subinfo->spredict_ct, sizeof(int) * (ncases+1)); |
| 181 |
ESL_ALLOC(subinfo->awrong_ct, sizeof(int) * (ncases+1)); |
| 182 |
ESL_ALLOC(subinfo->swrong_ct, sizeof(int) * (ncases+1)); |
| 183 |
for(i = 0; i <= ncases; i++) |
| 184 |
{ |
| 185 |
subinfo->apredict_ct[i] = 0; |
| 186 |
subinfo->spredict_ct[i] = 0; |
| 187 |
subinfo->awrong_ct[i] = 0; |
| 188 |
subinfo->swrong_ct[i] = 0; |
| 189 |
} |
| 190 |
return subinfo; |
| 191 |
|
| 192 |
ERROR: |
| 193 |
cm_Fail("Memory allocation error."); |
| 194 |
return NULL; |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
void |
| 202 |
FreeSubInfo(CMSubInfo_t *subinfo) |
| 203 |
{ |
| 204 |
free(subinfo->imp_cc); |
| 205 |
free(subinfo->apredict_ct); |
| 206 |
free(subinfo->spredict_ct); |
| 207 |
free(subinfo->awrong_ct); |
| 208 |
free(subinfo->swrong_ct); |
| 209 |
free(subinfo); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
void |
| 228 |
map_orig2sub_cm(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, int print_flag) |
| 229 |
{ |
| 230 |
int status; |
| 231 |
int k_s; |
| 232 |
int v_o; |
| 233 |
int v_s; |
| 234 |
int v; |
| 235 |
int n_o; |
| 236 |
int n_s; |
| 237 |
char **nodetypes; |
| 238 |
char **sttypes; |
| 239 |
int sub_k; |
| 240 |
int orig_k; |
| 241 |
int sub_nd; |
| 242 |
int orig_nd; |
| 243 |
int x, y; |
| 244 |
CP9Map_t *orig_cp9map; |
| 245 |
CP9Map_t *sub_cp9map; |
| 246 |
|
| 247 |
ESL_ALLOC(sttypes, sizeof(char *) * 10); |
| 248 |
sttypes[0] = "D"; |
| 249 |
sttypes[1] = "MP"; |
| 250 |
sttypes[2] = "ML"; |
| 251 |
sttypes[3] = "MR"; |
| 252 |
sttypes[4] = "IL"; |
| 253 |
sttypes[5] = "IR"; |
| 254 |
sttypes[6] = "S"; |
| 255 |
sttypes[7] = "E"; |
| 256 |
sttypes[8] = "B"; |
| 257 |
sttypes[9] = "EL"; |
| 258 |
|
| 259 |
ESL_ALLOC(nodetypes, sizeof(char *) * 8); |
| 260 |
nodetypes[0] = "BIF"; |
| 261 |
nodetypes[1] = "MATP"; |
| 262 |
nodetypes[2] = "MATL"; |
| 263 |
nodetypes[3] = "MATR"; |
| 264 |
nodetypes[4] = "BEGL"; |
| 265 |
nodetypes[5] = "BEGR"; |
| 266 |
nodetypes[6] = "ROOT"; |
| 267 |
nodetypes[7] = "END"; |
| 268 |
|
| 269 |
|
| 270 |
if(sub_cm->M > orig_cm->M) |
| 271 |
cm_Fail("ERROR: sub_cm has more states than orig_cm in map_orig2sub_cm()\n"); |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
orig_cp9map = AllocCP9Map(orig_cm); |
| 278 |
sub_cp9map = AllocCP9Map(sub_cm); |
| 279 |
|
| 280 |
CP9_map_cm2hmm(orig_cm, orig_cp9map, print_flag); |
| 281 |
CP9_map_cm2hmm(sub_cm, sub_cp9map, print_flag); |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
v_s = 0; |
| 286 |
v_o = 0; |
| 287 |
map_orig2sub_cm_helper(orig_cm, sub_cm, submap, v_o, v_s); |
| 288 |
|
| 289 |
|
| 290 |
k_s = 1; |
| 291 |
for(x = 0; x <= 1; x++) |
| 292 |
for(y = 0; y <= 1; y++) |
| 293 |
map_orig2sub_cm_helper(orig_cm, sub_cm, submap, |
| 294 |
orig_cp9map->hns2cs[submap->spos-1][k_s][x], |
| 295 |
sub_cp9map->hns2cs[0][k_s][y]); |
| 296 |
|
| 297 |
|
| 298 |
k_s = 1; |
| 299 |
for(x = 0; x <= 1; x++) |
| 300 |
for(y = 0; y <= 1; y++) |
| 301 |
map_orig2sub_cm_helper(orig_cm, sub_cm, submap, |
| 302 |
orig_cp9map->hns2cs[submap->epos][k_s][x], |
| 303 |
sub_cp9map->hns2cs[submap->epos-submap->spos+1][k_s][y]); |
| 304 |
|
| 305 |
for(sub_k = 1; sub_k <= sub_cp9map->hmm_M; sub_k++) |
| 306 |
{ |
| 307 |
orig_k = sub_k + submap->spos - 1; |
| 308 |
sub_nd = sub_cp9map->pos2nd[sub_k]; |
| 309 |
orig_nd = orig_cp9map->pos2nd[orig_k]; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
cm2sub_cm_check_id_next_node(orig_cm, sub_cm, orig_nd, sub_nd, submap, orig_cp9map, |
| 322 |
sub_cp9map, print_flag); |
| 323 |
for(k_s = 0; k_s < 3; k_s++) |
| 324 |
|
| 325 |
for(x = 0; x <= 1; x++) |
| 326 |
for(y = 0; y <= 1; y++) |
| 327 |
map_orig2sub_cm_helper(orig_cm, sub_cm, submap, |
| 328 |
orig_cp9map->hns2cs[orig_k][k_s][x], |
| 329 |
sub_cp9map->hns2cs[sub_k][k_s][y]); |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
if(print_flag) |
| 342 |
{ |
| 343 |
|
| 344 |
for(v = 0; v <= sub_cm->M; v++) |
| 345 |
if(submap->s2o_id[v] == TRUE) |
| 346 |
printf("submap->s2o_id[%d] TRUE\n", v); |
| 347 |
else |
| 348 |
printf("submap->s2o_id[%d] FALSE\n", v); |
| 349 |
|
| 350 |
printf("\n\n\nMAP\n\n\n"); |
| 351 |
for(v_s = 0; v_s < sub_cm->M; v_s++) |
| 352 |
{ |
| 353 |
n_s = sub_cm->ndidx[v_s]; |
| 354 |
v_o = submap->s2o_smap[v_s][0]; |
| 355 |
if(sub_cm->sttype[v_s] == E_st) |
| 356 |
printf("sub v:%4d END\n", v_s); |
| 357 |
if(sub_cm->sttype[v_s] == S_st) |
| 358 |
printf("sub v:%4d START\n", v_s); |
| 359 |
if(sub_cm->sttype[v_s] == B_st) |
| 360 |
printf("sub v:%4d BIF_B\n", v_s); |
| 361 |
if((sub_cm->sttype[v_s] != B_st && |
| 362 |
sub_cm->sttype[v_s] != S_st) && |
| 363 |
sub_cm->sttype[v_s] != E_st) |
| 364 |
{ |
| 365 |
if(v_o == -1 && sub_cm->sttype[(v_s+1)] == E_st) |
| 366 |
continue; |
| 367 |
if(v_o == -1 && sub_cm->sttype[v_s] != E_st) |
| 368 |
cm_Fail("ERROR sub_cm state: %d type: %s node type: %s doesn't map to any state in orig_cm\n", v_s, sttypes[(int) sub_cm->sttype[v_s]], nodetypes[(int) sub_cm->ndtype[n_s]]); |
| 369 |
|
| 370 |
n_o = orig_cm->ndidx[v_o]; |
| 371 |
if(print_flag) printf("sub v:%4d(%4d) %6s%6s | orig v:%4d(%4d) %6s%6s\n", v_s, n_s, nodetypes[(int) sub_cm->ndtype[n_s]], sttypes[(int) sub_cm->sttype[v_s]], v_o, n_o, nodetypes[(int) orig_cm->ndtype[n_o]], sttypes[(int) orig_cm->sttype[v_o]]); |
| 372 |
|
| 373 |
if(submap->o2s_smap[v_o][0] != v_s && submap->o2s_smap[v_o][1] != v_s) |
| 374 |
cm_Fail("ERROR inconsistency; neither o2s_smap[%d][0] and [1] is %d\n", v_o, v_s); |
| 375 |
|
| 376 |
v_o = submap->s2o_smap[v_s][1]; |
| 377 |
if(v_o != -1) |
| 378 |
{ |
| 379 |
n_o = orig_cm->ndidx[v_o]; |
| 380 |
if(print_flag) printf(" | orig v:%4d(%4d) %6s%6s\n", v_o, n_o, nodetypes[(int) orig_cm->ndtype[n_o]], sttypes[(int) orig_cm->sttype[v_o]]); |
| 381 |
|
| 382 |
if(submap->o2s_smap[v_o][0] != v_s && submap->o2s_smap[v_o][1] != v_s) |
| 383 |
{ |
| 384 |
cm_Fail("ERROR inconsistency; neither o2s_smap[%d][0] and [1] is %d\n", v_o, v_s); |
| 385 |
} |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
FreeCP9Map(orig_cp9map); |
| 393 |
FreeCP9Map(sub_cp9map); |
| 394 |
free(sttypes); |
| 395 |
free(nodetypes); |
| 396 |
return; |
| 397 |
|
| 398 |
ERROR: |
| 399 |
cm_Fail("Memory allocation error."); |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
static int |
| 419 |
map_orig2sub_cm_helper(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, int orig_v, int sub_v) |
| 420 |
{ |
| 421 |
int sub_nd; |
| 422 |
int orig_nd; |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
if(orig_v == -1 || sub_v == -1) |
| 427 |
return 0; |
| 428 |
|
| 429 |
|
| 430 |
if(submap->o2s_smap[orig_v][0] == sub_v || submap->o2s_smap[orig_v][1] == sub_v) |
| 431 |
return 0; |
| 432 |
|
| 433 |
orig_nd = orig_cm->ndidx[orig_v]; |
| 434 |
sub_nd = sub_cm->ndidx[sub_v]; |
| 435 |
|
| 436 |
if(sub_cm->sttype[sub_v] == IL_st || sub_cm->sttype[sub_v] == IR_st) |
| 437 |
{ |
| 438 |
|
| 439 |
|
| 440 |
if(orig_cm->sttype[(orig_v+1)] == E_st || sub_cm->sttype[(sub_v+1)] == E_st) |
| 441 |
return 0; |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
if(sub_cm->ndtype[sub_nd] == MATP_nd) |
| 449 |
if(orig_cm->ndtype[orig_nd] == MATP_nd && sub_cm->sttype[sub_v] != orig_cm->sttype[orig_v]) |
| 450 |
return 0; |
| 451 |
|
| 452 |
|
| 453 |
if(submap->o2s_smap[orig_v][0] == -1) |
| 454 |
{ |
| 455 |
if (submap->o2s_smap[orig_v][1] != -1) |
| 456 |
cm_Fail("ERROR in map_orig2sub_cm_helper, submap->o2s_smap[%d][0] is -1 but submap->o2s_smap[%d][1] is not, this shouldn't happen.\n", orig_v, orig_v); |
| 457 |
else |
| 458 |
submap->o2s_smap[orig_v][0] = sub_v; |
| 459 |
} |
| 460 |
else if (submap->o2s_smap[orig_v][1] != -1) |
| 461 |
{ |
| 462 |
if(submap->o2s_smap[orig_v][0] == sub_v || submap->o2s_smap[orig_v][1] == sub_v) |
| 463 |
|
| 464 |
return 0; |
| 465 |
else |
| 466 |
cm_Fail("ERROR in map_orig2sub_cm_helper, submap->o2s_smap[%d][0] is not -1 and submap->o2s_smap[%d][1] is not -1, this shouldn't happen.\n", orig_v, orig_v); |
| 467 |
} |
| 468 |
else |
| 469 |
{ |
| 470 |
if(submap->o2s_smap[orig_v][0] == sub_v || submap->o2s_smap[orig_v][1] == sub_v) |
| 471 |
|
| 472 |
return 0; |
| 473 |
submap->o2s_smap[orig_v][1] = sub_v; |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
if(submap->s2o_smap[sub_v][0] == -1) |
| 478 |
if (submap->s2o_smap[sub_v][1] != -1) |
| 479 |
cm_Fail("ERROR in map_sub2orig_cm_helper, submap->s2o_smap[%d][0] is -1 but submap->s2o_smap[%d][1] is not, this shouldn't happen.\n", sub_v, sub_v); |
| 480 |
else |
| 481 |
submap->s2o_smap[sub_v][0] = orig_v; |
| 482 |
else if (submap->s2o_smap[sub_v][1] != -1) |
| 483 |
cm_Fail("ERROR in map_sub2orig_cm_helper, submap->s2o_smap[%d][0] is not -1 and submap->s2o_smap[%d][1] is not -1, this shouldn't happen.\n", sub_v, sub_v); |
| 484 |
else |
| 485 |
submap->s2o_smap[sub_v][1] = orig_v; |
| 486 |
return 1; |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
int |
| 563 |
build_sub_cm(CM_t *orig_cm, char *errbuf, CM_t **ret_cm, int sstruct, int estruct, CMSubMap_t **ret_submap, int print_flag) |
| 564 |
{ |
| 565 |
int status; |
| 566 |
CM_t *sub_cm; |
| 567 |
CMConsensus_t *con; |
| 568 |
Parsetree_t *mtr; |
| 569 |
char *sub_cstr; |
| 570 |
int *sub_ct; |
| 571 |
int cpos; |
| 572 |
int sub_cpos; |
| 573 |
char ***tmap; |
| 574 |
double *orig_psi; |
| 575 |
int v_s; |
| 576 |
int n_s; |
| 577 |
FILE *ofp; |
| 578 |
int spos; |
| 579 |
|
| 580 |
int epos; |
| 581 |
|
| 582 |
CMSubMap_t *submap; |
| 583 |
|
| 584 |
|
| 585 |
if((orig_cm->flags & CMH_LOCAL_BEGIN) || (orig_cm->flags & CMH_LOCAL_END)) ESL_FAIL(eslEINCOMPAT, errbuf, "build_sub_cm() trying to build a sub CM of a CM already in local mode, not yet supported.\n"); |
| 586 |
if(orig_cm->flags & CM_IS_SUB) ESL_FAIL(eslEINCOMPAT, errbuf, "build_sub_cm(), trying to build a sub CM of a CM that is itself a sub CM."); |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
cm_find_and_detach_dual_inserts(orig_cm, |
| 595 |
FALSE, |
| 596 |
TRUE); |
| 597 |
|
| 598 |
|
| 599 |
if((con = CreateCMConsensus(orig_cm, orig_cm->abc)) == NULL) ESL_FAIL(eslFAIL, errbuf, "build_sub_cm(), unable to create cm consensus data"); |
| 600 |
if(print_flag) |
| 601 |
{ |
| 602 |
printf("con->cseq : %s\n", con->cseq); |
| 603 |
printf("con->cstr : %s\n", con->cstr); |
| 604 |
printf("clen : %d\n", con->clen); |
| 605 |
} |
| 606 |
|
| 607 |
spos = sstruct; |
| 608 |
epos = estruct; |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
ESL_ALLOC(sub_ct, sizeof(int) * (epos - spos + 1)); |
| 618 |
|
| 619 |
for (cpos = (spos-1); cpos < epos; cpos++) |
| 620 |
{ |
| 621 |
sub_cpos = cpos - (spos-1); |
| 622 |
if(con->ct[cpos] != -1 && |
| 623 |
(con->ct[cpos] < (spos-1) || |
| 624 |
con->ct[cpos] >= epos)) |
| 625 |
sub_ct[sub_cpos] = -1; |
| 626 |
else |
| 627 |
sub_ct[sub_cpos] = con->ct[cpos]; |
| 628 |
} |
| 629 |
|
| 630 |
for (cpos = (spos-1); cpos < epos; cpos++) |
| 631 |
{ |
| 632 |
sub_cpos = cpos - (spos-1); |
| 633 |
if ((cpos+1) < sstruct || (cpos+1) > estruct) |
| 634 |
|
| 635 |
{ |
| 636 |
|
| 637 |
|
| 638 |
if (sub_ct[sub_cpos] != -1) |
| 639 |
sub_ct[sub_ct[sub_cpos]] = -1; |
| 640 |
sub_ct[sub_cpos] = -1; |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
ESL_ALLOC(sub_cstr, sizeof(char) * (epos - spos + 2)); |
| 650 |
for (cpos = (spos-1); cpos < epos; cpos++) |
| 651 |
{ |
| 652 |
sub_cpos = cpos - (spos-1); |
| 653 |
if(sub_ct[sub_cpos] == -1) sub_cstr[sub_cpos] = '.'; |
| 654 |
else if (sub_ct[sub_cpos] > cpos) sub_cstr[sub_cpos] = '<'; |
| 655 |
else if (sub_ct[sub_cpos] < cpos) sub_cstr[sub_cpos] = '>'; |
| 656 |
else cm_Fail("ERROR: weird error in build_sub_cm()\n"); |
| 657 |
} |
| 658 |
sub_cstr[(epos-spos+1)] = '\0'; |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
if((status = ConsensusModelmaker(orig_cm->abc, errbuf, sub_cstr, (epos-spos+1), TRUE, &sub_cm, &mtr)) != eslOK) return status; |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
if ((status = cm_SetCtime(sub_cm)) != eslOK) ESL_FAIL(status, errbuf, "Failed to record timestamp"); |
| 668 |
|
| 669 |
|
| 670 |
CM_t *new; |
| 671 |
if((status = CMRebalance(sub_cm, errbuf, &new)) != eslOK) return status; |
| 672 |
FreeCM(sub_cm); |
| 673 |
sub_cm = new; |
| 674 |
|
| 675 |
submap = AllocSubMap(sub_cm, orig_cm, sstruct, estruct); |
| 676 |
if(print_flag) |
| 677 |
{ |
| 678 |
printf("\n\norig struct: %s\n", con->cstr); |
| 679 |
printf("\n\nnew struct : %s\n", sub_cstr); |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
map_orig2sub_cm(orig_cm, sub_cm, submap, print_flag); |
| 684 |
|
| 685 |
|
| 686 |
orig_psi = cm_ExpectedStateOccupancy(orig_cm); |
| 687 |
|
| 688 |
tmap = cm_CreateTransitionMap(); |
| 689 |
|
| 690 |
CMZero(sub_cm); |
| 691 |
CMSetNullModel(sub_cm, orig_cm->null); |
| 692 |
sub_cm->el_selfsc = orig_cm->el_selfsc; |
| 693 |
sub_cm->beta_W = orig_cm->beta_W; |
| 694 |
sub_cm->tau = orig_cm->tau; |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
sub_cm->config_opts = orig_cm->config_opts; |
| 699 |
sub_cm->align_opts = orig_cm->align_opts; |
| 700 |
sub_cm->search_opts = orig_cm->search_opts; |
| 701 |
sub_cm->flags = 0; |
| 702 |
if(sub_cm->config_opts & CM_CONFIG_SUB) sub_cm->config_opts &= ~CM_CONFIG_SUB; |
| 703 |
if(sub_cm->align_opts & CM_ALIGN_SUB) sub_cm->align_opts &= ~CM_ALIGN_SUB; |
| 704 |
sub_cm->flags |= CM_IS_SUB; |
| 705 |
|
| 706 |
|
| 707 |
for(v_s = 0; v_s < sub_cm->M; v_s++) |
| 708 |
{ |
| 709 |
if(sub_cm->sttype[(v_s+1)] == E_st) |
| 710 |
esl_vec_FNorm(sub_cm->e[v_s], orig_cm->abc->K); |
| 711 |
else if(sub_cm->sttype[v_s] != S_st && |
| 712 |
sub_cm->sttype[v_s] != D_st && |
| 713 |
sub_cm->sttype[v_s] != B_st && |
| 714 |
sub_cm->sttype[v_s] != E_st) |
| 715 |
cm2sub_cm_emit_probs(orig_cm, sub_cm, orig_psi, v_s, submap->s2o_smap[v_s][0], submap->s2o_smap[v_s][1], submap); |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
for(v_s = 0; v_s < sub_cm->M; v_s++) |
| 723 |
{ |
| 724 |
if(sub_cm->sttype[(v_s+1)] == E_st) |
| 725 |
esl_vec_FNorm(sub_cm->t[v_s], sub_cm->cnum[v_s]); |
| 726 |
else if(v_s == 0 || |
| 727 |
(sub_cm->sttype[v_s] != S_st && |
| 728 |
sub_cm->sttype[v_s] != B_st && |
| 729 |
sub_cm->sttype[v_s] != E_st)) |
| 730 |
cm2sub_cm_trans_probs(orig_cm, sub_cm, orig_psi, tmap, v_s, submap); |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
for(n_s = 0; n_s < sub_cm->nodes; n_s++) |
| 739 |
{ |
| 740 |
if(sub_cm->ndtype[n_s] == MATP_nd && (sub_cm->sttype[(sub_cm->nodemap[n_s] + 5)+1] != E_st)) |
| 741 |
{ |
| 742 |
|
| 743 |
if((submap->s2o_smap[sub_cm->nodemap[n_s] + 4][1] != -1) || |
| 744 |
(submap->s2o_smap[sub_cm->nodemap[n_s] + 5][1] != -1)) |
| 745 |
ESL_FAIL(eslEINCONCEIVABLE, errbuf, "build_sub_cm(), MATP_IL or MATP_IR node: %d map to 2 cm states\n", n_s); |
| 746 |
if(submap->s2o_smap[sub_cm->nodemap[n_s] + 4][0] != (submap->s2o_smap[sub_cm->nodemap[n_s] + 5][0] - 1)) |
| 747 |
ESL_FAIL(eslEINCONCEIVABLE, errbuf, "build_sub_cm(), MATP_IL or MATP_IR node: %d don't map to adjacent orig_cm states\n", n_s); |
| 748 |
} |
| 749 |
if(sub_cm->ndtype[n_s] == ROOT_nd && sub_cm->ndtype[n_s+1] != BIF_nd) |
| 750 |
|
| 751 |
cm2sub_cm_subtract_root_subpaths(orig_cm, sub_cm, orig_psi, tmap, submap, print_flag); |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
for(v_s = 0; v_s < sub_cm->M; v_s++) |
| 756 |
{ |
| 757 |
if(sub_cm->sttype[v_s] == S_st) |
| 758 |
cm2sub_cm_trans_probs_S(orig_cm, sub_cm, orig_psi, tmap, v_s, submap); |
| 759 |
|
| 760 |
if(sub_cm->sttype[v_s] == E_st || sub_cm->sttype[v_s] == B_st) |
| 761 |
cm2sub_cm_trans_probs_B_E(orig_cm, sub_cm, orig_psi, tmap, v_s, submap, print_flag); |
| 762 |
|
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
cm_find_and_detach_dual_inserts(sub_cm, |
| 770 |
FALSE, |
| 771 |
TRUE); |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
if(sub_cm->qdbinfo->setby == CM_QDBINFO_SETBY_INIT) sub_cm->qdbinfo->setby = CM_QDBINFO_SETBY_SUBINIT; |
| 777 |
if(sub_cm->W == 0) { |
| 778 |
sub_cm->W = orig_cm->W; |
| 779 |
sub_cm->W_setby = CM_W_SETBY_SUBCOPY; |
| 780 |
} |
| 781 |
|
| 782 |
|
| 783 |
CMRenormalize(sub_cm); |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
if(print_flag) { |
| 790 |
ofp = fopen("sub.cm", "w"); |
| 791 |
printf("%-40s ... ", "Saving model to file"); |
| 792 |
fflush(stdout); |
| 793 |
cm_file_WriteASCII(ofp, -1, sub_cm); |
| 794 |
printf("done.\n"); |
| 795 |
|
| 796 |
printf("\nDEBUG PRINT OF ORIG_CM PARAMETERS:\n"); |
| 797 |
debug_print_cm_params(stdout, orig_cm); |
| 798 |
printf("\nDEBUG PRINT OF SUB_CM PARAMETERS:\n"); |
| 799 |
debug_print_cm_params(stdout, sub_cm); |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
cm_FreeTransitionMap(tmap); |
| 804 |
free(sub_cstr); |
| 805 |
free(sub_ct); |
| 806 |
FreeCMConsensus(con); |
| 807 |
FreeParsetree(mtr); |
| 808 |
free(orig_psi); |
| 809 |
|
| 810 |
*ret_cm = sub_cm; |
| 811 |
*ret_submap = submap; |
| 812 |
|
| 813 |
return eslOK; |
| 814 |
|
| 815 |
ERROR: |
| 816 |
ESL_FAIL(eslEMEM, errbuf, "build_sub_cm() memory allocation error."); |
| 817 |
return FALSE; |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
void |
| 844 |
CP9NodeForPosn(CP9_t *hmm, int i0, int j0, int x, CP9_MX *post, |
| 845 |
int *ret_node, int *ret_type, float pmass, int is_start, |
| 846 |
int print_flag) |
| 847 |
{ |
| 848 |
|
| 849 |
|
| 850 |
int max_k; |
| 851 |
int max_type; |
| 852 |
|
| 853 |
int max_sc; |
| 854 |
int k; |
| 855 |
|
| 856 |
if(!is_start) pmass = 1. - pmass; |
| 857 |
|
| 858 |
|
| 859 |
if(x > j0 || x < i0) |
| 860 |
|
| 861 |
cm_Fail("ERROR in CP9NodeForPosn(), asking for position x: %d outside subseq bounds i0: %d j0: %d\n", x, i0, j0); |
| 862 |
|
| 863 |
if(post->mmx[x][0] > post->imx[x][0]) |
| 864 |
{ |
| 865 |
max_sc = post->mmx[x][0]; |
| 866 |
max_type = 0; |
| 867 |
} |
| 868 |
else |
| 869 |
{ |
| 870 |
max_sc = post->imx[x][0]; |
| 871 |
max_type = 1; |
| 872 |
} |
| 873 |
max_k = 0; |
| 874 |
|
| 875 |
for(k = 1; k <= hmm->M; k++) |
| 876 |
{ |
| 877 |
if(post->mmx[x][k] > max_sc) |
| 878 |
{ |
| 879 |
max_k = k; |
| 880 |
max_sc = post->mmx[x][k]; |
| 881 |
max_type = 0; |
| 882 |
} |
| 883 |
if(post->imx[x][k] > max_sc) |
| 884 |
{ |
| 885 |
max_k = k; |
| 886 |
max_sc = post->imx[x][k]; |
| 887 |
max_type = 1; |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
if(print_flag) |
| 892 |
{ |
| 893 |
if(max_type == 0) |
| 894 |
printf("MATCH | mx->mmx[%3d][%3d]: %9d | %8f\n", x, max_k, post->mmx[x][max_k], Score2Prob(post->mmx[x][max_k], 1.)); |
| 895 |
else |
| 896 |
printf("INSERT | mx->imx[%3d][%3d]: %9d | %8f\n", x, max_k, post->imx[x][max_k], Score2Prob(post->imx[x][max_k], 1.)); |
| 897 |
} |
| 898 |
*ret_node = max_k; |
| 899 |
*ret_type = max_type; |
| 900 |
return; |
| 901 |
} |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
void |
| 927 |
StripWUSSGivenCC(ESL_MSA *msa, float gapthresh, int first_match, int last_match) |
| 928 |
{ |
| 929 |
int status; |
| 930 |
int *matassign; |
| 931 |
int gaps; |
| 932 |
int apos; |
| 933 |
int idx; |
| 934 |
int cc; |
| 935 |
int *ct; |
| 936 |
|
| 937 |
|
| 938 |
if(msa->flags & eslMSA_DIGITAL) |
| 939 |
cm_Fail("ERROR in StripWUSSGivenCC, MSA is digitized.\n"); |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
ESL_ALLOC(matassign, sizeof(int) * (msa->alen+1)); |
| 945 |
matassign[0] = 0; |
| 946 |
for (apos = 0; apos < msa->alen; apos++) |
| 947 |
{ |
| 948 |
for (gaps = 0, idx = 0; idx < msa->nseq; idx++) |
| 949 |
if (esl_abc_CIsGap(msa->abc, msa->aseq[idx][apos])) gaps++; |
| 950 |
matassign[apos+1] = ((double) gaps / (double) msa->nseq > gapthresh) ? 0 : 1; |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
ESL_ALLOC(ct, (msa->alen+1) * sizeof(int)); |
| 960 |
if (esl_wuss2ct(msa->ss_cons, msa->alen, ct) != eslOK) |
| 961 |
cm_Fail("Consensus structure string is inconsistent"); |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
cc = 0; |
| 970 |
for (apos = 1; apos <= msa->alen; apos++) |
| 971 |
{ |
| 972 |
if (! matassign[apos]) |
| 973 |
{ |
| 974 |
if (ct[apos] != 0) ct[ct[apos]] = 0; |
| 975 |
ct[apos] = 0; |
| 976 |
} |
| 977 |
else |
| 978 |
{ |
| 979 |
cc++; |
| 980 |
if(cc < first_match || cc > last_match) |
| 981 |
{ |
| 982 |
if (ct[apos] != 0) ct[ct[apos]] = 0; |
| 983 |
ct[apos] = 0; |
| 984 |
} |
| 985 |
} |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
for (apos = 1; apos <= msa->alen; apos++) |
| 994 |
{ |
| 995 |
if (ct[apos] == 0 ) msa->ss_cons[apos-1] = '.'; |
| 996 |
else if (ct[apos] > apos) msa->ss_cons[apos-1] = '<'; |
| 997 |
else if (ct[apos] < apos) msa->ss_cons[apos-1] = '>'; |
| 998 |
else cm_Fail("ERROR: weird error in StripWUSSGivenCC\n"); |
| 999 |
} |
| 1000 |
|
| 1001 |
return; |
| 1002 |
|
| 1003 |
ERROR: |
| 1004 |
cm_Fail("Memory allocation error."); |
| 1005 |
} |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
static void |
| 1031 |
cm2sub_cm_emit_probs(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, int v_s, int v_o1, int v_o2, |
| 1032 |
CMSubMap_t *submap) |
| 1033 |
{ |
| 1034 |
int is_left; |
| 1035 |
int i, j; |
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
if(v_o1 == -1) |
| 1040 |
{ |
| 1041 |
cm_Fail("ERROR in cm2sub_cm_emit_probs, sub_cm state %d maps to 0 states in orig_cm (spos: %d epos: %d)\n", v_s, submap->spos, submap->epos); |
| 1042 |
} |
| 1043 |
|
| 1044 |
if(sub_cm->sttype[v_s] == MP_st) |
| 1045 |
{ |
| 1046 |
for(i = 0; i < (orig_cm->abc->K*orig_cm->abc->K); i++) |
| 1047 |
sub_cm->e[v_s][i] = orig_cm->e[v_o1][i]; |
| 1048 |
return; |
| 1049 |
} |
| 1050 |
|
| 1051 |
if(submap->s2o_id[v_s] == TRUE) |
| 1052 |
{ |
| 1053 |
|
| 1054 |
for(i = 0; i < orig_cm->abc->K; i++) |
| 1055 |
sub_cm->e[v_s][i] = orig_cm->e[v_o1][i]; |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
return; |
| 1060 |
} |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
if(orig_cm->sttype[v_o1] == MP_st) |
| 1070 |
{ |
| 1071 |
if(orig_cm->sttype[v_o2] == ML_st) |
| 1072 |
is_left = TRUE; |
| 1073 |
else if(orig_cm->sttype[v_o2] == MR_st) |
| 1074 |
is_left = FALSE; |
| 1075 |
else |
| 1076 |
cm_Fail("ERROR v_s: %d maps to a MP_st and another non-ML and non-MR state\n"); |
| 1077 |
|
| 1078 |
for(i = 0; i < orig_cm->abc->K; i++) |
| 1079 |
if(is_left) |
| 1080 |
for(j = (i*orig_cm->abc->K); j < ((i+1)*orig_cm->abc->K); j++) |
| 1081 |
sub_cm->e[v_s][i] += orig_psi[v_o1] * orig_cm->e[v_o1][j]; |
| 1082 |
else |
| 1083 |
for(j = i; j < (orig_cm->abc->K*orig_cm->abc->K); j+=orig_cm->abc->K) |
| 1084 |
sub_cm->e[v_s][i] += orig_psi[v_o1] * orig_cm->e[v_o1][j]; |
| 1085 |
if(orig_cm->sttype[v_o2] == MP_st) |
| 1086 |
cm_Fail("ERROR sub_cm state: %d maps to two MATP_MP states\n", v_s); |
| 1087 |
|
| 1088 |
|
| 1089 |
for(i = 0; i < orig_cm->abc->K; i++) |
| 1090 |
sub_cm->e[v_s][i] += orig_psi[v_o2] * orig_cm->e[v_o2][i]; |
| 1091 |
esl_vec_FNorm(sub_cm->e[v_s], orig_cm->abc->K); |
| 1092 |
return; |
| 1093 |
} |
| 1094 |
else if(v_o2 != -1) |
| 1095 |
cm_Fail("ERROR sub_cm state: %d maps to two states (%d and %d), but neither is a MATP_MP\n", v_s, v_o1, v_o2); |
| 1096 |
|
| 1097 |
|
| 1098 |
for(i = 0; i < orig_cm->abc->K; i++) |
| 1099 |
sub_cm->e[v_s][i] = orig_cm->e[v_o1][i]; |
| 1100 |
|
| 1101 |
return; |
| 1102 |
} |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
static void |
| 1132 |
cm2sub_cm_trans_probs(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, char ***tmap, int v_s, CMSubMap_t *submap) |
| 1133 |
{ |
| 1134 |
int v_o; |
| 1135 |
int yoffset; |
| 1136 |
int y_s; |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
if(submap->s2o_id[v_s] == TRUE) |
| 1141 |
{ |
| 1142 |
v_o = submap->s2o_smap[v_s][0]; |
| 1143 |
for(yoffset = 0; yoffset < sub_cm->cnum[v_s]; yoffset++) |
| 1144 |
{ |
| 1145 |
|
| 1146 |
sub_cm->t[v_s][yoffset] = orig_psi[v_o] * orig_cm->t[v_o][yoffset]; |
| 1147 |
} |
| 1148 |
return; |
| 1149 |
} |
| 1150 |
|
| 1151 |
|
| 1152 |
v_o = submap->s2o_smap[v_s][0]; |
| 1153 |
|
| 1154 |
if(v_o == -1) |
| 1155 |
{ |
| 1156 |
if(sub_cm->sttype[v_s] != S_st && |
| 1157 |
sub_cm->sttype[v_s] != E_st && |
| 1158 |
sub_cm->sttype[v_s] != B_st) |
| 1159 |
|
| 1160 |
cm_Fail("ERROR, sub_cm state v_s: %d maps to no state in sub_cm, but it's not a B, E or S state\n", v_s); |
| 1161 |
} |
| 1162 |
else |
| 1163 |
{ |
| 1164 |
if(sub_cm->sttype[v_s] == S_st || |
| 1165 |
sub_cm->sttype[v_s] == E_st || |
| 1166 |
sub_cm->sttype[v_s] == B_st) |
| 1167 |
if(v_s != 0) |
| 1168 |
cm_Fail("ERROR, sub_cm state v_s: %d is S, E or B but maps to a orig_cm state: v_o:%d\n", v_o); |
| 1169 |
|
| 1170 |
for(yoffset = 0; yoffset < sub_cm->cnum[v_s]; yoffset++) |
| 1171 |
{ |
| 1172 |
y_s = sub_cm->cfirst[v_s] + yoffset; |
| 1173 |
if(sub_cm->sttype[(y_s+1)] != E_st) |
| 1174 |
|
| 1175 |
{ |
| 1176 |
cm2sub_cm_add_single_trans(orig_cm, sub_cm, submap, v_o, submap->s2o_smap[y_s][0], v_s, yoffset, orig_psi, tmap); |
| 1177 |
cm2sub_cm_add_single_trans(orig_cm, sub_cm, submap, v_o, submap->s2o_smap[y_s][1], v_s, yoffset, orig_psi, tmap); |
| 1178 |
} |
| 1179 |
} |
| 1180 |
} |
| 1181 |
|
| 1182 |
|
| 1183 |
v_o = submap->s2o_smap[v_s][1]; |
| 1184 |
if(v_o != -1) |
| 1185 |
{ |
| 1186 |
for(yoffset = 0; yoffset < sub_cm->cnum[v_s]; yoffset++) |
| 1187 |
{ |
| 1188 |
y_s = sub_cm->cfirst[v_s] + yoffset; |
| 1189 |
if(sub_cm->sttype[(y_s+1)] != E_st) |
| 1190 |
|
| 1191 |
{ |
| 1192 |
cm2sub_cm_add_single_trans(orig_cm, sub_cm, submap, v_o, submap->s2o_smap[y_s][0], v_s, yoffset, orig_psi, tmap); |
| 1193 |
cm2sub_cm_add_single_trans(orig_cm, sub_cm, submap, v_o, submap->s2o_smap[y_s][1], v_s, yoffset, orig_psi, tmap); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
} |
| 1197 |
return; |
| 1198 |
} |
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
static void |
| 1220 |
cm2sub_cm_trans_probs_S(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, char ***tmap, int v_start, CMSubMap_t *submap) |
| 1221 |
{ |
| 1222 |
int yoffset; |
| 1223 |
int y_s; |
| 1224 |
|
| 1225 |
int sub_nd; |
| 1226 |
|
| 1227 |
int v_s_insert; |
| 1228 |
int v_o_insert; |
| 1229 |
|
| 1230 |
float sum; |
| 1231 |
float il_psi; |
| 1232 |
float temp_psi; |
| 1233 |
float temp_psi_sum; |
| 1234 |
float diff; |
| 1235 |
|
| 1236 |
int orig_il1, orig_il2, orig_ir1, orig_ir2; |
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
sub_nd = sub_cm->ndidx[v_start]; |
| 1241 |
|
| 1242 |
if(sub_cm->ndtype[sub_nd] == BEGL_nd) |
| 1243 |
{ |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
if(sub_cm->ndtype[sub_nd + 1] == BIF_nd) |
| 1249 |
sub_cm->t[v_start][0] = 1.0; |
| 1250 |
else |
| 1251 |
for(yoffset = 0; yoffset < sub_cm->cnum[v_start]; yoffset++) |
| 1252 |
{ |
| 1253 |
y_s = sub_cm->cfirst[v_start] + yoffset; |
| 1254 |
|
| 1255 |
sub_cm->t[v_start][yoffset] = orig_psi[submap->s2o_smap[y_s][0]]; |
| 1256 |
if(submap->s2o_smap[y_s][1] != -1) |
| 1257 |
sub_cm->t[v_start][yoffset] += orig_psi[submap->s2o_smap[y_s][1]]; |
| 1258 |
} |
| 1259 |
} |
| 1260 |
|
| 1261 |
else if(sub_cm->ndtype[sub_nd] == BEGR_nd) |
| 1262 |
{ |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
v_s_insert = v_start + 1; |
| 1271 |
if(sub_cm->ndtype[sub_nd + 1] == BIF_nd) |
| 1272 |
{ |
| 1273 |
|
| 1274 |
|
| 1275 |
v_o_insert = submap->s2o_smap[v_s_insert][0]; |
| 1276 |
if(submap->s2o_smap[v_s_insert][1] == -1) |
| 1277 |
{ |
| 1278 |
diff = sub_cm->t[v_s_insert][0] - (orig_psi[v_o_insert] * orig_cm->t[v_o_insert][0]); |
| 1279 |
if(diff >= 0. && diff > 0.0001) |
| 1280 |
cm_Fail("ERROR, code for calc'ing BEGR_IL -> BIF_B is wrong, sub_cm->t[v_s_insert:%d][0] should be %f (based on your understanding) but its really %f\n", v_s_insert, (orig_psi[v_o_insert] * orig_cm->t[v_o_insert][0]), (sub_cm->t[v_s_insert][0])); |
| 1281 |
if(diff <= 0. && diff < -0.0001) |
| 1282 |
cm_Fail("ERROR, code for calc'ing BEGR_IL -> BIF_B is wrong, sub_cm->t[v_s_insert:%d][0] should be %f (based on your understanding) but its really %f\n", v_s_insert, (orig_psi[v_o_insert] * orig_cm->t[v_o_insert][0]), (sub_cm->t[v_s_insert][0])); |
| 1283 |
} |
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
sub_cm->t[v_s_insert][1] = orig_psi[v_o_insert] * (1. - orig_cm->t[v_o_insert][0]); |
| 1290 |
if(submap->s2o_smap[v_s_insert][1] != -1) |
| 1291 |
{ |
| 1292 |
|
| 1293 |
cm_Fail("ERROR, BEGR_IL: %d maps to 2 orig_cm states, was hoping this was impossible - need to implement.\n", v_s_insert); |
| 1294 |
v_o_insert = submap->s2o_smap[v_s_insert][1]; |
| 1295 |
sub_cm->t[v_s_insert][1] += orig_psi[v_o_insert] * (1. - orig_cm->t[v_o_insert][0]); |
| 1296 |
} |
| 1297 |
|
| 1298 |
esl_vec_FNorm(sub_cm->t[v_s_insert], sub_cm->cnum[v_s_insert]); |
| 1299 |
il_psi = orig_psi[submap->s2o_smap[v_s_insert][0]]; |
| 1300 |
if(submap->s2o_smap[v_s_insert][1] != -1) |
| 1301 |
{ |
| 1302 |
cm_Fail("ERROR, BEGR_IL: %d maps to 2 orig_cm states, was hoping this was impossible - need to implement.\n", v_s_insert); |
| 1303 |
il_psi+= orig_psi[submap->s2o_smap[v_s_insert][1]]; |
| 1304 |
} |
| 1305 |
sub_cm->t[v_start][0] = (1. - sub_cm->t[v_s_insert][0]) * il_psi; |
| 1306 |
sub_cm->t[v_start][1] = 1. - sub_cm->t[v_start][0]; |
| 1307 |
} |
| 1308 |
|
| 1309 |
else |
| 1310 |
{ |
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
sum = 0.; |
| 1317 |
esl_vec_FNorm(sub_cm->t[v_s_insert], sub_cm->cnum[v_s_insert]); |
| 1318 |
il_psi = orig_psi[submap->s2o_smap[v_s_insert][0]]; |
| 1319 |
if(submap->s2o_smap[v_s_insert][1] != -1) |
| 1320 |
{ |
| 1321 |
cm_Fail("ERROR, BEGR_IL: %d maps to 2 orig_cm states, was hoping this was impossible - need to implement.\n", v_s_insert); |
| 1322 |
il_psi += orig_psi[submap->s2o_smap[v_s_insert][1]]; |
| 1323 |
} |
| 1324 |
sub_cm->t[v_start][0] = (1. - sub_cm->t[v_s_insert][0]) * il_psi; |
| 1325 |
sum = sub_cm->t[v_start][0]; |
| 1326 |
|
| 1327 |
for(yoffset = 1; yoffset < sub_cm->cnum[v_start]; yoffset++) |
| 1328 |
|
| 1329 |
|
| 1330 |
{ |
| 1331 |
y_s = sub_cm->cfirst[v_start] + yoffset; |
| 1332 |
temp_psi = orig_psi[submap->s2o_smap[y_s][0]]; |
| 1333 |
if(submap->s2o_smap[y_s][1] != -1) |
| 1334 |
temp_psi += orig_psi[submap->s2o_smap[y_s][1]]; |
| 1335 |
|
| 1336 |
sub_cm->t[v_start][yoffset] = temp_psi - il_psi * sub_cm->t[v_s_insert][yoffset]; |
| 1337 |
sum += sub_cm->t[v_start][yoffset]; |
| 1338 |
} |
| 1339 |
|
| 1340 |
if(sum < 1.0 && ((1.0 - sum) > 0.001)) |
| 1341 |
cm_Fail("ERROR calculating transitions out of BEGR_S incorrectly\n"); |
| 1342 |
if(sum > 1.0 && ((sum - 1.0) > 0.001)) |
| 1343 |
cm_Fail("ERROR calculating transitions out of BEGR_S incorrectly\n"); |
| 1344 |
} |
| 1345 |
} |
| 1346 |
else if(sub_cm->ndtype[sub_nd] == ROOT_nd) |
| 1347 |
{ |
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
if(sub_cm->ndtype[sub_nd + 1] == BIF_nd) |
| 1353 |
{ |
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
orig_il1 = submap->s2o_smap[1][0]; |
| 1364 |
orig_il2 = submap->s2o_smap[1][1]; |
| 1365 |
|
| 1366 |
orig_ir1 = submap->s2o_smap[2][0]; |
| 1367 |
orig_ir2 = submap->s2o_smap[2][1]; |
| 1368 |
|
| 1369 |
if(orig_ir1 < orig_il1) |
| 1370 |
{ |
| 1371 |
sub_cm->t[0][1] -= orig_psi[orig_ir1] * |
| 1372 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ir1, orig_il1, 0, tmap, orig_psi); |
| 1373 |
} |
| 1374 |
if(orig_ir2 != -1 && orig_ir2 < orig_il1) |
| 1375 |
{ |
| 1376 |
sub_cm->t[0][1] -= orig_psi[orig_ir2] * |
| 1377 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ir2, orig_il1, 0, tmap, orig_psi); |
| 1378 |
} |
| 1379 |
if(orig_il2 != -1 && orig_ir1 < orig_il2) |
| 1380 |
{ |
| 1381 |
sub_cm->t[0][1] -= orig_psi[orig_ir1] * |
| 1382 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ir1, orig_il2, 0, tmap, orig_psi); |
| 1383 |
} |
| 1384 |
if((orig_ir2 != -1 && orig_il2 != -1) && (orig_ir2 < orig_il2)) |
| 1385 |
{ |
| 1386 |
sub_cm->t[0][1] -= orig_psi[orig_ir2] * |
| 1387 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ir2, orig_il2, 0, tmap, orig_psi); |
| 1388 |
} |
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
sub_cm->t[0][2] = 1.0 - (sub_cm->t[0][0] + sub_cm->t[0][1]); |
| 1398 |
|
| 1399 |
v_s_insert = v_start + 1; |
| 1400 |
v_o_insert = submap->s2o_smap[v_s_insert][0]; |
| 1401 |
if(submap->s2o_smap[v_s_insert][1] == -1) |
| 1402 |
{ |
| 1403 |
diff = sub_cm->t[v_s_insert][0] - (orig_psi[v_o_insert] * orig_cm->t[v_o_insert][0]); |
| 1404 |
if(diff >= 0. && diff >= 0.0001) |
| 1405 |
cm_Fail("ERROR, code for calc'ing ROOT_IL -> BIF_B is wrong, sub_cm->t[v_s_insert:%d][0] should be %f (based on your understanding) but its really %f\n", v_s_insert, (orig_psi[v_o_insert] * orig_cm->t[v_o_insert][0]), (sub_cm->t[v_s_insert][0])); |
| 1406 |
if(diff <= 0. && diff <= -0.0001) |
| 1407 |
cm_Fail("ERROR, code for calc'ing ROOT_IL -> BIF_B is wrong, sub_cm->t[v_s_insert:%d][0] should be %f (based on your understanding) but its really %f\n", v_s_insert, (orig_psi[v_o_insert] * orig_cm->t[v_o_insert][0]), (sub_cm->t[v_s_insert][0])); |
| 1408 |
} |
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
temp_psi_sum = orig_psi[v_o_insert]; |
| 1421 |
|
| 1422 |
if(submap->s2o_smap[v_s_insert][1] != -1) |
| 1423 |
{ |
| 1424 |
v_o_insert = submap->s2o_smap[v_s_insert][1]; |
| 1425 |
temp_psi_sum += orig_psi[v_o_insert]; |
| 1426 |
} |
| 1427 |
sub_cm->t[v_s_insert][0] /= temp_psi_sum; |
| 1428 |
sub_cm->t[v_s_insert][1] /= temp_psi_sum; |
| 1429 |
sub_cm->t[v_s_insert][2] = 1. - (sub_cm->t[v_s_insert][0] + sub_cm->t[v_s_insert][1]); |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
v_s_insert = v_start + 2; |
| 1434 |
v_o_insert = submap->s2o_smap[v_s_insert][0]; |
| 1435 |
if(submap->s2o_smap[v_s_insert][1] == -1) |
| 1436 |
{ |
| 1437 |
diff = sub_cm->t[v_s_insert][0] - (orig_psi[v_o_insert] * orig_cm->t[v_o_insert][0]); |
| 1438 |
if(diff >= 0. && diff > 0.0001) |
| 1439 |
cm_Fail("ERROR, code for calc'ing ROOT_IR -> BIF_B is wrong, sub_cm->t[v_s_insert:%d][0] should be %f (based on your understanding) but its really %f\n", v_s_insert, (orig_psi[v_o_insert] * orig_cm->t[v_o_insert][0]), (sub_cm->t[v_s_insert][0])); |
| 1440 |
if(diff <= 0. && diff < -0.0001) |
| 1441 |
cm_Fail("ERROR, code for calc'ing ROOT_IR -> BIF_B is wrong, sub_cm->t[v_s_insert:%d][0] should be %f (based on your understanding) but its really %f\n", v_s_insert, (orig_psi[v_o_insert] * orig_cm->t[v_o_insert][0]), (sub_cm->t[v_s_insert][0])); |
| 1442 |
} |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
temp_psi_sum = orig_psi[v_o_insert]; |
| 1447 |
|
| 1448 |
if(submap->s2o_smap[v_s_insert][1] != -1) |
| 1449 |
{ |
| 1450 |
v_o_insert = submap->s2o_smap[v_s_insert][1]; |
| 1451 |
temp_psi_sum += orig_psi[v_o_insert]; |
| 1452 |
} |
| 1453 |
sub_cm->t[v_s_insert][0] /= temp_psi_sum; |
| 1454 |
sub_cm->t[v_s_insert][1] = 1. - (sub_cm->t[v_s_insert][0]); |
| 1455 |
|
| 1456 |
} |
| 1457 |
else |
| 1458 |
{ |
| 1459 |
|
| 1460 |
} |
| 1461 |
} |
| 1462 |
|
| 1463 |
return; |
| 1464 |
} |
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
static void |
| 1487 |
cm2sub_cm_trans_probs_B_E(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, char ***tmap, int v_be, CMSubMap_t *submap, |
| 1488 |
int print_flag) |
| 1489 |
{ |
| 1490 |
int orig_v; |
| 1491 |
int sub_v; |
| 1492 |
|
| 1493 |
int sub_nd; |
| 1494 |
int psub_nd; |
| 1495 |
int sub_i; |
| 1496 |
int bif_end_yoffset; |
| 1497 |
int orig_v1, orig_v2, orig_i; |
| 1498 |
float contribution; |
| 1499 |
int orig_il, orig_ir, sub_il, sub_ir; |
| 1500 |
int into_end_flag; |
| 1501 |
|
| 1502 |
if(print_flag) printf("in cm2sub_cm_trans_probs_B_E: sub_v: %d\n", v_be); |
| 1503 |
|
| 1504 |
sub_nd = sub_cm->ndidx[v_be]; |
| 1505 |
psub_nd = sub_nd - 1; |
| 1506 |
|
| 1507 |
into_end_flag = FALSE; |
| 1508 |
if(sub_cm->sttype[v_be] == E_st) |
| 1509 |
into_end_flag = TRUE; |
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
switch (sub_cm->ndtype[psub_nd]) { |
| 1514 |
case MATP_nd: |
| 1515 |
if(print_flag) printf("prev node type MATP\n"); |
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
bif_end_yoffset = 2; |
| 1528 |
sub_il = sub_cm->nodemap[psub_nd] + 4; |
| 1529 |
sub_ir = sub_cm->nodemap[psub_nd] + 5; |
| 1530 |
|
| 1531 |
orig_il = submap->s2o_smap[sub_il][0]; |
| 1532 |
orig_ir = submap->s2o_smap[sub_ir][0]; |
| 1533 |
if(into_end_flag && orig_ir != -1) |
| 1534 |
cm_Fail("ERROR in cm2sub_cm_trans_probs_B_E(), into_end_flag is TRUE but MATP_IR maps to a orig_cm state.\n"); |
| 1535 |
if(orig_ir == -1 && !into_end_flag) |
| 1536 |
cm_Fail("ERROR in cm2sub_cm_trans_probs_B_E(), into_end_flag is FALSE but MATP_IR doesn't map to a orig_cm state.\n"); |
| 1537 |
|
| 1538 |
for(sub_v = sub_cm->nodemap[psub_nd]; sub_v < sub_il; sub_v++) |
| 1539 |
{ |
| 1540 |
orig_v = submap->s2o_smap[sub_v][0]; |
| 1541 |
sub_cm->t[sub_v][bif_end_yoffset] = orig_psi[orig_v] - |
| 1542 |
(sub_cm->t[sub_v][0] + sub_cm->t[sub_v][1]); |
| 1543 |
} |
| 1544 |
|
| 1545 |
sub_cm->t[sub_il][bif_end_yoffset] = orig_psi[orig_il] - |
| 1546 |
(sub_cm->t[sub_il][0] + sub_cm->t[sub_il][1]); |
| 1547 |
|
| 1548 |
bif_end_yoffset = 1; |
| 1549 |
if(into_end_flag) |
| 1550 |
sub_cm->t[sub_ir][bif_end_yoffset] = 1.0; |
| 1551 |
else |
| 1552 |
sub_cm->t[sub_ir][bif_end_yoffset] = orig_psi[orig_ir] - sub_cm->t[sub_ir][0]; |
| 1553 |
break; |
| 1554 |
|
| 1555 |
case MATL_nd: |
| 1556 |
case MATR_nd: |
| 1557 |
if(print_flag) printf("prev node type MATL or MATR\n"); |
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
bif_end_yoffset = 1; |
| 1563 |
sub_i = sub_cm->nodemap[psub_nd] + 2; |
| 1564 |
orig_i = submap->s2o_smap[sub_i][0]; |
| 1565 |
if(into_end_flag && orig_i != -1) |
| 1566 |
cm_Fail("ERROR in cm2sub_cm_trans_probs_B_E(), into_end_flag is TRUE but MAT*_I* maps to a orig_cm state.\n"); |
| 1567 |
|
| 1568 |
for(sub_v = sub_cm->nodemap[psub_nd]; sub_v < sub_i; sub_v++) |
| 1569 |
{ |
| 1570 |
orig_v1 = submap->s2o_smap[sub_v][0]; |
| 1571 |
orig_v2 = submap->s2o_smap[sub_v][1]; |
| 1572 |
if(into_end_flag) |
| 1573 |
sub_cm->t[sub_v][bif_end_yoffset] = 1.0; |
| 1574 |
else |
| 1575 |
{ |
| 1576 |
if(orig_v1 < orig_i) |
| 1577 |
{ |
| 1578 |
contribution = cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, |
| 1579 |
orig_v1, orig_i, sub_v, tmap, orig_psi); |
| 1580 |
sub_cm->t[sub_v][bif_end_yoffset] = orig_psi[orig_v1] * (1. - contribution); |
| 1581 |
if(print_flag) printf("curr v1 < i1 sub_cm->t[sub_v:%d][1] now: %f (added: psi:%f * 1-cont: %f (%f))\n", sub_v, sub_cm->t[sub_v][1], orig_psi[orig_v1], (1.-contribution), (orig_psi[orig_v1] * (1. - contribution))); |
| 1582 |
} |
| 1583 |
else |
| 1584 |
{ |
| 1585 |
contribution = orig_psi[orig_i] * cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, |
| 1586 |
orig_i, orig_v1, sub_v, tmap, orig_psi); |
| 1587 |
sub_cm->t[sub_v][bif_end_yoffset] = orig_psi[orig_v1] * (1. - (contribution / orig_psi[orig_v1])); |
| 1588 |
if(print_flag) printf("curr i1 < v1 sub_cm->t[sub_v:%d][1] now: %f (added: psi:%f * 1-cont: %f (%f))\n", sub_v, sub_cm->t[sub_v][1], orig_psi[orig_v1], (1.-contribution), (orig_psi[orig_v1] * (1. - contribution))); |
| 1589 |
} |
| 1590 |
if(orig_v2 != -1) |
| 1591 |
{ |
| 1592 |
if(orig_v2 < orig_i) |
| 1593 |
{ |
| 1594 |
contribution = cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, |
| 1595 |
orig_v2, orig_i, sub_v, tmap, orig_psi); |
| 1596 |
sub_cm->t[sub_v][bif_end_yoffset] += orig_psi[orig_v2] * (1. - contribution); |
| 1597 |
if(print_flag) printf("curr v2 < i1 sub_cm->t[sub_v:%d][1] now: %f (added: psi:%f * 1-cont: %f (%f))\n", sub_v, sub_cm->t[sub_v][1], orig_psi[orig_v2], (1.-contribution), (orig_psi[orig_v2] * (1. - contribution))); |
| 1598 |
} |
| 1599 |
else |
| 1600 |
{ |
| 1601 |
contribution = orig_psi[orig_i] * cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, |
| 1602 |
orig_i, orig_v2, sub_v, tmap, orig_psi); |
| 1603 |
sub_cm->t[sub_v][bif_end_yoffset] += orig_psi[orig_v2] * (1. - (contribution / orig_psi[orig_v2])); |
| 1604 |
if(print_flag) printf("curr i1 < v2 sub_cm->t[sub_v:%d][1] now: %f (added: psi:%f * 1-cont: %f (%f))\n", sub_v, sub_cm->t[sub_v][1], orig_psi[orig_v2], (1.-contribution), (orig_psi[orig_v2] * (1. - contribution))); |
| 1605 |
} |
| 1606 |
} |
| 1607 |
} |
| 1608 |
} |
| 1609 |
|
| 1610 |
if(into_end_flag) |
| 1611 |
|
| 1612 |
sub_cm->t[sub_i][1] = 1.; |
| 1613 |
else |
| 1614 |
sub_cm->t[sub_i][1] = orig_psi[orig_i] * |
| 1615 |
(1. - cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, |
| 1616 |
orig_i, orig_i, sub_i,tmap, orig_psi)); |
| 1617 |
break; |
| 1618 |
|
| 1619 |
case ROOT_nd: |
| 1620 |
case BEGL_nd: |
| 1621 |
case BEGR_nd: |
| 1622 |
{ } |
| 1623 |
break; |
| 1624 |
|
| 1625 |
default: |
| 1626 |
cm_Fail("ERROR bogus node type transiting to END or BIF\n"); |
| 1627 |
break; |
| 1628 |
} |
| 1629 |
|
| 1630 |
if(print_flag) printf("Returning from cm2sub_cm_trans_probs_B_E\n"); |
| 1631 |
return; |
| 1632 |
} |
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
static void |
| 1644 |
cm2sub_cm_add_single_trans(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, int orig_v, int orig_y, |
| 1645 |
int sub_v, int yoffset, double *orig_psi, char ***tmap) |
| 1646 |
{ |
| 1647 |
int start; |
| 1648 |
|
| 1649 |
if(orig_v == -1 || orig_y == -1) |
| 1650 |
return; |
| 1651 |
start = orig_v; |
| 1652 |
if(orig_y < start) |
| 1653 |
start = orig_y; |
| 1654 |
sub_cm->t[sub_v][yoffset] += orig_psi[start] * |
| 1655 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_v, orig_y, sub_v, tmap, orig_psi); |
| 1656 |
return; |
| 1657 |
} |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
static float |
| 1715 |
cm2sub_cm_sum_subpaths(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, int orig_v, int orig_y, |
| 1716 |
int init_sub_start, char ***tmap, double *orig_psi) |
| 1717 |
{ |
| 1718 |
int status; |
| 1719 |
int v,x,y; |
| 1720 |
int start, end; |
| 1721 |
float to_return; |
| 1722 |
char tmap_val; |
| 1723 |
int is_insert; |
| 1724 |
float insert_to_start; |
| 1725 |
float end_to_insert; |
| 1726 |
int skip_flag; |
| 1727 |
int init_sub_nd; |
| 1728 |
int sub_insert1; |
| 1729 |
int sub_insert2; |
| 1730 |
int orig_insert1; |
| 1731 |
int orig_insert2; |
| 1732 |
float self_loop_factor; |
| 1733 |
int sub_start1; |
| 1734 |
int sub_start2; |
| 1735 |
int sub_end1; |
| 1736 |
int sub_end2; |
| 1737 |
double *sub_psi; |
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
if(orig_v == -1 || orig_y == -1) |
| 1742 |
return 0.; |
| 1743 |
|
| 1744 |
start = orig_v; |
| 1745 |
end = orig_y; |
| 1746 |
if(start > end) |
| 1747 |
{ start = orig_y; end = orig_v; } |
| 1748 |
if(start == end) |
| 1749 |
return orig_cm->t[start][0]; |
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
ESL_ALLOC(sub_psi, sizeof(double) * (end - start + 1)); |
| 1754 |
sub_psi[0] = 1.; |
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
sub_start1 = submap->o2s_smap[start][0]; |
| 1764 |
sub_start2 = submap->o2s_smap[start][1]; |
| 1765 |
sub_end1 = submap->o2s_smap[end ][0]; |
| 1766 |
sub_end2 = submap->o2s_smap[end ][1]; |
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
init_sub_nd = sub_cm->ndidx[init_sub_start]; |
| 1773 |
orig_insert1 = orig_insert2 = sub_insert1 = sub_insert2 = -1; |
| 1774 |
if(sub_cm->ndtype[init_sub_nd] == MATP_nd) |
| 1775 |
{ |
| 1776 |
sub_insert1 = sub_cm->nodemap[init_sub_nd] + 4; |
| 1777 |
sub_insert2 = sub_cm->nodemap[init_sub_nd] + 5; |
| 1778 |
} |
| 1779 |
else if(sub_cm->ndtype[init_sub_nd] == ROOT_nd) |
| 1780 |
{ |
| 1781 |
sub_insert1 = 1; |
| 1782 |
sub_insert2 = 2; |
| 1783 |
} |
| 1784 |
else if(sub_cm->ndtype[init_sub_nd] == MATL_nd || |
| 1785 |
sub_cm->ndtype[init_sub_nd] == MATR_nd || |
| 1786 |
sub_cm->ndtype[init_sub_nd] == BEGR_nd) |
| 1787 |
sub_insert1 = sub_cm->cfirst[init_sub_start]; |
| 1788 |
|
| 1789 |
|
| 1790 |
if(sub_insert1 != -1) orig_insert1 = submap->s2o_smap[sub_insert1][0]; |
| 1791 |
if(sub_insert2 != -1) orig_insert2 = submap->s2o_smap[sub_insert2][0]; |
| 1792 |
|
| 1793 |
|
| 1794 |
for (v = (start+1); v <= end; v++) |
| 1795 |
{ |
| 1796 |
sub_psi[v-start] = 0.; |
| 1797 |
is_insert = FALSE; |
| 1798 |
if(orig_cm->sttype[v] == IL_st || orig_cm->sttype[v] == IR_st) |
| 1799 |
is_insert = TRUE; |
| 1800 |
if(orig_cm->sttype[v] == S_st) |
| 1801 |
{ |
| 1802 |
|
| 1803 |
|
| 1804 |
sub_psi[v-start] = sub_psi[(v-1)-start]; |
| 1805 |
} |
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
skip_flag = FALSE; |
| 1819 |
if (v != end && v == orig_insert1 && sub_insert1 >= init_sub_start) |
| 1820 |
{ |
| 1821 |
if(cm_trans_check(sub_cm, sub_insert1, sub_end1 ) || |
| 1822 |
cm_trans_check(sub_cm, sub_insert1, sub_end2 ) || |
| 1823 |
cm_trans_check(sub_cm, sub_insert1, sub_start1) || |
| 1824 |
cm_trans_check(sub_cm, sub_insert1, sub_start2)) |
| 1825 |
skip_flag = TRUE; |
| 1826 |
} |
| 1827 |
else if (v != end && v == orig_insert2 && sub_insert2 >= init_sub_start) |
| 1828 |
{ |
| 1829 |
if(cm_trans_check(sub_cm, sub_insert2, sub_end1 ) || |
| 1830 |
cm_trans_check(sub_cm, sub_insert2, sub_end2 ) || |
| 1831 |
cm_trans_check(sub_cm, sub_insert2, sub_start1) || |
| 1832 |
cm_trans_check(sub_cm, sub_insert2, sub_start2)) |
| 1833 |
skip_flag = TRUE; |
| 1834 |
} |
| 1835 |
if(!skip_flag) |
| 1836 |
{ |
| 1837 |
for (y = orig_cm->pnum[v]-1; y >= is_insert; y--) |
| 1838 |
{ |
| 1839 |
x = orig_cm->plast[v] - y; |
| 1840 |
|
| 1841 |
tmap_val = tmap[(int) orig_cm->stid[x]][(int) orig_cm->ndtype[orig_cm->ndidx[v]+is_insert]][(int) orig_cm->stid[v]]; |
| 1842 |
|
| 1843 |
if((x - start) < 0) sub_psi[v-start] += 0.; |
| 1844 |
else sub_psi[v-start] += sub_psi[x-start] * orig_cm->t[x][(int) tmap_val]; |
| 1845 |
} |
| 1846 |
if(v != end && is_insert) |
| 1847 |
sub_psi[v-start] += sub_psi[v-start] * |
| 1848 |
(orig_cm->t[v][0] / (1-orig_cm->t[v][0])); |
| 1849 |
} |
| 1850 |
} |
| 1851 |
to_return = sub_psi[end-start]; |
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
insert_to_start = 0.; |
| 1865 |
end_to_insert = 0.; |
| 1866 |
|
| 1867 |
if((orig_cm->sttype[start] != IL_st && orig_cm->sttype[start] != IR_st) && |
| 1868 |
(orig_cm->sttype[end] != IL_st && orig_cm->sttype[end] != IR_st)) |
| 1869 |
{ |
| 1870 |
if(orig_insert1 != -1 && orig_insert1 < start) |
| 1871 |
{ |
| 1872 |
if(orig_cm->sttype[start] == IL_st || orig_cm->sttype[start] == IR_st) |
| 1873 |
self_loop_factor = (1. + (orig_cm->t[start][0] / (1. - orig_cm->t[start][0]))); |
| 1874 |
else |
| 1875 |
self_loop_factor = 1.0; |
| 1876 |
insert_to_start += self_loop_factor * orig_psi[orig_insert1] * |
| 1877 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_insert1, start, init_sub_start, tmap, orig_psi); |
| 1878 |
} |
| 1879 |
if(orig_insert1 != -1 && orig_insert1 > end) |
| 1880 |
end_to_insert += cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, end, orig_insert1, init_sub_start, tmap, orig_psi); |
| 1881 |
|
| 1882 |
if(orig_insert2 != -1 && orig_insert2 < start) |
| 1883 |
{ |
| 1884 |
self_loop_factor = 1.0; |
| 1885 |
if(orig_cm->sttype[start] == IL_st || |
| 1886 |
orig_cm->sttype[start] == IR_st) |
| 1887 |
self_loop_factor = (1. + (orig_cm->t[start][0] / (1. - orig_cm->t[start][0]))); |
| 1888 |
insert_to_start += self_loop_factor * orig_psi[orig_insert2] * cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_insert2, start, init_sub_start, tmap, orig_psi); |
| 1889 |
} |
| 1890 |
if(orig_insert2 != -1 && orig_insert2 > end) |
| 1891 |
end_to_insert += cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, end, orig_insert2, init_sub_start, tmap, orig_psi); |
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
} |
| 1896 |
to_return *= (1. - (insert_to_start / orig_psi[start])); |
| 1897 |
to_return *= (1. - end_to_insert); |
| 1898 |
|
| 1899 |
|
| 1900 |
free(sub_psi); |
| 1901 |
return (float) to_return; |
| 1902 |
|
| 1903 |
ERROR: |
| 1904 |
cm_Fail("Memory allocation error."); |
| 1905 |
return 0.; |
| 1906 |
} |
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
void |
| 1921 |
debug_print_cm_params(FILE *fp, CM_t *cm) |
| 1922 |
{ |
| 1923 |
int status; |
| 1924 |
int v, i; |
| 1925 |
int yoffset; |
| 1926 |
|
| 1927 |
char **nodetypes; |
| 1928 |
char **sttypes; |
| 1929 |
|
| 1930 |
ESL_ALLOC(nodetypes, sizeof(char *) * 8); |
| 1931 |
nodetypes[0] = "BIF"; |
| 1932 |
nodetypes[1] = "MATP"; |
| 1933 |
nodetypes[2] = "MATL"; |
| 1934 |
nodetypes[3] = "MATR"; |
| 1935 |
nodetypes[4] = "BEGL"; |
| 1936 |
nodetypes[5] = "BEGR"; |
| 1937 |
nodetypes[6] = "ROOT"; |
| 1938 |
nodetypes[7] = "END"; |
| 1939 |
|
| 1940 |
ESL_ALLOC(sttypes, sizeof(char *) * 10); |
| 1941 |
sttypes[0] = "D"; |
| 1942 |
sttypes[1] = "MP"; |
| 1943 |
sttypes[2] = "ML"; |
| 1944 |
sttypes[3] = "MR"; |
| 1945 |
sttypes[4] = "IL"; |
| 1946 |
sttypes[5] = "IR"; |
| 1947 |
sttypes[6] = "S"; |
| 1948 |
sttypes[7] = "E"; |
| 1949 |
sttypes[8] = "B"; |
| 1950 |
sttypes[9] = "EL"; |
| 1951 |
|
| 1952 |
fprintf(fp, "cm->nodes: %d\n", cm->nodes); |
| 1953 |
fprintf(fp, "cm->M: %d\n", cm->M); |
| 1954 |
for(v = 0; v < cm->M; v++) |
| 1955 |
{ |
| 1956 |
fprintf(fp, "v:%4d:%4d %4s %2s\n", v, cm->ndidx[v], nodetypes[(int) cm->ndtype[cm->ndidx[v]]], sttypes[(int) cm->sttype[v]]); |
| 1957 |
if(cm->nodemap[cm->ndidx[v]] == v) |
| 1958 |
fprintf(fp, "beg: %0.6f (%.6f %10d)| end %0.6f (%.6f %10d)\n", |
| 1959 |
cm->begin[v], cm->beginsc[v], cm->ibeginsc[v], |
| 1960 |
cm->end[v], cm->endsc[v], cm->iendsc[v]); |
| 1961 |
if(cm->sttype[v] == MP_st) |
| 1962 |
{ |
| 1963 |
fprintf(fp, "\tE: "); |
| 1964 |
for(i = 0; i < cm->abc->K*cm->abc->K; i++) |
| 1965 |
fprintf(fp, "%0.6f (%.6f %6d) ", cm->e[v][i], cm->esc[v][i], cm->iesc[v][i]); |
| 1966 |
fprintf(fp, "\n"); |
| 1967 |
} |
| 1968 |
else if(cm->sttype[v] == ML_st || |
| 1969 |
cm->sttype[v] == MR_st || |
| 1970 |
cm->sttype[v] == IL_st || |
| 1971 |
cm->sttype[v] == IR_st) |
| 1972 |
{ |
| 1973 |
fprintf(fp, "\tE: "); |
| 1974 |
for(i = 0; i < cm->abc->K; i++) |
| 1975 |
fprintf(fp, "%0.6f (%0.6f %10d) ", cm->e[v][i], cm->esc[v][i], cm->iesc[v][i]); |
| 1976 |
fprintf(fp, "\n"); |
| 1977 |
} |
| 1978 |
if(cm->sttype[v] != B_st && cm->sttype[v] != E_st) |
| 1979 |
{ |
| 1980 |
fprintf(fp, "\tT: "); |
| 1981 |
for(yoffset = 0; yoffset < cm->cnum[v]; yoffset++) |
| 1982 |
fprintf(fp, "%0.6f (%0.6f %10d) ", cm->t[v][yoffset], cm->tsc[v][yoffset], cm->itsc[v][yoffset]); |
| 1983 |
fprintf(fp, "\n"); |
| 1984 |
} |
| 1985 |
else if(cm->sttype[v] == B_st) |
| 1986 |
{ |
| 1987 |
fprintf(fp, "\tL: %d | R: %d\n", cm->cfirst[v], cm->cnum[v]); |
| 1988 |
} |
| 1989 |
else if(cm->sttype[v] == E_st) |
| 1990 |
fprintf(fp, "\n\n"); |
| 1991 |
} |
| 1992 |
fprintf(fp, "\n\n"); |
| 1993 |
free(nodetypes); |
| 1994 |
free(sttypes); |
| 1995 |
return; |
| 1996 |
|
| 1997 |
ERROR: |
| 1998 |
cm_Fail("Memory allocation error."); |
| 1999 |
} |
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
int |
| 2030 |
check_sub_cm_by_sampling(CM_t *orig_cm, CM_t *sub_cm, char *errbuf, ESL_RANDOMNESS *r, CMSubMap_t *submap, CMSubInfo_t *subinfo, |
| 2031 |
float chi_thresh, int nsamples, int print_flag) |
| 2032 |
{ |
| 2033 |
int status; |
| 2034 |
CP9_t *orig_hmm; |
| 2035 |
CP9_t *sub_hmm; |
| 2036 |
CP9Map_t *orig_cp9map; |
| 2037 |
CP9Map_t *sub_cp9map; |
| 2038 |
|
| 2039 |
|
| 2040 |
if((status = build_cp9_hmm(orig_cm, errbuf, FALSE, 0.0001, print_flag, &orig_hmm, &orig_cp9map)) != eslOK) return status; |
| 2041 |
if((status = build_cp9_hmm(sub_cm, errbuf, FALSE, 0.0001, print_flag, &sub_hmm, &sub_cp9map)) != eslOK) return status; |
| 2042 |
CP9Logoddsify(orig_hmm); |
| 2043 |
CP9Logoddsify(sub_hmm); |
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
cm2sub_cm_find_impossible_misc_cases(orig_cm, sub_cm, submap, subinfo, orig_cp9map, sub_cp9map, print_flag); |
| 2050 |
cm2sub_cm_find_impossible_matr_cases(orig_cm, sub_cm, submap, subinfo, orig_cp9map, sub_cp9map, print_flag); |
| 2051 |
|
| 2052 |
if((status = CP9_check_by_sampling(orig_cm, sub_hmm, errbuf, r, subinfo, submap->spos, submap->epos, chi_thresh, nsamples, print_flag)) != eslOK) return status; |
| 2053 |
if(print_flag) printf("CM Plan 9 built from sub_cm passed sampling check; sub_cm was built correctly.\n"); |
| 2054 |
|
| 2055 |
FreeCPlan9(orig_hmm); |
| 2056 |
FreeCPlan9(sub_hmm); |
| 2057 |
FreeCP9Map(orig_cp9map); |
| 2058 |
FreeCP9Map(sub_cp9map); |
| 2059 |
return eslOK; |
| 2060 |
} |
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
int |
| 2084 |
check_orig_psi_vs_sub_psi(CM_t *orig_cm, CM_t *sub_cm, char *errbuf,CMSubMap_t *submap, double threshold, |
| 2085 |
int print_flag) |
| 2086 |
{ |
| 2087 |
int v_s; |
| 2088 |
int v_o; |
| 2089 |
double temp_psi; |
| 2090 |
int violation; |
| 2091 |
int v_ct; |
| 2092 |
int detached_insert; |
| 2093 |
int is_insert; |
| 2094 |
int root_v_ct; |
| 2095 |
float diff; |
| 2096 |
double *orig_psi; |
| 2097 |
double *sub_psi; |
| 2098 |
|
| 2099 |
|
| 2100 |
if((orig_psi = cm_ExpectedStateOccupancy(orig_cm)) == NULL) ESL_FAIL(eslFAIL, errbuf, "check_orig_psi_vs_sub_cm(), unable to calculate expected state occupancy for orig_cm()"); |
| 2101 |
if((sub_psi = cm_ExpectedStateOccupancy(sub_cm)) == NULL) ESL_FAIL(eslFAIL, errbuf, "check_orig_psi_vs_sub_cm(), unable to calculate expected state occupancy for sub_cm()"); |
| 2102 |
|
| 2103 |
if(print_flag) |
| 2104 |
{ |
| 2105 |
printf("Printing psi in check_orig_psi_vs_sub_psi():\n"); |
| 2106 |
for(v_o = 0; v_o < orig_cm->M; v_o++) |
| 2107 |
printf("orig_psi[%4d]: %.6f\n", v_o, orig_psi[v_o]); |
| 2108 |
|
| 2109 |
} |
| 2110 |
|
| 2111 |
v_ct = 0; |
| 2112 |
root_v_ct = 0; |
| 2113 |
if(print_flag == TRUE) printf("\n"); |
| 2114 |
for(v_s = 0; v_s < sub_cm->M; v_s++) |
| 2115 |
{ |
| 2116 |
detached_insert = FALSE; |
| 2117 |
if(sub_cm->sttype[v_s] == IL_st || sub_cm->sttype[v_s] == IR_st) |
| 2118 |
is_insert = TRUE; |
| 2119 |
else |
| 2120 |
is_insert = FALSE; |
| 2121 |
|
| 2122 |
if(print_flag) printf("\tv_s: %4d (%.6f) ", v_s, sub_psi[v_s]); |
| 2123 |
v_o = submap->s2o_smap[v_s][0]; |
| 2124 |
if(sub_cm->sttype[v_s+1] == E_st) detached_insert = TRUE; |
| 2125 |
if(v_o != -1) |
| 2126 |
{ |
| 2127 |
if(print_flag) printf("v_o1: %4d (%.6f) ", v_o, orig_psi[v_o]); |
| 2128 |
temp_psi = orig_psi[v_o]; |
| 2129 |
v_o = submap->s2o_smap[v_s][1]; |
| 2130 |
if(v_o != -1) |
| 2131 |
{ |
| 2132 |
if(is_insert) |
| 2133 |
ESL_FAIL(eslFAIL, errbuf, "check_orig_psi_vs_sub_psi(), sub insert state maps to 2 orig_cm inserts."); |
| 2134 |
temp_psi += orig_psi[v_o]; |
| 2135 |
if(print_flag) |
| 2136 |
printf("v_o2: %4d (%.6f)\n", v_o, orig_psi[v_o]); |
| 2137 |
} |
| 2138 |
else |
| 2139 |
if(print_flag) printf("\n"); |
| 2140 |
|
| 2141 |
violation = FALSE; |
| 2142 |
if(detached_insert) |
| 2143 |
temp_psi = 0.0; |
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
if(is_insert && !detached_insert) |
| 2159 |
{ |
| 2160 |
diff = (sub_psi[v_s] - (sub_psi[v_s] * sub_cm->t[v_s][0])) - |
| 2161 |
(temp_psi - (temp_psi * orig_cm->t[submap->s2o_smap[v_s][0]][0])); |
| 2162 |
} |
| 2163 |
else |
| 2164 |
diff = sub_psi[v_s] - temp_psi; |
| 2165 |
if((diff > threshold) || ((-1. * diff) > threshold)) |
| 2166 |
{ |
| 2167 |
violation = TRUE; |
| 2168 |
v_ct++; |
| 2169 |
if((sub_cm->ndidx[v_s] == 0) || (sub_cm->ndidx[v_s] == 1)) |
| 2170 |
{ |
| 2171 |
root_v_ct++; |
| 2172 |
} |
| 2173 |
} |
| 2174 |
if(violation) |
| 2175 |
printf("sub: %.6f | orig: %.6f | diff: %.6f VIOLATION\n\n", sub_psi[v_s], temp_psi, (sub_psi[v_s]-temp_psi)); |
| 2176 |
else if(detached_insert && print_flag) |
| 2177 |
printf("sub: %.6f | orig: %.6f | diff: %.6f (DEAD INSERT)\n\n", sub_psi[v_s], temp_psi, (sub_psi[v_s]-temp_psi)); |
| 2178 |
else if(print_flag) |
| 2179 |
printf("sub: %.6f | orig: %.6f | diff: %.6f\n\n", sub_psi[v_s], temp_psi, (sub_psi[v_s]-temp_psi)); |
| 2180 |
} |
| 2181 |
else |
| 2182 |
{ |
| 2183 |
if(!detached_insert && |
| 2184 |
sub_cm->sttype[v_s] != E_st && |
| 2185 |
sub_cm->sttype[v_s] != B_st && |
| 2186 |
sub_cm->sttype[v_s] != S_st && |
| 2187 |
sub_cm->sttype[v_s] != EL_st) |
| 2188 |
ESL_FAIL(eslFAIL, errbuf, "check_orig_psi_vs_sub_psi() state v_s:%d maps to nothing and its not E,B,S,EL\n", v_s); |
| 2189 |
if(print_flag) printf("E B S or EL\n"); |
| 2190 |
} |
| 2191 |
} |
| 2192 |
|
| 2193 |
if(v_ct > 0) ESL_FAIL(eslFAIL, errbuf, "check_orig_psi_vs_sub_psi(): check failed"); |
| 2194 |
else |
| 2195 |
if(print_flag) printf("v_ct is 0 with thresh: %f!\n", threshold); |
| 2196 |
if(root_v_ct > 0) |
| 2197 |
printf("ROOT v_ct is %d with thresh: %f!\n", root_v_ct, threshold); |
| 2198 |
|
| 2199 |
|
| 2200 |
free(orig_psi); |
| 2201 |
free(sub_psi); |
| 2202 |
|
| 2203 |
return eslOK; |
| 2204 |
} |
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
int |
| 2220 |
cm_trans_check(CM_t *cm, int a, int b) |
| 2221 |
{ |
| 2222 |
|
| 2223 |
|
| 2224 |
if((a == -1 || b == -1) || (a > b)) |
| 2225 |
return FALSE; |
| 2226 |
|
| 2227 |
if((b - cm->cfirst[a]) < cm->cnum[a]) |
| 2228 |
{ return TRUE; } |
| 2229 |
|
| 2230 |
return FALSE; |
| 2231 |
|
| 2232 |
} |
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
static void |
| 2305 |
cm2sub_cm_subtract_root_subpaths(CM_t *orig_cm, CM_t *sub_cm, double *orig_psi, char ***tmap, |
| 2306 |
CMSubMap_t *submap, int print_flag) |
| 2307 |
|
| 2308 |
{ |
| 2309 |
int sub_root_s; |
| 2310 |
int sub_il; |
| 2311 |
int sub_ir; |
| 2312 |
int yoffset; |
| 2313 |
int sub_y; |
| 2314 |
int orig_y; |
| 2315 |
int orig_il; |
| 2316 |
int orig_ir; |
| 2317 |
int orig_ss; |
| 2318 |
int orig_ss1; |
| 2319 |
int orig_ss2; |
| 2320 |
|
| 2321 |
sub_root_s = 0; |
| 2322 |
sub_il = 1; |
| 2323 |
sub_ir = 2; |
| 2324 |
orig_il = submap->s2o_smap[sub_il][0]; |
| 2325 |
orig_ir = submap->s2o_smap[sub_ir][0]; |
| 2326 |
|
| 2327 |
if(print_flag) printf("\n\nin cm2sum_cm_subtract_root_subpaths_helper: orig_il: %d orig_ir: %d\n", orig_il, orig_ir); |
| 2328 |
|
| 2329 |
for(yoffset = 0; yoffset < sub_cm->cnum[0]; yoffset++) |
| 2330 |
if(print_flag) printf("Before t[0][%d] = %f\n", yoffset, sub_cm->t[0][yoffset]); |
| 2331 |
|
| 2332 |
orig_ss = submap->s2o_smap[3][0]; |
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
for(yoffset = 2; yoffset < sub_cm->cnum[0]; yoffset++) |
| 2337 |
|
| 2338 |
|
| 2339 |
{ |
| 2340 |
sub_y = yoffset + sub_cm->cfirst[0]; |
| 2341 |
orig_y = submap->s2o_smap[sub_y][0]; |
| 2342 |
if((orig_il > orig_ss && orig_il < orig_y) || |
| 2343 |
(orig_il < orig_ss && orig_il > orig_y) || |
| 2344 |
(orig_ir > orig_ss && orig_ir < orig_y) || |
| 2345 |
(orig_ir < orig_ss && orig_ir > orig_y)) |
| 2346 |
cm_Fail("ERROR in cm2sub_cm_subtract_root_subpaths_helper() split set state guarantee violated!\n"); |
| 2347 |
} |
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
if((orig_il < orig_ir) && (orig_ir < orig_ss)) |
| 2352 |
if(print_flag) printf("ROOT NODE case 1A\n"); |
| 2353 |
if((orig_il < orig_ss) && (orig_ss < orig_ir)) |
| 2354 |
if(print_flag) printf("ROOT NODE case 1B\n"); |
| 2355 |
if((orig_ss < orig_il) && (orig_il < orig_ir)) |
| 2356 |
if(print_flag) printf("ROOT NODE case 1C\n"); |
| 2357 |
|
| 2358 |
if((orig_ir < orig_il) && (orig_il < orig_ss)) |
| 2359 |
if(print_flag) printf("ROOT NODE case 2A\n"); |
| 2360 |
if((orig_ir < orig_ss) && (orig_ss < orig_il)) |
| 2361 |
if(print_flag) printf("ROOT NODE case 2B\n"); |
| 2362 |
if((orig_ss < orig_ir) && (orig_ir < orig_il)) |
| 2363 |
if(print_flag) printf("ROOT NODE case 2C\n"); |
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
if(orig_ir < orig_il) |
| 2373 |
{ |
| 2374 |
if(print_flag) printf("0 sub from S->IR, IR -> IL\n"); |
| 2375 |
sub_cm->t[sub_root_s][1] -= orig_psi[orig_ir] * |
| 2376 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ir, orig_il, 0, tmap, orig_psi); |
| 2377 |
} |
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
for(yoffset = 0; yoffset < sub_cm->cnum[0]; yoffset++) |
| 2382 |
{ |
| 2383 |
sub_y = sub_cm->cfirst[0] + yoffset; |
| 2384 |
orig_ss1 = submap->s2o_smap[sub_y][0]; |
| 2385 |
orig_ss2 = submap->s2o_smap[sub_y][1]; |
| 2386 |
if(sub_cm->ndidx[sub_y] != 0) |
| 2387 |
{ |
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
if(orig_ir < orig_ss && orig_ss < orig_il) |
| 2395 |
{ |
| 2396 |
if(print_flag) printf("3 (2b) sub from IL, IR -> SS -> IL\n"); |
| 2397 |
|
| 2398 |
|
| 2399 |
sub_cm->t[sub_il][yoffset] -= orig_psi[orig_ir] * |
| 2400 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ir, orig_ss1, |
| 2401 |
sub_il, tmap, orig_psi) * |
| 2402 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ss1, orig_il, |
| 2403 |
sub_il, tmap, orig_psi); |
| 2404 |
if(orig_ss2 != -1) |
| 2405 |
|
| 2406 |
sub_cm->t[1][yoffset] -= orig_psi[orig_ir] * |
| 2407 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ir, orig_ss2, |
| 2408 |
sub_il, tmap, orig_psi) * |
| 2409 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ss2, orig_il, |
| 2410 |
sub_il, tmap, orig_psi); |
| 2411 |
|
| 2412 |
} |
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
if(orig_ss < orig_il && orig_il < orig_ir) |
| 2419 |
{ |
| 2420 |
if(print_flag) printf("4 (1c) sub from IL, SS -> IL -> IR\n"); |
| 2421 |
|
| 2422 |
|
| 2423 |
sub_cm->t[sub_il][yoffset] -= orig_psi[orig_ss1] * |
| 2424 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ss1, orig_il, |
| 2425 |
sub_il, tmap, orig_psi) * |
| 2426 |
(1. + (orig_cm->t[orig_il][0] / (1 - orig_cm->t[orig_il][0]))) * |
| 2427 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_il, orig_ir, |
| 2428 |
sub_il, tmap, orig_psi); |
| 2429 |
|
| 2430 |
if(orig_ss2 != -1) |
| 2431 |
|
| 2432 |
sub_cm->t[sub_il][yoffset] -= orig_psi[orig_ss2] * |
| 2433 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ss2, orig_il, |
| 2434 |
sub_il, tmap, orig_psi) * |
| 2435 |
(1. + (orig_cm->t[orig_il][0] / (1 - orig_cm->t[orig_il][0]))) * |
| 2436 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_il, orig_ir, |
| 2437 |
sub_il, tmap, orig_psi); |
| 2438 |
} |
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
if(orig_ir < orig_il && orig_il < orig_ss) |
| 2445 |
{ |
| 2446 |
if(print_flag) printf("5 (2a) sub from IL, IR -> IL -> SS\n"); |
| 2447 |
|
| 2448 |
|
| 2449 |
sub_cm->t[sub_il][yoffset] -= orig_psi[orig_ir] * |
| 2450 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ir, orig_il, |
| 2451 |
sub_il, tmap, orig_psi) * |
| 2452 |
(1. + (orig_cm->t[orig_il][0] / (1 - orig_cm->t[orig_il][0]))) * |
| 2453 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_il, orig_ss1, |
| 2454 |
sub_il, tmap, orig_psi); |
| 2455 |
|
| 2456 |
if(orig_ss2 != -1) |
| 2457 |
|
| 2458 |
sub_cm->t[sub_il][yoffset] -= orig_psi[orig_ir] * |
| 2459 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ir, orig_il, |
| 2460 |
sub_il, tmap, orig_psi) * |
| 2461 |
(1. + (orig_cm->t[orig_il][0] / (1 - orig_cm->t[orig_il][0]))) * |
| 2462 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_il, orig_ss2, |
| 2463 |
sub_il, tmap, orig_psi); |
| 2464 |
|
| 2465 |
} |
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
if(orig_il < orig_ss && orig_ss < orig_ir) |
| 2472 |
{ |
| 2473 |
if(print_flag) printf("6 (1b) sub from IL, IL -> SS -> IR\n"); |
| 2474 |
if(print_flag) printf("1B before sub 1: sub_cm->t[sub_il:%d][yoffset:%d]: %f\n", sub_il, yoffset, sub_cm->t[sub_il][yoffset]); |
| 2475 |
|
| 2476 |
sub_cm->t[sub_il][yoffset] -= orig_psi[orig_il] * |
| 2477 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_il, orig_ss1, |
| 2478 |
sub_il, tmap, orig_psi) * |
| 2479 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ss1, orig_ir, |
| 2480 |
sub_il, tmap, orig_psi); |
| 2481 |
|
| 2482 |
if(print_flag) printf("1B before sub 2: sub_cm->t[sub_il:%d][yoffset:%d]: %f\n", sub_il, yoffset, sub_cm->t[sub_il][yoffset]); |
| 2483 |
if(orig_ss2 != -1) |
| 2484 |
|
| 2485 |
sub_cm->t[sub_il][yoffset] -= orig_psi[orig_il] * |
| 2486 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_il, orig_ss2, |
| 2487 |
sub_il, tmap, orig_psi) * |
| 2488 |
cm2sub_cm_sum_subpaths(orig_cm, sub_cm, submap, orig_ss2, orig_ir, |
| 2489 |
sub_il, tmap, orig_psi); |
| 2490 |
if(print_flag) printf("1B after sub 2: sub_cm->t[sub_il:%d][yoffset:%d]: %f\n", sub_il, yoffset, sub_cm->t[sub_il][yoffset]); |
| 2491 |
|
| 2492 |
} |
| 2493 |
} |
| 2494 |
} |
| 2495 |
for(yoffset = 0; yoffset < sub_cm->cnum[0]; yoffset++) |
| 2496 |
if(print_flag) printf("After t[0][%d] = %f\n", yoffset, sub_cm->t[0][yoffset]); |
| 2497 |
|
| 2498 |
return; |
| 2499 |
} |
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
|
| 2516 |
|
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
static int |
| 2525 |
cm2sub_cm_check_id_next_node(CM_t *orig_cm, CM_t *sub_cm, int orig_nd, int sub_nd, |
| 2526 |
CMSubMap_t *submap, CP9Map_t *orig_cp9map, |
| 2527 |
CP9Map_t *sub_cp9map, int print_flag) |
| 2528 |
{ |
| 2529 |
int v_s; |
| 2530 |
int left_check, right_check; |
| 2531 |
left_check = FALSE; |
| 2532 |
right_check = FALSE; |
| 2533 |
|
| 2534 |
if((orig_nd+1) > (orig_cm->nodes-1)) |
| 2535 |
return FALSE; |
| 2536 |
if((sub_nd+1) > (sub_cm->nodes-1)) |
| 2537 |
return FALSE; |
| 2538 |
if(orig_cm->ndtype[orig_nd] != sub_cm->ndtype[sub_nd]) |
| 2539 |
return FALSE; |
| 2540 |
if(orig_cm->ndtype[orig_nd+1] != sub_cm->ndtype[sub_nd+1]) |
| 2541 |
return FALSE; |
| 2542 |
|
| 2543 |
if(orig_cp9map->nd2lpos[orig_nd+1] == -1 && sub_cp9map->nd2lpos[sub_nd+1] == -1) |
| 2544 |
left_check = TRUE; |
| 2545 |
if(orig_cp9map->nd2lpos[orig_nd+1] == (sub_cp9map->nd2lpos[sub_nd+1] + submap->spos -1)) |
| 2546 |
left_check = TRUE; |
| 2547 |
if(orig_cp9map->nd2rpos[orig_nd+1] == -1 && sub_cp9map->nd2rpos[sub_nd+1] == -1) |
| 2548 |
right_check = TRUE; |
| 2549 |
if(orig_cp9map->nd2rpos[orig_nd+1] == (sub_cp9map->nd2rpos[sub_nd+1] + submap->spos -1)) |
| 2550 |
right_check = TRUE; |
| 2551 |
|
| 2552 |
if(left_check && right_check) |
| 2553 |
{ |
| 2554 |
v_s = sub_cm->nodemap[sub_nd]; |
| 2555 |
while(sub_cm->ndidx[v_s] == sub_nd) |
| 2556 |
{ |
| 2557 |
if(print_flag) printf("setting submap->s2o_id[v_s:%d] to TRUE\n", v_s); |
| 2558 |
if(sub_cm->sttype[v_s+1] != E_st) submap->s2o_id[v_s] = TRUE; |
| 2559 |
v_s++; |
| 2560 |
} |
| 2561 |
return TRUE; |
| 2562 |
} |
| 2563 |
return FALSE; |
| 2564 |
} |
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
static void |
| 2617 |
cm2sub_cm_find_impossible_misc_cases(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, CMSubInfo_t *subinfo, |
| 2618 |
CP9Map_t *orig_cp9map, CP9Map_t *sub_cp9map, int print_flag) |
| 2619 |
|
| 2620 |
{ |
| 2621 |
int status; |
| 2622 |
int k; |
| 2623 |
int sub_starts; |
| 2624 |
int orig_starts; |
| 2625 |
int orig_nd1; |
| 2626 |
int orig_nd2; |
| 2627 |
int sub_nd1; |
| 2628 |
int sub_nd2; |
| 2629 |
int temp; |
| 2630 |
int nd; |
| 2631 |
int orig_special_matps; |
| 2632 |
int sub_special_matl; |
| 2633 |
int sub_both_matps; |
| 2634 |
CMEmitMap_t *orig_emap; |
| 2635 |
CMEmitMap_t *sub_emap; |
| 2636 |
|
| 2637 |
int orig_il1; |
| 2638 |
int orig_il2; |
| 2639 |
int orig_ir1; |
| 2640 |
int orig_ir2; |
| 2641 |
|
| 2642 |
char **nodetypes; |
| 2643 |
ESL_ALLOC(nodetypes, sizeof(char *) * 8); |
| 2644 |
nodetypes[0] = "BIF"; |
| 2645 |
nodetypes[1] = "MATP"; |
| 2646 |
nodetypes[2] = "MATL"; |
| 2647 |
nodetypes[3] = "MATR"; |
| 2648 |
nodetypes[4] = "BEGL"; |
| 2649 |
nodetypes[5] = "BEGR"; |
| 2650 |
nodetypes[6] = "ROOT"; |
| 2651 |
nodetypes[7] = "END"; |
| 2652 |
|
| 2653 |
if(print_flag) printf("in cm2sub_find_impossible_misc_cases()\n"); |
| 2654 |
|
| 2655 |
orig_emap = CreateEmitMap(orig_cm); |
| 2656 |
sub_emap = CreateEmitMap(sub_cm); |
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
subinfo->imp_cc[0] = 1; |
| 2665 |
subinfo->imp_cc[submap->sub_clen] = 1; |
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
orig_il1 = submap->s2o_smap[1][0]; |
| 2670 |
orig_il2 = submap->s2o_smap[1][1]; |
| 2671 |
orig_ir1 = submap->s2o_smap[2][0]; |
| 2672 |
orig_ir2 = submap->s2o_smap[2][1]; |
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
if(orig_il2 != -1) |
| 2678 |
{ |
| 2679 |
if(orig_cm->sttype[orig_il1+1] == E_st) |
| 2680 |
orig_il1 = orig_il2; |
| 2681 |
else if(orig_cm->sttype[orig_il2+1] == E_st) |
| 2682 |
{ |
| 2683 |
|
| 2684 |
} |
| 2685 |
else |
| 2686 |
cm_Fail("ERROR, can't determine which state was detached\n"); |
| 2687 |
} |
| 2688 |
if(orig_ir2 != -1) |
| 2689 |
{ |
| 2690 |
if(orig_cm->sttype[orig_ir1+1] == E_st) |
| 2691 |
orig_ir1 = orig_ir2; |
| 2692 |
else if(orig_cm->sttype[orig_ir2+1] == E_st) |
| 2693 |
{ |
| 2694 |
|
| 2695 |
} |
| 2696 |
else |
| 2697 |
cm_Fail("ERROR, can't determine which state was detached\n"); |
| 2698 |
} |
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
if(orig_cm->ndidx[orig_il1] == orig_cm->ndidx[orig_ir1]) |
| 2703 |
{ |
| 2704 |
|
| 2705 |
subinfo->imp_cc[0] = FALSE; |
| 2706 |
if(submap->spos == submap->sstruct && submap->epos == submap->estruct) |
| 2707 |
subinfo->imp_cc[submap->sub_clen] = FALSE; |
| 2708 |
} |
| 2709 |
|
| 2710 |
for(k = 1; k < submap->sub_clen; k++) |
| 2711 |
{ |
| 2712 |
if(print_flag) printf("k: %d\n", k); |
| 2713 |
if((k+submap->spos-1) == 0) |
| 2714 |
orig_nd1 = 0; |
| 2715 |
else |
| 2716 |
orig_nd1 = orig_cp9map->pos2nd[k+submap->spos-1]; |
| 2717 |
orig_nd2 = orig_cp9map->pos2nd[k+submap->spos-1+1]; |
| 2718 |
|
| 2719 |
orig_special_matps = FALSE; |
| 2720 |
if((orig_cm->ndtype[orig_nd1] == MATP_nd && |
| 2721 |
orig_cm->ndtype[orig_nd2] == MATP_nd) && |
| 2722 |
(orig_cp9map->nd2rpos[orig_nd1] == (k+submap->spos-1) && |
| 2723 |
orig_cp9map->nd2lpos[orig_nd2] == (k+submap->spos))) |
| 2724 |
{ |
| 2725 |
if((orig_cp9map->nd2lpos[orig_nd1] < submap->spos) || |
| 2726 |
(orig_cp9map->nd2rpos[orig_nd2] > submap->epos)) |
| 2727 |
{ |
| 2728 |
|
| 2729 |
orig_special_matps = TRUE; |
| 2730 |
} |
| 2731 |
} |
| 2732 |
|
| 2733 |
if(orig_nd2 < orig_nd1) |
| 2734 |
{ |
| 2735 |
temp = orig_nd1; |
| 2736 |
orig_nd1 = orig_nd2; |
| 2737 |
orig_nd2 = temp; |
| 2738 |
} |
| 2739 |
orig_starts = 0; |
| 2740 |
|
| 2741 |
if(print_flag) printf("orig_nd1: %d | orig_nd2: %d\n", orig_nd1, orig_nd2); |
| 2742 |
for(nd = orig_nd1; nd <= orig_nd2; nd++) |
| 2743 |
{ |
| 2744 |
if(print_flag) printf("orig_cm->ndtype[%d]: %s L: %4d R: %4d (submap->spos: %4d) (submap->epos: %4d)\n", nd, nodetypes[(int) orig_cm->ndtype[nd]], orig_emap->lpos[nd], orig_emap->rpos[nd], submap->spos, submap->epos); |
| 2745 |
if(orig_cm->ndtype[nd] == BEGL_nd || |
| 2746 |
orig_cm->ndtype[nd] == BEGR_nd) |
| 2747 |
{ orig_starts++; } |
| 2748 |
} |
| 2749 |
sub_nd1 = sub_cp9map->pos2nd[k]; |
| 2750 |
sub_nd2 = sub_cp9map->pos2nd[k+1]; |
| 2751 |
|
| 2752 |
sub_special_matl = FALSE; |
| 2753 |
if(sub_cm->ndtype[sub_nd1] == MATL_nd) |
| 2754 |
sub_special_matl = TRUE; |
| 2755 |
|
| 2756 |
if(sub_nd2 < sub_nd1) |
| 2757 |
{ |
| 2758 |
temp = sub_nd1; |
| 2759 |
sub_nd1 = sub_nd2; |
| 2760 |
sub_nd2 = temp; |
| 2761 |
} |
| 2762 |
|
| 2763 |
sub_both_matps = FALSE; |
| 2764 |
if((sub_cm->ndtype[sub_nd1] == MATP_nd && sub_cm->ndtype[sub_nd2] == MATP_nd) && |
| 2765 |
(!(sub_cp9map->nd2lpos[sub_nd1] < sub_cp9map->nd2lpos[sub_nd2] && sub_cp9map->nd2rpos[sub_nd1] > sub_cp9map->nd2rpos[sub_nd2]))) |
| 2766 |
sub_both_matps = TRUE; |
| 2767 |
|
| 2768 |
sub_starts = 0; |
| 2769 |
if(print_flag) printf("sub_nd1: %d | sub_nd2: %d\n", sub_nd1, sub_nd2); |
| 2770 |
for(nd = sub_nd1; nd <= sub_nd2; nd++) |
| 2771 |
{ |
| 2772 |
if(print_flag) printf("sub_cm->ndtype[%d]: %s L: %4d R: %4d (submap->spos: %4d) (submap->epos: %4d)\n", nd, nodetypes[(int) sub_cm->ndtype[nd]], (sub_emap->lpos[nd]+submap->spos-1), (sub_emap->rpos[nd]+submap->spos-1), submap->spos, submap->epos); |
| 2773 |
if(sub_cm->ndtype[nd] == BEGL_nd || sub_cm->ndtype[nd] == BEGR_nd) |
| 2774 |
{ |
| 2775 |
sub_starts++; |
| 2776 |
if(sub_cm->ndtype[sub_nd1] != MATP_nd && sub_cm->ndtype[sub_nd2] != MATP_nd) |
| 2777 |
cm_Fail("ERROR in cm2sub_cm_find_impossible_misc_cases() found impossible case not involving any MATP in the sub_cm, k: %d submap->epos-submap->spos+1: %d\n", k, submap->sub_clen); |
| 2778 |
if(orig_cm->ndtype[orig_nd1] != MATP_nd && orig_cm->ndtype[orig_nd2] != MATP_nd) |
| 2779 |
cm_Fail("ERROR in cm2sub_cm_find_impossible_misc_cases() found impossible case not involving any MATP in the orig_cm\n, k: %d | submap->epos-submap->spos+1: %d", k, submap->sub_clen); |
| 2780 |
} |
| 2781 |
} |
| 2782 |
|
| 2783 |
if(print_flag) printf("sub_starts: %d | orig_starts: %d\n", sub_starts, orig_starts); |
| 2784 |
|
| 2785 |
if(sub_starts > 0 && orig_starts == 0) |
| 2786 |
subinfo->imp_cc[k] = 3; |
| 2787 |
else if((sub_starts > 0 && sub_starts > orig_starts) && |
| 2788 |
sub_both_matps == TRUE) |
| 2789 |
subinfo->imp_cc[k] = 4; |
| 2790 |
else if(sub_starts > 0 && orig_special_matps && sub_special_matl) |
| 2791 |
subinfo->imp_cc[k] = 5; |
| 2792 |
else if(sub_starts == 0 && orig_starts > 0 && orig_special_matps && sub_special_matl) |
| 2793 |
subinfo->imp_cc[k] = 6; |
| 2794 |
|
| 2795 |
} |
| 2796 |
FreeEmitMap(orig_emap); |
| 2797 |
FreeEmitMap(sub_emap); |
| 2798 |
free(nodetypes); |
| 2799 |
return; |
| 2800 |
|
| 2801 |
ERROR: |
| 2802 |
cm_Fail("Memory allocation error."); |
| 2803 |
} |
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
|
| 2823 |
|
| 2824 |
|
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
static void |
| 2838 |
cm2sub_cm_find_impossible_matr_cases(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, CMSubInfo_t *subinfo, |
| 2839 |
CP9Map_t *orig_cp9map, CP9Map_t *sub_cp9map, int print_flag) |
| 2840 |
{ |
| 2841 |
int status; |
| 2842 |
int sub_k; |
| 2843 |
int orig_k; |
| 2844 |
int orig_nd; |
| 2845 |
int sub_nd; |
| 2846 |
int next_sub_nd; |
| 2847 |
int next_orig_nd; |
| 2848 |
int sub_nd1; |
| 2849 |
int sub_nd2; |
| 2850 |
int orig_nd1; |
| 2851 |
int orig_nd2; |
| 2852 |
int tmp_k; |
| 2853 |
int tmp_sub_nd; |
| 2854 |
int tmp_orig_nd; |
| 2855 |
int correct_node_types_flag; |
| 2856 |
int orig_matr_stretch_flag; |
| 2857 |
int sub_matr_stretch_flag; |
| 2858 |
|
| 2859 |
char **nodetypes; |
| 2860 |
ESL_ALLOC(nodetypes, sizeof(char *) * 8); |
| 2861 |
nodetypes[0] = "BIF"; |
| 2862 |
nodetypes[1] = "MATP"; |
| 2863 |
nodetypes[2] = "MATL"; |
| 2864 |
nodetypes[3] = "MATR"; |
| 2865 |
nodetypes[4] = "BEGL"; |
| 2866 |
nodetypes[5] = "BEGR"; |
| 2867 |
nodetypes[6] = "ROOT"; |
| 2868 |
nodetypes[7] = "END"; |
| 2869 |
|
| 2870 |
for(sub_k = 1; sub_k < submap->sub_clen; sub_k++) |
| 2871 |
{ |
| 2872 |
orig_k = sub_k + submap->spos - 1; |
| 2873 |
if(print_flag) printf("CASE 2 k: %d\n", sub_k); |
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
sub_nd = sub_cp9map->pos2nd[sub_k]; |
| 2878 |
next_sub_nd = sub_cp9map->pos2nd[sub_k+1]; |
| 2879 |
orig_nd = orig_cp9map->pos2nd[orig_k]; |
| 2880 |
next_orig_nd = orig_cp9map->pos2nd[orig_k+1]; |
| 2881 |
if(sub_nd < next_sub_nd) |
| 2882 |
{ |
| 2883 |
sub_nd1 = sub_nd; |
| 2884 |
sub_nd2 = next_sub_nd; |
| 2885 |
} |
| 2886 |
else |
| 2887 |
{ |
| 2888 |
sub_nd1 = next_sub_nd; |
| 2889 |
sub_nd2 = sub_nd; |
| 2890 |
} |
| 2891 |
if(orig_nd < next_orig_nd) |
| 2892 |
{ |
| 2893 |
orig_nd1 = orig_nd; |
| 2894 |
orig_nd2 = next_orig_nd; |
| 2895 |
} |
| 2896 |
else |
| 2897 |
{ |
| 2898 |
orig_nd1 = next_orig_nd; |
| 2899 |
orig_nd2 = orig_nd; |
| 2900 |
} |
| 2901 |
|
| 2902 |
if(print_flag) printf("CASE 2 k: %d sub_nd: %d next_sub_nd: %d\n", sub_k, sub_nd, next_sub_nd); |
| 2903 |
if(print_flag) printf("CASE 2 k: %d orig_nd: %d next_orig_nd: %d\n", sub_k, orig_nd, next_orig_nd); |
| 2904 |
|
| 2905 |
|
| 2906 |
if(sub_nd1 != sub_nd2-1) |
| 2907 |
{ |
| 2908 |
|
| 2909 |
|
| 2910 |
if((orig_cm->ndtype[orig_nd1] == MATL_nd && sub_cm->ndtype[sub_nd1] == MATL_nd) && |
| 2911 |
(orig_cm->ndtype[orig_nd2] == MATP_nd && sub_cm->ndtype[sub_nd2] == MATP_nd)) |
| 2912 |
correct_node_types_flag = TRUE; |
| 2913 |
else |
| 2914 |
correct_node_types_flag = FALSE; |
| 2915 |
if(print_flag) printf("CASE 2 k: %d correct_node_types_flag: %d\n", sub_k, correct_node_types_flag); |
| 2916 |
|
| 2917 |
if(correct_node_types_flag == TRUE) |
| 2918 |
{ |
| 2919 |
|
| 2920 |
|
| 2921 |
orig_matr_stretch_flag = TRUE; |
| 2922 |
for(tmp_orig_nd = orig_nd1+1; tmp_orig_nd < orig_nd2; tmp_orig_nd++) |
| 2923 |
{ |
| 2924 |
if(orig_cm->ndtype[tmp_orig_nd] != MATR_nd) |
| 2925 |
{ |
| 2926 |
orig_matr_stretch_flag = FALSE; |
| 2927 |
break; |
| 2928 |
} |
| 2929 |
} |
| 2930 |
if(print_flag) printf("CASE 2 k: %d orig_matr_stretch_flag: %d\n", sub_k, orig_matr_stretch_flag); |
| 2931 |
if(orig_matr_stretch_flag == TRUE) |
| 2932 |
{ |
| 2933 |
|
| 2934 |
|
| 2935 |
sub_matr_stretch_flag = TRUE; |
| 2936 |
for(tmp_sub_nd = sub_nd1+1; tmp_sub_nd < sub_nd2; tmp_sub_nd++) |
| 2937 |
if(sub_cm->ndtype[tmp_sub_nd] != MATR_nd) |
| 2938 |
{ |
| 2939 |
sub_matr_stretch_flag = FALSE; |
| 2940 |
break; |
| 2941 |
} |
| 2942 |
if(print_flag) printf("CASE 2 k: %d sub_matr_stretch_flag: %d\n", sub_k, sub_matr_stretch_flag); |
| 2943 |
if(sub_matr_stretch_flag == TRUE) |
| 2944 |
{ |
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
tmp_sub_nd = sub_cp9map->pos2nd[sub_k] + 1; |
| 2970 |
tmp_k = sub_cp9map->nd2rpos[tmp_sub_nd] + submap->spos - 1; |
| 2971 |
tmp_orig_nd = orig_cp9map->pos2nd[tmp_k]; |
| 2972 |
|
| 2973 |
for(tmp_sub_nd = sub_nd1+1; tmp_sub_nd < sub_nd2; tmp_sub_nd++) |
| 2974 |
{ |
| 2975 |
tmp_k = sub_cp9map->nd2rpos[tmp_sub_nd] + submap->spos - 1; |
| 2976 |
tmp_orig_nd = orig_cp9map->pos2nd[tmp_k]; |
| 2977 |
|
| 2978 |
if(print_flag) printf("10.18.06: %s %3d %3d | %s %3d %3d (xcc: %3d)\n", nodetypes[(int) sub_cm->ndtype[tmp_sub_nd]], tmp_sub_nd, (sub_cp9map->nd2rpos[tmp_sub_nd]+submap->spos-1), nodetypes[(int) orig_cm->ndtype[tmp_orig_nd]], orig_cp9map->nd2lpos[tmp_orig_nd], orig_cp9map->nd2rpos[tmp_orig_nd], tmp_k); |
| 2979 |
if(orig_cp9map->nd2rpos[tmp_orig_nd] == (sub_cp9map->nd2rpos[tmp_sub_nd]+submap->spos-1)) |
| 2980 |
{ |
| 2981 |
if(orig_cm->ndtype[tmp_orig_nd] != MATP_nd && orig_cm->ndtype[tmp_orig_nd] != MATR_nd) |
| 2982 |
cm_Fail("ERROR 2 in cm2sub_cm_find_impossible_matr_cases() found impossible MATR case that can't be classified as case 1 or case 2, k: %d | submap->spos: %d submap->epos: %d", sub_k, submap->spos, submap->epos); |
| 2983 |
if(orig_cm->ndtype[tmp_orig_nd] == MATP_nd && orig_cp9map->nd2lpos[tmp_orig_nd] >= submap->spos) |
| 2984 |
cm_Fail("ERROR 3 in cm2sub_cm_find_impossible_matr_cases() found impossible MATR case that can't be classified as case 1 or case 2, k: %d | submap->spos: %d submap->epos: %d", sub_k, submap->spos, submap->epos); |
| 2985 |
} |
| 2986 |
else if(orig_cp9map->nd2lpos[tmp_orig_nd] == (sub_cp9map->nd2rpos[tmp_sub_nd]+submap->spos-1)) |
| 2987 |
{ |
| 2988 |
if(orig_cm->ndtype[tmp_orig_nd] != MATP_nd && orig_cm->ndtype[tmp_orig_nd] != MATL_nd) |
| 2989 |
cm_Fail("ERROR 4 in cm2sub_cm_find_impossible_matr_cases() found impossible MATR case that can't be classified as case 1 or case 2, k: %d | submap->spos: %d submap->epos: %d", sub_k, submap->spos, submap->epos); |
| 2990 |
if(orig_cm->ndtype[tmp_orig_nd] == MATP_nd && orig_cp9map->nd2rpos[tmp_orig_nd] <= submap->epos) |
| 2991 |
cm_Fail("ERROR 5 in cm2sub_cm_find_impossible_matr_cases() found impossible MATR case that can't be classified as case 1 or case 2, k: %d | submap->spos: %d submap->epos: %d | orig_cp9map->nd2rpos[%d]: %d", sub_k, submap->spos, submap->epos, tmp_orig_nd, orig_cp9map->nd2rpos[tmp_orig_nd]); |
| 2992 |
} |
| 2993 |
} |
| 2994 |
|
| 2995 |
subinfo->imp_cc[sub_k] = 2; |
| 2996 |
} |
| 2997 |
} |
| 2998 |
} |
| 2999 |
} |
| 3000 |
} |
| 3001 |
free(nodetypes); |
| 3002 |
return; |
| 3003 |
|
| 3004 |
ERROR: |
| 3005 |
cm_Fail("Memory allocation error."); |
| 3006 |
} |
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
|
| 3013 |
|
| 3014 |
|
| 3015 |
|
| 3016 |
|
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
|
| 3021 |
|
| 3022 |
|
| 3023 |
|
| 3024 |
|
| 3025 |
|
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
|
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
int |
| 3040 |
check_sub_cm(CM_t *orig_cm, CM_t *sub_cm, char *errbuf, CMSubMap_t *submap, CMSubInfo_t *subinfo, float pthresh, int print_flag) |
| 3041 |
{ |
| 3042 |
int status; |
| 3043 |
CP9_t *sub_hmm; |
| 3044 |
CP9_t *orig_hmm; |
| 3045 |
|
| 3046 |
CP9Map_t *orig_cp9map; |
| 3047 |
CP9Map_t *sub_cp9map; |
| 3048 |
|
| 3049 |
int k; |
| 3050 |
double **orig_phi; |
| 3051 |
int *violation; |
| 3052 |
int v_ct; |
| 3053 |
int apredict_total_ct; |
| 3054 |
int awrong_total_ct; |
| 3055 |
int i; |
| 3056 |
float diff; |
| 3057 |
int nd; |
| 3058 |
|
| 3059 |
v_ct = 0; |
| 3060 |
apredict_total_ct = 0; |
| 3061 |
awrong_total_ct = 0; |
| 3062 |
|
| 3063 |
|
| 3064 |
if((status = build_cp9_hmm(orig_cm, errbuf, FALSE, 0.0001, print_flag, &orig_hmm, &orig_cp9map)) != eslOK) return status; |
| 3065 |
if((status = build_cp9_hmm(sub_cm, errbuf, FALSE, 0.0001, print_flag, &sub_hmm, &sub_cp9map)) != eslOK) return status; |
| 3066 |
CP9Logoddsify(orig_hmm); |
| 3067 |
CP9Logoddsify(sub_hmm); |
| 3068 |
|
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
cm2sub_cm_find_impossible_misc_cases(orig_cm, sub_cm, submap, subinfo, orig_cp9map, sub_cp9map, print_flag); |
| 3074 |
cm2sub_cm_find_impossible_matr_cases(orig_cm, sub_cm, submap, subinfo, orig_cp9map, sub_cp9map, print_flag); |
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
fill_phi_cp9(orig_hmm, &orig_phi, 1, FALSE); |
| 3079 |
CP9_reconfig2sub(orig_hmm, submap->spos, submap->epos, submap->spos, submap->epos, orig_phi); |
| 3080 |
|
| 3081 |
if(print_flag) |
| 3082 |
{ |
| 3083 |
printf("PRINTING BUILT SUB HMM PARAMS:\n"); |
| 3084 |
debug_print_cp9_params(stdout, sub_hmm, TRUE); |
| 3085 |
printf("DONE PRINTING BUILT SUB HMM PARAMS:\n"); |
| 3086 |
|
| 3087 |
printf("PRINTING BUILT & RECONFIGED ORIG HMM PARAMS:\n"); |
| 3088 |
debug_print_cp9_params(stdout, orig_hmm, TRUE); |
| 3089 |
printf("DONE PRINTING BUILT & RECONFIGED ORIG HMM PARAMS:\n"); |
| 3090 |
} |
| 3091 |
|
| 3092 |
|
| 3093 |
if(print_flag) |
| 3094 |
{ |
| 3095 |
printf("COMPARING CP9 HMM parameters in check_sub_cm()\n"); |
| 3096 |
printf("orig | sub\n"); |
| 3097 |
} |
| 3098 |
ESL_ALLOC(violation, sizeof(int) * (submap->sub_clen+1)); |
| 3099 |
for(k = 0; k <= sub_hmm->M; k++) |
| 3100 |
{ |
| 3101 |
violation[k] = FALSE; |
| 3102 |
if(print_flag) printf("Node: %d\n", k); |
| 3103 |
if(k > 0) |
| 3104 |
{ |
| 3105 |
for(i = 0; i < orig_cm->abc->K; i++) |
| 3106 |
{ |
| 3107 |
diff = orig_hmm->mat[(submap->spos+k-1)][i] - sub_hmm->mat[k][i]; |
| 3108 |
if(print_flag) printf("mat[%d][%d] = %8.5f | %8.5f | (%8.5f)\n", 0, i, orig_hmm->mat[(submap->spos+k-1)][i], sub_hmm->mat[k][i], diff); |
| 3109 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3110 |
{ |
| 3111 |
ESL_FAIL(eslFAIL, errbuf, "check_sub_cm(): emission probability incorrect"); |
| 3112 |
} |
| 3113 |
} |
| 3114 |
} |
| 3115 |
for(i = 0; i < orig_cm->abc->K; i++) |
| 3116 |
{ |
| 3117 |
diff = orig_hmm->ins[(submap->spos+k-1)][i] - sub_hmm->ins[k][i]; |
| 3118 |
if(print_flag) printf("ins[%d][%d] = %8.5f | %8.5f | (%8.5f)\n", 0, i, orig_hmm->ins[(submap->spos+k-1)][i], sub_hmm->ins[k][i], diff); |
| 3119 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3120 |
{ |
| 3121 |
ESL_FAIL(eslFAIL, errbuf, "check_sub_cm(): emission probability incorrect"); |
| 3122 |
} |
| 3123 |
} |
| 3124 |
|
| 3125 |
|
| 3126 |
if(print_flag) printf("\n"); |
| 3127 |
diff = orig_hmm->t[(submap->spos+k-1)][CTMM] - sub_hmm->t[k][CTMM]; |
| 3128 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3129 |
{ |
| 3130 |
violation[k] = TRUE; |
| 3131 |
if(print_flag) printf("\tCTMM[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->t[(submap->spos+k-1)][CTMM], sub_hmm->t[k][CTMM], diff); |
| 3132 |
} |
| 3133 |
else |
| 3134 |
if(print_flag) printf("\tCTMM[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->t[(submap->spos+k-1)][CTMM], sub_hmm->t[k][CTMM], diff); |
| 3135 |
|
| 3136 |
diff = orig_hmm->t[(submap->spos+k-1)][CTMI] - sub_hmm->t[k][CTMI]; |
| 3137 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3138 |
{ |
| 3139 |
violation[k] = TRUE; |
| 3140 |
if(print_flag) printf("\tCTMI[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->t[(submap->spos+k-1)][CTMI], sub_hmm->t[k][CTMI], diff); |
| 3141 |
} |
| 3142 |
else |
| 3143 |
if(print_flag) printf("\tCTMI[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->t[(submap->spos+k-1)][CTMI], sub_hmm->t[k][CTMI], diff); |
| 3144 |
|
| 3145 |
diff = orig_hmm->t[(submap->spos+k-1)][CTMD] - sub_hmm->t[k][CTMD]; |
| 3146 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3147 |
{ |
| 3148 |
violation[k] = TRUE; |
| 3149 |
if(print_flag) printf("\tCTMD[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->t[(submap->spos+k-1)][CTMD], sub_hmm->t[k][CTMD], diff); |
| 3150 |
} |
| 3151 |
else |
| 3152 |
if(print_flag) printf("\tCTMD[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->t[(submap->spos+k-1)][CTMD], sub_hmm->t[k][CTMD], diff); |
| 3153 |
|
| 3154 |
diff = orig_hmm->t[(submap->spos+k-1)][CTIM] - sub_hmm->t[k][CTIM]; |
| 3155 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3156 |
{ |
| 3157 |
violation[k] = TRUE; |
| 3158 |
if(print_flag) printf("\tCTIM[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->t[(submap->spos+k-1)][CTIM], sub_hmm->t[k][CTIM], diff); |
| 3159 |
} |
| 3160 |
else |
| 3161 |
if(print_flag) printf("\tCTIM[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->t[(submap->spos+k-1)][CTIM], sub_hmm->t[k][CTIM], diff); |
| 3162 |
|
| 3163 |
diff = orig_hmm->t[(submap->spos+k-1)][CTII] - sub_hmm->t[k][CTII]; |
| 3164 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3165 |
{ |
| 3166 |
violation[k] = TRUE; |
| 3167 |
if(print_flag) printf("\tCTII[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->t[(submap->spos+k-1)][CTII], sub_hmm->t[k][CTII], diff); |
| 3168 |
} |
| 3169 |
else |
| 3170 |
if(print_flag) printf("\tCTII[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->t[(submap->spos+k-1)][CTII], sub_hmm->t[k][CTII], diff); |
| 3171 |
|
| 3172 |
diff = orig_hmm->t[(submap->spos+k-1)][CTID] - sub_hmm->t[k][CTID]; |
| 3173 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3174 |
{ |
| 3175 |
violation[k] = TRUE; |
| 3176 |
if(print_flag) printf("\tCTID[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->t[(submap->spos+k-1)][CTID], sub_hmm->t[k][CTID], diff); |
| 3177 |
} |
| 3178 |
else |
| 3179 |
if(print_flag) printf("\tCTID[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->t[(submap->spos+k-1)][CTID], sub_hmm->t[k][CTID], diff); |
| 3180 |
|
| 3181 |
diff = orig_hmm->t[(submap->spos+k-1)][CTDM] - sub_hmm->t[k][CTDM]; |
| 3182 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3183 |
{ |
| 3184 |
violation[k] = TRUE; |
| 3185 |
if(print_flag) printf("\tCTDM[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->t[(submap->spos+k-1)][CTDM], sub_hmm->t[k][CTDM], diff); |
| 3186 |
} |
| 3187 |
else |
| 3188 |
if(print_flag) printf("\tCTDM[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->t[(submap->spos+k-1)][CTDM], sub_hmm->t[k][CTDM], diff); |
| 3189 |
|
| 3190 |
diff = orig_hmm->t[(submap->spos+k-1)][CTDI] - sub_hmm->t[k][CTDI]; |
| 3191 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3192 |
{ |
| 3193 |
violation[k] = TRUE; |
| 3194 |
if(print_flag) printf("\tCTDI[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->t[(submap->spos+k-1)][CTDI], sub_hmm->t[k][CTDI], diff); |
| 3195 |
} |
| 3196 |
else |
| 3197 |
if(print_flag) printf("\tCTDI[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->t[(submap->spos+k-1)][CTDI], sub_hmm->t[k][CTDI], diff); |
| 3198 |
|
| 3199 |
diff = orig_hmm->t[(submap->spos+k-1)][CTDD] - sub_hmm->t[k][CTDD]; |
| 3200 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3201 |
{ |
| 3202 |
violation[k] = TRUE; |
| 3203 |
if(print_flag) printf("\tCTDD[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->t[(submap->spos+k-1)][CTDD], sub_hmm->t[k][CTDD], diff); |
| 3204 |
} |
| 3205 |
else |
| 3206 |
if(print_flag) printf("\tCTDD[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->t[(submap->spos+k-1)][CTDD], sub_hmm->t[k][CTDD], diff); |
| 3207 |
|
| 3208 |
if(k > 0) |
| 3209 |
{ |
| 3210 |
diff = orig_hmm->begin[(submap->spos+k-1)] - sub_hmm->begin[k]; |
| 3211 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3212 |
{ |
| 3213 |
violation[0] = TRUE; |
| 3214 |
if(print_flag) printf("\t beg[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->begin[(submap->spos+k-1)], sub_hmm->begin[k], diff); |
| 3215 |
} |
| 3216 |
else |
| 3217 |
if(print_flag) printf("\t beg[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->begin[(submap->spos+k-1)], sub_hmm->begin[k], diff); |
| 3218 |
|
| 3219 |
diff = orig_hmm->end[(submap->spos+k-1)] - sub_hmm->end[k]; |
| 3220 |
if((diff > 0 && diff > pthresh) || (diff < 0 && diff < (-1. * pthresh))) |
| 3221 |
{ |
| 3222 |
violation[k] = TRUE; |
| 3223 |
if(print_flag) printf("\t end[%d] = %8.5f | %8.5f | %8.5f VIOLATION\n", k, orig_hmm->end[(submap->spos+k-1)], sub_hmm->end[k], diff); |
| 3224 |
} |
| 3225 |
else |
| 3226 |
if(print_flag) printf("\t end[%d] = %8.5f | %8.5f | %8.5f\n", k, orig_hmm->end[(submap->spos+k-1)], sub_hmm->end[k], diff); |
| 3227 |
} |
| 3228 |
} |
| 3229 |
|
| 3230 |
|
| 3231 |
for(nd = 0; nd <= (submap->epos-submap->spos+1); nd++) |
| 3232 |
{ |
| 3233 |
if(violation[nd] && subinfo->imp_cc[nd] == 0) |
| 3234 |
{ |
| 3235 |
v_ct++; |
| 3236 |
printf("VIOLATION[%3d]: TRUE | submap->spos: %3d | submap->epos: %3d | subinfo->imp_cc: %d\n", nd, submap->spos, submap->epos, subinfo->imp_cc[nd]); |
| 3237 |
} |
| 3238 |
else if(violation[nd] && subinfo->imp_cc[nd] != 0) |
| 3239 |
{ |
| 3240 |
subinfo->apredict_ct[subinfo->imp_cc[nd]]++; |
| 3241 |
apredict_total_ct++; |
| 3242 |
if(print_flag) |
| 3243 |
printf("PREDICTED VIOLATION[%3d]: TRUE | submap->spos: %3d | submap->epos: %3d | subinfo->imp_cc: %d (apredict_total_ct: %d)\n", nd, submap->spos, submap->epos, subinfo->imp_cc[nd], apredict_total_ct); |
| 3244 |
} |
| 3245 |
else if(!violation[nd] && subinfo->imp_cc[nd] != 0) |
| 3246 |
{ |
| 3247 |
subinfo->apredict_ct[subinfo->imp_cc[nd]]++; |
| 3248 |
apredict_total_ct++; |
| 3249 |
subinfo->awrong_ct[subinfo->imp_cc[nd]]++; |
| 3250 |
awrong_total_ct++; |
| 3251 |
if(print_flag) printf("NON-VIOLATION[%3d] %3d : submap->spos: %3d | submap->epos: %3d | subinfo->imp_cc: %d\n", nd, awrong_total_ct, submap->spos, submap->epos, subinfo->imp_cc[nd]); |
| 3252 |
} |
| 3253 |
} |
| 3254 |
|
| 3255 |
|
| 3256 |
for(k = 0; k <= orig_hmm->M; k++) |
| 3257 |
free(orig_phi[k]); |
| 3258 |
free(orig_phi); |
| 3259 |
|
| 3260 |
free(violation); |
| 3261 |
FreeCPlan9(orig_hmm); |
| 3262 |
FreeCPlan9(sub_hmm); |
| 3263 |
FreeCP9Map(orig_cp9map); |
| 3264 |
FreeCP9Map(sub_cp9map); |
| 3265 |
|
| 3266 |
if(v_ct > 0) ESL_FAIL(eslFAIL, errbuf, "check_sub_cm(): check failed"); |
| 3267 |
return eslOK; |
| 3268 |
|
| 3269 |
ERROR: |
| 3270 |
ESL_FAIL(status, errbuf, "memory allocation error"); |
| 3271 |
return FALSE; |
| 3272 |
} |
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
|
| 3287 |
|
| 3288 |
|
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
|
| 3297 |
int |
| 3298 |
sub_cm2cm_parsetree(CM_t *orig_cm, CM_t *sub_cm, Parsetree_t **ret_orig_tr, Parsetree_t *sub_tr, |
| 3299 |
CMSubMap_t *submap, int print_flag) |
| 3300 |
{ |
| 3301 |
int status; |
| 3302 |
Parsetree_t *orig_tr; |
| 3303 |
int *ss_used; |
| 3304 |
int *ss_emitl; |
| 3305 |
int *ss_emitr; |
| 3306 |
int *il_ct; |
| 3307 |
int *ir_ct; |
| 3308 |
int *il_used; |
| 3309 |
int *ir_used; |
| 3310 |
int *tr_nd_for_bifs; |
| 3311 |
int x; |
| 3312 |
int nd; |
| 3313 |
int sub_v; |
| 3314 |
int orig_v1; |
| 3315 |
int orig_v2; |
| 3316 |
int orig_nd1; |
| 3317 |
int orig_nd2; |
| 3318 |
int cm_nd; |
| 3319 |
int i; |
| 3320 |
int parent_tr_nd; |
| 3321 |
ESL_STACK *pda; |
| 3322 |
int pos; |
| 3323 |
int ss; |
| 3324 |
int on_right; |
| 3325 |
int emitl_flag; |
| 3326 |
int emitr_flag; |
| 3327 |
|
| 3328 |
char **nodetypes; |
| 3329 |
ESL_ALLOC(nodetypes, sizeof(char *) * 8); |
| 3330 |
nodetypes[0] = "BIF"; |
| 3331 |
nodetypes[1] = "MATP"; |
| 3332 |
nodetypes[2] = "MATL"; |
| 3333 |
nodetypes[3] = "MATR"; |
| 3334 |
nodetypes[4] = "BEGL"; |
| 3335 |
nodetypes[5] = "BEGR"; |
| 3336 |
nodetypes[6] = "ROOT"; |
| 3337 |
nodetypes[7] = "END"; |
| 3338 |
|
| 3339 |
char **sttypes; |
| 3340 |
ESL_ALLOC(sttypes, sizeof(char *) * 10); |
| 3341 |
sttypes[0] = "D"; |
| 3342 |
sttypes[1] = "MP"; |
| 3343 |
sttypes[2] = "ML"; |
| 3344 |
sttypes[3] = "MR"; |
| 3345 |
sttypes[4] = "IL"; |
| 3346 |
sttypes[5] = "IR"; |
| 3347 |
sttypes[6] = "S"; |
| 3348 |
sttypes[7] = "E"; |
| 3349 |
sttypes[8] = "B"; |
| 3350 |
sttypes[9] = "EL"; |
| 3351 |
|
| 3352 |
if(print_flag) printf("orig_cm nodes: %d\n", orig_cm->nodes); |
| 3353 |
|
| 3354 |
ESL_ALLOC(ss_used, sizeof(int) * orig_cm->nodes + 1); |
| 3355 |
ESL_ALLOC(ss_emitl, sizeof(int) * orig_cm->nodes + 1); |
| 3356 |
ESL_ALLOC(ss_emitr, sizeof(int) * orig_cm->nodes + 1); |
| 3357 |
ESL_ALLOC(il_used, sizeof(int) * orig_cm->nodes + 1); |
| 3358 |
ESL_ALLOC(ir_used, sizeof(int) * orig_cm->nodes + 1); |
| 3359 |
ESL_ALLOC(il_ct, sizeof(int) * orig_cm->nodes + 1); |
| 3360 |
ESL_ALLOC(ir_ct, sizeof(int) * orig_cm->nodes + 1); |
| 3361 |
ESL_ALLOC(tr_nd_for_bifs,sizeof(int) * orig_cm->nodes + 1); |
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
|
| 3366 |
|
| 3367 |
for(nd = 0; nd < orig_cm->nodes; nd++) |
| 3368 |
{ |
| 3369 |
ss_used[nd] = -1; |
| 3370 |
ss_emitl[nd] = -1; |
| 3371 |
ss_emitr[nd] = -1; |
| 3372 |
il_ct[nd] = 0; |
| 3373 |
ir_ct[nd] = 0; |
| 3374 |
il_used[nd] = -1; |
| 3375 |
ir_used[nd] = -1; |
| 3376 |
tr_nd_for_bifs[nd] = -1; |
| 3377 |
} |
| 3378 |
|
| 3379 |
for(x = 0; x < sub_tr->n; x++) |
| 3380 |
{ |
| 3381 |
sub_v = sub_tr->state[x]; |
| 3382 |
if(print_flag) printf("x: %d sub_v: %d\n", x, sub_v); |
| 3383 |
orig_v1 = submap->s2o_smap[sub_v][0]; |
| 3384 |
orig_v2 = submap->s2o_smap[sub_v][1]; |
| 3385 |
if(print_flag) printf("orig_v1: %d | orig_v2: %d\n", orig_v1, orig_v2); |
| 3386 |
if(orig_v1 == -1) |
| 3387 |
{ |
| 3388 |
if(sub_cm->sttype[sub_v] != S_st && |
| 3389 |
sub_cm->sttype[sub_v] != E_st && |
| 3390 |
sub_cm->sttype[sub_v] != B_st && |
| 3391 |
sub_cm->sttype[sub_v] != EL_st) |
| 3392 |
cm_Fail("ERROR 0 in sub_cm2cm_parstree()\n"); |
| 3393 |
continue; |
| 3394 |
} |
| 3395 |
orig_nd1 = orig_cm->ndidx[orig_v1]; |
| 3396 |
if(orig_v2 != -1) |
| 3397 |
orig_nd2 = orig_cm->ndidx[orig_v2]; |
| 3398 |
else |
| 3399 |
orig_nd2 = -1; |
| 3400 |
|
| 3401 |
|
| 3402 |
if(orig_cm->sttype[orig_v1] == IL_st) |
| 3403 |
{ |
| 3404 |
il_used[orig_nd1] = orig_v1; |
| 3405 |
il_ct[orig_nd1]++; |
| 3406 |
if(orig_v2 != -1) |
| 3407 |
cm_Fail("ERROR 1 in sub_cm2cm_parstree()\n"); |
| 3408 |
} |
| 3409 |
else if(orig_cm->sttype[orig_v1] == IR_st) |
| 3410 |
{ |
| 3411 |
ir_used[orig_nd1] = orig_v1; |
| 3412 |
ir_ct[orig_nd1]++; |
| 3413 |
if(orig_v2 != -1) |
| 3414 |
cm_Fail("ERROR 2 in sub_cm2cm_parstree()\n"); |
| 3415 |
} |
| 3416 |
else if(sub_cm->ndtype[sub_cm->ndidx[sub_v]] == MATP_nd) |
| 3417 |
{ |
| 3418 |
ss_used[orig_nd1] = orig_v1; |
| 3419 |
if(orig_v2 != -1) |
| 3420 |
cm_Fail("ERROR 3 in sub_cm2cm_parsetree()\n"); |
| 3421 |
} |
| 3422 |
else if(orig_cm->ndtype[orig_nd1] == MATP_nd) |
| 3423 |
{ |
| 3424 |
if(orig_v2 == -1) |
| 3425 |
cm_Fail("ERROR 4 in sub_cm2cm_parsetree()\n"); |
| 3426 |
|
| 3427 |
if(sub_cm->ndtype[sub_cm->ndidx[sub_v]] != MATL_nd && |
| 3428 |
sub_cm->ndtype[sub_cm->ndidx[sub_v]] != MATR_nd) |
| 3429 |
cm_Fail("ERROR 5 in sub_cm2cm_parsetree()\n"); |
| 3430 |
if(orig_cm->ndtype[orig_nd2] != MATP_nd) |
| 3431 |
cm_Fail("ERROR 6 in sub_cm2cm_parsetree()\n"); |
| 3432 |
|
| 3433 |
if(sub_cm->sttype[sub_v] == D_st) |
| 3434 |
{ |
| 3435 |
if(ss_used[orig_nd1] == -1 || |
| 3436 |
orig_cm->sttype[ss_used[orig_nd1]] == D_st) |
| 3437 |
ss_used[orig_nd1] = orig_cm->nodemap[orig_nd1] + 3; |
| 3438 |
|
| 3439 |
|
| 3440 |
|
| 3441 |
} |
| 3442 |
else |
| 3443 |
{ |
| 3444 |
if(ss_used[orig_nd1] == -1 || |
| 3445 |
orig_cm->sttype[ss_used[orig_nd1]] == D_st) |
| 3446 |
{ |
| 3447 |
|
| 3448 |
if(orig_cm->sttype[orig_v1] == ML_st || |
| 3449 |
orig_cm->sttype[orig_v2] == ML_st) |
| 3450 |
ss_used[orig_nd1] = orig_cm->nodemap[orig_nd1] + 1; |
| 3451 |
else if(orig_cm->sttype[orig_v1] == MR_st || |
| 3452 |
orig_cm->sttype[orig_v2] == MR_st) |
| 3453 |
ss_used[orig_nd1] = orig_cm->nodemap[orig_nd1] + 2; |
| 3454 |
else |
| 3455 |
cm_Fail("ERROR 7 in sub_cm2cm_parsetree()\n"); |
| 3456 |
} |
| 3457 |
|
| 3458 |
|
| 3459 |
|
| 3460 |
|
| 3461 |
else if(orig_cm->sttype[ss_used[orig_nd1]] == ML_st) |
| 3462 |
{ |
| 3463 |
if(orig_cm->sttype[orig_v1] == MR_st || |
| 3464 |
orig_cm->sttype[orig_v2] == MR_st) |
| 3465 |
{ |
| 3466 |
ss_used[orig_nd1] = orig_cm->nodemap[orig_nd1]; |
| 3467 |
} |
| 3468 |
else |
| 3469 |
cm_Fail("ERROR 8 in sub_cm2cm_parsetree()\n"); |
| 3470 |
} |
| 3471 |
else if(orig_cm->sttype[ss_used[orig_nd1]] == MR_st) |
| 3472 |
{ |
| 3473 |
if(orig_cm->sttype[orig_v1] == ML_st || |
| 3474 |
orig_cm->sttype[orig_v2] == ML_st) |
| 3475 |
{ |
| 3476 |
ss_used[orig_nd1] = orig_cm->nodemap[orig_nd1]; |
| 3477 |
} |
| 3478 |
else |
| 3479 |
cm_Fail("ERROR 9 in sub_cm2cm_parsetree()\n"); |
| 3480 |
} |
| 3481 |
} |
| 3482 |
} |
| 3483 |
else |
| 3484 |
{ |
| 3485 |
if(orig_v2 != -1) |
| 3486 |
cm_Fail("ERROR 5 in sub_cm2cm_parsetree()\n"); |
| 3487 |
ss_used[orig_nd1] = orig_v1; |
| 3488 |
} |
| 3489 |
} |
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
for(nd = 0; nd < orig_cm->nodes; nd++) |
| 3496 |
{ |
| 3497 |
if(ss_used[nd] == -1) |
| 3498 |
{ |
| 3499 |
if(orig_cm->ndtype[nd] == MATP_nd) |
| 3500 |
ss_used[nd] = orig_cm->nodemap[nd] + 3; |
| 3501 |
if(orig_cm->ndtype[nd] == MATL_nd || |
| 3502 |
orig_cm->ndtype[nd] == MATR_nd) |
| 3503 |
ss_used[nd] = orig_cm->nodemap[nd] + 1; |
| 3504 |
if(orig_cm->ndtype[nd] == BIF_nd || |
| 3505 |
orig_cm->ndtype[nd] == BEGL_nd || |
| 3506 |
orig_cm->ndtype[nd] == BEGR_nd || |
| 3507 |
orig_cm->ndtype[nd] == END_nd) |
| 3508 |
ss_used[nd] = orig_cm->nodemap[nd]; |
| 3509 |
} |
| 3510 |
} |
| 3511 |
|
| 3512 |
|
| 3513 |
|
| 3514 |
|
| 3515 |
|
| 3516 |
|
| 3517 |
pos = 1; |
| 3518 |
ss = 0; |
| 3519 |
if((pda = esl_stack_ICreate()) == NULL) goto ERROR; |
| 3520 |
if((status = esl_stack_IPush(pda, 0)) != eslOK) goto ERROR; |
| 3521 |
if((status = esl_stack_IPush(pda, ss)) != eslOK) goto ERROR; |
| 3522 |
while (esl_stack_IPop(pda, &ss) != eslEOD) |
| 3523 |
{ |
| 3524 |
esl_stack_IPop(pda, &on_right); |
| 3525 |
|
| 3526 |
if (on_right) |
| 3527 |
{ |
| 3528 |
pos += ir_ct[orig_cm->ndidx[ss]]; |
| 3529 |
if (orig_cm->sttype[ss] == MP_st || orig_cm->sttype[ss] == MR_st) |
| 3530 |
pos++; |
| 3531 |
ss_emitr[orig_cm->ndidx[ss]] = pos - 1; |
| 3532 |
} |
| 3533 |
else |
| 3534 |
{ |
| 3535 |
ss_emitl[orig_cm->ndidx[ss]] = pos; |
| 3536 |
if (orig_cm->sttype[ss] == MP_st || orig_cm->sttype[ss] == ML_st) |
| 3537 |
pos++; |
| 3538 |
|
| 3539 |
if (orig_cm->sttype[ss] == B_st) |
| 3540 |
{ |
| 3541 |
|
| 3542 |
if((status = esl_stack_IPush(pda, 1)) != eslOK) goto ERROR; |
| 3543 |
if((status = esl_stack_IPush(pda, ss)) != eslOK) goto ERROR; |
| 3544 |
|
| 3545 |
if((status = esl_stack_IPush(pda, 0)) != eslOK) goto ERROR; |
| 3546 |
if((status = esl_stack_IPush(pda, orig_cm->cnum[ss])) != eslOK) goto ERROR; |
| 3547 |
|
| 3548 |
if((status = esl_stack_IPush(pda, 0)) != eslOK) goto ERROR; |
| 3549 |
if((status = esl_stack_IPush(pda, orig_cm->cfirst[ss])) != eslOK) goto ERROR; |
| 3550 |
} |
| 3551 |
else |
| 3552 |
{ |
| 3553 |
|
| 3554 |
if((status = esl_stack_IPush(pda, 1)) != eslOK) goto ERROR; |
| 3555 |
if((status = esl_stack_IPush(pda, ss)) != eslOK) goto ERROR; |
| 3556 |
|
| 3557 |
if (orig_cm->sttype[ss] != E_st) { |
| 3558 |
if((status = esl_stack_IPush(pda, 0)) != eslOK) goto ERROR; |
| 3559 |
if((status = esl_stack_IPush(pda, ss_used[orig_cm->ndidx[ss]+1])) != eslOK) goto ERROR; |
| 3560 |
} |
| 3561 |
} |
| 3562 |
pos += il_ct[orig_cm->ndidx[ss]]; |
| 3563 |
} |
| 3564 |
} |
| 3565 |
|
| 3566 |
if(print_flag) |
| 3567 |
{ |
| 3568 |
for(nd = 0; nd < orig_cm->nodes; nd++) |
| 3569 |
{ |
| 3570 |
printf("ss_used[%4d] (%4s) first state(%4d) | ", nd, nodetypes[(int) orig_cm->ndtype[nd]], orig_cm->nodemap[nd]); |
| 3571 |
if(ss_used[nd] != -1) |
| 3572 |
printf("%4d (%2s) | L: %3d R: %3d\n", ss_used[nd], sttypes[(int) orig_cm->sttype[ss_used[nd]]], ss_emitl[nd], ss_emitr[nd]); |
| 3573 |
else |
| 3574 |
printf("%4d\n", -1); |
| 3575 |
} |
| 3576 |
for(nd = 0; nd < orig_cm->nodes; nd++) |
| 3577 |
printf("il_ct[%4d] (st used: %4d) ct: %4d | ir_ct[%4d] ct: %4d (st used: %4d)\n", nd, il_used[nd], il_ct[nd], nd, ir_used[nd], ir_ct[nd]); |
| 3578 |
|
| 3579 |
} |
| 3580 |
|
| 3581 |
orig_tr = CreateParsetree(100); |
| 3582 |
for(cm_nd = 0; cm_nd < orig_cm->nodes; cm_nd++) |
| 3583 |
{ |
| 3584 |
emitl_flag = 0; |
| 3585 |
emitr_flag = 0; |
| 3586 |
if(orig_cm->sttype[ss_used[cm_nd]] == MP_st || |
| 3587 |
orig_cm->sttype[ss_used[cm_nd]] == ML_st) |
| 3588 |
emitl_flag = 1; |
| 3589 |
if(orig_cm->sttype[ss_used[cm_nd]] == MP_st || |
| 3590 |
orig_cm->sttype[ss_used[cm_nd]] == MR_st) |
| 3591 |
emitr_flag = 1; |
| 3592 |
|
| 3593 |
|
| 3594 |
if(orig_cm->ndtype[cm_nd] == BEGR_nd) |
| 3595 |
{ |
| 3596 |
parent_tr_nd = tr_nd_for_bifs[orig_cm->ndidx[orig_cm->plast[orig_cm->nodemap[cm_nd]]]]; |
| 3597 |
if(print_flag) printf("tr_nd_for_bifs[%d]\n", (orig_cm->ndidx[orig_cm->plast[orig_cm->nodemap[cm_nd]]])); |
| 3598 |
if(print_flag) printf("parent_tr_nd for cm_nd %d: %d\n", cm_nd, parent_tr_nd); |
| 3599 |
InsertTraceNode(orig_tr, parent_tr_nd, TRACE_RIGHT_CHILD, ss_emitl[cm_nd], ss_emitr[cm_nd], ss_used[cm_nd]); |
| 3600 |
orig_tr->nxtr[parent_tr_nd] = orig_tr->n - 1; |
| 3601 |
} |
| 3602 |
else |
| 3603 |
{ |
| 3604 |
InsertTraceNode(orig_tr, orig_tr->n-1, TRACE_LEFT_CHILD, ss_emitl[cm_nd], ss_emitr[cm_nd], ss_used[cm_nd]); |
| 3605 |
if(print_flag) printf("inserted trace node for orig_cm st %4s | emitl: %d | emitr: %d\n", sttypes[(int) orig_cm->sttype[ss_used[cm_nd]]], ss_emitl[cm_nd], ss_emitr[cm_nd]); |
| 3606 |
} |
| 3607 |
|
| 3608 |
|
| 3609 |
|
| 3610 |
|
| 3611 |
if(orig_cm->ndtype[cm_nd] == BIF_nd) |
| 3612 |
{ |
| 3613 |
tr_nd_for_bifs[cm_nd] = orig_tr->n - 1; |
| 3614 |
if(print_flag) printf("set tr_nd_for_bifs[%d]: %d\n", cm_nd, orig_tr->n); |
| 3615 |
} |
| 3616 |
|
| 3617 |
|
| 3618 |
for(i = 0; i < il_ct[cm_nd]; i++) |
| 3619 |
{ |
| 3620 |
InsertTraceNode(orig_tr, orig_tr->n-1, TRACE_LEFT_CHILD, (ss_emitl[cm_nd] + emitl_flag + i), (ss_emitr[cm_nd] - emitr_flag), il_used[cm_nd]); |
| 3621 |
if(print_flag) printf("inserted trace node for orig_cm st %4s | emitl: %d | emitr: %d\n", sttypes[(int) orig_cm->sttype[il_used[cm_nd]]], orig_tr->emitl[orig_tr->n-1], orig_tr->emitr[orig_tr->n+1]); |
| 3622 |
} |
| 3623 |
|
| 3624 |
for(i = 0; i < ir_ct[cm_nd]; i++) |
| 3625 |
{ |
| 3626 |
InsertTraceNode(orig_tr, orig_tr->n-1, TRACE_LEFT_CHILD, (ss_emitl[cm_nd] + emitl_flag + il_ct[cm_nd]), (ss_emitr[cm_nd] - emitr_flag - i), ir_used[cm_nd]); |
| 3627 |
if(print_flag) printf("inserted trace node for orig_cm st %4s | emitl: %d | emitr: %d\n", sttypes[(int) orig_cm->sttype[ir_used[cm_nd]]], orig_tr->emitl[orig_tr->n-1], orig_tr->emitr[orig_tr->n+1]); |
| 3628 |
} |
| 3629 |
if(print_flag) printf("END nd: %4d\n", cm_nd); |
| 3630 |
} |
| 3631 |
*ret_orig_tr = orig_tr; |
| 3632 |
|
| 3633 |
free(ss_used); |
| 3634 |
free(ss_emitl); |
| 3635 |
free(ss_emitr); |
| 3636 |
free(il_used); |
| 3637 |
free(ir_used); |
| 3638 |
free(il_ct); |
| 3639 |
free(ir_ct); |
| 3640 |
free(tr_nd_for_bifs); |
| 3641 |
free(nodetypes); |
| 3642 |
free(sttypes); |
| 3643 |
esl_stack_Destroy(pda); |
| 3644 |
return eslOK; |
| 3645 |
|
| 3646 |
ERROR: |
| 3647 |
return eslEMEM; |
| 3648 |
} |
| 3649 |
|
| 3650 |
|
| 3651 |
|
| 3652 |
|
| 3653 |
|
| 3654 |
|
| 3655 |
|
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
|
| 3660 |
|
| 3661 |
|
| 3662 |
int |
| 3663 |
SubCMLogoddsify(CM_t *cm, char *errbuf, CM_t *mother_cm, CMSubMap_t *mother_map) |
| 3664 |
{ |
| 3665 |
if(!(mother_cm->flags & CMH_BITS)) ESL_FAIL(eslEINCOMPAT, errbuf, "SubCMLogoddsify(), mother_cm's CMH_BITS flag down, it's bit scores are invalid."); |
| 3666 |
|
| 3667 |
int v, mv, x, y; |
| 3668 |
|
| 3669 |
for (v = 0; v < cm->M; v++) { |
| 3670 |
if (mother_map->s2o_id[v] == TRUE) { |
| 3671 |
if (cm->sttype[v] != B_st && cm->sttype[v] != E_st) { |
| 3672 |
mv = mother_map->s2o_smap[v][0]; |
| 3673 |
esl_vec_FCopy(mother_cm->tsc[mv], cm->cnum[v], cm->tsc[v]); |
| 3674 |
esl_vec_ICopy(mother_cm->itsc[mv], cm->cnum[v], cm->itsc[v]); |
| 3675 |
#if eslDEBUGLEVEL >= 1 |
| 3676 |
for(x = 0; x < cm->cnum[v]; x++) { |
| 3677 |
if(esl_FCompare_old(mother_cm->t[mv][x], cm->t[v][x], 1E-5) != eslOK) ESL_FAIL(eslEINCONCEIVABLE, errbuf, "You've got it wrong, mother_cm->t[mv:%d][x:%d] %.3f != cm->t[v:%d][x:%d] %.3f\n", mv, x, mother_cm->t[mv][x], v, x, cm->t[v][x]); |
| 3678 |
} |
| 3679 |
#endif |
| 3680 |
} |
| 3681 |
if (cm->sttype[v] == MP_st) { |
| 3682 |
esl_vec_FCopy(mother_cm->esc[mv], cm->abc->K * cm->abc->K, cm->esc[v]); |
| 3683 |
esl_vec_ICopy(mother_cm->iesc[mv], cm->abc->K * cm->abc->K, cm->iesc[v]); |
| 3684 |
} |
| 3685 |
if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || |
| 3686 |
cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) { |
| 3687 |
esl_vec_FCopy(mother_cm->esc[mv], cm->abc->K, cm->esc[v]); |
| 3688 |
esl_vec_ICopy(mother_cm->iesc[mv], cm->abc->K, cm->iesc[v]); |
| 3689 |
} |
| 3690 |
cm->beginsc[v] = mother_cm->beginsc[mv]; |
| 3691 |
cm->ibeginsc[v] = mother_cm->ibeginsc[mv]; |
| 3692 |
|
| 3693 |
cm->endsc[v] = mother_cm->endsc[mv]; |
| 3694 |
cm->iendsc[v] = mother_cm->iendsc[mv]; |
| 3695 |
} |
| 3696 |
else { |
| 3697 |
if (cm->sttype[v] != B_st && cm->sttype[v] != E_st) { |
| 3698 |
for (x = 0; x < cm->cnum[v]; x++) { |
| 3699 |
cm->tsc[v][x] = sreLOG2(cm->t[v][x]); |
| 3700 |
cm->itsc[v][x] = Prob2Score(cm->t[v][x], 1.0); |
| 3701 |
|
| 3702 |
} |
| 3703 |
} |
| 3704 |
if (cm->sttype[v] == MP_st) { |
| 3705 |
for (x = 0; x < cm->abc->K; x++) { |
| 3706 |
for (y = 0; y < cm->abc->K; y++) { |
| 3707 |
cm->esc[v][x*cm->abc->K+y] = sreLOG2(cm->e[v][x*cm->abc->K+y] / (cm->null[x]*cm->null[y])); |
| 3708 |
cm->iesc[v][x*cm->abc->K+y] = Prob2Score(cm->e[v][x*cm->abc->K+y], (cm->null[x]*cm->null[y])); |
| 3709 |
|
| 3710 |
} |
| 3711 |
} |
| 3712 |
} |
| 3713 |
if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || |
| 3714 |
cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) { |
| 3715 |
for (x = 0; x < cm->abc->K; x++) { |
| 3716 |
cm->esc[v][x] = sreLOG2(cm->e[v][x] / cm->null[x]); |
| 3717 |
cm->iesc[v][x] = Prob2Score(cm->e[v][x], cm->null[x]); |
| 3718 |
|
| 3719 |
|
| 3720 |
} |
| 3721 |
} |
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
cm->beginsc[v] = sreLOG2(cm->begin[v]); |
| 3726 |
cm->ibeginsc[v] = Prob2Score(cm->begin[v], 1.0); |
| 3727 |
|
| 3728 |
|
| 3729 |
cm->endsc[v] = sreLOG2(cm->end[v]); |
| 3730 |
cm->iendsc[v] = Prob2Score(cm->end[v], 1.0); |
| 3731 |
|
| 3732 |
} |
| 3733 |
} |
| 3734 |
cm->iel_selfsc = Prob2Score(sreEXP2(cm->el_selfsc), 1.0); |
| 3735 |
|
| 3736 |
|
| 3737 |
|
| 3738 |
|
| 3739 |
|
| 3740 |
|
| 3741 |
|
| 3742 |
if(cm->oesc != NULL || cm->ioesc != NULL) FreeOptimizedEmitScores(cm->oesc, cm->ioesc, cm->M); |
| 3743 |
|
| 3744 |
cm->oesc = SubFCalcAndCopyOptimizedEmitScoresFromMother(cm, mother_cm, mother_map); |
| 3745 |
|
| 3746 |
|
| 3747 |
|
| 3748 |
|
| 3749 |
|
| 3750 |
cm->ioesc = ICopyOptimizedEmitScoresFromFloats(cm, cm->oesc); |
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
if(cm->flags & CM_RSEARCHTRANS) { |
| 3760 |
float alpha = DEFAULT_RALPHA; |
| 3761 |
float beta = DEFAULT_RBETA; |
| 3762 |
float alphap = DEFAULT_RALPHAP; |
| 3763 |
float betap = DEFAULT_RBETAP; |
| 3764 |
float beginsc = DEFAULT_RBEGINSC; |
| 3765 |
float endsc = DEFAULT_RENDSC; |
| 3766 |
int nd; |
| 3767 |
|
| 3768 |
for (v=0; v<cm->M; v++) |
| 3769 |
{ |
| 3770 |
if (cm->sttype[v] != B_st && cm->sttype[v] != E_st) |
| 3771 |
{ |
| 3772 |
for (x=0; x<cm->cnum[v]; x++) |
| 3773 |
{ |
| 3774 |
cm->tsc[v][x] = -1. * rsearch_calculate_gap_penalty |
| 3775 |
(cm->stid[v], cm->stid[cm->cfirst[v]+x], |
| 3776 |
cm->ndtype[cm->ndidx[v]], cm->ndtype[cm->ndidx[cm->cfirst[v]+x]], |
| 3777 |
alpha, beta, alphap, betap); |
| 3778 |
|
| 3779 |
|
| 3780 |
cm->itsc[v][x] = (int) floor(0.5 + INTSCALE * cm->tsc[v][x]); |
| 3781 |
} |
| 3782 |
} |
| 3783 |
} |
| 3784 |
|
| 3785 |
for (v=cm->M - 1; v>=0; v--) { |
| 3786 |
cm->beginsc[v] = IMPOSSIBLE; |
| 3787 |
cm->endsc[v] = IMPOSSIBLE; |
| 3788 |
} |
| 3789 |
|
| 3790 |
|
| 3791 |
for (nd = 2; nd < cm->nodes; nd++) { |
| 3792 |
if (cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATL_nd || |
| 3793 |
cm->ndtype[nd] == MATR_nd || cm->ndtype[nd] == BIF_nd) |
| 3794 |
{ |
| 3795 |
cm->beginsc[cm->nodemap[nd]] = beginsc; |
| 3796 |
cm->ibeginsc[cm->nodemap[nd]] = INTSCALE * beginsc; |
| 3797 |
} |
| 3798 |
} |
| 3799 |
|
| 3800 |
|
| 3801 |
for (nd = 1; nd < cm->nodes; nd++) { |
| 3802 |
if ((cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATL_nd || |
| 3803 |
cm->ndtype[nd] == MATR_nd || cm->ndtype[nd] == BEGL_nd || |
| 3804 |
cm->ndtype[nd] == BEGR_nd) && |
| 3805 |
cm->ndtype[nd+1] != END_nd) |
| 3806 |
{ |
| 3807 |
cm->endsc[cm->nodemap[nd]] = endsc; |
| 3808 |
cm->iendsc[cm->nodemap[nd]] = INTSCALE * endsc; |
| 3809 |
} |
| 3810 |
} |
| 3811 |
|
| 3812 |
cm->flags |= CMH_LOCAL_BEGIN; |
| 3813 |
cm->flags |= CMH_LOCAL_END; |
| 3814 |
} |
| 3815 |
|
| 3816 |
cm->flags |= CMH_BITS; |
| 3817 |
|
| 3818 |
|
| 3819 |
if(cm->cmcons != NULL) FreeCMConsensus(cm->cmcons); |
| 3820 |
if((cm->cmcons = CreateCMConsensus(cm, cm->abc)) == NULL) return eslFAIL; |
| 3821 |
|
| 3822 |
return eslOK; |
| 3823 |
} |
| 3824 |
|
| 3825 |
|
| 3826 |
|
| 3827 |
|
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
float ** |
| 3838 |
SubFCalcAndCopyOptimizedEmitScoresFromMother(CM_t *cm, CM_t *mother_cm, CMSubMap_t *mother_map) |
| 3839 |
{ |
| 3840 |
int status; |
| 3841 |
float **esc_vAA; |
| 3842 |
ESL_DSQ a,b; |
| 3843 |
int v; |
| 3844 |
int cur_cell; |
| 3845 |
int npairs = 0; |
| 3846 |
int nsinglets = 0; |
| 3847 |
float *ptr_to_start; |
| 3848 |
float **leftAA; |
| 3849 |
float **rightAA; |
| 3850 |
int mv; |
| 3851 |
|
| 3852 |
|
| 3853 |
for(v = 0; v < cm->M; v++) { |
| 3854 |
switch(cm->sttype[v]) { |
| 3855 |
case IL_st: |
| 3856 |
case ML_st: |
| 3857 |
case IR_st: |
| 3858 |
case MR_st: |
| 3859 |
nsinglets++; |
| 3860 |
break; |
| 3861 |
case MP_st: |
| 3862 |
npairs++; |
| 3863 |
break; |
| 3864 |
} |
| 3865 |
} |
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
|
| 3870 |
|
| 3871 |
ESL_ALLOC(leftAA, sizeof(float *) * cm->abc->Kp); |
| 3872 |
ESL_ALLOC(rightAA, sizeof(float *) * cm->abc->Kp); |
| 3873 |
for(a = 0; a <= cm->abc->K; a++) leftAA[a] = rightAA[a] = NULL; |
| 3874 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3875 |
ESL_ALLOC(leftAA[a], sizeof(float) * cm->abc->K); |
| 3876 |
ESL_ALLOC(rightAA[a], sizeof(float) * cm->abc->K); |
| 3877 |
esl_vec_FSet(leftAA[a], cm->abc->K, 0.); |
| 3878 |
esl_vec_FSet(rightAA[a], cm->abc->K, 0.); |
| 3879 |
esl_abc_FCount(cm->abc, leftAA[a], a, 1.); |
| 3880 |
esl_abc_FCount(cm->abc, rightAA[a], a, 1.); |
| 3881 |
} |
| 3882 |
leftAA[cm->abc->Kp-1] = rightAA[cm->abc->Kp-1] = NULL; |
| 3883 |
|
| 3884 |
|
| 3885 |
ESL_ALLOC(esc_vAA, sizeof(float *) * (cm->M)); |
| 3886 |
ESL_ALLOC(esc_vAA[0], sizeof(float) * ((cm->abc->Kp * nsinglets) + (cm->abc->Kp * cm->abc->Kp * npairs))); |
| 3887 |
ptr_to_start = esc_vAA[0]; |
| 3888 |
cur_cell = 0; |
| 3889 |
for(v = 0; v < cm->M; v++) { |
| 3890 |
switch(cm->sttype[v]) { |
| 3891 |
case IL_st: |
| 3892 |
case ML_st: |
| 3893 |
case IR_st: |
| 3894 |
case MR_st: |
| 3895 |
esc_vAA[v] = ptr_to_start + cur_cell; |
| 3896 |
cur_cell += cm->abc->Kp; |
| 3897 |
if (mother_map->s2o_id[v] == TRUE) { |
| 3898 |
mv = mother_map->s2o_smap[v][0]; |
| 3899 |
esl_vec_FCopy(mother_cm->oesc[mv], cm->abc->Kp, esc_vAA[v]); |
| 3900 |
} |
| 3901 |
else { |
| 3902 |
for(a = 0; a < cm->abc->K; a++) |
| 3903 |
esc_vAA[v][a] = cm->esc[v][a]; |
| 3904 |
esc_vAA[v][cm->abc->K] = IMPOSSIBLE; |
| 3905 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) |
| 3906 |
esc_vAA[v][a] = esl_abc_FAvgScore(cm->abc, a, cm->esc[v]); |
| 3907 |
esc_vAA[v][cm->abc->Kp-1] = IMPOSSIBLE; |
| 3908 |
} |
| 3909 |
break; |
| 3910 |
case MP_st: |
| 3911 |
esc_vAA[v] = ptr_to_start + cur_cell; |
| 3912 |
esl_vec_FSet(esc_vAA[v], cm->abc->Kp * cm->abc->Kp, IMPOSSIBLE); |
| 3913 |
cur_cell += cm->abc->Kp * cm->abc->Kp; |
| 3914 |
if (mother_map->s2o_id[v] == TRUE) { |
| 3915 |
mv = mother_map->s2o_smap[v][0]; |
| 3916 |
esl_vec_FCopy(mother_cm->oesc[mv], cm->abc->Kp * cm->abc->Kp, esc_vAA[v]); |
| 3917 |
} |
| 3918 |
else { |
| 3919 |
|
| 3920 |
for(a = 0; a < cm->abc->K; a++) { |
| 3921 |
for(b = 0; b < cm->abc->K; b++) { |
| 3922 |
esc_vAA[v][(a * cm->abc->Kp) + b] = cm->esc[v][(a * cm->abc->K) + b]; |
| 3923 |
} |
| 3924 |
} |
| 3925 |
|
| 3926 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3927 |
for(b = 0; b < cm->abc->K; b++) { |
| 3928 |
esc_vAA[v][(a * cm->abc->Kp) + b] = FastPairScoreLeftOnlyDegenerate(cm->abc->K, cm->esc[v], leftAA[a], b); |
| 3929 |
} |
| 3930 |
} |
| 3931 |
|
| 3932 |
for(a = 0; a < cm->abc->K; a++) { |
| 3933 |
for(b = cm->abc->K+1; b < cm->abc->Kp-1; b++) { |
| 3934 |
esc_vAA[v][(a * cm->abc->Kp) + b] = FastPairScoreRightOnlyDegenerate(cm->abc->K, cm->esc[v], rightAA[b], a); |
| 3935 |
} |
| 3936 |
} |
| 3937 |
|
| 3938 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3939 |
for(b = cm->abc->K+1; b < cm->abc->Kp-1; b++) { |
| 3940 |
esc_vAA[v][(a * cm->abc->Kp) + b] = FastPairScoreBothDegenerate(cm->abc->K, cm->esc[v], leftAA[a], rightAA[b]); |
| 3941 |
} |
| 3942 |
} |
| 3943 |
|
| 3944 |
} |
| 3945 |
break; |
| 3946 |
default: |
| 3947 |
esc_vAA[v] = NULL; |
| 3948 |
break; |
| 3949 |
} |
| 3950 |
} |
| 3951 |
for(a = 0; a < cm->abc->Kp; a++) { |
| 3952 |
if(leftAA[a] != NULL) free(leftAA[a]); |
| 3953 |
if(rightAA[a] != NULL) free(rightAA[a]); |
| 3954 |
} |
| 3955 |
free(leftAA); |
| 3956 |
free(rightAA); |
| 3957 |
return esc_vAA; |
| 3958 |
|
| 3959 |
ERROR: |
| 3960 |
cm_Fail("memory allocation error."); |
| 3961 |
return NULL; |
| 3962 |
} |
| 3963 |
|
| 3964 |
|
| 3965 |
|
| 3966 |
|
| 3967 |
|
| 3968 |
|
| 3969 |
|
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
|
| 3977 |
|
| 3978 |
|
| 3979 |
|
| 3980 |
|
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
|
| 3987 |
|
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
|
| 3996 |
|
| 3997 |
void |
| 3998 |
CP9_reconfig2sub(CP9_t *hmm, int spos, int epos, int spos_nd, |
| 3999 |
int epos_nd, double **orig_phi) |
| 4000 |
{ |
| 4001 |
|
| 4002 |
|
| 4003 |
|
| 4004 |
|
| 4005 |
|
| 4006 |
|
| 4007 |
|
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
if(spos > 1) |
| 4014 |
{ |
| 4015 |
hmm->begin[spos_nd] = 1.-((orig_phi[spos-1][HMMINSERT] * (1. - hmm->t[spos-1][CTII])) + |
| 4016 |
(orig_phi[spos ][HMMDELETE] - (orig_phi[spos-1][HMMINSERT] * hmm->t[spos-1][CTID]))); |
| 4017 |
hmm->t[spos_nd-1][CTMI] = (orig_phi[spos-1][HMMINSERT] * (1. - hmm->t[spos-1][CTII])); |
| 4018 |
hmm->t[spos_nd-1][CTMD] = orig_phi[spos ][HMMDELETE] - (orig_phi[spos-1][HMMINSERT] * hmm->t[spos-1][CTID]); |
| 4019 |
hmm->t[spos_nd-1][CTMM] = 0.; |
| 4020 |
hmm->t[spos_nd-1][CTMEL] = 0.; |
| 4021 |
hmm->t[spos_nd-1][CTDM] = 0.; |
| 4022 |
hmm->t[spos_nd-1][CTDI] = 0.; |
| 4023 |
hmm->t[spos_nd-1][CTDD] = 0.; |
| 4024 |
|
| 4025 |
hmm->bsc[spos_nd] = Prob2Score(hmm->begin[1], 1.0); |
| 4026 |
|
| 4027 |
hmm->tsc[CTMM][spos_nd-1] = -INFTY; |
| 4028 |
hmm->tsc[CTMEL][spos_nd-1] = -INFTY; |
| 4029 |
hmm->tsc[CTDM][spos_nd-1] = -INFTY; |
| 4030 |
hmm->tsc[CTDI][spos_nd-1] = -INFTY; |
| 4031 |
hmm->tsc[CTDD][spos_nd-1] = -INFTY; |
| 4032 |
|
| 4033 |
hmm->tsc[CTMI][spos_nd-1] = Prob2Score(hmm->t[spos_nd-1][CTMI], 1.0); |
| 4034 |
hmm->tsc[CTMD][spos_nd-1] = Prob2Score(hmm->t[spos_nd-1][CTMD], 1.0); |
| 4035 |
} |
| 4036 |
|
| 4037 |
if(epos < hmm->M) |
| 4038 |
{ |
| 4039 |
hmm->end[epos_nd] = hmm->t[epos][CTMM] + hmm->t[epos][CTMD]; |
| 4040 |
hmm->t[epos_nd][CTDM] += hmm->t[epos][CTDD]; |
| 4041 |
hmm->t[epos_nd][CTIM] += hmm->t[epos][CTID]; |
| 4042 |
hmm->t[epos_nd][CTMM] = 0.; |
| 4043 |
hmm->t[epos_nd][CTMEL] = 0.; |
| 4044 |
hmm->t[epos_nd][CTMD] = 0.; |
| 4045 |
hmm->t[epos_nd][CTDD] = 0.; |
| 4046 |
hmm->t[epos_nd][CTID] = 0.; |
| 4047 |
|
| 4048 |
hmm->esc[epos_nd] = Prob2Score(hmm->end[epos_nd], 1.0); |
| 4049 |
hmm->tsc[CTDM][epos_nd] = Prob2Score(hmm->t[epos_nd][CTDM], 1.0); |
| 4050 |
hmm->tsc[CTIM][epos_nd] = Prob2Score(hmm->t[epos_nd][CTIM], 1.0); |
| 4051 |
hmm->tsc[CTMM][epos_nd] = -INFTY; |
| 4052 |
hmm->tsc[CTMEL][epos_nd] = -INFTY; |
| 4053 |
hmm->tsc[CTMD][epos_nd] = -INFTY; |
| 4054 |
hmm->tsc[CTDD][epos_nd] = -INFTY; |
| 4055 |
hmm->tsc[CTID][epos_nd] = -INFTY; |
| 4056 |
} |
| 4057 |
hmm->flags |= CPLAN9_HASBITS; |
| 4058 |
|
| 4059 |
return; |
| 4060 |
} |
| 4061 |
|
| 4062 |
#if 0 |
| 4063 |
|
| 4064 |
|
| 4065 |
static void debug_print_misc_sub_cm_info(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, CP9Map_t *orig_cp9map); |
| 4066 |
static void debug_sub_cm_check_all_trans(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap); |
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
|
| 4071 |
|
| 4072 |
static void |
| 4073 |
debug_print_misc_sub_cm_info(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap, CP9Map_t *orig_cp9map) |
| 4074 |
{ |
| 4075 |
int status; |
| 4076 |
int orig_il1; |
| 4077 |
int orig_il2; |
| 4078 |
int orig_ir1; |
| 4079 |
int orig_ir2; |
| 4080 |
int orig_ss; |
| 4081 |
|
| 4082 |
char **nodetypes; |
| 4083 |
char **sttypes; |
| 4084 |
char **sides; |
| 4085 |
|
| 4086 |
int orig_n1_type; |
| 4087 |
int side_idx; |
| 4088 |
|
| 4089 |
ESL_ALLOC(nodetypes, sizeof(char *) * 8); |
| 4090 |
nodetypes[0] = "BIF"; |
| 4091 |
nodetypes[1] = "MATP"; |
| 4092 |
nodetypes[2] = "MATL"; |
| 4093 |
nodetypes[3] = "MATR"; |
| 4094 |
nodetypes[4] = "BEGL"; |
| 4095 |
nodetypes[5] = "BEGR"; |
| 4096 |
nodetypes[6] = "ROOT"; |
| 4097 |
nodetypes[7] = "END"; |
| 4098 |
|
| 4099 |
ESL_ALLOC(sttypes, sizeof(char *) * 10); |
| 4100 |
sttypes[0] = "D"; |
| 4101 |
sttypes[1] = "MP"; |
| 4102 |
sttypes[2] = "ML"; |
| 4103 |
sttypes[3] = "MR"; |
| 4104 |
sttypes[4] = "IL"; |
| 4105 |
sttypes[5] = "IR"; |
| 4106 |
sttypes[6] = "S"; |
| 4107 |
sttypes[7] = "E"; |
| 4108 |
sttypes[8] = "B"; |
| 4109 |
sttypes[9] = "EL"; |
| 4110 |
|
| 4111 |
ESL_ALLOC(sides, sizeof(char *) * 3); |
| 4112 |
sides[0] = "L"; |
| 4113 |
sides[1] = "R"; |
| 4114 |
sides[2] = "N"; |
| 4115 |
|
| 4116 |
|
| 4117 |
orig_il1 = submap->s2o_smap[1][0]; |
| 4118 |
orig_il2 = submap->s2o_smap[1][1]; |
| 4119 |
orig_ir1 = submap->s2o_smap[2][0]; |
| 4120 |
orig_ir2 = submap->s2o_smap[2][1]; |
| 4121 |
|
| 4122 |
|
| 4123 |
|
| 4124 |
|
| 4125 |
if(orig_il2 != -1) |
| 4126 |
{ |
| 4127 |
if(orig_cm->sttype[orig_il1+1] == E_st) |
| 4128 |
orig_il1 = orig_il2; |
| 4129 |
else if(orig_cm->sttype[orig_il2+1] == E_st) |
| 4130 |
{ |
| 4131 |
|
| 4132 |
} |
| 4133 |
else |
| 4134 |
cm_Fail("ERROR, can't determine which state was detached in debug_print_misc_sub_cm_info\n"); |
| 4135 |
} |
| 4136 |
if(orig_ir2 != -1) |
| 4137 |
{ |
| 4138 |
if(orig_cm->sttype[orig_ir1+1] == E_st) |
| 4139 |
orig_ir1 = orig_ir2; |
| 4140 |
else if(orig_cm->sttype[orig_ir2+1] == E_st) |
| 4141 |
{ |
| 4142 |
|
| 4143 |
} |
| 4144 |
else |
| 4145 |
cm_Fail("ERROR, can't determine which state was detached in debug_print_misc_sub_cm_info\n"); |
| 4146 |
} |
| 4147 |
|
| 4148 |
|
| 4149 |
|
| 4150 |
|
| 4151 |
printf("10.16.06 IL1: %3d %4s %2s | start: %3d | end: %3d\n", orig_il1, nodetypes[(int) orig_cm->ndtype[orig_cm->ndidx[orig_il1]]], sttypes[(int) orig_cm->sttype[orig_il1]], submap->spos, submap->epos); |
| 4152 |
|
| 4153 |
if(sub_cm->ndtype[1] == BIF_nd) |
| 4154 |
{ |
| 4155 |
orig_n1_type = 0; |
| 4156 |
} |
| 4157 |
else |
| 4158 |
{ |
| 4159 |
orig_n1_type = orig_cm->ndtype[orig_cm->ndidx[(submap->s2o_smap[3][0])]]; |
| 4160 |
} |
| 4161 |
|
| 4162 |
if(orig_n1_type == MATP_nd && sub_cm->ndtype[1] != MATR_nd) |
| 4163 |
{ |
| 4164 |
if(orig_cp9map->nd2lpos[orig_cm->ndidx[(submap->s2o_smap[3][0])]] == submap->spos) |
| 4165 |
side_idx = 0; |
| 4166 |
else if(orig_cp9map->nd2rpos[orig_cm->ndidx[(submap->s2o_smap[3][0])]] == submap->spos) |
| 4167 |
side_idx = 1; |
| 4168 |
else |
| 4169 |
cm_Fail("ERROR MATP confusion! orig_cm node: %d | left: %d | right: %d | submap->spos: %d\n", (orig_cm->ndidx[(submap->s2o_smap[3][0])]), (orig_cp9map->nd2lpos[orig_cm->ndidx[(submap->s2o_smap[3][0])]]), (orig_cp9map->nd2rpos[orig_cm->ndidx[(submap->s2o_smap[3][0])]]), submap->spos); |
| 4170 |
} |
| 4171 |
else if (orig_n1_type == MATP_nd && sub_cm->ndtype[1] == MATR_nd) |
| 4172 |
{ |
| 4173 |
if(orig_cp9map->nd2lpos[orig_cm->ndidx[(submap->s2o_smap[3][0])]] == submap->epos) |
| 4174 |
side_idx = 0; |
| 4175 |
else if(orig_cp9map->nd2rpos[orig_cm->ndidx[(submap->s2o_smap[3][0])]] == submap->epos) |
| 4176 |
side_idx = 1; |
| 4177 |
else |
| 4178 |
cm_Fail("ERROR MATP confusion! orig_cm node: %d | left: %d | right: %d | submap->spos: %d\n", (orig_cm->ndidx[(submap->s2o_smap[3][0])]), (orig_cp9map->nd2lpos[orig_cm->ndidx[(submap->s2o_smap[3][0])]]), (orig_cp9map->nd2rpos[orig_cm->ndidx[(submap->s2o_smap[3][0])]]), submap->spos); |
| 4179 |
} |
| 4180 |
else |
| 4181 |
{ |
| 4182 |
side_idx = 2; |
| 4183 |
} |
| 4184 |
printf("10.16.06 IR1: %3d %4s %2s | sub-n1: %4s | orig-n1: %4s%1s | case: ", orig_ir1, nodetypes[(int) orig_cm->ndtype[orig_cm->ndidx[orig_ir1]]], sttypes[(int) orig_cm->sttype[orig_ir1]], nodetypes[(int) sub_cm->ndtype[1]], nodetypes[(int) orig_n1_type], sides[side_idx]); |
| 4185 |
|
| 4186 |
|
| 4187 |
orig_ss = submap->s2o_smap[3][0]; |
| 4188 |
|
| 4189 |
|
| 4190 |
if((orig_il1 < orig_ir1) && (orig_ir1 < orig_ss)) |
| 4191 |
printf("1A\n"); |
| 4192 |
if((orig_il1 < orig_ss) && (orig_ss < orig_ir1)) |
| 4193 |
printf("1B\n"); |
| 4194 |
if((orig_ss < orig_il1) && (orig_il1 < orig_ir1)) |
| 4195 |
printf("1C\n"); |
| 4196 |
|
| 4197 |
if((orig_ir1 < orig_il1) && (orig_il1 < orig_ss)) |
| 4198 |
printf("2A\n"); |
| 4199 |
if((orig_ir1 < orig_ss) && (orig_ss < orig_il1)) |
| 4200 |
printf("2B\n"); |
| 4201 |
if((orig_ss < orig_ir1) && (orig_ir1 < orig_il1)) |
| 4202 |
printf("2C\n"); |
| 4203 |
|
| 4204 |
printf("\n"); |
| 4205 |
|
| 4206 |
|
| 4207 |
int ilmap, irmap; |
| 4208 |
int ildual, irdual; |
| 4209 |
int iloff, iroff; |
| 4210 |
int other_insert_il; |
| 4211 |
int other_insert_ir; |
| 4212 |
|
| 4213 |
if(orig_cm->sttype[orig_il1] == IL_st) |
| 4214 |
ilmap = 0; |
| 4215 |
else |
| 4216 |
ilmap = 1; |
| 4217 |
if(orig_cm->sttype[orig_ir1] == IL_st) |
| 4218 |
irmap = 0; |
| 4219 |
else |
| 4220 |
irmap = 1; |
| 4221 |
|
| 4222 |
if(orig_cm->ndtype[orig_cm->ndidx[orig_il1]] == MATP_nd || |
| 4223 |
orig_cm->ndtype[orig_cm->ndidx[orig_il1]] == ROOT_nd) |
| 4224 |
ildual = TRUE; |
| 4225 |
else |
| 4226 |
ildual = FALSE; |
| 4227 |
if(orig_cm->ndtype[orig_cm->ndidx[orig_ir1]] == MATP_nd || |
| 4228 |
orig_cm->ndtype[orig_cm->ndidx[orig_ir1]] == ROOT_nd) |
| 4229 |
irdual = TRUE; |
| 4230 |
else |
| 4231 |
irdual = FALSE; |
| 4232 |
|
| 4233 |
iloff = -1; |
| 4234 |
if(ildual == TRUE) |
| 4235 |
{ |
| 4236 |
|
| 4237 |
|
| 4238 |
|
| 4239 |
if(ilmap == 0) |
| 4240 |
other_insert_il = orig_il1 + 1; |
| 4241 |
else |
| 4242 |
other_insert_il = orig_il1 - 1; |
| 4243 |
if(submap->o2s_smap[other_insert_il][0] == -1 && |
| 4244 |
submap->o2s_smap[other_insert_il][1] == -1) |
| 4245 |
iloff = TRUE; |
| 4246 |
else |
| 4247 |
iloff = FALSE; |
| 4248 |
} |
| 4249 |
|
| 4250 |
iroff = -1; |
| 4251 |
if(irdual == TRUE) |
| 4252 |
{ |
| 4253 |
if(irmap == 0) |
| 4254 |
other_insert_ir = orig_ir1 + 1; |
| 4255 |
else |
| 4256 |
other_insert_ir = orig_ir1 - 1; |
| 4257 |
if(submap->o2s_smap[other_insert_ir][0] == -1 && |
| 4258 |
submap->o2s_smap[other_insert_ir][1] == -1) |
| 4259 |
iroff = TRUE; |
| 4260 |
else |
| 4261 |
iroff = FALSE; |
| 4262 |
} |
| 4263 |
|
| 4264 |
CMEmitMap_t *orig_emap; |
| 4265 |
int other_cc_il, other_cc_ir; |
| 4266 |
orig_emap = CreateEmitMap(orig_cm); |
| 4267 |
other_cc_il = -1; |
| 4268 |
other_cc_ir = -1; |
| 4269 |
if(ildual == TRUE) |
| 4270 |
{ |
| 4271 |
if(orig_cm->sttype[other_insert_il] == IL_st) |
| 4272 |
{ |
| 4273 |
other_cc_il = orig_emap->lpos[orig_cm->ndidx[other_insert_il]] + 1; |
| 4274 |
if(other_cc_il > submap->spos) |
| 4275 |
cm_Fail("ERROR FUNKY\n"); |
| 4276 |
ildual = 4; |
| 4277 |
} |
| 4278 |
else |
| 4279 |
{ |
| 4280 |
other_cc_il = orig_emap->rpos[orig_cm->ndidx[other_insert_il]] - 1; |
| 4281 |
if(other_cc_il < submap->epos) |
| 4282 |
ildual = 1; |
| 4283 |
if(other_cc_il == submap->epos) |
| 4284 |
ildual = 2; |
| 4285 |
if(other_cc_il > submap->epos) |
| 4286 |
ildual = 3; |
| 4287 |
} |
| 4288 |
} |
| 4289 |
|
| 4290 |
if(irdual == TRUE) |
| 4291 |
{ |
| 4292 |
if(orig_cm->sttype[other_insert_ir] == IL_st) |
| 4293 |
{ |
| 4294 |
other_cc_ir = orig_emap->lpos[orig_cm->ndidx[other_insert_ir]] + 1; |
| 4295 |
if(other_cc_ir > submap->spos) |
| 4296 |
irdual = 1; |
| 4297 |
if(other_cc_ir == submap->spos) |
| 4298 |
irdual = 2; |
| 4299 |
if(other_cc_ir < submap->spos) |
| 4300 |
irdual = 3; |
| 4301 |
} |
| 4302 |
else |
| 4303 |
{ |
| 4304 |
other_cc_ir = orig_emap->rpos[orig_cm->ndidx[other_insert_ir]] - 1; |
| 4305 |
if(other_cc_ir < submap->epos) |
| 4306 |
cm_Fail("ERROR FUNKY\n"); |
| 4307 |
irdual = 4; |
| 4308 |
} |
| 4309 |
} |
| 4310 |
|
| 4311 |
|
| 4312 |
printf("10.17.06 ilmap: %5s ildual: %2d iloff: %2d irmap: %5s irdual: %2d iroff: %2d subn1: %4s orign1: %4s%1s\n", sides[ilmap], ildual, iloff, sides[irmap], irdual, iroff, nodetypes[(int) sub_cm->ndtype[1]], nodetypes[(int) orig_n1_type], sides[side_idx]); |
| 4313 |
|
| 4314 |
int start_flag; |
| 4315 |
int v; |
| 4316 |
int vend; |
| 4317 |
|
| 4318 |
if(orig_il1 < orig_ir1) |
| 4319 |
{ |
| 4320 |
v = orig_il1; |
| 4321 |
vend = orig_ir1; |
| 4322 |
} |
| 4323 |
else |
| 4324 |
{ |
| 4325 |
v = orig_ir1; |
| 4326 |
vend = orig_il1; |
| 4327 |
} |
| 4328 |
start_flag = 0; |
| 4329 |
for(; v <= vend; v++) |
| 4330 |
if(orig_cm->sttype[v] == S_st) |
| 4331 |
start_flag = 1; |
| 4332 |
return; |
| 4333 |
|
| 4334 |
ERROR: |
| 4335 |
cm_Fail("Memory allocation error."); |
| 4336 |
} |
| 4337 |
|
| 4338 |
|
| 4339 |
|
| 4340 |
|
| 4341 |
|
| 4342 |
void |
| 4343 |
debug_sub_cm_check_all_trans(CM_t *orig_cm, CM_t *sub_cm, CMSubMap_t *submap) |
| 4344 |
{ |
| 4345 |
int status; |
| 4346 |
int nd; |
| 4347 |
int v; |
| 4348 |
int y, yoffset; |
| 4349 |
float sum, ndsum; |
| 4350 |
int orig_nd, orig_v1, orig_v2; |
| 4351 |
|
| 4352 |
char **nodetypes; |
| 4353 |
ESL_ALLOC(nodetypes, sizeof(char *) * 8); |
| 4354 |
nodetypes[0] = "BIF"; |
| 4355 |
nodetypes[1] = "MATP"; |
| 4356 |
nodetypes[2] = "MATL"; |
| 4357 |
nodetypes[3] = "MATR"; |
| 4358 |
nodetypes[4] = "BEGL"; |
| 4359 |
nodetypes[5] = "BEGR"; |
| 4360 |
nodetypes[6] = "ROOT"; |
| 4361 |
nodetypes[7] = "END"; |
| 4362 |
|
| 4363 |
char **sttypes; |
| 4364 |
ESL_ALLOC(sttypes, sizeof(char *) * 10); |
| 4365 |
sttypes[0] = "D"; |
| 4366 |
sttypes[1] = "MP"; |
| 4367 |
sttypes[2] = "ML"; |
| 4368 |
sttypes[3] = "MR"; |
| 4369 |
sttypes[4] = "IL"; |
| 4370 |
sttypes[5] = "IR"; |
| 4371 |
sttypes[6] = "S"; |
| 4372 |
sttypes[7] = "E"; |
| 4373 |
sttypes[8] = "B"; |
| 4374 |
sttypes[9] = "EL"; |
| 4375 |
|
| 4376 |
for(nd = 0; nd < sub_cm->nodes; nd++) |
| 4377 |
{ |
| 4378 |
sum = 0.; |
| 4379 |
if(sub_cm->ndtype[nd] != END_nd && sub_cm->ndtype[nd] != BIF_nd) |
| 4380 |
{ |
| 4381 |
ndsum = 0.; |
| 4382 |
v = sub_cm->nodemap[nd]; |
| 4383 |
while(sub_cm->ndidx[v] == nd && sub_cm->sttype[v] != IL_st && sub_cm->sttype[v] != IR_st) |
| 4384 |
{ |
| 4385 |
sum = 0.; |
| 4386 |
for(y = sub_cm->cfirst[v]; y < sub_cm->cfirst[v]+sub_cm->cnum[v]; y++) |
| 4387 |
{ |
| 4388 |
yoffset = y - sub_cm->cfirst[v]; |
| 4389 |
printf("\t\tsub_cm->t[%3d][%3d]: %f\n", v, yoffset, sub_cm->t[v][yoffset]); |
| 4390 |
sum += sub_cm->t[v][yoffset]; |
| 4391 |
} |
| 4392 |
orig_v1 = submap->s2o_smap[v][0]; |
| 4393 |
orig_v2 = submap->s2o_smap[v][1]; |
| 4394 |
orig_nd = orig_cm->ndidx[orig_v1]; |
| 4395 |
if(sub_cm->ndtype[nd+1] != END_nd) |
| 4396 |
{ |
| 4397 |
if(orig_v2 != -1) |
| 4398 |
printf("sum t[%4d %4s %2s %2s] nd: %4d: %f\n", v, nodetypes[(int) orig_cm->ndtype[orig_nd]], sttypes[(int) orig_cm->sttype[orig_v1]], sttypes[(int) orig_cm->sttype[orig_v2]], nd, sum); |
| 4399 |
else |
| 4400 |
printf("sum t[%4d %4s %2s ] nd: %4d: %f\n", v, nodetypes[(int) orig_cm->ndtype[orig_nd]], sttypes[(int) orig_cm->sttype[orig_v1]], nd, sum); |
| 4401 |
} |
| 4402 |
ndsum += sum; |
| 4403 |
v++; |
| 4404 |
} |
| 4405 |
if(sub_cm->ndtype[nd+1] != END_nd) |
| 4406 |
printf("\tndsum t nd (%4s): %4d: %f\n", nodetypes[(int) orig_cm->ndtype[orig_nd]], nd, ndsum); |
| 4407 |
} |
| 4408 |
} |
| 4409 |
free(nodetypes); |
| 4410 |
free(sttypes); |
| 4411 |
return; |
| 4412 |
|
| 4413 |
ERROR: |
| 4414 |
cm_Fail("Memory allocation error."); |
| 4415 |
} |
| 4416 |
#endif |