| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : MG_alignment.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // =============================================================== // |
|---|
| 10 | |
|---|
| 11 | #include "merge.hxx" |
|---|
| 12 | |
|---|
| 13 | #include <awt_sel_boxes.hxx> |
|---|
| 14 | #include <aw_root.hxx> |
|---|
| 15 | #include <aw_awar.hxx> |
|---|
| 16 | #include <aw_msg.hxx> |
|---|
| 17 | #include <arbdbt.h> |
|---|
| 18 | #include <arb_strarray.h> |
|---|
| 19 | #include <arb_global_defs.h> |
|---|
| 20 | #include <AliAdmin.h> |
|---|
| 21 | |
|---|
| 22 | #include <unistd.h> |
|---|
| 23 | |
|---|
| 24 | static void copy_and_check_alignments_ignoreResult() { MG_copy_and_check_alignments(); } |
|---|
| 25 | int MG_copy_and_check_alignments() { |
|---|
| 26 | // returns 0 if alignments are ok for merging. |
|---|
| 27 | // otherwise an error message is shown in message box. |
|---|
| 28 | // checks types and names. |
|---|
| 29 | |
|---|
| 30 | GB_ERROR error = NULL; |
|---|
| 31 | |
|---|
| 32 | GB_begin_transaction(GLOBAL_gb_dst); |
|---|
| 33 | GB_begin_transaction(GLOBAL_gb_src); |
|---|
| 34 | |
|---|
| 35 | ConstStrArray names; |
|---|
| 36 | GBT_get_alignment_names(names, GLOBAL_gb_src); |
|---|
| 37 | |
|---|
| 38 | GBDATA *gb_dst_presets = NULL; |
|---|
| 39 | |
|---|
| 40 | for (int i = 0; names[i] && !error; ++i) { |
|---|
| 41 | const char *name = names[i]; |
|---|
| 42 | GBDATA *gb_dst_ali = GBT_get_alignment(GLOBAL_gb_dst, name); |
|---|
| 43 | |
|---|
| 44 | if (!gb_dst_ali) { |
|---|
| 45 | GB_clear_error(); // ignore "alignment not found" |
|---|
| 46 | |
|---|
| 47 | GBDATA *gb_src_ali = GBT_get_alignment(GLOBAL_gb_src, name); |
|---|
| 48 | mg_assert(gb_src_ali); |
|---|
| 49 | |
|---|
| 50 | if (!gb_dst_presets) gb_dst_presets = GBT_get_presets(GLOBAL_gb_dst); |
|---|
| 51 | |
|---|
| 52 | gb_dst_ali = GB_create_container(gb_dst_presets, "alignment"); |
|---|
| 53 | GB_copy(gb_dst_ali, gb_src_ali); |
|---|
| 54 | GBT_add_new_changekey(GLOBAL_gb_dst, (char *)GBS_global_string("%s/data", name), GB_STRING); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | char *src_type = GBT_get_alignment_type_string(GLOBAL_gb_src, name); |
|---|
| 58 | char *dst_type = GBT_get_alignment_type_string(GLOBAL_gb_dst, name); |
|---|
| 59 | |
|---|
| 60 | if (strcmp(src_type, dst_type) != 0) { |
|---|
| 61 | error = GBS_global_string("The alignments '%s' have different types (%s != %s)", name, src_type, dst_type); |
|---|
| 62 | } |
|---|
| 63 | free(dst_type); |
|---|
| 64 | free(src_type); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | GB_commit_transaction(GLOBAL_gb_dst); |
|---|
| 68 | GB_commit_transaction(GLOBAL_gb_src); |
|---|
| 69 | |
|---|
| 70 | if (error) aw_message(error); |
|---|
| 71 | |
|---|
| 72 | return !!error; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | static void bindAdmin(AW_window *aws, const char *at_ali, const char *at_modify, const char *button_id, AdminType type) { |
|---|
| 76 | const char *awarname_select[] = { |
|---|
| 77 | NULL, |
|---|
| 78 | AWAR_MERGE_TMP_SRC "alignment_name", |
|---|
| 79 | AWAR_MERGE_TMP_DST "alignment_name" |
|---|
| 80 | }; |
|---|
| 81 | const char *awarbase[] = { |
|---|
| 82 | NULL, |
|---|
| 83 | AWAR_MERGE_TMP_SRC, |
|---|
| 84 | AWAR_MERGE_TMP_DST |
|---|
| 85 | }; |
|---|
| 86 | |
|---|
| 87 | AW_root *aw_root = aws->get_root(); |
|---|
| 88 | GBDATA *gb_main = get_gb_main(type); |
|---|
| 89 | |
|---|
| 90 | aw_root->awar_string(awarname_select[type], NO_ALI_SELECTED, AW_ROOT_DEFAULT); |
|---|
| 91 | AliAdmin *const admin = new AliAdmin(type, gb_main, awarname_select[type], awarbase[type]); // do not free (bound to callbacks) |
|---|
| 92 | |
|---|
| 93 | aws->at(at_ali); |
|---|
| 94 | awt_create_ALI_selection_list(gb_main, aws, awarname_select[type], "*="); |
|---|
| 95 | |
|---|
| 96 | aws->at(at_modify); |
|---|
| 97 | aws->callback(makeCreateWindowCallback(ALI_create_admin_window, admin)); |
|---|
| 98 | aws->create_button(button_id, "MODIFY"); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | AW_window *MG_create_merge_alignment_window(AW_root *awr) { |
|---|
| 102 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 103 | |
|---|
| 104 | aws->init(awr, "MERGE_ALIGNMENTS", "MERGE ALIGNMENTS"); |
|---|
| 105 | aws->load_xfig("merge/alignment.fig"); |
|---|
| 106 | |
|---|
| 107 | aws->at("close"); aws->callback((AW_CB0)AW_POPDOWN); |
|---|
| 108 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 109 | |
|---|
| 110 | aws->at("help"); |
|---|
| 111 | aws->callback(makeHelpCallback("mg_alignment.hlp")); |
|---|
| 112 | aws->create_button("HELP", "HELP", "H"); |
|---|
| 113 | |
|---|
| 114 | aws->at("check"); |
|---|
| 115 | aws->callback(makeWindowCallback(copy_and_check_alignments_ignoreResult)); |
|---|
| 116 | aws->create_button("CHECK", "Check"); |
|---|
| 117 | |
|---|
| 118 | bindAdmin(aws, "ali1", "modify1", "MODIFY_DB1", SOURCE_ADMIN); |
|---|
| 119 | bindAdmin(aws, "ali2", "modify2", "MODIFY_DB2", TARGET_ADMIN); |
|---|
| 120 | |
|---|
| 121 | aws->button_length(0); |
|---|
| 122 | aws->shadow_width(1); |
|---|
| 123 | aws->at("icon"); |
|---|
| 124 | aws->callback(makeHelpCallback("mg_alignment.hlp")); |
|---|
| 125 | aws->create_button("HELP_MERGE", "#merge/icon.xpm"); |
|---|
| 126 | |
|---|
| 127 | return aws; |
|---|
| 128 | } |
|---|