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(); // 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
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 
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 
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 }
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2492
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
Definition: arbdb.cxx:2120
const char * GB_ERROR
Definition: arb_core.h:25
GB_TYPES type
GB_ERROR GB_commit_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2515
AW_window * ALI_create_admin_window(AW_root *root, AliAdmin *admin)
Definition: AdminGui.cxx:164
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:717
void at(int x, int y)
Definition: AW_at.cxx:93
GBDATA * GBT_get_alignment(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:684
void GBT_get_alignment_names(ConstStrArray &names, GBDATA *gbd)
Definition: adali.cxx:316
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
GB_ERROR GBT_add_new_changekey(GBDATA *gb_main, const char *name, int type)
char * GBT_get_alignment_type_string(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:727
GBDATA * GLOBAL_gb_dst
Definition: MG_main.cxx:32
static void copy_and_check_alignments_ignoreResult()
static FullNameMap names
GBDATA * GB_create_container(GBDATA *father, const char *key)
Definition: arbdb.cxx:1803
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:365
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:932
AW_root * get_root()
Definition: aw_window.hxx:348
#define NULp
Definition: cxxforward.h:97
#define AWAR_MERGE_TMP_SRC
Definition: merge.hxx:29
#define NO_ALI_SELECTED
void callback(const WindowCallback &cb)
Definition: AW_window.cxx:130
GBDATA * gb_main
Definition: adname.cxx:33
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:29
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:446