ARB
ED4_detect_bad_ali.cxx
Go to the documentation of this file.
1 // ========================================================= //
2 // //
3 // File : ED4_detect_bad_ali.cxx //
4 // Purpose : detect alignment errors in helix regions //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in May 23 //
7 // http://www.arb-home.de/ //
8 // //
9 // ========================================================= //
10 
11 #include "ed4_detect_bad_ali.hxx"
12 #include "ed4_class.hxx"
13 
14 #include <AW_helix.hxx>
15 
16 #include <aw_awar_defs.hxx>
17 #include <aw_awar.hxx>
18 #include <aw_msg.hxx>
19 #include <aw_select.hxx>
20 #include <aw_root.hxx>
21 
22 #include <arbdbt.h>
23 #include <arb_defs.h>
24 
25 #include <string>
26 #include <map>
27 #include <vector>
28 #include <items.h>
29 #include <item_sel_list.h>
30 
31 using namespace std;
32 
33 const long NOT_CALCULATED = -1;
34 
35 typedef map<string, long> BadPositionsForSpecies;
37 
38 typedef map<size_t, size_t> PairedPositions;
39 
41  GBDATA *gb_main;
42  const AW_helix& helix;
43 
44  string ali;
45  string error;
46 
47  char symbol2count[256];
48 
49  BadPositionsForSpecies bad_positions; // list of examined species
50  PairedPositions paired_positions; // list of paring positions of all involved helices
51 
52  void note_error(GB_ERROR err) {
53  if (err && !has_error()) error = err;
54  }
55 
56  void init_bad_positions(const char *species_list) {
57  bad_positions.clear();
58  if (!has_error()) {
59  ConstStrArray species;
60  GBT_split_string(species, species_list, ";", SPLIT_DROPEMPTY);
61 
62  for (size_t i = 0; i<species.size(); ++i) {
63  bad_positions[species[i]] = NOT_CALCULATED;
64  }
65  if (bad_positions.empty()) {
66  note_error("No species found");
67  }
68  }
69  }
70  void add_pair_position(size_t pos, size_t pair_pos) {
71  if (pos>pair_pos) swap(pos, pair_pos);
72  arb_assert(pos<pair_pos);
73  if (paired_positions.find(pos) != paired_positions.end()) {
74  note_error(GBS_global_string("Duplicate entry for helix position %i", info2bio(pos)));
75  }
76  else {
77  paired_positions[pos] = pair_pos;
78  }
79  }
80  void init_paired_positions(const CharPtrArray& helices) {
81  paired_positions.clear();
82  if (!has_error()) {
83  if (helices.size() == 1 && strcmp(helices[0], "*") == 0) {
84  // use all helices
85  for (long pos = helix.first_pair_position(); pos != -1; pos = helix.next_pair_position(pos)) {
86  const BI_helix_entry& entry = helix.entry(pos);
87  if (entry.helix_nr[0] == '-') { // only add left helices
88  add_pair_position(pos, entry.pair_pos);
89  }
90  }
91  }
92  else {
93  for (size_t i = 0; i<helices.size() && !has_error(); ++i) {
94  long firstPos = helix.first_position(helices[i]);
95  if (firstPos == -1) {
96  note_error(GBS_global_string("Invalid helix number '%s'", helices[i]));
97  }
98  else {
99  long lastPos = helix.last_position(helices[i]);
100  arb_assert(lastPos != -1); // otherwise BI_helix is corrupted
101 
102  for (long pos = firstPos; pos<=lastPos && pos>0 && !has_error(); ) {
103  const BI_helix_entry& entry = helix.entry(pos);
104  add_pair_position(pos, entry.pair_pos);
105  pos = entry.next_pair_pos;
106  }
107  }
108  }
109  }
110 
111  if (paired_positions.empty()) {
112  note_error("List of helix positions to examine is empty");
113  }
114  }
115  }
116  void init_bad_symbol_table(const char *bad_symbols) {
117  memset(symbol2count, 0, 256);
118  int count = 0;;
119  for (int i = 0; bad_symbols[i]; ++i) {
120  if (bad_symbols[i] != ' ') { // ignore space
121  symbol2count[safeCharIndex(bad_symbols[i])] = 1;
122  ++count;
123  }
124  }
125  if (!count) {
126  note_error("no 'bad' helix symbol defined");
127  }
128  }
129 
130  long calculate_bad_positions(const string& species) {
131  long bad = -1;
132 
133  {
134  GB_transaction ta(gb_main);
135  GBDATA *gb_species = GBT_find_species(gb_main, species.c_str());
136 
137  if (!gb_species) {
138  note_error(GBS_global_string("no such species: '%s'", species.c_str()));
139  }
140  else {
141  GBDATA *gb_seq = GBT_find_sequence(gb_species, ali.c_str());
142  if (!gb_seq) {
143  note_error(GBS_global_string("species '%s' has no data in alignment '%s'",
144  species.c_str(), ali.c_str()));
145  }
146  else {
147  GB_CSTR sequence = GB_read_char_pntr(gb_seq);
148  const size_t seq_len = GB_read_string_count(gb_seq);
149 
150  bad = 0;
151  for (PairedPositions::const_iterator pp = paired_positions.begin(); pp != paired_positions.end(); ++pp) {
152  const size_t p1 = pp->first;
153  const size_t p2 = pp->second;
154 
155  const char b1 = p1<seq_len ? sequence[p1] : '.';
156  const char b2 = p2<seq_len ? sequence[p2] : '.';
157 
158  const char sym = helix.get_symbol(b1, b2);
159  bad += symbol2count[safeCharIndex(sym)];
160  }
161  }
162  }
163  }
164 
165  return bad;
166  }
167 
168  void update_bad_position_counts() {
169  for (BadPositionsForSpecies::iterator bp = bad_positions.begin(); bp != bad_positions.end(); ++bp) {
170  if (bp->second == NOT_CALCULATED) {
171  bp->second = calculate_bad_positions(bp->first);
172  }
173  }
174  }
175 
176 public:
177  HelixAlignmentQuality(GBDATA *gb_main_, const AW_helix& helix_, const char *ali_,
178  const char *species_list, // @@@ pass ConstStrArray instead?
179  const CharPtrArray& helices, // contains helix numbers to use (as text) or one entry containing a '*' (meaning: all)
180  const char *bad_symbols)
181  : gb_main(gb_main_),
182  helix(helix_),
183  ali(ali_)
184  {
185  note_error(helix.get_error());
186  init_bad_positions(species_list);
187  init_paired_positions(helices);
188  init_bad_symbol_table(bad_symbols);
189  }
190 
191  bool has_error() const { return !error.empty(); }
192  GB_ERROR get_error() const { return has_error() ? error.c_str() : NULp; }
193 
194  size_t size() const { arb_assert(!has_error()); return bad_positions.size(); }
195  size_t positions() const { arb_assert(!has_error()); return paired_positions.size(); }
196 
198  arb_assert(!has_error());
199  update_bad_position_counts();
200  return bad_positions;
201  }
202 };
203 
204 // --------------------------------------------------------------------------------
205 
208 
209 public:
211  bad_pos(bad_pos_)
212  {}
213 
214  bool operator()(const string& s1, const string& s2) const {
215  long b1 = bad_pos.find(s1)->second;
216  long b2 = bad_pos.find(s2)->second;
217  long cmp = b2 - b1;
218  if (!cmp) cmp = s1.compare(s2);
219  return cmp<0;
220  }
221 };
222 
223 typedef vector<string> StringVector;
224 
226  result.clear();
227 
228  for (BadPositionsForSpeciesConst::const_iterator s = bad_pos.begin(); s != bad_pos.end(); ++s) {
229  long badCount = long(s->second);
230  if (badCount>0) result.push_back(s->first);
231  }
232 
233  sort(result.begin(), result.end(), BadPositionsOrder(bad_pos));
234 }
235 
236 static void parse_helix_list(StrArray& result_helices, const char *helix_list) {
237  ConstStrArray list_entries;
238  GBT_split_string(list_entries, helix_list, ",", SPLIT_KEEPEMPTY);
239 
240  for (size_t i = 0; i<list_entries.size(); ++i) {
241  const char *entry = list_entries[i];
242  if (strcmp(entry, "*") == 0) {
243  result_helices.erase();
244  result_helices.put(strdup("*"));
245  return;
246  }
247  else {
248  const char *minus = strchr(entry, '-');
249  if (minus) {
250  int h1 = atoi(entry);
251  int h2 = atoi(minus+1);
252 
253  if (h1>h2) swap(h1, h2);
254 
255  for (int h = h1; h<=h2; ++h) {
256  result_helices.put(GBS_global_string_copy("%i", h));
257  }
258  }
259  else {
260  // note that 'entry' may be an empty string here. leads to useful error "Invalid helix number ''"
261  result_helices.put(strdup(entry));
262  }
263  }
264  }
265 }
266 
267 #define StrArray_FROM_HELIXLIST(varname, helixlist) StrArray varname; parse_helix_list(varname, helixlist)
268 
269 // --------------------------------------------------------------------------------
270 
271 #ifdef UNIT_TESTS
272 #ifndef TEST_UNIT_H
273 #include <test_unit.h>
274 #endif
275 #include <arb_strbuf.h>
276 
277 static char *BadPositionsToString(BadPositionsForSpeciesConst& bad_pos) {
278  StringVector sortedSpecies;
279  getSpeciesSortedByBadPositions(bad_pos, sortedSpecies);
280 
281  GBS_strstruct result(sortedSpecies.size()*(8+1+3+1)+1);
282 
283  for (StringVector::const_iterator s = sortedSpecies.begin(); s != sortedSpecies.end(); ++s) {
284  const string& species = *s;
285  long badCount = bad_pos.find(species)->second;
286  result.ncat(species.c_str(), species.length());
287  result.put('=');
288  result.putlong(badCount);
289  result.put(',');
290  }
291 
292  result.cut_tail(1);
293  return result.release();
294 }
295 
296 
297 
298 void TEST_count_bad_ali_positions() {
299  GB_shell shell;
300  {
301  AW_root aw_root("min_ascii.arb", UNITTEST_MOCK);
302  GBDATA *gb_main = GB_open("TEST_trees.arb", "r");
303 
304  char *ali = GBT_get_default_alignment(gb_main);
305 
306  AW_helix helix(&aw_root);
307  helix.init(gb_main, ali);
308 
309  char *marked_species;
310  char *all_species;
311  {
312  GB_transaction ta(gb_main);
313 
314  marked_species = GBT_store_marked_species(gb_main, false);
315  GBT_mark_all(gb_main, 1);
316  all_species = GBT_store_marked_species(gb_main, false);
317  }
318 
319  StrArray_FROM_HELIXLIST(helices_none, "");
320  StrArray_FROM_HELIXLIST(helices_all, "*");
321  StrArray_FROM_HELIXLIST(helices_1to5, "1-5");
322  StrArray_FROM_HELIXLIST(helices_4to5, "4-5");
323  StrArray_FROM_HELIXLIST(helices_1, "1");
324  StrArray_FROM_HELIXLIST(helices_51, "5,1");
325  StrArray_FROM_HELIXLIST(helices_514, "5,1,4");
326  StrArray_FROM_HELIXLIST(helices_515, "5,1,5");
327 
328  {
329  HelixAlignmentQuality marked_quality(gb_main, helix, ali, marked_species, helices_1, "#");
330  HelixAlignmentQuality all_quality (gb_main, helix, ali, all_species, helices_51, "#");
331  HelixAlignmentQuality all2_quality (gb_main, helix, ali, all_species, helices_514, "#*+");
332  HelixAlignmentQuality all3_quality (gb_main, helix, ali, all_species, helices_all, "#*+");
333  HelixAlignmentQuality all4_quality (gb_main, helix, ali, all_species, helices_4to5, "#*+");
334 
335  TEST_EXPECT_NO_ERROR(marked_quality.get_error());
336  TEST_EXPECT_NO_ERROR(all_quality.get_error());
337  TEST_EXPECT_NO_ERROR(all2_quality.get_error());
338  TEST_EXPECT_NO_ERROR(all3_quality.get_error());
339  TEST_EXPECT_NO_ERROR(all4_quality.get_error());
340 
341  // test number of examined species:
342  TEST_EXPECT_EQUAL(marked_quality.size(), 6);
343  TEST_EXPECT_EQUAL(all_quality.size(), 15);
344  TEST_EXPECT_EQUAL(all2_quality.size(), 15);
345  TEST_EXPECT_EQUAL(all3_quality.size(), 15);
346  TEST_EXPECT_EQUAL(all4_quality.size(), 15);
347 
348  TEST_EXPECT_EQUAL(marked_quality.positions(), 10);
349  TEST_EXPECT_EQUAL(all_quality.positions(), 18);
350  TEST_EXPECT_EQUAL(all2_quality.positions(), 20);
351  TEST_EXPECT_EQUAL(all3_quality.positions(), 20);
352  TEST_EXPECT_EQUAL(all4_quality.positions(), 10);
353 
354  TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(marked_quality.results()), "CorGluta=3,CorAquat=1,CytAquat=1");
355  TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(all_quality.results()), "CloTyro3=7,CytAquat=7,CloInnoc=3,CorGluta=3,CloBifer=1,CloCarni=1,CloPaste=1,CloTyro2=1,CloTyro4=1,CloTyrob=1,CorAquat=1");
356  TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(all2_quality.results()), "CloTyro3=10,CytAquat=8,CloTyro2=7,CloTyro4=7,CloTyrob=7,CorGluta=4,CloInnoc=3,CloBifer=2,CloButy2=1,CloButyr=1,CloCarni=1,CloPaste=1,CorAquat=1");
357  TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(all3_quality.results()), "CloTyro3=10,CytAquat=8,CloTyro2=7,CloTyro4=7,CloTyrob=7,CorGluta=4,CloInnoc=3,CloBifer=2,CloButy2=1,CloButyr=1,CloCarni=1,CloPaste=1,CorAquat=1");
358  TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(all4_quality.results()), "CytAquat=6,CloTyro3=5,CloInnoc=2,CloTyro2=2,CloTyro4=2,CloTyrob=2,CloBifer=1");
359  }
360 
361  // test errors:
362  {
363  HelixAlignmentQuality err1(gb_main, helix, ali, "", helices_51, "#");
364  HelixAlignmentQuality err2(gb_main, helix, ali, marked_species, helices_none, "#");
365  HelixAlignmentQuality err3(gb_main, helix, ali, marked_species, helices_51, " "); // define no bad helix symbol (spaces are ignored)
366  HelixAlignmentQuality err4(gb_main, helix, ali, marked_species, helices_515, "#");
367  HelixAlignmentQuality err5(gb_main, helix, ali, "fakeSpec", helices_51, "#");
368  HelixAlignmentQuality err6(gb_main, helix, ali, marked_species, helices_1to5, "#");
369 
370  TEST_EXPECT_ERROR_CONTAINS(err1.get_error(), "No species found");
371  TEST_EXPECT_ERROR_CONTAINS(err2.get_error(), "Invalid helix number ''");
372  TEST_EXPECT_ERROR_CONTAINS(err3.get_error(), "no 'bad' helix symbol defined");
373  TEST_EXPECT_ERROR_CONTAINS(err4.get_error(), "Duplicate entry for helix position 65");
374 
375  TEST_EXPECT_NO_ERROR(err5.get_error()); // no error yet
376  TEST_EXPECT_EQUAL(err5.size(), 1); // number of species
377  TEST_EXPECT_EQUAL(err5.positions(), 18);
378  err5.results(); // triggers error
379  TEST_EXPECT_ERROR_CONTAINS(err5.get_error(), "no such species: 'fakeSpec'");
380 
381  TEST_EXPECT_ERROR_CONTAINS(err6.get_error(), "Invalid helix number '2'");
382  }
383 
384  free(all_species);
385  free(marked_species);
386  free(ali);
387 
388  GB_close(gb_main);
389  }
390 }
391 
392 #endif // UNIT_TESTS
393 
394 // --------------------------------------------------------------------------------
395 
396 #define AWAR_BADALI_BASE "badali/"
397 #define AWAR_BADALI_HELIXLIST AWAR_BADALI_BASE "helixlist" // helix-numbers (comma-separated)
398 #define AWAR_BADALI_SYMBOLS AWAR_BADALI_BASE "symbols" // helix-symbols which count as "bad"
399 
400 #define AWAR_BADALI_TEMP "tmp/" AWAR_BADALI_BASE
401 #define AWAR_BADALI_SPECIES AWAR_BADALI_TEMP "selected" // selected species
402 #define AWAR_BADALI_FIELD AWAR_BADALI_TEMP "field" // name of field to store bad positions
403 
405  aw_root->awar_string(AWAR_BADALI_HELIXLIST, "", aw_def)->set_srt(" =,:,,=,");
406  aw_root->awar_string(AWAR_BADALI_SYMBOLS, "#", aw_def);
407  aw_root->awar_string(AWAR_BADALI_SPECIES, "", aw_def);
408  aw_root->awar_string(AWAR_BADALI_FIELD, "", aw_def);
409 }
410 
411 static ARB_ERROR add_species_to_list_cb(ED4_base *base, StrArray *species) {
412  ARB_ERROR error = NULp;
413 
414  if (base->is_species_manager()) {
415  ED4_species_manager *species_manager = base->to_species_manager();
416  ED4_species_name_terminal *species_name_terminal = species_manager->search_spec_child_rek(LEV_SPECIES_NAME)->to_species_name_terminal();
417 
418  if (species_name_terminal->get_species_pointer() && !species_manager->is_SAI_manager()) {
419  char *species_name = GB_read_as_string(species_name_terminal->get_species_pointer());
420  species->put(species_name);
421  }
422  }
423 
424  return error;
425 }
426 
429  StrArray species;
431  aw_message_if(error.deliver());
432  return GBT_join_strings(species, ';');
433 }
434 
436  // Performs the following jobs:
437  // - calculate alignment errors.
438  // - update the list of worst helix alignments (in GUI).
439  // - update/write contents of database field (alignment error count; optional)
440 
441  AW_root *aw_root = aww->get_root();
442  GBDATA *gb_main = ED4_ROOT->get_gb_main();
443  const char *target_field;
444 
445  {
446  GB_transaction ta(gb_main);
447 
449  if (!target_field) {
450  if (GB_have_error()) {
451  aw_message(GBS_global_string("Invalid target field selected: %s", GB_await_error()));
452  return;
453  }
454  }
455  }
456 
457  char *species_list = create_list_of_loaded_species();
458  char *bad_symbols = aw_root->awar(AWAR_BADALI_SYMBOLS)->read_string();
459 
461 
462  // @@@ better show progress (next command may need much time)
463  HelixAlignmentQuality quality(gb_main,
464  *ED4_ROOT->helix,
466  species_list,
467  helices,
468  bad_symbols);
469 
470  sellst->clear();
471  if (!quality.has_error()) {
472  BadPositionsForSpeciesConst& bad_pos = quality.results();
473  if (!quality.has_error()) {
474  const bool writeToField = target_field;
475  if (writeToField) {
476  GB_transaction ta(gb_main);
477  GB_ERROR error = NULp;
479 
480  for (BadPositionsForSpeciesConst::const_iterator bp = bad_pos.begin(); bp != bad_pos.end() && !error; ++bp) { // this loop includes zero counts
481  const char* species_name = bp->first.c_str();
482  long bad_positions = bp->second;
483 
484  GBDATA *gb_species = GBT_find_species_rel_species_data(gb_species_data, species_name);
485  if (!gb_species) {
486  error = GBS_global_string("Could not find species '%s' (Reason: %s)", species_name, GB_await_error());
487  }
488  else {
489  GBDATA *gb_field = GBT_searchOrCreate_itemfield_according_to_changekey(gb_species, target_field, SPECIES_get_selector().change_key_path);
490  if (!gb_field) error = GB_await_error();
491  if (!error) error = GB_write_lossless_int(gb_field, bad_positions);
492  }
493  }
494 
495  aw_message_if(error);
496  }
497 
498  StringVector order;
499  getSpeciesSortedByBadPositions(bad_pos, order);
500 
501  for (StringVector::const_iterator species = order.begin(); species != order.end(); ++species) { // this loop excludes zero counts
502  const char *species_name = species->c_str();
503  size_t bad = bad_pos.find(*species)->second;
504 
505  sellst->insert(GBS_global_string("%-8s | %zu", species_name, bad), species_name);
506  }
507  sellst->insert_default("<acceptable helix alignment>", "");
508  }
509  }
510 
511  if (quality.has_error()) {
512  sellst->clear();
513  sellst->insert_default(GBS_global_string("<Error: %s>", quality.get_error()), "");
514  }
515 
516  sellst->update();
517 
518  free(bad_symbols);
519  free(species_list);
520 }
521 
523 
524 static void jump_to_next_helix_cb(AW_window *, JumpWhy called) {
525  ED4_MostRecentWinContext context;
526 
528  AW_root *aw_root = win->aww->get_root();
529 
531 
532  AW_awar *awar_helixnr = aw_root->awar(win->awar_path_for_helixNr);
533  int current_helixnr = atoi(awar_helixnr->read_char_pntr());
534  int wanted_helixnr = 0;
535  int preference = current_helixnr>0 ? 1 : -1;
536 
537  if (current_helixnr == 0) {
538  wanted_helixnr = atoi(helices[0]);
539  }
540  else {
541  if (called == BY_SELECTION) {
542  wanted_helixnr = abs(current_helixnr);
543  }
544  else { // if called == BY_BUTTON => select new helix
545  wanted_helixnr = atoi(helices[0]);
546  for (size_t i = 0; i<helices.size()-1; ++i) {
547  if (abs(current_helixnr) == abs(atoi(helices[i]))) {
548  wanted_helixnr = atoi(helices[i+1]);
549  }
550  }
551  }
552  }
553 
554  wanted_helixnr *= preference; // choose left or right helix
555 
556  if (wanted_helixnr != 0) {
557  if (wanted_helixnr != current_helixnr || called == BY_BUTTON) { // avoid triggering callback w/o real change
558  awar_helixnr->write_string(GBS_global_string("%i", wanted_helixnr));
559  // callback is NOT bound to AWAR (but to inputfield) -> call it manually:
561  }
562  }
563  else {
564  aw_message("No helix to jump to.");
565  }
566 }
567 
569 
570 static void selected_changed_cb(AW_root *aw_root, SelectedAwar whatChanged) {
571  static bool in_callback = false;
572 
573  if (!in_callback) {
574  LocallyModify<bool> flag(in_callback, true);
575 
576  const char *source_awar_name = AWAR_BADALI_SPECIES;
577  const char *dest_awar_name = AWAR_SPECIES_NAME;
578 
579  if (whatChanged == SELECTED_SPECIES) {
580  swap(source_awar_name, dest_awar_name);
581  }
582 
583  const char *selected_species = aw_root->awar(source_awar_name)->read_char_pntr();
584  if (selected_species[0]) { // if nothing selected => do not change other AWAR
585  aw_root->awar(dest_awar_name)->write_string(selected_species);
586  if (SELECTED_BAD_ALI) {
588  }
589  }
590  }
591 }
592 
593 void ED4_popup_detect_bad_alignment_window(AW_window *editor_window, const WindowCallback *helixSettings_cb) {
594  static AW_window_simple *aws = NULp;
595 
596  ED4_LocalWinContext uses(editor_window);
597 
598  if (!aws) {
599  AW_root *aw_root = editor_window->get_root();
600 
601  aws = new AW_window_simple;
602 
603  aws->init(aw_root, "DETECT_BAD_ALI", "Detect bad helix alignment");
604  aws->load_xfig("edit4/detect_bad_ali.fig");
605 
606  aws->button_length(10);
607 
608  aws->at("close");
609  aws->callback(AW_POPDOWN);
610  aws->create_button("CLOSE", "CLOSE", "C");
611 
612  aws->at("help");
613  aws->callback(makeHelpCallback("bad_alignment.hlp"));
614  aws->create_button("HELP", "HELP", "H");
615 
616  aws->at("list");
617  AW_selection_list *sellst = aws->create_selection_list(AWAR_BADALI_SPECIES);
618  sellst->insert_default("<not calculated>", "");
619  sellst->update();
620 
621  aws->at("config");
622  aws->auto_space(5, 5);
623  aws->label_length(20);
624 
625  aws->label("Helices to examine\n"
626  "(comma-separated list)");
627  aws->create_input_field(AWAR_BADALI_HELIXLIST, 15);
628 
629  aws->callback(makeWindowCallback(jump_to_next_helix_cb, BY_BUTTON));
630  aws->create_autosize_button("JUMP", "Jump", "J");
631 
632  aws->at_newline();
633 
634  aws->label("Detected symbols");
635  aws->create_input_field(AWAR_BADALI_SYMBOLS, 5);
636 
637  aws->callback(*helixSettings_cb);
638  aws->create_autosize_button("HELIX_SETTINGS", "Helix settings", "H");
639 
640  aws->at_newline();
641  aws->label("Write to database field");
643 
644  aws->at("calc");
645  aws->callback(makeWindowCallback(calc_and_update_alignment_errors_cb, sellst));
646  aws->create_button("CALCULATE", "Calculate", "C");
647 
650  }
651 
652  e4_assert(aws);
653  aws->activate();
654 
655 }
656 
657 
vector< string > StringVector
static void calc_and_update_alignment_errors_cb(AW_window *aww, AW_selection_list *sellst)
BadPositionsOrder(BadPositionsForSpeciesConst bad_pos_)
#define arb_assert(cond)
Definition: arb_assert.h:245
string result
map< string, long > BadPositionsForSpecies
GBDATA * GB_open(const char *path, const char *opent)
Definition: ad_load.cxx:1363
void cut_tail(size_t byte_count)
Definition: arb_strbuf.h:145
AW_helix * helix
Definition: ed4_class.hxx:1445
AW_awar * set_srt(const char *srt)
Definition: AW_awar.cxx:567
size_t size() const
Definition: arb_strarray.h:85
Definition: BI_helix.hxx:73
const BI_helix_entry & entry(size_t pos) const
Definition: BI_helix.hxx:107
CONSTEXPR_INLINE unsigned char safeCharIndex(char c)
Definition: dupstr.h:73
void insert_default(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:385
long GBT_mark_all(GBDATA *gb_main, int flag)
Definition: aditem.cxx:295
map< size_t, size_t > PairedPositions
BadPositionsForSpeciesConst results()
const long NOT_CALCULATED
long
Definition: AW_awar.cxx:152
static void selected_changed_cb(AW_root *aw_root, SelectedAwar whatChanged)
long pair_pos
Definition: BI_helix.hxx:74
char * GB_read_as_string(GBDATA *gbd)
Definition: arbdb.cxx:1060
static void getSpeciesSortedByBadPositions(BadPositionsForSpeciesConst &bad_pos, StringVector &result)
long first_position(const char *helixNr) const
Definition: BI_helix.cxx:369
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
ED4_root * ED4_ROOT
Definition: ED4_main.cxx:49
int is_species_manager() const
Definition: ed4_class.hxx:1109
bool GB_have_error()
Definition: arb_msg.cxx:338
STL namespace.
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
char * release()
Definition: arb_strbuf.h:129
#define e4_assert(bed)
Definition: ed4_class.hxx:14
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:231
void insert(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:380
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
long last_position(const char *helixNr) const
Definition: BI_helix.cxx:377
const char * read_char_pntr() const
Definition: AW_awar.cxx:168
void putlong(long l)
Definition: arb_strbuf.h:240
#define AWAR_BADALI_SYMBOLS
size_t GB_read_string_count(GBDATA *gbd)
Definition: arbdb.cxx:916
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
static char * create_list_of_loaded_species()
GB_ERROR deliver() const
Definition: arb_error.h:116
static void parse_helix_list(StrArray &result_helices, const char *helix_list)
#define StrArray_FROM_HELIXLIST(varname, helixlist)
GBDATA * get_gb_main() const
Definition: ed4_class.hxx:1422
GBDATA * gb_species_data
Definition: adname.cxx:33
long first_pair_position() const
Definition: BI_helix.cxx:342
static GB_ERROR get_error()
Definition: BI_helix.hxx:96
static ARB_ERROR add_species_to_list_cb(ED4_base *base, StrArray *species)
const BadPositionsForSpecies BadPositionsForSpeciesConst
static void error(const char *msg)
Definition: mkptypes.cxx:96
CONSTEXPR_INLINE_Cxx14 void swap(unsigned char &c1, unsigned char &c2)
Definition: ad_io_inline.h:19
ASSERTING_CONSTEXPR_INLINE int info2bio(int infopos)
Definition: arb_defs.h:27
GB_ERROR GB_write_lossless_int(GBDATA *gbd, int32_t i)
Definition: arbdb.cxx:1523
ED4_root_group_manager * root_group_man
Definition: ed4_class.hxx:1432
long next_pair_position(size_t pos) const
Definition: BI_helix.cxx:346
#define AWAR_SPECIES_NAME
ARB_ERROR route_down_hierarchy(const ED4_route_cb &cb) FINAL_OVERRIDE
Definition: ED4_base.cxx:394
#define cmp(h1, h2)
Definition: admap.cxx:50
const char * prepare_and_get_selected_itemfield(AW_root *awr, const char *awar_name, GBDATA *gb_main, const ItemSelector &itemtype, FailIfField failIf)
GBDATA * GBT_find_species_rel_species_data(GBDATA *gb_species_data, const char *name)
Definition: aditem.cxx:133
GB_ERROR get_error() const
char * read_string() const
Definition: AW_awar.cxx:198
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:568
void ED4_popup_detect_bad_alignment_window(AW_window *editor_window, const WindowCallback *helixSettings_cb)
long next_pair_pos
Definition: BI_helix.hxx:78
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
Definition: adali.cxx:718
void ED4_create_detect_bad_alignment_awars(AW_root *aw_root, AW_default aw_def)
char get_symbol(char left, char right) const
Definition: BI_helix.cxx:79
long int flag
Definition: f2c.h:39
GBDATA * GBT_searchOrCreate_itemfield_according_to_changekey(GBDATA *gb_item, const char *field_name, const char *change_key_path)
Definition: adChangeKey.cxx:61
char * GBT_join_strings(const CharPtrArray &strings, char separator)
void ncat(const char *from, size_t count)
Definition: arb_strbuf.h:189
static void jump_to_next_helix_cb(AW_window *, JumpWhy called)
char * helix_nr
Definition: BI_helix.hxx:76
#define AWAR_BADALI_HELIXLIST
char awar_path_for_helixNr[50]
Definition: ed4_class.hxx:719
const char * get_alignment_name() const
Definition: ed4_class.hxx:1458
ED4_window * current_ed4w()
Definition: ed4_class.hxx:1398
ItemSelector & SPECIES_get_selector()
Definition: species.cxx:140
#define abs(x)
Definition: f2c.h:151
#define TEST_EXPECT_NO_ERROR(call)
Definition: test_unit.h:1118
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
void ED4_set_helixnr(AW_window *aww, const char *awar_name)
AW_root * get_root()
Definition: aw_window.hxx:359
#define AWAR_BADALI_FIELD
AW_window_simple * win
#define NULp
Definition: cxxforward.h:116
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:139
#define TEST_EXPECT_ERROR_CONTAINS(call, part)
Definition: test_unit.h:1114
GB_ERROR write_string(const char *aw_string)
void GBT_split_string(ConstStrArray &dest, const char *namelist, const char *separator, SplitMode mode)
Definition: arb_strarray.h:223
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:757
char * GBT_store_marked_species(GBDATA *gb_main, bool unmark_all)
Definition: aditem.cxx:377
CONSTEXPR long FIELD_FILTER_INT_WRITEABLE
Definition: item_sel_list.h:43
HelixAlignmentQuality(GBDATA *gb_main_, const AW_helix &helix_, const char *ali_, const char *species_list, const CharPtrArray &helices, const char *bad_symbols)
AW_window_menu_modes * aww
Definition: ed4_class.hxx:705
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
Definition: arbdb.cxx:904
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:584
bool operator()(const string &s1, const string &s2) const
#define AWAR_BADALI_SPECIES
#define TEST_EXPECT_EQUAL(expr, want)
Definition: test_unit.h:1294
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 GB_close(GBDATA *gbd)
Definition: arbdb.cxx:655
void put(char c)
Definition: arb_strbuf.h:174
GBDATA * GBT_get_species_data(GBDATA *gb_main)
Definition: aditem.cxx:105
GB_write_int const char s
Definition: AW_awar.cxx:154