Changeset 6587
- Timestamp:
- 09/04/10 17:39:23 (22 months ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
MERGE/MG_adapt_ali.cxx (modified) (3 diffs)
-
MERGE/MG_preserves.cxx (modified) (15 diffs)
-
lib/pictures/merge/preserves.fig (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/MERGE/MG_adapt_ali.cxx
r6569 r6587 601 601 char *ref_list = strdup(reference_species_names); 602 602 603 char *tok; 604 for (tok = strtok(ref_list, " \n,;"); tok; tok = strtok(NULL, " \n,;")) { 603 for (char *tok = strtok(ref_list, " \n,;"); tok; tok = strtok(NULL, " \n,;")) { 605 604 bool is_SAI = strncmp(tok, "SAI:", 4) == 0; 606 605 GBDATA *gb_species_left = 0; … … 621 620 tok, 622 621 gb_species_left ? "right" : "left")); 623 continue;624 }625 626 // look for sequence/SAI "data"627 GBDATA *gb_seq_left = GBT_read_sequence(gb_species_left, alignment_name);628 if (!gb_seq_left) continue;629 GBDATA *gb_seq_right = GBT_read_sequence(gb_species_right, alignment_name);630 if (!gb_seq_right) continue;631 632 GB_TYPES type_left = GB_read_type(gb_seq_left);633 GB_TYPES type_right = GB_read_type(gb_seq_right);634 635 if (type_left != type_right) {636 aw_message(GBS_global_string("Warning: data type of '%s' differs in both databases", tok));637 continue;638 }639 640 const char *warning;641 if (type_right == GB_STRING) {642 warning = rem->add_reference(GB_read_char_pntr(gb_seq_left), GB_read_char_pntr(gb_seq_right));643 622 } 644 623 else { 645 char *sleft = GB_read_as_string(gb_seq_left); 646 char *sright = GB_read_as_string(gb_seq_right); 647 648 warning = rem->add_reference(sleft, sright); 649 650 free(sleft); 651 free(sright); 652 } 653 654 if (warning) { 655 aw_message(GBS_global_string("Warning: '%s' %s", tok, warning)); 624 // look for sequence/SAI "data" 625 GBDATA *gb_seq_left = GBT_read_sequence(gb_species_left, alignment_name); 626 GBDATA *gb_seq_right = GBT_read_sequence(gb_species_right, alignment_name); 627 628 if (gb_seq_left && gb_seq_right) { 629 GB_TYPES type_left = GB_read_type(gb_seq_left); 630 GB_TYPES type_right = GB_read_type(gb_seq_right); 631 632 if (type_left != type_right) { 633 aw_message(GBS_global_string("Warning: data type of '%s' differs in both databases", tok)); 634 } 635 else { 636 const char *warning; 637 if (type_right == GB_STRING) { 638 warning = rem->add_reference(GB_read_char_pntr(gb_seq_left), GB_read_char_pntr(gb_seq_right)); 639 } 640 else { 641 char *sleft = GB_read_as_string(gb_seq_left); 642 char *sright = GB_read_as_string(gb_seq_right); 643 644 warning = rem->add_reference(sleft, sright); 645 646 free(sleft); 647 free(sright); 648 } 649 650 if (warning) aw_message(GBS_global_string("Warning: '%s' %s", tok, warning)); 651 } 652 } 656 653 } 657 654 } … … 685 682 } 686 683 687 GB_ERROR MG_transfer_sequence(MG_remap *remap, GBDATA *source_species, GBDATA *destination_species, const char *alignment_name) {684 static GB_ERROR MG_transfer_sequence(MG_remap *remap, GBDATA *source_species, GBDATA *destination_species, const char *alignment_name) { 688 685 // align sequence after copy 689 686 GB_ERROR error = NULL; -
trunk/MERGE/MG_preserves.cxx
r6381 r6587 14 14 15 15 #include "merge.hxx" 16 #include "MG_adapt_ali.hxx" 16 17 17 18 #include <arbdbt.h> … … 27 28 // find species/SAIs to preserve alignment 28 29 29 #define AWAR_REMAP_CANDIDATE "tmp/merge/remap_candidates" 30 #define AWAR_REMAP_ALIGNMENT "tmp/merge/remap_alignment" 30 #define AWAR_REMAP_CANDIDATE "tmp/merge/remap_candidates" 31 #define AWAR_REMAP_ALIGNMENT "tmp/merge/remap_alignment" 32 #define AWAR_REMAP_SEL_REFERENCE "tmp/merge/remap_reference" 31 33 32 34 struct preserve_para { 33 35 AW_window *window; 34 AW_selection_list *ali_id; 35 AW_selection_list *cand_id; 36 AW_selection_list *ali_id; // alignments 37 AW_selection_list *cand_id; // reference candidates 38 AW_selection_list *ref_id; // used references 36 39 }; 37 40 … … 61 64 } 62 65 63 // initialize the alignment selection list64 66 static void init_alignments(preserve_para *para) { 65 AW_window *aww = para->window; 66 AW_selection_list *id = para->ali_id; 67 68 aww->clear_selection_list(id); 69 aww->insert_default_selection(id, "All", "All"); 70 71 // insert alignments available in both databases 67 // initialize the alignment selection list 72 68 char **ali_names = get_global_alignments(); 73 for (int i = 0; ali_names[i]; ++i) { 74 aww->insert_selection(id, ali_names[i], ali_names[i]); 75 } 69 para->window->init_selection_list_from_array(para->ali_id, ali_names, "All"); 76 70 GBT_free_names(ali_names); 77 78 aww->update_selection_list(id); 79 aww->get_root()->awar(AWAR_REMAP_ALIGNMENT)->write_string("All"); // select "All" 80 } 81 82 // clear the candidate list 71 } 72 83 73 static void clear_candidates(preserve_para *para) { 74 // clear the candidate list 84 75 AW_window *aww = para->window; 85 76 AW_selection_list *id = para->cand_id; … … 88 79 aww->insert_default_selection(id, "????", "????"); 89 80 aww->update_selection_list(id); 90 91 aww->get_root()->awar(AWAR_REMAP_CANDIDATE)->write_string(""); // deselect92 81 } 93 82 … … 135 124 136 125 public: 137 Candidate(bool is_species, const char *name_, GBDATA *gb_src, GBDATA *gb_dst, const char * *ali_names)126 Candidate(bool is_species, const char *name_, GBDATA *gb_src, GBDATA *gb_dst, const char *const *ali_names) 138 127 : name(is_species ? name_ : string("SAI:")+name_) 139 128 { … … 175 164 const char *get_name() const { return name.c_str(); } 176 165 const char *get_entry() const { 177 bool isSAI = memcmp(get_name(), "SAI:", 4) == 0; 178 return GBS_global_string(isSAI ? "%-24s %i %li %f" : "%-8s %i %li %f", 179 get_name(), found_alignments, base_count_diff, score); 166 return GBS_global_string("%24s %i %li %f", get_name(), found_alignments, base_count_diff, score); 180 167 } 181 168 182 169 bool operator < (const Candidate& other) const { // sort highest score first 183 170 int ali_diff = found_alignments-other.found_alignments; 184 185 if (ali_diff) { 186 return ali_diff>0; 187 } 188 171 if (ali_diff) return ali_diff>0; 189 172 return score > other.score; 190 173 } … … 198 181 199 182 // add all candidate species to 'candidates' 200 static void find_species_candidates(Candidates& candidates, const char * *ali_names) {183 static void find_species_candidates(Candidates& candidates, const char *const *ali_names) { 201 184 aw_status("Examining species (kill to stop)"); 202 185 aw_status(0.0); … … 238 221 239 222 // add all candidate SAIs to 'candidates' 240 static void find_SAI_candidates(Candidates& candidates, const char * *ali_names) {223 static void find_SAI_candidates(Candidates& candidates, const char *const *ali_names) { 241 224 aw_status("Examining SAIs"); 242 225 aw_status(0.0); … … 275 258 } 276 259 277 // FIND button278 // (rebuild candidates list)279 260 static void calculate_preserves_cb(AW_window *, AW_CL cl_para) { 261 // FIND button (rebuild candidates list) 262 280 263 GB_transaction ta1(GLOBAL_gb_merge); 281 264 GB_transaction ta2(GLOBAL_gb_dest); … … 295 278 char **ali_names = get_global_alignments(); 296 279 297 find_SAI_candidates(candidates, const_cast<const char**>(ali_names));298 find_species_candidates(candidates, const_cast<const char**>(ali_names));280 find_SAI_candidates(candidates, ali_names); 281 find_species_candidates(candidates, ali_names); 299 282 300 283 GBT_free_names(ali_names); 301 284 } 302 285 else { 303 c har *ali_names[2] = { ali, 0 };304 find_SAI_candidates(candidates, const_cast<const char**>(ali_names));305 find_species_candidates(candidates, const_cast<const char**>(ali_names));286 const char *ali_names[2] = { ali, 0 }; 287 find_SAI_candidates(candidates, ali_names); 288 find_species_candidates(candidates, ali_names); 306 289 } 307 290 … … 326 309 } 327 310 328 // ADD button 329 // (add current selected candidate to references) 311 312 313 static char **read_references(AW_root *aw_root) { 314 char *ref_string = aw_root->awar(AWAR_REMAP_SPECIES_LIST)->read_string(); 315 char **refs = GBT_split_string(ref_string, " \n,;", true, NULL); 316 317 free(ref_string); 318 return refs; 319 } 320 static void write_references(AW_root *aw_root, const char *const *ref_array) { 321 char *ref_string = GBT_join_names(ref_array, '\n'); 322 aw_root->awar(AWAR_REMAP_SPECIES_LIST)->write_string(ref_string); 323 aw_root->awar(AWAR_REMAP_ENABLE)->write_int(ref_string[0] != 0); 324 free(ref_string); 325 } 326 static void select_reference(AW_root *aw_root, const char *ref_to_select) { 327 aw_root->awar(AWAR_REMAP_SEL_REFERENCE)->write_string(ref_to_select); 328 } 329 static char *get_selected_reference(AW_root *aw_root) { 330 return aw_root->awar(AWAR_REMAP_SEL_REFERENCE)->read_string(); 331 } 332 333 static void refresh_reference_list_cb(AW_root *aw_root, AW_CL cl_para) { 334 preserve_para *para = (preserve_para*)cl_para; 335 char **refs = read_references(aw_root); 336 para->window->init_selection_list_from_array(para->ref_id, refs, ""); 337 GBT_free_names(refs); 338 } 339 330 340 static void add_selected_cb(AW_window *, AW_CL cl_para) { 331 preserve_para *para = (preserve_para*)cl_para; 332 AW_window *aww = para->window; 333 AW_root *awr = aww->get_root(); 334 335 char *current = awr->awar(AWAR_REMAP_CANDIDATE)->read_string(); 336 char *references = awr->awar(AWAR_REMAP_SPECIES_LIST)->read_string(); 337 if (references && references[0]) { 338 string ref = string(references); 339 size_t pos = ref.find(current); 340 int len = strlen(current); 341 342 for (; 343 pos != string::npos; 344 pos = ref.find(current, pos+1)) 345 { 346 if (pos == 0 || ref[pos-1] == '\n') { 347 if ((pos+len) == ref.length()) break; // at eos -> skip 348 char behind = ref[pos+len]; 349 if (behind == '\n') break; // already there -> skip 350 } 351 } 352 353 if (pos == string::npos) { 354 string appended = ref+'\n'+current; 355 awr->awar(AWAR_REMAP_SPECIES_LIST)->write_string(appended.c_str()); 356 } 357 } 358 else { 359 awr->awar(AWAR_REMAP_SPECIES_LIST)->write_string(current); 360 } 361 362 free(references); 363 free(current); 364 365 awr->awar(AWAR_REMAP_ENABLE)->write_int(1); 366 } 367 368 // CLEAR button 369 // (clear references) 341 // ADD button (add currently selected candidate to references) 342 343 preserve_para *para = (preserve_para*)cl_para; 344 AW_root *aw_root = para->window->get_root(); 345 346 char **refs = read_references(aw_root); 347 char *candidate = aw_root->awar(AWAR_REMAP_CANDIDATE)->read_string(); 348 char *selected = get_selected_reference(aw_root); 349 int cand_index = GBT_names_index_of(refs, candidate); 350 int sel_index = GBT_names_index_of(refs, selected); 351 352 if (cand_index == -1) GBT_names_add(refs, sel_index+1, candidate); 353 else GBT_names_move(refs, cand_index, sel_index); 354 355 write_references(aw_root, refs); 356 select_reference(aw_root, candidate); 357 358 free(selected); 359 free(candidate); 360 GBT_free_names(refs); 361 362 para->window->move_selection(para->cand_id, 1); 363 } 364 370 365 static void clear_references_cb(AW_window *aww) { 371 AW_root *awr = aww->get_root(); 372 awr->awar(AWAR_REMAP_SPECIES_LIST)->write_string(""); 373 awr->awar(AWAR_REMAP_ENABLE)->write_int(0); 374 } 375 376 // SELECT PRESERVES window 366 // CLEAR button (clear references) 367 aww->get_root()->awar(AWAR_REMAP_SPECIES_LIST)->write_string(""); 368 } 369 370 static void del_reference_cb(AW_window *aww) { 371 AW_root *aw_root = aww->get_root(); 372 char **refs = read_references(aw_root); 373 char *selected = get_selected_reference(aw_root); 374 int sel_index = GBT_names_index_of(refs, selected); 375 376 if (sel_index >= 0) { 377 select_reference(aw_root, refs[sel_index+1]); 378 GBT_names_erase(refs, sel_index); 379 write_references(aw_root, refs); 380 } 381 382 free(selected); 383 GBT_free_names(refs); 384 } 385 386 static void lower_reference_cb(AW_window *aww) { 387 AW_root *aw_root = aww->get_root(); 388 char **refs = read_references(aw_root); 389 char *selected = get_selected_reference(aw_root); 390 int sel_index = GBT_names_index_of(refs, selected); 391 392 if (sel_index >= 0) { 393 GBT_names_move(refs, sel_index, sel_index+1); 394 write_references(aw_root, refs); 395 } 396 397 free(selected); 398 GBT_free_names(refs); 399 } 400 static void raise_reference_cb(AW_window *aww) { 401 AW_root *aw_root = aww->get_root(); 402 char **refs = read_references(aw_root); 403 char *selected = get_selected_reference(aw_root); 404 int sel_index = GBT_names_index_of(refs, selected); 405 406 if (sel_index > 0) { 407 GBT_names_move(refs, sel_index, sel_index-1); 408 write_references(aw_root, refs); 409 } 410 411 free(selected); 412 GBT_free_names(refs); 413 } 414 415 static void test_references_cb(AW_window *aww) { 416 char *reference_species_names = aww->get_root()->awar(AWAR_REMAP_SPECIES_LIST)->read_string(); 417 GB_transaction tm(GLOBAL_gb_merge); 418 GB_transaction td(GLOBAL_gb_dest); 419 420 MG_remaps test_mapping(GLOBAL_gb_merge, GLOBAL_gb_dest, true, reference_species_names); // will raise aw_message's in case of problems 421 422 free(reference_species_names); 423 } 424 425 static void init_preserve_awars(AW_root *aw_root) { 426 aw_root->awar_string(AWAR_REMAP_ALIGNMENT, "", GLOBAL_gb_dest); 427 aw_root->awar_string(AWAR_REMAP_CANDIDATE, "", GLOBAL_gb_dest); 428 aw_root->awar_string(AWAR_REMAP_SEL_REFERENCE, "", GLOBAL_gb_dest); 429 } 430 377 431 AW_window *MG_select_preserves_cb(AW_root *aw_root) { 378 aw_root->awar_string(AWAR_REMAP_ALIGNMENT, "", GLOBAL_gb_dest);379 aw_root->awar_string(AWAR_REMAP_CANDIDATE, "", GLOBAL_gb_dest);432 // SELECT PRESERVES window 433 init_preserve_awars(aw_root); 380 434 381 435 AW_window_simple *aws = new AW_window_simple; … … 391 445 aws->create_button("HELP", "HELP", "H"); 392 446 447 // ---------- 448 449 preserve_para *para = new preserve_para; // do not free (is passed to callback) 450 para->window = aws; 451 452 aws->at("ali"); 453 para->ali_id = aws->create_selection_list(AWAR_REMAP_ALIGNMENT, 0, "", 10, 30); 454 455 // ---------- 456 393 457 aws->at("adapt"); 394 458 aws->label("Adapt alignments"); … … 396 460 397 461 aws->at("reference"); 398 aws->create_text_field(AWAR_REMAP_SPECIES_LIST); 399 400 preserve_para *para = new preserve_para; // do not free (is passed to callback) 401 para->window = aws; 402 403 aws->at("candidate"); 404 para->cand_id = aws->create_selection_list(AWAR_REMAP_CANDIDATE, 0, "", 10, 30); 405 406 aws->at("ali"); 407 para->ali_id = aws->create_selection_list(AWAR_REMAP_ALIGNMENT, 0, "", 10, 30); 462 // aws->create_text_field(AWAR_REMAP_SPECIES_LIST); // @@@ needs to be a selection list! 463 para->ref_id = aws->create_selection_list(AWAR_REMAP_SEL_REFERENCE, 0, "", 10, 30); 464 465 aws->button_length(8); 466 467 aws->at("clear"); 468 aws->callback(clear_references_cb); 469 aws->create_button("CLEAR", "Clear", "C"); 470 471 aws->at("del"); 472 aws->callback(del_reference_cb); 473 aws->create_button("DEL", "Del", "L"); 474 475 aws->at("up"); 476 aws->callback(raise_reference_cb); 477 aws->create_button("UP", "Up", "U"); 478 479 aws->at("down"); 480 aws->callback(lower_reference_cb); 481 aws->create_button("DOWN", "Down", "D"); 482 483 aws->at("test"); 484 aws->callback(test_references_cb); 485 aws->create_button("TEST", "Test", "T"); 486 487 // ---------- 408 488 409 489 aws->at("find"); … … 411 491 aws->create_autosize_button("FIND", "Find candidates", "F", 1); 412 492 493 aws->at("add"); 494 aws->callback(add_selected_cb, (AW_CL)para); 495 aws->create_button("ADD", "Add", "A"); 496 497 aws->at("candidate"); 498 para->cand_id = aws->create_selection_list(AWAR_REMAP_CANDIDATE, 0, "", 10, 30); 499 413 500 { 414 501 GB_transaction ta1(GLOBAL_gb_merge); … … 419 506 } 420 507 421 aws->button_length(8); 422 423 aws->at("add"); 424 aws->callback(add_selected_cb, (AW_CL)para); 425 aws->create_button("ADD", "Add", "A"); 426 427 aws->at("clear"); 428 aws->callback(clear_references_cb); 429 aws->create_button("CLEAR", "Clear", "C"); 508 { 509 AW_awar *awar_list = aw_root->awar(AWAR_REMAP_SPECIES_LIST); 510 awar_list->add_callback(refresh_reference_list_cb, (AW_CL)para); 511 awar_list->touch(); // trigger callback 512 } 430 513 431 514 return aws; -
trunk/lib/pictures/merge/preserves.fig
r3045 r6587 1 #FIG 3.2 1 #FIG 3.2 Produced by xfig version 3.2.5 2 2 Landscape 3 3 Center 4 4 Metric 5 A4 5 A4 6 6 100.00 7 7 Single … … 15 15 8460 7740 16 16 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 0 0 2 17 2340 1350 7290 1350 18 4 0 -1 0 0 18 12 0.0000 4 165 570 1425 975 $close\001 19 4 2 -1 0 0 18 12 0.0000 4 180 465 8175 975 $help\001 20 4 2 -1 0 0 18 12 0.0000 4 165 525 3690 4500 $to:ali\001 21 4 1 -1 0 0 18 12 0.0000 4 180 4770 4800 1260 Find and select species/SAIs for alignment adaption\001 22 4 2 -1 0 0 18 12 0.0000 4 165 1170 6705 4455 $to:reference\001 23 4 0 -1 0 0 18 12 0.0000 4 165 300 1530 2475 $ali\001 24 4 0 -1 0 0 18 12 0.0000 4 180 870 1530 2070 Alignment\001 25 4 2 -1 0 0 18 12 0.0000 4 165 1470 8055 7560 $to:XY:candidate\001 26 4 0 -1 0 0 18 12 0.0000 4 165 945 1530 5535 $candidate\001 27 4 0 -1 0 0 18 12 0.0000 4 165 420 7020 2475 $add\001 28 4 0 -1 0 0 18 12 0.0000 4 165 540 7020 3015 $clear\001 29 4 0 -1 0 0 18 12 0.0000 4 165 945 4185 2475 $reference\001 30 4 0 -1 0 0 18 12 0.0000 4 165 420 4230 5085 $find\001 31 4 0 -1 0 0 18 12 0.0000 4 135 975 1530 5175 Candidates\001 32 4 0 -1 0 0 18 12 0.0000 4 180 885 4185 1935 $adapt\001 33 4 0 -1 0 0 18 12 0.0000 4 180 1515 4230 2115 using References\001 17 1800 1350 7740 1350 18 4 0 -1 0 0 18 12 0.0000 4 210 675 1425 975 $close\001 19 4 2 -1 0 0 18 12 0.0000 4 225 570 8175 975 $help\001 20 4 2 -1 0 0 18 12 0.0000 4 210 645 3690 4500 $to:ali\001 21 4 1 -1 0 0 18 12 0.0000 4 210 5385 4800 1260 Find and select species/SAIs for alignment adaption\001 22 4 2 -1 0 0 18 12 0.0000 4 210 1380 6705 4455 $to:reference\001 23 4 0 -1 0 0 18 12 0.0000 4 210 360 1530 2475 $ali\001 24 4 0 -1 0 0 18 12 0.0000 4 210 1050 1530 2070 Alignment\001 25 4 2 -1 0 0 18 12 0.0000 4 210 1785 8055 7560 $to:XY:candidate\001 26 4 0 -1 0 0 18 12 0.0000 4 210 1140 1530 5535 $candidate\001 27 4 0 -1 0 0 18 12 0.0000 4 210 1095 4185 2475 $reference\001 28 4 0 -1 0 0 18 12 0.0000 4 210 510 4230 5085 $find\001 29 4 0 -1 0 0 18 12 0.0000 4 165 1185 1530 5175 Candidates\001 30 4 0 -1 0 0 18 12 0.0000 4 225 705 4185 1935 $adapt\001 31 4 0 -1 0 0 18 12 0.0000 4 210 1815 4230 2115 using References\001 32 4 0 -1 0 0 18 12 0.0000 4 210 510 7020 5085 $add\001 33 4 0 -1 0 0 18 12 0.0000 4 210 630 7020 2475 $clear\001 34 4 0 -1 0 0 18 12 0.0000 4 210 435 7020 2970 $del\001 35 4 0 -1 0 0 18 12 0.0000 4 225 390 7020 3465 $up\001 36 4 0 -1 0 0 18 12 0.0000 4 210 675 7020 3960 $down\001 37 4 0 -1 0 0 18 12 0.0000 4 210 510 7020 4410 $test\001
