ARB
EDB_root_bact.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : EDB_root_bact.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #include <ed4_extern.hxx>
12 #include "ed4_class.hxx"
13 
14 #include <aw_msg.hxx>
15 #include <arb_progress.h>
16 #include <arbdbt.h>
17 #include <arb_strbuf.h>
18 #include <ad_config.h>
19 
20 void EDB_root_bact::calc_no_of_all(const char *string_to_scan, long *group, long *species) {
21  *group = 0;
22  *species = 0;
23 
24  if (string_to_scan) {
25  long i = 0;
26  while (string_to_scan[i]) {
27  if (string_to_scan[i] == 1) {
28  if (string_to_scan[i+1] == 'L' || string_to_scan[i+1] == 'S') {
29  (*species)++;
30  i++;
31  }
32  else if (string_to_scan[i+1] == 'F' || string_to_scan[i+1] == 'G') {
33  (*group)++;
34  i++;
35  }
36  }
37  i++;
38  }
39  }
40 }
41 
43  ED4_reference_terminals& refterms,
44  char *str,
45  int group_depth,
46  ED4_datamode datamode)
47 {
48  GBDATA *gb_item = NULp;
50 
51  switch (datamode) {
52  case ED4_D_EXTENDED: gb_item = GBT_find_SAI(gb_main, str); break;
53  case ED4_D_SPECIES: gb_item = GBT_find_species(gb_main, str); break;
54  }
55 
56  if (!gb_item) { // didn't find this species/SAI
59  char dummy[150];
60  sprintf(dummy, "%zu. %s\n", not_found_counter, str);
62  not_found_message->cat(dummy);
63  }
64  return ED4_R_BREAK;
65  }
66 
67  // check whether sequence has data in desired alignment
68  bool has_alignment = GB_entry(gb_item, ED4_ROOT->get_alignment_name());
69  if (!has_alignment) {
70  if (datamode == ED4_D_SPECIES) { // only warn about species w/o data (SAIs are skipped silently)
73  char dummy[150];
74  sprintf(dummy, "%zu. %s (no data in alignment)\n", not_found_counter, str);
75  not_found_message->cat(dummy);
76  }
77  }
78  return ED4_R_BREAK;
79  }
80 
81  ED4_species_type spec_type = (datamode == ED4_D_EXTENDED) ? ED4_SP_SAI : ED4_SP_SPECIES;
82 
83 
84  {
85  char namebuffer[NAME_BUFFERSIZE];
86  int count_two = 0;
87 
88  sprintf(namebuffer, "Species_Manager.%ld.%d", ED4_counter, count_two);
89  ED4_species_manager *species_manager = new ED4_species_manager(spec_type, namebuffer, 0, 0, multi_species_manager);
90 
91  species_manager->set_property(PROP_MOVABLE);
92  if (spec_type == ED4_SP_SAI) {
93  ED4_abstract_group_manager *group_man = species_manager->get_parent(ED4_level(LEV_GROUP|LEV_ROOTGROUP))->to_abstract_group_manager();
94  group_man->table().ignore_me(); // ignore SAI tables (does not work - instead ignore SAIs when calculating consensus)
95  }
96  species_manager->set_species_pointer(gb_item);
97  multi_species_manager->append_member(species_manager);
98 
99  sprintf(namebuffer, "MultiName_Manager.%ld.%d", ED4_counter, count_two);
100  ED4_multi_name_manager *multi_name_manager = new ED4_multi_name_manager(namebuffer, 0, 0, species_manager);
101  species_manager->append_member(multi_name_manager);
102 
103  sprintf(namebuffer, "MultiSeq_Manager.%ld.%d", ED4_counter, count_two++);
104  ED4_multi_sequence_manager *multi_sequence_manager = new ED4_multi_sequence_manager(namebuffer, 0, 0, species_manager);
105  species_manager->append_member(multi_sequence_manager);
106 
107  sprintf(namebuffer, "Name_Manager%ld.%d", ED4_counter, count_two++);
108  ED4_name_manager *name_manager = new ED4_name_manager(namebuffer, 0, 0, multi_name_manager);
109  name_manager->set_property(PROP_MOVABLE); // only Speciesname should be movable
110  multi_name_manager->append_member(name_manager);
111 
112  {
113  sprintf(namebuffer, "Species_Name_Term%ld.%d", ED4_counter, count_two++);
114  ED4_species_name_terminal *species_name_terminal = new ED4_species_name_terminal(namebuffer, MAXNAME_WIDTH-(group_depth*BRACKET_WIDTH), TERMINAL_HEIGHT, name_manager);
115  species_name_terminal->set_property((ED4_properties) (PROP_SELECTABLE | PROP_DRAGABLE | PROP_IS_HANDLE));
116  species_name_terminal->set_links(NULp, refterms.sequence());
117  species_name_terminal->set_species_pointer(GB_entry(gb_item, "name"));
118  name_manager->append_member(species_name_terminal);
119  }
120 
121  {
122  sprintf(namebuffer, "Flag_Term%ld.%d", ED4_counter, count_two++);
123  ED4_flag_terminal *flag_terminal = new ED4_flag_terminal(namebuffer, FLAG_WIDTH, TERMINAL_HEIGHT, name_manager);
124  flag_terminal->set_links(NULp, refterms.sequence());
125  name_manager->append_member(flag_terminal);
126  }
127 
128  GBDATA *gb_ali_xxx = GB_entry(gb_item, ED4_ROOT->get_alignment_name());
129  if (gb_ali_xxx) {
130  search_sequence_data_rek(multi_sequence_manager, refterms, gb_ali_xxx, count_two, &max_seq_terminal_length, datamode == ED4_D_EXTENDED);
131  }
132  }
133 
134  return ED4_R_OK;
135 }
136 
138  ED4_reference_terminals& refterms,
139  GBDATA *gb_ali_xxx, // alignment-container (or any subcontainer of)
140  int count_too,
141  ED4_index *max_sequence_terminal_length,
142  bool isSAI)
143 {
144  char namebuffer[NAME_BUFFERSIZE];
146 
147  e4_assert(gb_ali_xxx);
148 
149  for (GBDATA *gb_ali_child = GB_child(gb_ali_xxx); gb_ali_child; gb_ali_child = GB_nextChild(gb_ali_child)) {
150  GB_TYPES type = GB_read_type(gb_ali_child);
151 
152  if (type == GB_INTS || type == GB_FLOATS) {
153  continue;
154  }
155 
156  if (type == GB_DB) { // we have to unpack container
157  search_sequence_data_rek(multi_sequence_manager, refterms, gb_ali_child, count_too, max_sequence_terminal_length, isSAI);
158  }
159  else { // otherwise we enter the data
160  char *key_string = GB_read_key(gb_ali_child);
161  if (key_string[0] != '_') { // don't show sequences starting with an underscore
162  sprintf(namebuffer, "Sequence_Manager.%ld.%d", ED4_counter, count_too++);
163  ED4_sequence_manager *seq_manager = new ED4_sequence_manager(namebuffer, 0, 0, multi_sequence_manager);
164  seq_manager->set_property(PROP_MOVABLE);
165  multi_sequence_manager->append_member(seq_manager);
166 
167  {
168  ED4_sequence_info_terminal *sequence_info_terminal = new ED4_sequence_info_terminal(key_string, SEQUENCE_INFO_WIDTH, TERMINAL_HEIGHT, seq_manager);
169  sequence_info_terminal->set_property((ED4_properties) (PROP_SELECTABLE | PROP_DRAGABLE | PROP_IS_HANDLE));
170  sequence_info_terminal->set_both_links(refterms.sequence_info());
171  sequence_info_terminal->set_species_pointer(gb_ali_child);
172  seq_manager->append_member(sequence_info_terminal);
173  }
174 
175  ED4_text_terminal *text_terminal = NULp;
176 
177  bool is_data = false;
178  bool is_data2 = false;
179  bool is_bits = false;
180  bool is_quality = false;
181 
182  if (strcmp(key_string, "data") == 0) is_data = true; // SAI or species
183  else if (strcmp(key_string, "data2") == 0) is_data2 = true; // used by SAIs with two entries (e.g. first and second digit of 2-digit-numbers)
184  else if (strcmp(key_string, "bits") == 0) is_bits = true; // used by binary SAIs (e.g. MARKERLINE)
185  else if (strcmp(key_string, "quality") == 0) is_quality = true; // used by "quality" entry written by chimera check; see ../STAT/ST_quality.cxx@chimera_check_quality_string
186 
187  bool is_aligned = is_data || is_data2 || is_bits || is_quality;
188 
189  if (is_aligned) {
190  bool shall_display_secinfo = is_data;
191 
192  if (isSAI) {
193  GBDATA *gb_sai = GB_get_grandfather(gb_ali_child);
194  GBDATA *gb_disp_sec = GB_searchOrCreate_int(gb_sai, "showsec", 0);
195  shall_display_secinfo = GB_read_int(gb_disp_sec);
196  }
197 
198  sprintf(namebuffer, "Sequence_Term%ld.%d", ED4_counter, count_too++);
199  ED4_sequence_terminal *seq_term = new ED4_sequence_terminal(namebuffer, 0, TERMINAL_HEIGHT, seq_manager, shall_display_secinfo);
200  seq_term->species_name = seq_term->get_name_of_species();
201 
202  if (is_data) seq_term->set_property(PROP_CONSENSUS_RELEVANT);
204 
205  text_terminal = seq_term;
206  }
207  else {
208  sprintf(namebuffer, "PureText_Term%ld.%d", ED4_counter, count_too++);
209  text_terminal = new ED4_pure_text_terminal(namebuffer, 0, TERMINAL_HEIGHT, seq_manager);
210  }
211 
212  text_terminal->set_property(PROP_CURSOR_ALLOWED);
213  text_terminal->set_both_links(refterms.sequence());
214  seq_manager->append_member(text_terminal);
215 #if defined(DEBUG)
216  // ensure only 1 terminal is consensus-relevant!
217  if (is_data) {
218  seq_manager->get_consensus_relevant_terminal(); // does an error otherwise!
219  }
220 #endif // DEBUG
221  text_terminal->set_species_pointer(gb_ali_child);
222 
223  long string_length;
224  if (gb_ali_child) {
225  string_length = GB_read_count(gb_ali_child);
226  }
227  else {
228  string_length = 100;
229  }
230 
231  int pixel_length = device->get_string_size(ED4_G_SEQUENCES, string_length) + 100; // @@@ "+ 100" looks like a hack
232 
233  *max_sequence_terminal_length = std::max(*max_sequence_terminal_length, long(pixel_length));
234  text_terminal->extension.size[WIDTH] = pixel_length;
235 
236  if (MAXSEQUENCECHARACTERLENGTH < string_length) {
237  MAXSEQUENCECHARACTERLENGTH = string_length;
238  refterms.sequence()->extension.size[WIDTH] = pixel_length;
239  }
240 
242  ED4_ROOT->scroll_links.link_for_hor_slider = text_terminal;
243  }
244  else if (*max_sequence_terminal_length > ED4_ROOT->scroll_links.link_for_hor_slider->extension.size[WIDTH]) {
245  ED4_ROOT->scroll_links.link_for_hor_slider = text_terminal;
246  }
247  }
248  free(key_string);
249  }
250  }
251 
252  return ED4_R_OK;
253 }
254 
256  ED4_reference_terminals& refterms,
257  const char *str,
258  int *index,
259  int group_depth,
260  arb_progress *progress)
261 {
262  const int MAXNAMELEN = 1024;
263 
264  bool expect_separator = true;
265  ED4_datamode datamode = ED4_D_SPECIES;
266  ED4_returncode retCode = ED4_R_OK;
267 
268  char *name = ARB_calloc<char>(MAXNAMELEN);
269  int npos = 0;
270 
271  do {
272  if (expect_separator) {
273  if (str[(*index)+1] == 'L') {
274  datamode = ED4_D_SPECIES;
275  }
276  else if (str[(*index)+1] == 'S') {
277  datamode = ED4_D_EXTENDED;
278  }
279  else {
280  const char *entry = str+*index+1;
281  char tag = entry[0];
282  const char *sep = strchr(entry, 1);
283 
284  if (sep) {
285  int len = sep-entry+1;
286  char *content = ARB_strndup(entry+1, len);
287  char *message = GBS_global_string_copy("Unknown or misplaced tag-id '%c' (with content '%s'). Error in configuration-data!\nTrying to continue..", tag, content);
288 
289  fprintf(stderr, "ARB_EDIT4: %s\n", message);
290  aw_message(message);
291 
292  free(message);
293  free(content);
294  retCode = ED4_R_WARNING;
295 
296  (*index) += sep-entry+1; // set index to next separator
297  continue;
298  }
299  else {
300  fprintf(stderr, "Error reading configuration: Unexpected end of data (at '%s')\n", str+*index);
301 
302  e4_assert(0);
303  retCode = ED4_R_ERROR;
304  break;
305  }
306  e4_assert(0); // never reached!
307  }
308 
309  (*index) += 2;
310  }
311 
312  if (str[*index] != 1) {
313  name[npos++] = str[*index];
314  expect_separator = false;
315  (*index)++;
316  }
317 
318  if (str[*index] == 1 || str[*index] == '\0') {
319  name[npos] = '\0'; // speciesname-generation finished
320  npos = 0;
321 
322  if (progress) {
323  progress->inc();
324  if (progress->aborted()) ED4_exit();
325  }
326 
327  fill_data(multi_species_manager, refterms, name, group_depth, datamode);
328 
329  ED4_counter++;
330  expect_separator = true;
331  }
332  }
333  while (!((str[(*index)] == 1) && (str[(*index)+1] == 'G' || str[(*index)+1]=='E' || str[(*index)+1]=='F')) && (str[*index] != '\0'));
334 
335  free(name);
336 
337  return retCode;
338 }
339 
341  ED4_reference_terminals& refterms,
342  const char *str,
343  int *index,
344  arb_progress& progress)
345 {
346  static int group_depth = 0;
347 
348  while (str[(*index)] != '\0' && str[(*index)+1] != 'E') { // E =
349  if (str[(*index)+1] == 'L' || str[(*index)+1] == 'S') { // L = species, S = SAI
350  fill_species(parent, refterms, str, index, group_depth, &progress);
351  ED4_counter++; // counter is only needed to generate ids
352  }
353 
354  if (str[(*index)] && (str[(*index)+1] == 'G' || str[(*index)+1] == 'F')) { // Group or folded group
355  group_depth++;
356  bool is_folded = str[(*index)+1]=='F';
357 
358  char groupname[GB_GROUP_NAME_MAX];
359  {
360  ED4_index gpos = 0;
361  for (*index += 2, gpos = 0; str[*index] != 1; (*index)++) { // Jump over 'G' and Blank to get Groupname
362  groupname[gpos++] = str[*index];
363  }
364  groupname[gpos] = '\0';
365  }
366 
367  ED4_multi_species_manager *multi_species_manager;
368  ED4_build_group_manager_start(parent, groupname, group_depth, is_folded, refterms, multi_species_manager);
369 
370  ED4_counter++;
371  scan_string(multi_species_manager, refterms, str, index, progress);
372 
373  ED4_build_group_manager_end(multi_species_manager);
374 
375  if (is_folded) multi_species_manager->hide_children();
376  }
377  }
378 
379  if (str[(*index)] && str[(*index)+1] == 'E') {
380  (*index)+=2;
381  group_depth--;
382  }
383 }
384 
385 void EDB_root_bact::save_current_config(char *confname) { // and save it in database
386  GB_ERROR error;
388  GBT_config cfg(gb_main, confname, error);
389 
390  error = NULp; // ignore not-found error
391 
392  int counter = 0;
393  ED4_device_manager *device_manager = ED4_ROOT->get_device_manager();
394 
395  for (int i=0; i<device_manager->members(); i++) {
396  ED4_base *area = device_manager->member(i);
397  if (area->is_area_manager()) {
398  GBS_strstruct area_config(10000);
399  area->generate_configuration_string(area_config);
400  cfg.set_definition(counter++, area_config.release());
401  }
402  }
403 
404  // add/update comment
405  {
406  char *newComment = GBS_log_action_to(cfg.get_comment(), "saved from ARB_EDIT4", true);
407  cfg.set_comment(newComment);
408  free(newComment);
409  }
410 
411  error = cfg.save(gb_main, confname, true);
412  aw_message_if(error);
413 }
414 
void set_both_links(ED4_base *ref)
Definition: ed4_class.hxx:972
AW_device * get_device() const
Definition: ed4_class.hxx:767
GB_TYPES type
void calc_no_of_all(const char *string_to_scan, long *group, long *species)
size_t not_found_counter
Definition: ED4_main.cxx:63
AW_pos size[2]
Definition: ed4_defs.hxx:255
long GB_read_int(GBDATA *gbd)
Definition: arbdb.cxx:729
char * GB_read_key(GBDATA *gbd)
Definition: arbdb.cxx:1652
GBDATA * GB_child(GBDATA *father)
Definition: adquery.cxx:322
int MAXNAME_WIDTH
Definition: ED4_main.cxx:57
ED4_base * member(ED4_index i) const
Definition: ed4_class.hxx:795
ED4_datamode
Definition: ed4_defs.hxx:146
BaseFrequencies & table()
Definition: ed4_class.hxx:1648
#define BRACKET_WIDTH
Definition: ed4_defs.hxx:77
void set_species_pointer(GBDATA *gbd)
Definition: ed4_class.hxx:949
ED4_returncode search_sequence_data_rek(ED4_multi_sequence_manager *multi_sequence_manager, ED4_reference_terminals &refterms, GBDATA *gb_ali_xxx, int count_too, ED4_index *max_sequence_terminal_length, bool isSAI)
ED4_root * ED4_ROOT
Definition: ED4_main.cxx:49
char * release()
Definition: arb_strbuf.h:129
void cat(const char *from)
Definition: arb_strbuf.h:199
ED4_group_manager * ED4_build_group_manager_start(ED4_manager *group_parent, GB_CSTR group_name, int group_depth, bool is_folded, ED4_reference_terminals &refterms, ED4_multi_species_manager *&multi_species_manager)
Definition: ED4_base.cxx:233
GBDATA * GB_get_grandfather(GBDATA *gbd)
Definition: arbdb.cxx:1728
long ED4_counter
Definition: ED4_main.cxx:61
#define e4_assert(bed)
Definition: ed4_class.hxx:14
const int WIDTH
#define MAXNAMELEN
void save_current_config(char *confname)
GBDATA * GBT_find_SAI(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:177
ED4_level
Definition: ed4_defs.hxx:118
#define SEQUENCE_INFO_WIDTH
Definition: ed4_defs.hxx:80
char * get_name_of_species()
Definition: ED4_base.cxx:680
long GB_read_count(GBDATA *gbd)
Definition: arbdb.cxx:758
void append_member(ED4_base *new_member)
Definition: arbdb.h:78
GB_TYPES GB_read_type(GBDATA *gbd)
Definition: arbdb.cxx:1643
void ED4_build_group_manager_end(ED4_multi_species_manager *multi_species_manager)
Definition: ED4_base.cxx:316
ED4_index members() const
Definition: ed4_class.hxx:797
#define MAX_SHOWN_MISSING_SPECIES
Definition: ed4_defs.hxx:55
int get_string_size(int gc, long textlen) const
Definition: AW_device.cxx:443
ED4_returncode
Definition: ed4_defs.hxx:159
void hide_children()
Definition: ED4_base.cxx:819
GBDATA * get_gb_main() const
Definition: ed4_class.hxx:1422
bool aborted()
Definition: arb_progress.h:335
static int group[MAXN+1]
Definition: ClustalV.cxx:65
ED4_species_type
Definition: ed4_class.hxx:886
void message(char *errortext)
ED4_window * first_window
Definition: ed4_class.hxx:1428
const char * get_comment() const
Definition: ad_config.h:63
ED4_returncode fill_data(ED4_multi_species_manager *multi_species_manager, ED4_reference_terminals &refterms, char *str, int group_depth, ED4_datamode datamode)
static void error(const char *msg)
Definition: mkptypes.cxx:96
void scan_string(ED4_multi_species_manager *parent, ED4_reference_terminals &refterms, const char *str, int *index, arb_progress &progress)
void set_comment(const char *newComment)
Definition: ad_config.h:64
int FLAG_WIDTH
Definition: ED4_main.cxx:59
GBDATA * GB_searchOrCreate_int(GBDATA *gb_container, const char *fieldpath, long default_value)
Definition: adquery.cxx:569
GB_ERROR save(GBDATA *gb_main, const char *name, bool warnIfSavingDefault) const
Definition: ad_config.h:67
void ignore_me()
Definition: chartable.h:238
GBS_strstruct * not_found_message
Definition: ED4_main.cxx:64
char * GBS_log_action_to(const char *comment, const char *action, bool stamp)
Definition: adstring.cxx:976
void ED4_exit() __ATTR__NORETURN
ED4_scroll_links scroll_links
Definition: ed4_class.hxx:1434
ED4_extension extension
Definition: ed4_class.hxx:924
int TERMINAL_HEIGHT
Definition: ED4_main.cxx:51
#define NAME_BUFFERSIZE
Definition: ed4_defs.hxx:111
Definition: arbdb.h:72
ED4_sequence_info_terminal * sequence_info()
Definition: ed4_class.hxx:1359
ED4_returncode fill_species(ED4_multi_species_manager *multi_species_manager, ED4_reference_terminals &refterms, const char *str, int *index, int group_depth, arb_progress *progress)
void generate_configuration_string(GBS_strstruct &buffer)
Definition: ED4_base.cxx:324
int MAXSEQUENCECHARACTERLENGTH
Definition: ED4_main.cxx:56
#define GB_GROUP_NAME_MAX
Definition: arbdbt.h:16
void set_property(ED4_properties prop)
Definition: ed4_class.hxx:975
char * ARB_strndup(const char *start, int len)
Definition: arb_string.h:83
const char * get_alignment_name() const
Definition: ed4_class.hxx:1458
ED4_sequence_terminal * sequence()
Definition: ed4_class.hxx:1358
ED4_properties
Definition: ed4_defs.hxx:174
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
long max_seq_terminal_length
Definition: ED4_main.cxx:66
#define NULp
Definition: cxxforward.h:116
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:139
int is_area_manager() const
Definition: ed4_class.hxx:1110
GB_TYPES
Definition: arbdb.h:62
GBDATA * GB_nextChild(GBDATA *child)
Definition: adquery.cxx:326
GBDATA * gb_main
Definition: adname.cxx:32
ED4_device_manager * get_device_manager()
Definition: ed4_class.hxx:2228
ED4_manager * get_parent(ED4_level lev) const
Definition: ed4_class.hxx:1821
const ED4_terminal * get_consensus_relevant_terminal() const
Definition: ED4_base.cxx:619
long ED4_index
Definition: ed4_defs.hxx:113
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
void aw_message_if(GB_ERROR error)
Definition: aw_msg.hxx:21
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:194
void set_definition(int area, char *new_def)
Definition: ad_config.h:57
#define max(a, b)
Definition: f2c.h:154