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 = NULp; |
---|
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 = NULp; |
---|
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_dropProtectMarksAndTempstate(gb_dst_ali, gb_src_ali); // @@@ handle error |
---|
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 | DbSel db = DbSel(type); |
---|
77 | mg_assert(validDb(db)); |
---|
78 | |
---|
79 | AW_root *aw_root = aws->get_root(); |
---|
80 | GBDATA *gb_main = get_gb_main(db); |
---|
81 | |
---|
82 | const char *awarname_select = (db == SRC_DB) ? AWAR_MERGE_TMP_SRC "alignment_name" : AWAR_MERGE_TMP_DST "alignment_name"; |
---|
83 | const char *awarbase = (db == SRC_DB) ? AWAR_MERGE_TMP_SRC : AWAR_MERGE_TMP_DST; |
---|
84 | |
---|
85 | aw_root->awar_string(awarname_select, NO_ALI_SELECTED, AW_ROOT_DEFAULT); |
---|
86 | AliAdmin *const admin = new AliAdmin(type, gb_main, awarname_select, awarbase); // do not free (bound to callbacks) |
---|
87 | |
---|
88 | aws->at(at_ali); |
---|
89 | awt_create_ALI_selection_list(gb_main, aws, awarname_select, "*="); |
---|
90 | |
---|
91 | aws->at(at_modify); |
---|
92 | aws->callback(makeCreateWindowCallback(ALI_create_admin_window, admin)); |
---|
93 | aws->create_button(button_id, "MODIFY"); |
---|
94 | } |
---|
95 | |
---|
96 | AW_window *MG_create_merge_alignment_window(AW_root *awr) { |
---|
97 | AW_window_simple *aws = new AW_window_simple; |
---|
98 | |
---|
99 | aws->init(awr, "MERGE_ALIGNMENTS", "MERGE ALIGNMENTS"); |
---|
100 | aws->load_xfig("merge/alignment.fig"); |
---|
101 | |
---|
102 | aws->at("close"); |
---|
103 | aws->callback(AW_POPDOWN); |
---|
104 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
105 | |
---|
106 | aws->at("help"); |
---|
107 | aws->callback(makeHelpCallback("mg_alignment.hlp")); |
---|
108 | aws->create_button("HELP", "HELP", "H"); |
---|
109 | |
---|
110 | aws->at("check"); |
---|
111 | aws->callback(makeWindowCallback(copy_and_check_alignments_ignoreResult)); |
---|
112 | aws->create_button("CHECK", "Check"); |
---|
113 | |
---|
114 | bindAdmin(aws, "ali1", "modify1", "MODIFY_DB1", SOURCE_ADMIN); |
---|
115 | bindAdmin(aws, "ali2", "modify2", "MODIFY_DB2", TARGET_ADMIN); |
---|
116 | |
---|
117 | aws->button_length(0); |
---|
118 | aws->shadow_width(1); |
---|
119 | aws->at("icon"); |
---|
120 | aws->callback(makeHelpCallback("mg_alignment.hlp")); |
---|
121 | aws->create_button("HELP_MERGE", "#merge/icon.xpm"); |
---|
122 | |
---|
123 | return aws; |
---|
124 | } |
---|