ARB
MG_alignment.cxx
Go to the documentation of this file.
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 
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 
31 
34 
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 
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 }
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
Definition: arbdb.cxx:2152
const char * GB_ERROR
Definition: arb_core.h:25
GB_TYPES type
AW_window * ALI_create_admin_window(AW_root *root, AliAdmin *admin)
Definition: AdminGui.cxx:162
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:720
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2561
void at(int x, int y)
Definition: AW_at.cxx:93
GBDATA * GBT_get_alignment(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:808
void GBT_get_alignment_names(ConstStrArray &names, GBDATA *gbd)
Definition: adali.cxx:317
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
char * GBT_get_alignment_type_string(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:863
GBDATA * GLOBAL_gb_dst
Definition: MG_main.cxx:32
static void copy_and_check_alignments_ignoreResult()
GB_ERROR GBT_add_alignment_changekeys(GBDATA *gb_main, const char *ali)
static FullNameMap names
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
GBDATA * GB_create_container(GBDATA *father, const char *key)
Definition: arbdb.cxx:1829
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
#define mg_assert(bed)
Definition: merge.hxx:24
bool validDb(DbSel db)
Definition: merge.hxx:37
void GB_clear_error()
Definition: arb_msg.cxx:354
static void error(const char *msg)
Definition: mkptypes.cxx:96
DbSel
Definition: merge.hxx:35
GBDATA * GLOBAL_gb_src
Definition: MG_main.cxx:31
int MG_copy_and_check_alignments()
AW_DB_selection * awt_create_ALI_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, const char *ali_type_match)
AdminType
Definition: AliAdmin.h:26
#define AWAR_MERGE_TMP_DST
Definition: merge.hxx:30
Definition: merge.hxx:35
AW_window * MG_create_merge_alignment_window(AW_root *awr)
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
AW_root * get_root()
Definition: aw_window.hxx:359
#define NULp
Definition: cxxforward.h:116
#define AWAR_MERGE_TMP_SRC
Definition: merge.hxx:29
#define NO_ALI_SELECTED
void callback(const WindowCallback &cb)
Definition: AW_window.cxx:133
GBDATA * gb_main
Definition: adname.cxx:32
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
GBDATA * GBT_get_presets(GBDATA *gb_main)
Definition: adali.cxx:30
GBDATA * get_gb_main(DbSel db)
Definition: merge.hxx:88
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
static void bindAdmin(AW_window *aws, const char *at_ali, const char *at_modify, const char *button_id, AdminType type)
void create_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, const char *color=NULp)
Definition: AW_button.cxx:448