ARB
ST_window.cxx
Go to the documentation of this file.
1 // ================================================================ //
2 // //
3 // File : ST_window.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ================================================================ //
10 
11 #include "st_ml.hxx"
12 #include "st_quality.hxx"
13 
14 #include <gui_aliview.hxx>
15 #include <ColumnStat.hxx>
16 #include <item_sel_list.h>
17 
18 #include <awt_filter.hxx>
19 #include <awt_config_manager.hxx>
20 
21 #include <aw_awars.hxx>
22 #include <aw_root.hxx>
23 #include <aw_msg.hxx>
24 
25 #include <arbdbt.h>
26 #include <arb_progress.h>
27 #include <arb_global_defs.h>
28 #include <arb_strbuf.h>
29 
30 #define ST_ML_AWAR "tmp/st_ml/"
31 
32 #define ST_ML_AWAR_COLSTAT_PREFIX ST_ML_AWAR "colstat/"
33 #define ST_ML_AWAR_COLSTAT_NAME ST_ML_AWAR_COLSTAT_PREFIX "name"
34 
35 #define ST_ML_AWAR_FILTER_PREFIX ST_ML_AWAR "filter/"
36 #define ST_ML_AWAR_FILTER_ALIGNMENT ST_ML_AWAR_FILTER_PREFIX "alignment"
37 #define ST_ML_AWAR_FILTER_NAME ST_ML_AWAR_FILTER_PREFIX "name"
38 #define ST_ML_AWAR_FILTER_FILTER ST_ML_AWAR_FILTER_PREFIX "filter"
39 #define ST_ML_AWAR_FILTER_SIMPLIFY ST_ML_AWAR_FILTER_PREFIX "simplify"
40 
41 #define ST_ML_AWAR_CQ_BUCKET_SIZE ST_ML_AWAR "bucket_size"
42 #define ST_ML_AWAR_CQ_MARKED_ONLY ST_ML_AWAR "marked_only"
43 #define ST_ML_AWAR_CQ_DEST_FIELD ST_ML_AWAR "dest_field"
44 #define ST_ML_AWAR_CQ_REPORT ST_ML_AWAR "report"
45 #define ST_ML_AWAR_CQ_KEEP_REPORTS ST_ML_AWAR "keep_reports"
46 
47 static void st_ok_cb(AW_window *aww, ST_ML *st_ml) {
48  AW_root *root = aww->get_root();
49  char *alignment_name = root->awar_string(AWAR_DEFAULT_ALIGNMENT, "-none-", st_ml->get_gb_main())->read_string();
50  char *tree_name = root->awar_string(AWAR_TREE, "", st_ml->get_gb_main())->read_string();
51  int marked_only = root->awar_int(ST_ML_AWAR_CQ_MARKED_ONLY)->read_int();
52 
54  if (!error) {
55  error = st_ml->calc_st_ml(tree_name, alignment_name, NULp, marked_only, st_ml->get_column_statistic(), NULp);
56  if (!error) st_ml->do_postcalc_callback();
57  }
58 
59  error = GB_end_transaction(st_ml->get_gb_main(), error);
60  aww->hide_or_notify(error);
61 
62  free(tree_name);
63  free(alignment_name);
64 }
65 
67  st_ml->set_postcalc_callback(postcalc_cb, cb_win);
68 }
69 
71  AW_window_simple *aws = new AW_window_simple;
72  aws->init(root, "COLUMN_STATISTIC", "COLUMN STATISTIC");
73 
74  aws->load_xfig("stat_main.fig");
75 
76  aws->callback(AW_POPDOWN);
77  aws->at("close");
78  aws->create_button("CLOSE", "CLOSE", "C");
79 
80  aws->callback(makeHelpCallback("st_ml.hlp"));
81  aws->at("help");
82  aws->create_button("HELP", "HELP", "H");
83 
86 
87  AW_awar *awar_default_alignment = root->awar_string(AWAR_DEFAULT_ALIGNMENT, "-none-", st_ml->get_gb_main());
88  root->awar_string(AWAR_TREE, "", st_ml->get_gb_main());
89 
90  st_ml->create_column_statistic(root, ST_ML_AWAR_COLSTAT_NAME, awar_default_alignment);
91 
92  aws->at("GO");
93  aws->callback(makeWindowCallback(st_ok_cb, st_ml));
94  aws->create_button("GO", "GO", "G");
95 
96  aws->at("awt_csp");
97  aws->callback(makeCreateWindowCallback(COLSTAT_create_selection_window, st_ml->get_column_statistic()));
98  aws->button_length(20);
99  aws->create_button("SELECT_CSP", ST_ML_AWAR_COLSTAT_NAME);
100 
101  aws->at("marked");
102  aws->create_toggle_field(ST_ML_AWAR_CQ_MARKED_ONLY, "Calculate for ..", "");
103  aws->insert_toggle("All species", "A", 0);
104  aws->insert_toggle("Marked species", "M", 1);
105  aws->update_toggle_field();
106 
107  return aws;
108 }
109 
111  return new ST_ML(gb_main);
112 }
114  delete st_ml;
115  st_ml = NULp;
116 }
117 
118 ST_ML_Color *STAT_get_color_string(ST_ML *st_ml, char *species_name, AP_tree *node, int start_ali_pos, int end_ali_pos) {
119  return st_ml->get_color_string(species_name, node, start_ali_pos, end_ali_pos);
120 }
121 
122 bool STAT_update_ml_likelihood(ST_ML *st_ml, char *result[4], int& latest_update, const char *species_name, AP_tree *node) {
124  return st_ml->update_ml_likelihood(result, latest_update, species_name, node);
125 }
126 
127 AP_tree *STAT_find_node_by_name(ST_ML *st_ml, const char *species_name) {
128  return st_ml->find_node_by_name(species_name);
129 }
130 
131 struct st_check_cb_data : public Noncopyable {
135 
136  st_check_cb_data(GBDATA *gb_main_, AW_root *root, const char *columnStatAwarName, const char *filterAwarName, AW_awar *awar_default_alignment) {
137  gb_main = gb_main_;
138  colstat = new ColumnStat(gb_main, root, columnStatAwarName, awar_default_alignment);
139  filter = new WeightedFilter(gb_main, root, filterAwarName, NULp, awar_default_alignment);
140  }
141 };
142 
144  GB_ERROR error = NULp;
145 
146  char *ali_name = awr->awar(ST_ML_AWAR_FILTER_ALIGNMENT)->read_string();
147  char *dest_field = awr->awar(ST_ML_AWAR_CQ_DEST_FIELD)->read_string();
148  bool fieldSelected = strcmp(dest_field, NO_FIELD_SELECTED) != 0;
149 
150  int fieldsRemoved = 0;
151  int qualitiesRemoved = 0;
152 
153  {
154  GB_transaction ta(gb_main);
155  long count = GBT_get_species_count(gb_main);
156 
157  arb_progress progress("Removing old reports", count);
158  for (GBDATA *gb_species = GBT_first_species(gb_main);
159  gb_species && !error;
160  gb_species = GBT_next_species(gb_species))
161  {
162  if (fieldSelected) {
163  GBDATA *gb_field = GB_entry(gb_species, dest_field);
164  if (gb_field) {
165  error = GB_delete(gb_field);
166  if (!error) fieldsRemoved++;
167  }
168  }
169  if (!error) {
170  GBDATA *gb_ali = GB_entry(gb_species, ali_name);
171  if (gb_ali) {
172  GBDATA *gb_quality = GB_entry(gb_ali, "quality");
173  if (gb_quality) {
174  error = GB_delete(gb_quality);
175  if (!error) qualitiesRemoved++;
176  }
177  }
178  }
179  progress.inc_and_check_user_abort(error);
180  }
181  }
182 
183  if (verbose) {
184  GBS_strstruct note(200);
185  note.cat("Removed ");
186  if (fieldsRemoved>0) {
187  note.nprintf(100, "%i '%s'", fieldsRemoved, dest_field);
188  if (qualitiesRemoved>0) note.cat(" and ");
189  }
190  if (qualitiesRemoved>0) note.nprintf(50, "%i 'quality'", qualitiesRemoved);
191  else if (!fieldsRemoved && !qualitiesRemoved) note.cat("no");
192  note.cat(" entries.");
193  aw_message(note.get_data());
194  }
195 
196  free(dest_field);
197  free(ali_name);
198 
199  return error;
200 }
201 
204 }
205 
206 static void st_check_cb(AW_window *aww, st_check_cb_data *data) {
207  arb_progress glob_progress("Chimera check");
208  GB_transaction ta(data->gb_main);
209 
210  AW_root *awr = aww->get_root();
211 
212  char *ali_name = awr->awar(ST_ML_AWAR_FILTER_ALIGNMENT)->read_string();
213  int bucket_size = awr->awar(ST_ML_AWAR_CQ_BUCKET_SIZE)->read_int();
214  char *tree_name = awr->awar(AWAR_TREE)->read_string();
215  int marked_only = awr->awar(ST_ML_AWAR_CQ_MARKED_ONLY)->read_int();
216 
218  bool keep_old_reports = awr->awar(ST_ML_AWAR_CQ_KEEP_REPORTS)->read_int();
219 
220  GB_ERROR error = NULp;
222  if (!dest_field) error = GB_await_error();
223 
224  if (!error && !keep_old_reports) {
225  error = st_remove_entries(awr, data->gb_main, false);
226  }
227  if (!error) {
228  error = st_ml_check_sequence_quality(data->gb_main, tree_name, ali_name, data->colstat, data->filter, bucket_size, marked_only, report, dest_field);
229  }
230 
231  free(ali_name);
232  free(tree_name);
233 
234  error = ta.close(error);
235  if (error) aw_message(error);
236 }
237 
238 static void STAT_create_awars(AW_root *root, GBDATA *gb_main) {
239  root->awar_string(AWAR_DEFAULT_ALIGNMENT, "-none-", gb_main);
240  root->awar_string(AWAR_TREE, "", gb_main);
241 
242  root->awar_string(ST_ML_AWAR_COLSTAT_NAME, "none");
243 
245  root->awar_string(ST_ML_AWAR_FILTER_NAME, "none");
248 
249  root->awar_int (ST_ML_AWAR_CQ_BUCKET_SIZE, 300);
252  root->awar_int (ST_ML_AWAR_CQ_REPORT, 0);
254 
256 }
257 
259  { ST_ML_AWAR_CQ_MARKED_ONLY, "marked_only" },
260  { ST_ML_AWAR_COLSTAT_NAME, "colstat" },
261  { ST_ML_AWAR_FILTER_NAME, "filter" },
262  { ST_ML_AWAR_CQ_BUCKET_SIZE, "bucketsize" },
263  { ST_ML_AWAR_CQ_DEST_FIELD, "destfield" }, // no need to store field-type here, because it is always GB_STRING
264  { ST_ML_AWAR_CQ_REPORT, "report" },
265  { ST_ML_AWAR_CQ_KEEP_REPORTS, "keepold" },
266 
267  { NULp, NULp }
268 };
269 
271  static AW_window_simple *aws = NULp;
272  if (!aws) {
273  aws = new AW_window_simple;
274  aws->init(root, "CHIMERA_CHECK", "Chimera Check of marked sequences");
275  aws->load_xfig("chimera_check.fig");
276 
277  STAT_create_awars(root, gb_main);
278 
279  aws->callback(AW_POPDOWN);
280  aws->at("close");
281  aws->create_button("CLOSE", "CLOSE", "C");
282 
283  aws->callback(makeHelpCallback("chimera_check.hlp"));
284  aws->at("help");
285  aws->create_button("HELP", "HELP", "H");
286 
287  AW_awar *awar_default_alignment = root->awar_string(AWAR_DEFAULT_ALIGNMENT, "-none-", gb_main);
288  st_check_cb_data *cb_data = new st_check_cb_data(gb_main, root, ST_ML_AWAR_COLSTAT_NAME, ST_ML_AWAR_FILTER_NAME, awar_default_alignment); // bound to cb (not freed)
289 
290  aws->at("which");
291  {
292  aws->create_option_menu(ST_ML_AWAR_CQ_MARKED_ONLY, true);
293  aws->insert_option("All in tree", "t", 0);
294  aws->insert_option("Only marked and in tree", "m", 1);
295  aws->update_option_menu();
296  }
297 
298  aws->at("colstat");
299  aws->callback(makeCreateWindowCallback(COLSTAT_create_selection_window, cb_data->colstat));
300  aws->create_button("SELECT_CSP", ST_ML_AWAR_COLSTAT_NAME);
301 
302 
303  aws->at("filter");
304  aws->callback(makeCreateWindowCallback(awt_create_select_filter_win, cb_data->filter->get_adfiltercbstruct()));
305  aws->create_button("SELECT_FILTER", ST_ML_AWAR_FILTER_NAME);
306 
307  aws->at("sb");
308  aws->create_input_field(ST_ML_AWAR_CQ_BUCKET_SIZE);
309 
311 
312  aws->at("report");
313  {
314  aws->create_option_menu(ST_ML_AWAR_CQ_REPORT, true);
315  aws->insert_option("No", "N", 0);
316  aws->insert_option("to temporary entry", "t", 1);
317  aws->insert_option("to permanent entry", "p", 2);
318  aws->update_option_menu();
319  }
320 
321  aws->at("keep");
322  aws->create_toggle(ST_ML_AWAR_CQ_KEEP_REPORTS);
323 
324  aws->at("del");
325  aws->callback(makeWindowCallback(st_remove_entries_cb, gb_main));
326  aws->create_button("DEL_ENTRIES", "Remove them now!", "R");
327 
328  aws->button_length(10);
329  aws->at("GO");
330  aws->callback(makeWindowCallback(st_check_cb, cb_data));
331  aws->create_button("GO", "GO", "G");
332 
333  aws->at("config");
334  AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "chimera", chimera_config_mapping);
335  }
336  return aws;
337 }
GBDATA * get_gb_main() const
Definition: st_ml.hxx:194
GB_ERROR calc_st_ml(const char *tree_name, const char *alignment_name, const char *species_names, int marked_only, ColumnStat *colstat, const WeightedFilter *weighted_filter) __ATTR__USERESULT
Definition: ST_ml.cxx:493
const char * GB_ERROR
Definition: arb_core.h:25
string result
st_check_cb_data(GBDATA *gb_main_, AW_root *root, const char *columnStatAwarName, const char *filterAwarName, AW_awar *awar_default_alignment)
Definition: ST_window.cxx:136
adfiltercbstruct * get_adfiltercbstruct()
Definition: gui_aliview.hxx:41
AW_window * STAT_create_main_window(AW_root *root, ST_ML *st_ml)
Definition: ST_window.cxx:70
void(* WindowCallbackSimple)(AW_window *)
Definition: cb.h:29
ColumnStat * get_column_statistic()
Definition: st_ml.hxx:175
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:717
void STAT_set_postcalc_callback(ST_ML *st_ml, WindowCallbackSimple postcalc_cb, AW_window *cb_win)
Definition: ST_window.cxx:66
AW_window * COLSTAT_create_selection_window(AW_root *aw_root, ColumnStat *column_stat)
Definition: ColumnStat.cxx:373
#define ST_ML_AWAR_CQ_DEST_FIELD
Definition: ST_window.cxx:43
unsigned char ST_ML_Color
Definition: st_ml.hxx:42
GBDATA * gb_main
Definition: ST_window.cxx:132
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2549
void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback &store_cb, const RestoreConfigCallback &load_or_reset_cb, const char *macro_id, const AWT_predefined_config *predef)
#define AWAR_DEFAULT_ALIGNMENT
Definition: aw_awar_defs.hxx:8
AW_window * STAT_create_chimera_check_window(AW_root *root, GBDATA *gb_main)
Definition: ST_window.cxx:270
#define ST_ML_AWAR_CQ_REPORT
Definition: ST_window.cxx:44
long read_int() const
Definition: AW_awar.cxx:187
ST_ML * st_ml
static char * alignment_name
#define ST_ML_AWAR_CQ_BUCKET_SIZE
Definition: ST_window.cxx:41
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
void cat(const char *from)
Definition: arb_strbuf.h:158
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2482
#define NO_FIELD_SELECTED
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1904
AP_tree * find_node_by_name(const char *species_name)
Definition: ST_ml.cxx:883
Definition: st_ml.hxx:111
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
#define ST_ML_AWAR_COLSTAT_NAME
Definition: ST_window.cxx:33
ST_ML * STAT_create_ST_ML(GBDATA *gb_main)
Definition: ST_window.cxx:110
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:353
boolean verbose
Definition: readseq.c:457
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
GB_ERROR st_ml_check_sequence_quality(GBDATA *gb_main, const char *tree_name, const char *alignment_name, ColumnStat *colstat, const WeightedFilter *weighted_filter, int bucket_size, int marked_only, st_report_enum report, const char *dest_field)
Definition: ST_quality.cxx:241
static void st_remove_entries_cb(AW_window *aww, GBDATA *gb_main)
Definition: ST_window.cxx:202
static AWT_config_mapping_def chimera_config_mapping[]
Definition: ST_window.cxx:258
CONSTEXPR long FIELD_FILTER_STRING_WRITEABLE
Definition: item_sel_list.h:42
static void STAT_create_awars(AW_root *root, GBDATA *gb_main)
Definition: ST_window.cxx:238
static void error(const char *msg)
Definition: mkptypes.cxx:96
void STAT_destroy_ST_ML(ST_ML *&st_ml)
Definition: ST_window.cxx:113
st_report_enum
Definition: st_window.hxx:28
#define AWAR_TREE
bool STAT_update_ml_likelihood(ST_ML *st_ml, char *result[4], int &latest_update, const char *species_name, AP_tree *node)
Definition: ST_window.cxx:122
AW_window * awt_create_select_filter_win(AW_root *aw_root, adfiltercbstruct *acbs)
Definition: AWT_filter.cxx:364
const char * prepare_and_get_selected_itemfield(AW_root *awr, const char *awar_name, GBDATA *gb_main, const ItemSelector &itemtype, FailIfField failIf)
ColumnStat * colstat
Definition: ST_window.cxx:133
char * read_string() const
Definition: AW_awar.cxx:201
#define ST_ML_AWAR_CQ_MARKED_ONLY
Definition: ST_window.cxx:42
#define ST_ML_AWAR_CQ_KEEP_REPORTS
Definition: ST_window.cxx:45
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
#define ST_ML_AWAR_FILTER_SIMPLIFY
Definition: ST_window.cxx:39
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
void set_postcalc_callback(WindowCallbackSimple postcalc_cb_, AW_window *cb_window_)
Definition: st_ml.hxx:200
GB_ERROR close(GB_ERROR error)
Definition: arbdbpp.cxx:32
bool update_ml_likelihood(char *result[4], int &latest_update, const char *species_name, AP_tree *node)
Definition: ST_ml.cxx:727
static void st_ok_cb(AW_window *aww, ST_ML *st_ml)
Definition: ST_window.cxx:47
void nprintf(size_t maxlen, const char *templat,...) __ATTR__FORMAT_MEMBER(2)
Definition: arb_strbuf.cxx:29
AW_awar * map(const char *awarn)
Definition: AW_awar.cxx:523
ItemSelector & SPECIES_get_selector()
Definition: species.cxx:139
GBDATA * GBT_first_species(GBDATA *gb_main)
Definition: aditem.cxx:124
void aw_message(const char *msg)
Definition: AW_status.cxx:932
static GB_ERROR st_remove_entries(AW_root *awr, GBDATA *gb_main, bool verbose)
Definition: ST_window.cxx:143
AW_root * get_root()
Definition: aw_window.hxx:348
GBDATA * GBT_next_species(GBDATA *gb_species)
Definition: aditem.cxx:128
#define NULp
Definition: cxxforward.h:97
WeightedFilter * filter
Definition: ST_window.cxx:134
const char * get_data() const
Definition: arb_strbuf.h:70
ST_ML_Color * get_color_string(const char *species_name, AP_tree *node, size_t start_ali_pos, size_t end_ali_pos)
Definition: ST_ml.cxx:796
AP_tree * STAT_find_node_by_name(ST_ML *st_ml, const char *species_name)
Definition: ST_window.cxx:127
long GBT_get_species_count(GBDATA *gb_main)
Definition: aditem.cxx:207
GB_transaction ta(gb_var)
ST_ML_Color * STAT_get_color_string(ST_ML *st_ml, char *species_name, AP_tree *node, int start_ali_pos, int end_ali_pos)
Definition: ST_window.cxx:118
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
void hide_or_notify(const char *error)
Definition: AW_window.cxx:1817
void create_column_statistic(AW_root *awr, const char *awarname, AW_awar *awar_default_alignment)
Definition: ST_ml.cxx:869
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
#define ST_ML_AWAR_FILTER_FILTER
Definition: ST_window.cxx:38
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
void inc_and_check_user_abort(GB_ERROR &error)
Definition: arb_progress.h:274
void aw_message_if(GB_ERROR error)
Definition: aw_msg.hxx:21
#define ST_ML_AWAR_FILTER_ALIGNMENT
Definition: ST_window.cxx:36
static void st_check_cb(AW_window *aww, st_check_cb_data *data)
Definition: ST_window.cxx:206
void do_postcalc_callback()
Definition: st_ml.hxx:204
#define ST_ML_AWAR_FILTER_NAME
Definition: ST_window.cxx:37