| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <memory.h> |
|---|
| 4 | #include <malloc.h> |
|---|
| 5 | #include <string.h> |
|---|
| 6 | #include <math.h> |
|---|
| 7 | |
|---|
| 8 | #include <arbdb.h> |
|---|
| 9 | #include <arbdbt.h> |
|---|
| 10 | |
|---|
| 11 | #include "ac.hxx" |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | //********************************************************************* |
|---|
| 22 | // |
|---|
| 23 | // class AC_SEQUENCE_LIST Konstruktor/Destruktor |
|---|
| 24 | // |
|---|
| 25 | //********************************************************************* |
|---|
| 26 | AC_SEQUENCE_LIST::AC_SEQUENCE_LIST() { |
|---|
| 27 | sequences = NULL; // Struct an dem die AC_SEQUENCE haengen |
|---|
| 28 | leftend = NULL; |
|---|
| 29 | rightend = NULL; |
|---|
| 30 | nsequences = 0; |
|---|
| 31 | max_relationship = 0.0; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | AC_SEQUENCE_LIST::~AC_SEQUENCE_LIST() { |
|---|
| 37 | } |
|---|
| 38 | //********************************************************************* |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | //********************************************************************* |
|---|
| 42 | // |
|---|
| 43 | // class AC_SEQUENCE_LIST:: remove_sequence() |
|---|
| 44 | // |
|---|
| 45 | // gibt den Speicher der Liste wieder frei |
|---|
| 46 | // |
|---|
| 47 | //********************************************************************* |
|---|
| 48 | void AC_SEQUENCE_LIST::remove_sequence(AC_SEQUENCE_INFO *sequence) { |
|---|
| 49 | |
|---|
| 50 | delete(sequence->seq); |
|---|
| 51 | sequence->seq = NULL; |
|---|
| 52 | |
|---|
| 53 | free(sequence->name); |
|---|
| 54 | sequence->name = NULL; |
|---|
| 55 | |
|---|
| 56 | } // end AC_SEQUENCE_LIST::remove_sequence() |
|---|
| 57 | //********************************************************************* |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | //********************************************************************* |
|---|
| 61 | // |
|---|
| 62 | // class AC_SEQUENCE_LIST:: remove_sequence_list() |
|---|
| 63 | // |
|---|
| 64 | // gibt den Speicher der Liste wieder frei |
|---|
| 65 | // |
|---|
| 66 | //********************************************************************* |
|---|
| 67 | void AC_SEQUENCE_LIST::remove_sequence_list(AC_SEQUENCE_INFO *sequence_list) { |
|---|
| 68 | |
|---|
| 69 | AC_SEQUENCE_INFO *ptr, *actual_sequence; |
|---|
| 70 | |
|---|
| 71 | if(sequence_list) { |
|---|
| 72 | for(ptr = sequence_list; ptr; ) { //die naechsten Seqs |
|---|
| 73 | actual_sequence = ptr; |
|---|
| 74 | ptr = ptr->next; |
|---|
| 75 | remove_sequence(actual_sequence); //loesche Sequenz |
|---|
| 76 | free (actual_sequence); //loesche Sequenzinfo = Strukt |
|---|
| 77 | } //endfor |
|---|
| 78 | sequence_list = NULL; |
|---|
| 79 | } //endif |
|---|
| 80 | |
|---|
| 81 | } // end AC_SEQUENCE_LIST::remove_sequence_list() |
|---|
| 82 | //********************************************************************* |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | //********************************************************************* |
|---|
| 88 | // class AC_SEQUENCE_LIST : member_function insert() |
|---|
| 89 | // - haengt neues listenelement am Anfang der liste ein |
|---|
| 90 | // oder |
|---|
| 91 | // - haengt das erste listenelement an die ROOT/I_NODE |
|---|
| 92 | //********************************************************************* |
|---|
| 93 | void AC_SEQUENCE_LIST::insert( AC_SEQUENCE_INFO *new_seq) { |
|---|
| 94 | |
|---|
| 95 | new_seq->next = this->sequences; |
|---|
| 96 | if (this->sequences) this->sequences->previous = new_seq; |
|---|
| 97 | this->sequences = new_seq; |
|---|
| 98 | new_seq->previous = NULL; |
|---|
| 99 | |
|---|
| 100 | this->nsequences = ++this->nsequences; |
|---|
| 101 | |
|---|
| 102 | } // end AC_SEQUENCE_LIST::insert() |
|---|
| 103 | //********************************************************************* |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | //********************************************************************* |
|---|
| 109 | // |
|---|
| 110 | // class AC_SEQUENCE_LIST::get_high_quality_sequence() |
|---|
| 111 | // |
|---|
| 112 | // liefert die Sequence mit der hoechsten Qualitaet. |
|---|
| 113 | // Sie nimmt im Zweifelsfall die erste mit der Hoechsten.... |
|---|
| 114 | // |
|---|
| 115 | //********************************************************************* |
|---|
| 116 | AC_SEQUENCE_INFO *AC_SEQUENCE_LIST::get_high_quality_sequence() { |
|---|
| 117 | |
|---|
| 118 | long maximum = 0; |
|---|
| 119 | AC_SEQUENCE_INFO *highest_quality_sequence; |
|---|
| 120 | AC_SEQUENCE_INFO *ac_sequence_info; |
|---|
| 121 | AC_SEQUENCE_INFO *ptr; |
|---|
| 122 | |
|---|
| 123 | highest_quality_sequence = ac_sequence_info = sequences; |
|---|
| 124 | |
|---|
| 125 | #ifdef COMMENT |
|---|
| 126 | long count = 0; |
|---|
| 127 | printf("Wait a minute -> I'm searching for the highest quality sequence...\n\n"); |
|---|
| 128 | #endif |
|---|
| 129 | |
|---|
| 130 | for( ptr = ac_sequence_info ; ptr ; ptr = ptr->next ) |
|---|
| 131 | { |
|---|
| 132 | if( maximum < ptr->seq->quality ) { |
|---|
| 133 | maximum = ptr->seq->quality; |
|---|
| 134 | highest_quality_sequence = ptr; |
|---|
| 135 | } // endif |
|---|
| 136 | |
|---|
| 137 | #ifdef COMMENT |
|---|
| 138 | if (count % 1000 == 0) { |
|---|
| 139 | printf("."); |
|---|
| 140 | } |
|---|
| 141 | count++; |
|---|
| 142 | #endif |
|---|
| 143 | |
|---|
| 144 | } // endfor |
|---|
| 145 | |
|---|
| 146 | //printf("\n\nMaxQuality : %d\n\n", maximum); |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | return highest_quality_sequence; |
|---|
| 150 | |
|---|
| 151 | } // end AC_SEQUENCE_LIST::get_high_quality_sequence() |
|---|
| 152 | //********************************************************************* |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | //********************************************************************* |
|---|
| 158 | // |
|---|
| 159 | // class AC_SEQUENCE_LIST::determine_distances_to() |
|---|
| 160 | // |
|---|
| 161 | // bestimmt die reale_Distanz und |
|---|
| 162 | // bestimmt die relative Distanz |
|---|
| 163 | // zwischen zwei Sequenzen. |
|---|
| 164 | // |
|---|
| 165 | //********************************************************************* |
|---|
| 166 | void AC_SEQUENCE_LIST::determine_distances_to(AC_SEQUENCE_INFO *reverence_seq, |
|---|
| 167 | AC_SEQUENCE_INFO_STATE reference_state) { |
|---|
| 168 | |
|---|
| 169 | AC_SEQUENCE_INFO *ac_sequence_info; |
|---|
| 170 | AC_SEQUENCE_INFO *ptr; |
|---|
| 171 | AC_SEQUENCE *that; |
|---|
| 172 | long real_distance; |
|---|
| 173 | double relative_distance; |
|---|
| 174 | |
|---|
| 175 | //-------------------------------------------- hole referenzsequenz |
|---|
| 176 | that = reverence_seq->seq; |
|---|
| 177 | that->sequence = GB_read_string(that->gb_data); // kopiert Reverenzsequenz |
|---|
| 178 | //----------------------------------------------- laufe liste durch |
|---|
| 179 | ac_sequence_info = this->sequences; |
|---|
| 180 | for(ptr = ac_sequence_info; ptr ; ptr = ptr->next) { |
|---|
| 181 | if(ptr->state!=reference_state) { |
|---|
| 182 | |
|---|
| 183 | //---------------------------------------- bestimme Distanz |
|---|
| 184 | relative_distance = ptr->seq->get_distance(that); |
|---|
| 185 | //----------------------------------------------- merks dir |
|---|
| 186 | |
|---|
| 187 | if(reference_state == LEFTEND) { |
|---|
| 188 | ptr->relative_leftdistance = relative_distance; |
|---|
| 189 | } else { // RIGHTEND |
|---|
| 190 | ptr->relative_rightdistance = relative_distance; |
|---|
| 191 | } // endelse |
|---|
| 192 | |
|---|
| 193 | } // endif |
|---|
| 194 | } // endfor |
|---|
| 195 | delete that->sequence; |
|---|
| 196 | that->sequence = NULL; // loescht Reverenzsequenz |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | } // end AC_SEQUENCE_LIST::determine_distances_to() |
|---|
| 200 | //********************************************************************* |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | //********************************************************************* |
|---|
| 205 | // |
|---|
| 206 | // class AC_SEQUENCE_LIST::get_seq_with_max_dist_to() |
|---|
| 207 | // |
|---|
| 208 | // liefert die erste Sequence mit |
|---|
| 209 | // dem groessten Abstand |
|---|
| 210 | // bei |
|---|
| 211 | // der groessten Qualitaet |
|---|
| 212 | // |
|---|
| 213 | // also MAX{ Abstand * Qualitaet } |
|---|
| 214 | // |
|---|
| 215 | //********************************************************************* |
|---|
| 216 | AC_SEQUENCE_INFO *AC_SEQUENCE_LIST::get_seq_with_max_dist_to() { |
|---|
| 217 | |
|---|
| 218 | long maxvalue = 0; |
|---|
| 219 | long product = 0; |
|---|
| 220 | AC_SEQUENCE_INFO *seq_with_max_dist; |
|---|
| 221 | AC_SEQUENCE_INFO *ac_sequence_info; |
|---|
| 222 | AC_SEQUENCE_INFO *ptr; |
|---|
| 223 | |
|---|
| 224 | ac_sequence_info = this->sequences; |
|---|
| 225 | |
|---|
| 226 | for( ptr = ac_sequence_info ; ptr ; ptr = ptr->next ) |
|---|
| 227 | { |
|---|
| 228 | product = ptr->relative_leftdistance * ptr->seq->quality; |
|---|
| 229 | if( maxvalue <= product ) { |
|---|
| 230 | maxvalue = product; |
|---|
| 231 | seq_with_max_dist = ptr; |
|---|
| 232 | } // endif |
|---|
| 233 | } // endfor |
|---|
| 234 | |
|---|
| 235 | if( 0 == maxvalue ) seq_with_max_dist = NULL; |
|---|
| 236 | |
|---|
| 237 | return seq_with_max_dist; |
|---|
| 238 | |
|---|
| 239 | } // end AC_SEQUENCE_LIST::get_seq_with_max_dist_to() |
|---|
| 240 | //********************************************************************* |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | //********************************************************************* |
|---|
| 244 | // |
|---|
| 245 | // class AC_SEQUENCE_LIST::determine_basepoints() |
|---|
| 246 | // |
|---|
| 247 | // |
|---|
| 248 | // betrachte die Kanten vom Leftend zum Rightend, |
|---|
| 249 | // der Abstand relative_leftdistance vom Rightend |
|---|
| 250 | // ist die Summe der Kanten. |
|---|
| 251 | // |
|---|
| 252 | // berechne ueber ein Gleichungssystem den Schnittpunkt |
|---|
| 253 | // der aktuellen Sequenz mit obiger Gerade. |
|---|
| 254 | // |
|---|
| 255 | // |
|---|
| 256 | // |
|---|
| 257 | //********************************************************************* |
|---|
| 258 | void AC_SEQUENCE_LIST::determine_basepoints() { |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | AC_SEQUENCE_INFO *ac_sequence_info; |
|---|
| 262 | AC_SEQUENCE_INFO *ptr; |
|---|
| 263 | double baseline, basepoint; |
|---|
| 264 | double li, re; |
|---|
| 265 | |
|---|
| 266 | ac_sequence_info = this->sequences; |
|---|
| 267 | |
|---|
| 268 | baseline = this->rightend->relative_leftdistance; // baseline = Abstand zwischen |
|---|
| 269 | // Leftend und Rightend |
|---|
| 270 | #ifdef GNUPLOT_relationship |
|---|
| 271 | |
|---|
| 272 | // printf("\n\nBaseline : %f", baseline*100); |
|---|
| 273 | printf("\n#GNUPLOT Basepoints : \n\n"); |
|---|
| 274 | #endif |
|---|
| 275 | |
|---|
| 276 | for( ptr = ac_sequence_info ; ptr ; ptr = ptr->next ) |
|---|
| 277 | { |
|---|
| 278 | li = ptr->relative_leftdistance; |
|---|
| 279 | re = ptr->relative_rightdistance; |
|---|
| 280 | basepoint = (baseline - (baseline - li + re)/2) * 100; |
|---|
| 281 | if( basepoint < 0 ) basepoint = 0; // kommt vor!! |
|---|
| 282 | if(100 < basepoint ) basepoint = 100; // kommt vor!! |
|---|
| 283 | ptr->relationship = basepoint; |
|---|
| 284 | |
|---|
| 285 | #ifdef GNUPLOT_relationship |
|---|
| 286 | printf("%f\n",ptr->relationship); |
|---|
| 287 | // printf("%f ",ptr->relationship); |
|---|
| 288 | #endif |
|---|
| 289 | |
|---|
| 290 | } //endfor |
|---|
| 291 | |
|---|
| 292 | } // end AC_SEQUENCE_LIST::determine_basepoints() |
|---|
| 293 | //********************************************************************* |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | //********************************************************************* |
|---|
| 299 | // |
|---|
| 300 | // class AC_SEQUENCE_LIST::reset_AC_SEQUENCE_INFO_struct_values() |
|---|
| 301 | // |
|---|
| 302 | // Setzt folgende Werte im Struct AC_SEQUENCE_INFO auf die |
|---|
| 303 | // Default-Werte zurueck: |
|---|
| 304 | // AC_SEQUENCE_INFO_STATE state, |
|---|
| 305 | // long real_leftdistance; |
|---|
| 306 | // double relative_leftdistance; |
|---|
| 307 | // long real_rightdistance; |
|---|
| 308 | // double relative_rightdistance; |
|---|
| 309 | // double relationship; |
|---|
| 310 | // |
|---|
| 311 | //********************************************************************* |
|---|
| 312 | void AC_SEQUENCE_LIST::reset_AC_SEQUENCE_INFO_struct_values() { |
|---|
| 313 | |
|---|
| 314 | AC_SEQUENCE_INFO *ac_sequence_info; |
|---|
| 315 | AC_SEQUENCE_INFO *ptr; |
|---|
| 316 | |
|---|
| 317 | ac_sequence_info = sequences; |
|---|
| 318 | |
|---|
| 319 | for(ptr = ac_sequence_info; ptr; ptr = ptr->next ) { |
|---|
| 320 | ptr->state = ORDINARY; |
|---|
| 321 | ptr->real_leftdistance = 0; |
|---|
| 322 | ptr->relative_leftdistance = 0.0; |
|---|
| 323 | ptr->real_rightdistance = 0; |
|---|
| 324 | ptr->relative_rightdistance = 0.0; |
|---|
| 325 | ptr->relationship = 0; |
|---|
| 326 | } // endfor |
|---|
| 327 | |
|---|
| 328 | } // end AC_SEQUENCE_LIST::reset_AC_SEQUENCE_INFO_struct_values() |
|---|
| 329 | //********************************************************************* |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
|---|
| 340 | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
|---|
| 341 | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | //********************************************************************* |
|---|
| 345 | // |
|---|
| 346 | // class AC_TREE Konstruktor/Destruktor |
|---|
| 347 | // |
|---|
| 348 | //********************************************************************* |
|---|
| 349 | AC_TREE::AC_TREE() { |
|---|
| 350 | node_state = I_NODE; // LEAF oder MASTER |
|---|
| 351 | left = NULL; |
|---|
| 352 | right = NULL; |
|---|
| 353 | |
|---|
| 354 | breakcondition_min_sequencenumber = 1; |
|---|
| 355 | breakcondition_relationship_distance = 1; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | |
|---|
| 359 | AC_TREE::~AC_TREE() { |
|---|
| 360 | } |
|---|
| 361 | //********************************************************************* |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | //********************************************************************* |
|---|
| 368 | // |
|---|
| 369 | // class AC_TREE:: remove_tree() |
|---|
| 370 | // |
|---|
| 371 | // hier wird rekursiv der Clusterbaum geloescht |
|---|
| 372 | // |
|---|
| 373 | //********************************************************************* |
|---|
| 374 | void AC_TREE::remove_tree() { |
|---|
| 375 | |
|---|
| 376 | AC_SEQUENCE_INFO *sequence_list; |
|---|
| 377 | |
|---|
| 378 | if(this) { |
|---|
| 379 | |
|---|
| 380 | sequence_list = this->sequences; |
|---|
| 381 | if(sequence_list) { |
|---|
| 382 | remove_sequence_list(sequence_list); |
|---|
| 383 | } |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | if(this->left) this->left->remove_tree(); |
|---|
| 387 | if(this->right) this->right->remove_tree(); |
|---|
| 388 | free (this); |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | } // end AC_TREE::remove_tree() |
|---|
| 392 | //********************************************************************* |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | //********************************************************************* |
|---|
| 399 | // |
|---|
| 400 | // class AC_TREE::print_tree() |
|---|
| 401 | // |
|---|
| 402 | // hier wird rekursiv der Clusterbaum rausgeschrieben |
|---|
| 403 | // |
|---|
| 404 | //********************************************************************* |
|---|
| 405 | void AC_TREE::print_tree() { |
|---|
| 406 | |
|---|
| 407 | AC_SEQUENCE_INFO *ptr; |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | if(this) { |
|---|
| 411 | printf("nodestate: "); |
|---|
| 412 | if(node_state == I_NODE) printf("*** I_NODE\n"); |
|---|
| 413 | else if(node_state == LEAF) printf(">>> LEAF\n"); |
|---|
| 414 | if(this->sequences) { |
|---|
| 415 | for(ptr = this->sequences; ptr; ptr = ptr->next) { //die naechsten Seqs |
|---|
| 416 | printf(" Seqnumber: %d '%s'\n", ptr->number, ptr->name); |
|---|
| 417 | } //endfor |
|---|
| 418 | printf("\n\n"); |
|---|
| 419 | |
|---|
| 420 | } |
|---|
| 421 | } |
|---|
| 422 | if(this->left) this->left->print_tree(); |
|---|
| 423 | if(this->right) this->right->print_tree(); |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | } // end AC_TREE::print_tree() |
|---|
| 428 | //********************************************************************* |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | //********************************************************************* |
|---|
| 433 | // |
|---|
| 434 | // class AC_TREE::print_formated_dbtree() |
|---|
| 435 | // |
|---|
| 436 | // hier wird rekursiv der Clusterbaum rausgeschrieben |
|---|
| 437 | // und das in dem wunderbaren ARB-Format |
|---|
| 438 | // (Knoten,Knoten) oder so ?? |
|---|
| 439 | // |
|---|
| 440 | //********************************************************************* |
|---|
| 441 | void AC_TREE::print_formated_dbtree() { |
|---|
| 442 | |
|---|
| 443 | AC_SEQUENCE_INFO *ptr; |
|---|
| 444 | |
|---|
| 445 | if(this->node_state == I_NODE) { |
|---|
| 446 | printf("\n("); |
|---|
| 447 | this->left->print_formated_dbtree(); |
|---|
| 448 | |
|---|
| 449 | if( (this->right->node_state == I_NODE) || |
|---|
| 450 | ( (this->right->node_state == LEAF) && |
|---|
| 451 | (this->right->sequences != NULL) ) ) { |
|---|
| 452 | printf(","); |
|---|
| 453 | this->right->print_formated_dbtree(); |
|---|
| 454 | } |
|---|
| 455 | printf("\n)"); |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | if(this->node_state == LEAF) { |
|---|
| 459 | if(this->sequences) { |
|---|
| 460 | ptr = this->sequences; |
|---|
| 461 | |
|---|
| 462 | printf("\n '%s'", ptr->name); //schreibe erste Seq |
|---|
| 463 | printf(" :0.00001"); |
|---|
| 464 | ptr = ptr->next; |
|---|
| 465 | |
|---|
| 466 | for(ptr; ptr; ptr = ptr->next) { //die naechsten Seqs |
|---|
| 467 | printf(",\n '%s'", ptr->name); |
|---|
| 468 | printf(" :0.00001"); |
|---|
| 469 | } //endfor |
|---|
| 470 | } //endif |
|---|
| 471 | } //endif |
|---|
| 472 | |
|---|
| 473 | |
|---|
| 474 | } // end AC_TREE::print_formated_dbtree() |
|---|
| 475 | //********************************************************************* |
|---|
| 476 | |
|---|
| 477 | |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | //********************************************************************* |
|---|
| 483 | // |
|---|
| 484 | // class AC_TREE::make_clustertree() |
|---|
| 485 | // |
|---|
| 486 | // hier wird rekursiv der Clusterbaum aufgebaut. |
|---|
| 487 | // Die Sequenzliste am root Knoten ist nicht leer. |
|---|
| 488 | // |
|---|
| 489 | //********************************************************************* |
|---|
| 490 | void AC_TREE::make_clustertree() { |
|---|
| 491 | |
|---|
| 492 | if ( (this->node_state == I_NODE) ) { |
|---|
| 493 | split(); // Verteile Liste auf die Soehne |
|---|
| 494 | // Setzt node_state auf LEAF als Abbruchsbedingung |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | if ( (this->node_state == I_NODE) ) { |
|---|
| 498 | this->left->make_clustertree(); |
|---|
| 499 | this->right->make_clustertree(); |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | } // end AC_TREE::make_clustertree() |
|---|
| 503 | //********************************************************************* |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | //********************************************************************* |
|---|
| 510 | // class AC_TREE::split() |
|---|
| 511 | // |
|---|
| 512 | // bestimme LEFTEND |
|---|
| 513 | // bestimme Distanzen zum LEFTEND (real/relativ) |
|---|
| 514 | // bestimme RIGHTEND |
|---|
| 515 | // bestimme Distanzen zum RIGHTEND (real/relativ) |
|---|
| 516 | // |
|---|
| 517 | // bestimme Schnittpunkt auf der Leftend <-> Rightendachse!!! |
|---|
| 518 | // |
|---|
| 519 | // legen den Schnittpunkt fest |
|---|
| 520 | // generiere zwei neue Knoten |
|---|
| 521 | // teile die Sequenzliste auf die Knoten auf |
|---|
| 522 | // |
|---|
| 523 | //********************************************************************* |
|---|
| 524 | void AC_TREE::split() { |
|---|
| 525 | |
|---|
| 526 | //---------------------------------------------------- leftend |
|---|
| 527 | this->leftend = get_high_quality_sequence(); |
|---|
| 528 | this->leftend->state = LEFTEND; |
|---|
| 529 | this->determine_distances_to(leftend, LEFTEND); // real, relative |
|---|
| 530 | |
|---|
| 531 | //--------------------------------------------------- rightend |
|---|
| 532 | this->rightend = get_seq_with_max_dist_to(); |
|---|
| 533 | |
|---|
| 534 | if( this->rightend != NULL ) { |
|---|
| 535 | this->rightend->state = RIGHTEND; |
|---|
| 536 | this->determine_distances_to(rightend, RIGHTEND); // real,relative |
|---|
| 537 | |
|---|
| 538 | #ifdef DEBUG_print_rightdistances |
|---|
| 539 | print_rightdistances(this); |
|---|
| 540 | #endif |
|---|
| 541 | #ifdef GNUPLOT_both_relativedistances |
|---|
| 542 | print_both_relativedistances(this); |
|---|
| 543 | printf("\n\n"); |
|---|
| 544 | #endif |
|---|
| 545 | //------------------------------------------------------------ relationship |
|---|
| 546 | this->determine_basepoints(); // basepoints |
|---|
| 547 | |
|---|
| 548 | //---------------------------------------------- zwei neue Soehne = I_Nodes |
|---|
| 549 | AC_TREE *inode_left = new AC_TREE; |
|---|
| 550 | this->left = inode_left; |
|---|
| 551 | AC_TREE *inode_right = new AC_TREE; |
|---|
| 552 | this->right = inode_right; |
|---|
| 553 | //-------------------------------------- Aufteilen der Liste auf die Soehne |
|---|
| 554 | this->divide_sequence_list(this, inode_left, inode_right); |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | //========================== Abbruchsbedingung fuer Seqenz-Listenaufteilung |
|---|
| 558 | if( (this->left->max_relationship <= breakcondition_relationship_distance) || |
|---|
| 559 | (this->left->nsequences <= breakcondition_min_sequencenumber) ) { |
|---|
| 560 | this->left->node_state = LEAF; |
|---|
| 561 | } |
|---|
| 562 | if( (this->right->max_relationship <= breakcondition_relationship_distance) || |
|---|
| 563 | (this->right->nsequences <= breakcondition_min_sequencenumber) ) { |
|---|
| 564 | this->right->node_state = LEAF; |
|---|
| 565 | } |
|---|
| 566 | //========================================================================= |
|---|
| 567 | |
|---|
| 568 | } //endif |
|---|
| 569 | |
|---|
| 570 | else { this->node_state = LEAF; // kein rightend gefunden |
|---|
| 571 | } |
|---|
| 572 | |
|---|
| 573 | } // end AC_TREE::split() |
|---|
| 574 | //********************************************************************* |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | |
|---|
| 578 | |
|---|
| 579 | //********************************************************************* |
|---|
| 580 | // |
|---|
| 581 | // class AC_TREE::divide_sequence_list() |
|---|
| 582 | // |
|---|
| 583 | // allokiert Speicher fuer das Sortier-Array |
|---|
| 584 | // liest die Werte in das Array ein |
|---|
| 585 | // |
|---|
| 586 | // |
|---|
| 587 | //********************************************************************* |
|---|
| 588 | void AC_TREE::divide_sequence_list(AC_TREE *that, AC_TREE *inode_left, |
|---|
| 589 | AC_TREE *inode_right) { |
|---|
| 590 | |
|---|
| 591 | //------------------------------------------------------- allokieren memory sortarray[] |
|---|
| 592 | AC_SEQUENCE_INFO **sort_array; |
|---|
| 593 | long number_of; |
|---|
| 594 | number_of = this->nsequences; |
|---|
| 595 | sort_array = (AC_SEQUENCE_INFO **)calloc(sizeof(void *),number_of); |
|---|
| 596 | |
|---|
| 597 | #ifdef DEBUG_print_unsorted_array |
|---|
| 598 | printf("\n\nunsorted array: \n\n"); |
|---|
| 599 | #endif |
|---|
| 600 | //------------------------------------------------------ einlesen der seqenptr in array |
|---|
| 601 | AC_SEQUENCE_INFO *ac_sequence_info; |
|---|
| 602 | AC_SEQUENCE_INFO *seq_ptr; |
|---|
| 603 | AC_SEQUENCE_INFO **array_ptr = sort_array; |
|---|
| 604 | |
|---|
| 605 | ac_sequence_info = this->sequences; |
|---|
| 606 | |
|---|
| 607 | for(seq_ptr = ac_sequence_info; seq_ptr; seq_ptr = seq_ptr->next) { |
|---|
| 608 | *array_ptr= seq_ptr; |
|---|
| 609 | |
|---|
| 610 | #ifdef DEBUG_print_unsorted_array |
|---|
| 611 | // printf("%f\n", (*array_ptr)->relationship); |
|---|
| 612 | printf("%f ", (*array_ptr)->relationship); |
|---|
| 613 | #endif |
|---|
| 614 | array_ptr++; |
|---|
| 615 | } // end for |
|---|
| 616 | //-------------------------------------------------- ende einlesen der seqenptr in array |
|---|
| 617 | |
|---|
| 618 | #ifdef DEBUG_print_unsorted_array |
|---|
| 619 | printf("\n\n"); |
|---|
| 620 | #endif |
|---|
| 621 | |
|---|
| 622 | //------------------------------------------------------------------ sortieren des array |
|---|
| 623 | //================================================================== |
|---|
| 624 | GB_mergesort((void **) (sort_array), 0, number_of, seq_info_cmp,0); |
|---|
| 625 | //================================================================== |
|---|
| 626 | //------------------------------------------------------------------------ end sortieren |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | // zum GNUPLOT Ausdruck |
|---|
| 631 | long dekrement; |
|---|
| 632 | #ifdef GNUPLOT_print_sorted_array |
|---|
| 633 | // long dekrement; |
|---|
| 634 | dekrement = number_of; |
|---|
| 635 | printf("\n\n#GNU sorted array: \n\n"); |
|---|
| 636 | for(array_ptr = sort_array; 0 < dekrement; array_ptr++, dekrement--) { |
|---|
| 637 | printf("%f \n", (*array_ptr)->relationship); |
|---|
| 638 | // printf("%f 10\n", (*array_ptr)->relationship); |
|---|
| 639 | // printf("%f ", (*array_ptr)->relationship); |
|---|
| 640 | } |
|---|
| 641 | printf("\n\n"); |
|---|
| 642 | #endif |
|---|
| 643 | |
|---|
| 644 | #ifdef GNUPLOT_print_sorted_left_right_reldist |
|---|
| 645 | // long dekrement; |
|---|
| 646 | dekrement = number_of; |
|---|
| 647 | printf("\n\nsorted array relative left/right distances : \n\n"); |
|---|
| 648 | for(array_ptr = sort_array; 0 < dekrement; array_ptr++, dekrement--) { |
|---|
| 649 | printf("%f ", |
|---|
| 650 | (*array_ptr)->relative_leftdistance); |
|---|
| 651 | printf("%f\n", |
|---|
| 652 | (*array_ptr)->relative_rightdistance); |
|---|
| 653 | } |
|---|
| 654 | printf("\n\n"); |
|---|
| 655 | #endif |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | //----------------------------------------------------------------- Schnittpunktbestimmung |
|---|
| 659 | double intersection_value = get_intersection_expglaettg(sort_array, number_of); |
|---|
| 660 | |
|---|
| 661 | //------------------------------------------------------ Umhaengen der Seqs auf die Soehne |
|---|
| 662 | separate_sequencelist(sort_array, intersection_value); |
|---|
| 663 | |
|---|
| 664 | //--------------------------------------------------------- Zuruecksetzen der Struct-Werte |
|---|
| 665 | this->left->reset_AC_SEQUENCE_INFO_struct_values(); |
|---|
| 666 | this->right->reset_AC_SEQUENCE_INFO_struct_values(); |
|---|
| 667 | |
|---|
| 668 | free (sort_array); |
|---|
| 669 | |
|---|
| 670 | } // end AC_TREE::divide_sequence_list() |
|---|
| 671 | //********************************************************************* |
|---|
| 672 | |
|---|
| 673 | |
|---|
| 674 | |
|---|
| 675 | //********************************************************************* |
|---|
| 676 | // |
|---|
| 677 | // class AC_TREE::separate_sequencelist() |
|---|
| 678 | // |
|---|
| 679 | // geht das sortierte array durch und haengt den ersten Teil an |
|---|
| 680 | // den linken Knoten, |
|---|
| 681 | // den zweiten Knoten, d.h. das Element das den intersection_value |
|---|
| 682 | // liefert sammt Rest an den zweiten Knoten. |
|---|
| 683 | // Zu merken ist der Verwandtschaftsgrad der beiden Seqs zu den |
|---|
| 684 | // aktuellen Referenz-Sequenzen. |
|---|
| 685 | // |
|---|
| 686 | // |
|---|
| 687 | // |
|---|
| 688 | //********************************************************************* |
|---|
| 689 | void AC_TREE::separate_sequencelist(AC_SEQUENCE_INFO **sort_array, |
|---|
| 690 | double intersection_value ) |
|---|
| 691 | { |
|---|
| 692 | AC_TREE *inode; |
|---|
| 693 | AC_SEQUENCE_INFO **array_ptr = sort_array; |
|---|
| 694 | long dekrement = this->nsequences; |
|---|
| 695 | double basepoint; |
|---|
| 696 | |
|---|
| 697 | for( array_ptr,dekrement; 0 < dekrement; array_ptr++, dekrement--) { |
|---|
| 698 | basepoint = (*array_ptr)->relationship; |
|---|
| 699 | |
|---|
| 700 | if( (*array_ptr)->state != ORDINARY ) { |
|---|
| 701 | if( (*array_ptr)->state == LEFTEND ) { // LEFTEND nach links |
|---|
| 702 | inode = this->left; |
|---|
| 703 | } |
|---|
| 704 | else if( (*array_ptr)->state == RIGHTEND ) { // RIGHTEND nach rechts |
|---|
| 705 | inode = this->right; |
|---|
| 706 | } |
|---|
| 707 | } |
|---|
| 708 | |
|---|
| 709 | else { // state == ORDINARY |
|---|
| 710 | |
|---|
| 711 | if( (basepoint < intersection_value) || (0 == basepoint) ) { |
|---|
| 712 | inode = this->left; |
|---|
| 713 | } |
|---|
| 714 | else if( intersection_value == basepoint ) { |
|---|
| 715 | inode = this->right; |
|---|
| 716 | } |
|---|
| 717 | else if( basepoint >= intersection_value) { |
|---|
| 718 | inode = this->right; |
|---|
| 719 | } |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | inode->insert(*array_ptr); // einfuegen des listenelements nach left oder right |
|---|
| 723 | // inode->nsequences++; // wird bereits von insert() erledigt ! |
|---|
| 724 | |
|---|
| 725 | if( basepoint < intersection_value ) { // Abbruchsbedingung groesster Abstand zu |
|---|
| 726 | this->left->max_relationship = basepoint; // LEFTEND/RIGHTEND |
|---|
| 727 | } |
|---|
| 728 | else { |
|---|
| 729 | this->right->max_relationship = abs(100 - intersection_value); |
|---|
| 730 | } |
|---|
| 731 | } |
|---|
| 732 | this->sequences = NULL; // sicher ist sicher !!! |
|---|
| 733 | // d.h. am aktuellen Knoten haengt |
|---|
| 734 | // keine !! Sequenzenliste mehr |
|---|
| 735 | |
|---|
| 736 | #ifdef DEBUG_print_nodeinfo |
|---|
| 737 | printf("\n\n"); |
|---|
| 738 | printf("\n***************************************************************************\n"); |
|---|
| 739 | printf("Status des Knotens: %d\n", this->node_state); |
|---|
| 740 | printf("Status des Knotens: %d ", this->left->node_state); |
|---|
| 741 | printf("%d", this->right->node_state); |
|---|
| 742 | printf("\n\n"); |
|---|
| 743 | |
|---|
| 744 | |
|---|
| 745 | printf("Anzahl Seqs im Knoten: %d\n", this->nsequences); |
|---|
| 746 | printf("Anzahl Seqs LEFT/RIGHT: %d ", this->left->nsequences); |
|---|
| 747 | printf("%d", this->right->nsequences); |
|---|
| 748 | |
|---|
| 749 | printf("\n\n"); |
|---|
| 750 | printf("Relationship zu LEFT/RIGHT: %f ", this->left->max_relationship); |
|---|
| 751 | printf("%f\n", this->right->max_relationship); |
|---|
| 752 | |
|---|
| 753 | |
|---|
| 754 | |
|---|
| 755 | printf("\n\n\n"); |
|---|
| 756 | #endif |
|---|
| 757 | |
|---|
| 758 | |
|---|
| 759 | |
|---|
| 760 | #ifdef DEBUG_print_subnode_list |
|---|
| 761 | AC_SEQUENCE_INFO *subnode_list; |
|---|
| 762 | printf("\n\n"); |
|---|
| 763 | subnode_list = this->left->sequences; |
|---|
| 764 | for( subnode_list; subnode_list; ) { |
|---|
| 765 | printf("Seq_Nr : %d ", subnode_list->number); |
|---|
| 766 | printf("left_side : %f\n", subnode_list->relationship); |
|---|
| 767 | subnode_list = subnode_list->next; |
|---|
| 768 | } |
|---|
| 769 | printf("\n\n"); |
|---|
| 770 | subnode_list = this->right->sequences; |
|---|
| 771 | for( subnode_list; subnode_list; ) { |
|---|
| 772 | printf("Seq_Nr : %d ", subnode_list->number); |
|---|
| 773 | printf("right_side : %f\n", subnode_list->relationship); |
|---|
| 774 | subnode_list = subnode_list->next; |
|---|
| 775 | } |
|---|
| 776 | printf("\n\n"); |
|---|
| 777 | #endif |
|---|
| 778 | |
|---|
| 779 | } // end separate_sequencelist() |
|---|
| 780 | //********************************************************************* |
|---|
| 781 | |
|---|
| 782 | |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | |
|---|
| 786 | |
|---|