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(); // from GBT_get_alignment |
---|
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) { |
---|
51 | gb_dst_presets = GBT_get_presets(GLOBAL_gb_dst); |
---|
52 | if (!gb_dst_presets) error = GB_await_error(); |
---|
53 | } |
---|
54 | if (!error) { |
---|
55 | gb_dst_ali = GB_create_container(gb_dst_presets, "alignment"); |
---|
56 | if (!gb_dst_ali) error = GB_await_error(); |
---|
57 | } |
---|
58 | if (!error) error = GB_copy_dropProtectMarksAndTempstate(gb_dst_ali, gb_src_ali); |
---|
59 | if (!error) error = GBT_add_alignment_changekeys(GLOBAL_gb_dst, name); |
---|
60 | } |
---|
61 | |
---|
62 | if (!error) { |
---|
63 | char *src_type = GBT_get_alignment_type_string(GLOBAL_gb_src, name); |
---|
64 | char *dst_type = GBT_get_alignment_type_string(GLOBAL_gb_dst, name); |
---|
65 | |
---|
66 | mg_assert(src_type); |
---|
67 | mg_assert(dst_type); |
---|
68 | |
---|
69 | if (strcmp(src_type, dst_type) != 0) { |
---|
70 | error = GBS_global_string("The alignments '%s' have different types (%s != %s)", name, src_type, dst_type); |
---|
71 | } |
---|
72 | free(dst_type); |
---|
73 | free(src_type); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | error = GB_end_transaction(GLOBAL_gb_dst, error); |
---|
78 | error = GB_end_transaction(GLOBAL_gb_src, error); |
---|
79 | |
---|
80 | if (error) aw_message(error); |
---|
81 | |
---|
82 | return !!error; |
---|
83 | } |
---|
84 | |
---|
85 | static void bindAdmin(AW_window *aws, const char *at_ali, const char *at_modify, const char *button_id, AdminType type) { |
---|
86 | DbSel db = DbSel(type); |
---|
87 | mg_assert(validDb(db)); |
---|
88 | |
---|
89 | AW_root *aw_root = aws->get_root(); |
---|
90 | GBDATA *gb_main = get_gb_main(db); |
---|
91 | |
---|
92 | const char *awarname_select = (db == SRC_DB) ? AWAR_MERGE_TMP_SRC "alignment_name" : AWAR_MERGE_TMP_DST "alignment_name"; |
---|
93 | const char *awarbase = (db == SRC_DB) ? AWAR_MERGE_TMP_SRC : AWAR_MERGE_TMP_DST; |
---|
94 | |
---|
95 | aw_root->awar_string(awarname_select, NO_ALI_SELECTED, AW_ROOT_DEFAULT); |
---|
96 | AliAdmin *const admin = new AliAdmin(type, gb_main, awarname_select, awarbase); // do not free (bound to callbacks) |
---|
97 | |
---|
98 | aws->at(at_ali); |
---|
99 | awt_create_ALI_selection_list(gb_main, aws, awarname_select, "*="); |
---|
100 | |
---|
101 | aws->at(at_modify); |
---|
102 | aws->callback(makeCreateWindowCallback(ALI_create_admin_window, admin)); |
---|
103 | aws->create_button(button_id, "MODIFY"); |
---|
104 | } |
---|
105 | |
---|
106 | AW_window *MG_create_merge_alignment_window(AW_root *awr) { |
---|
107 | AW_window_simple *aws = new AW_window_simple; |
---|
108 | |
---|
109 | aws->init(awr, "MERGE_ALIGNMENTS", "MERGE ALIGNMENTS"); |
---|
110 | aws->load_xfig("merge/alignment.fig"); |
---|
111 | |
---|
112 | aws->at("close"); |
---|
113 | aws->callback(AW_POPDOWN); |
---|
114 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
115 | |
---|
116 | aws->at("help"); |
---|
117 | aws->callback(makeHelpCallback("mg_alignment.hlp")); |
---|
118 | aws->create_button("HELP", "HELP", "H"); |
---|
119 | |
---|
120 | aws->at("check"); |
---|
121 | aws->callback(makeWindowCallback(copy_and_check_alignments_ignoreResult)); |
---|
122 | aws->create_button("CHECK", "Check"); |
---|
123 | |
---|
124 | bindAdmin(aws, "ali1", "modify1", "MODIFY_DB1", SOURCE_ADMIN); |
---|
125 | bindAdmin(aws, "ali2", "modify2", "MODIFY_DB2", TARGET_ADMIN); |
---|
126 | |
---|
127 | aws->button_length(0); |
---|
128 | aws->shadow_width(1); |
---|
129 | aws->at("icon"); |
---|
130 | aws->callback(makeHelpCallback("mg_alignment.hlp")); |
---|
131 | aws->create_button("HELP_MERGE", "#merge/icon.xpm"); |
---|
132 | |
---|
133 | return aws; |
---|
134 | } |
---|