ARB
ad_transpro.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : ad_transpro.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #include "NT_local.h"
12 
13 #include <TranslateRealign.h>
14 #include <awt_sel_boxes.hxx>
15 #include <AP_codon_table.hxx>
16 #include <AP_pro_a_nucs.hxx>
17 #include <aw_awars.hxx>
18 #include <aw_root.hxx>
19 #include <aw_msg.hxx>
20 #include <arbdbt.h>
21 #include <arb_defs.h>
22 
23 #define AWAR_TRANSPRO_PREFIX "transpro/"
24 #define AWAR_TRANSPRO_SOURCE AWAR_TRANSPRO_PREFIX "source"
25 #define AWAR_TRANSPRO_DEST AWAR_TRANSPRO_PREFIX "dest"
26 
27 // translator only:
28 #define AWAR_TRANSPRO_POS AWAR_TRANSPRO_PREFIX "pos" // [0..3]: 0-2 = reading frame; 3 = autodetect
29 #define AWAR_TRANSPRO_MODE AWAR_TRANSPRO_PREFIX "mode"
30 #define AWAR_TRANSPRO_XSTART AWAR_TRANSPRO_PREFIX "xstart"
31 #define AWAR_TRANSPRO_WRITE AWAR_TRANSPRO_PREFIX "write"
32 
33 // realigner only:
34 #define AWAR_REALIGN_INCALI AWAR_TRANSPRO_PREFIX "incali"
35 #define AWAR_REALIGN_UNMARK AWAR_TRANSPRO_PREFIX "unmark"
36 #define AWAR_REALIGN_CUTOFF "tmp/" AWAR_TRANSPRO_PREFIX "cutoff" // dangerous -> do not save
37 
38 static void transpro_event(AW_window *aww) {
40  if (!error) {
41 #if defined(DEBUG) && 0
42  test_AWT_get_codons();
43 #endif
44  AW_root *aw_root = aww->get_root();
45  char *ali_source = aw_root->awar(AWAR_TRANSPRO_SOURCE)->read_string();
46  char *ali_dest = aw_root->awar(AWAR_TRANSPRO_DEST)->read_string();
47  char *mode = aw_root->awar(AWAR_TRANSPRO_MODE)->read_string();
48  int startpos = aw_root->awar(AWAR_TRANSPRO_POS)->read_int();
49  bool save2fields = aw_root->awar(AWAR_TRANSPRO_WRITE)->read_int();
50  bool translate_all = aw_root->awar(AWAR_TRANSPRO_XSTART)->read_int();
51 
52  error = ALI_translate_marked(GLOBAL.gb_main, strcmp(mode, "fields") == 0, save2fields, startpos, translate_all, ali_source, ali_dest);
53  if (!error) error = GBT_check_data(GLOBAL.gb_main, NULp);
54 
55  free(mode);
56  free(ali_dest);
57  free(ali_source);
58  }
60 }
61 
63  AW_awar *awar_startpos = awr->awar(AWAR_TRANSPRO_POS);
64 
65  if (awar_startpos->read_int() != AUTODETECT_STARTPOS) {
66  int pos = bio2info(awr->awar(AWAR_CURSOR_POSITION)->read_int());
67  pos = pos % 3;
68  awar_startpos->write_int(pos);
69  }
70 }
71 
74 
75  AW_window_simple *aws = new AW_window_simple;
76  aws->init(root, "TRANSLATE_DNA_TO_PRO", "TRANSLATE DNA TO PRO");
77 
78  aws->load_xfig("transpro.fig");
79 
80  aws->at("close");
81  aws->callback(AW_POPDOWN);
82  aws->create_button("CLOSE", "CLOSE", "C");
83 
84  aws->callback(makeHelpCallback("translate_dna_2_pro.hlp"));
85  aws->at("help");
86  aws->create_button("HELP", "HELP", "H");
87 
88  aws->at("source");
90 
91  aws->at("dest");
93 
95  aws->at("table");
96  aws->create_option_menu(AWAR_PROTEIN_TYPE);
97  for (int code_nr=0; code_nr<AWT_CODON_TABLES; code_nr++) {
98  aws->insert_option(AWT_get_codon_code_name(code_nr), "", code_nr);
99  }
100  aws->update_option_menu();
101 
102  aws->at("mode");
103  aws->create_toggle_field(AWAR_TRANSPRO_MODE);
104  aws->insert_toggle("from fields 'codon_start' and 'transl_table'", "", "fields");
105  aws->insert_default_toggle("use settings below (same for all species):", "", "settings");
106  aws->update_toggle_field();
107 
108  aws->at("pos");
109  aws->create_option_menu(AWAR_TRANSPRO_POS);
110  for (int p = 1; p <= 3; ++p) {
111  char label[2] = { char(p+'0'), 0 };
112  aws->insert_option(label, label, bio2info(p));
113  }
114  aws->insert_option("choose best", "choose best", AUTODETECT_STARTPOS);
115 
116  aws->update_option_menu();
117  aws->get_root()->awar_int(AWAR_CURSOR_POSITION)->add_callback(nt_trans_cursorpos_changed);
118 
119  aws->at("write");
120  aws->label("Save settings (to 'codon_start'+'transl_table')");
121  aws->create_toggle(AWAR_TRANSPRO_WRITE);
122 
123  aws->at("start");
124  aws->label("Translate all data");
125  aws->create_toggle(AWAR_TRANSPRO_XSTART);
126 
127  aws->at("translate");
128  aws->callback(transpro_event);
129  aws->highlight();
130  aws->create_button("TRANSLATE", "TRANSLATE", "T");
131 
132  aws->window_fit();
133 
134  return aws;
135 }
136 
137 static void realign_event(AW_window *aww) {
138  AW_root *aw_root = aww->get_root();
139  char *ali_source = aw_root->awar(AWAR_TRANSPRO_DEST)->read_string();
140  char *ali_dest = aw_root->awar(AWAR_TRANSPRO_SOURCE)->read_string();
141  bool unmark_succeeded = aw_root->awar(AWAR_REALIGN_UNMARK)->read_int();
142  bool cutoff_dna = aw_root->awar(AWAR_REALIGN_CUTOFF)->read_int();
143  size_t neededLength = 0;
145  GB_ERROR error = ALI_realign_marked(gb_main, ali_source, ali_dest, neededLength, unmark_succeeded, cutoff_dna);
146 
147  if (!error && neededLength) {
148  bool auto_inc_alisize = aw_root->awar(AWAR_REALIGN_INCALI)->read_int();
149  if (auto_inc_alisize) {
150  {
151  GB_transaction ta(gb_main);
152  error = ta.close(GBT_set_alignment_len(gb_main, ali_dest, neededLength));
153  }
154  if (!error) {
155  aw_message(GBS_global_string("Alignment length of '%s' has been set to %zu\n"
156  "running re-aligner again!",
157  ali_dest, neededLength));
158 
159  error = ALI_realign_marked(gb_main, ali_source, ali_dest, neededLength, unmark_succeeded, cutoff_dna);
160  if (neededLength) {
161  error = GBS_global_string("internal error: neededLength=%zu (after autoinc)", neededLength);
162  }
163  }
164  }
165  else {
166  GB_transaction ta(gb_main);
167  long destLen = GBT_get_alignment_len(gb_main, ali_dest);
168  nt_assert(destLen>0 && size_t(destLen)<neededLength);
169  error = GBS_global_string("Missing %zu columns in alignment '%s' (got=%li, need=%zu)\n"
170  "(check toggle to permit auto-increment)",
171  size_t(neededLength-destLen), ali_dest, destLen, neededLength);
172  }
173  }
174 
175  if (error) aw_message(error);
176  free(ali_dest);
177  free(ali_source);
178 }
179 
181  AW_window_simple *aws = new AW_window_simple;
182  aws->init(root, "REALIGN_DNA", "Realign DNA");
183 
184  aws->load_xfig("realign_dna.fig");
185 
186  aws->at("close");
187  aws->callback(AW_POPDOWN);
188  aws->create_button("CLOSE", "CLOSE", "C");
189 
190  aws->callback(makeHelpCallback("realign_dna.hlp"));
191  aws->at("help");
192  aws->create_button("HELP", "HELP", "H");
193 
194  aws->at("source");
195 #if defined(DEVEL_RALF)
196  awt_create_ALI_selection_button(GLOBAL.gb_main, aws, AWAR_TRANSPRO_SOURCE, "dna=:rna="); // @@@ nonsense here - just testing awt_create_ALI_selection_button somewhere
197 #else // !defined(DEVEL_RALF)
199 #endif
200  aws->at("dest");
202 
203  aws->at("autolen"); aws->create_toggle(AWAR_REALIGN_INCALI);
204  aws->at("unmark"); aws->create_toggle(AWAR_REALIGN_UNMARK);
205  aws->at("cutoff"); aws->create_toggle(AWAR_REALIGN_CUTOFF);
206 
207  aws->at("realign");
208  aws->callback(realign_event);
209  aws->create_autosize_button("REALIGN", "Realign marked species", "R");
210 
211  return aws;
212 }
213 
214 
216  root->awar_string(AWAR_TRANSPRO_SOURCE, "", props);
217  root->awar_string(AWAR_TRANSPRO_DEST, "", props);
218  root->awar_string(AWAR_TRANSPRO_MODE, "settings", props);
219 
220  root->awar_int(AWAR_TRANSPRO_POS, 0, props);
221  root->awar_int(AWAR_TRANSPRO_XSTART, 1, props);
222  root->awar_int(AWAR_TRANSPRO_WRITE, 0, props);
223  root->awar_int(AWAR_REALIGN_INCALI, 0, props);
224  root->awar_int(AWAR_REALIGN_UNMARK, 0, props);
225  root->awar_int(AWAR_REALIGN_CUTOFF, 0, props);
226 }
227 
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
#define AWAR_REALIGN_UNMARK
Definition: ad_transpro.cxx:35
const char * GB_ERROR
Definition: arb_core.h:25
#define AWAR_TRANSPRO_POS
Definition: ad_transpro.cxx:28
#define AWAR_TRANSPRO_DEST
Definition: ad_transpro.cxx:25
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:720
#define AWAR_REALIGN_INCALI
Definition: ad_transpro.cxx:34
void NT_create_transpro_variables(AW_root *root, AW_default props)
#define AWAR_CURSOR_POSITION
GB_ERROR ALI_translate_marked(GBDATA *gb_main, bool use_entries, bool save_entries, int selected_startpos, bool translate_all, const char *ali_source, const char *ali_dest)
#define AWAR_TRANSPRO_SOURCE
Definition: ad_transpro.cxx:24
void GB_end_transaction_show_error(GBDATA *gbd, GB_ERROR error, void(*error_handler)(GB_ERROR))
Definition: arbdb.cxx:2584
long read_int() const
Definition: AW_awar.cxx:184
void awt_create_ALI_selection_button(GBDATA *gb_main, AW_window *aws, const char *varname, const char *ali_type_match)
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:833
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
static void transpro_event(AW_window *aww)
Definition: ad_transpro.cxx:38
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
#define AWAR_TRANSPRO_MODE
Definition: ad_transpro.cxx:29
AW_window * NT_create_dna_2_pro_window(AW_root *root)
Definition: ad_transpro.cxx:72
#define AWAR_TRANSPRO_WRITE
Definition: ad_transpro.cxx:31
GB_ERROR GBT_set_alignment_len(GBDATA *gb_main, const char *aliname, long new_len)
Definition: adali.cxx:848
static void error(const char *msg)
Definition: mkptypes.cxx:96
AW_window * NT_create_realign_dna_window(AW_root *root)
char * read_string() const
Definition: AW_awar.cxx:198
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
#define AWAR_TRANSPRO_XSTART
Definition: ad_transpro.cxx:30
const char * AWT_get_codon_code_name(int code)
#define nt_assert(cond)
Definition: NT_local.h:27
AW_DB_selection * awt_create_ALI_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, const char *ali_type_match)
GB_ERROR ALI_realign_marked(GBDATA *gb_main, const char *ali_source, const char *ali_dest, size_t &neededLength, bool unmark_succeeded, bool cutoff_dna)
ASSERTING_CONSTEXPR_INLINE int bio2info(int biopos)
Definition: arb_defs.h:26
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
static void realign_event(AW_window *aww)
GB_ERROR close(GB_ERROR error)
Definition: arbdbpp.cxx:35
const int AWAR_PROTEIN_TYPE_bacterial_code_index
#define AWAR_PROTEIN_TYPE
#define AWAR_REALIGN_CUTOFF
Definition: ad_transpro.cxx:36
#define AWT_CODON_TABLES
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
AW_root * get_root()
Definition: aw_window.hxx:359
#define AUTODETECT_STARTPOS
#define NULp
Definition: cxxforward.h:116
GBDATA * gb_main
Definition: NT_local.h:37
GB_transaction ta(gb_var)
static void nt_trans_cursorpos_changed(AW_root *awr)
Definition: ad_transpro.cxx:62
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
GB_ERROR GBT_check_data(GBDATA *Main, const char *alignment_name)
Definition: adali.cxx:218
GB_ERROR write_int(long aw_int)
NT_global GLOBAL
Definition: NT_main.cxx:46
const char * label