ARB
PARS_main.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : PARS_main.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #include "PerfMeter.h"
12 #include "pars_main.hxx"
13 #include "pars_klprops.hxx"
14 #include "pars_awars.h"
15 #include "ap_tree_nlen.hxx"
16 #include "ap_main.hxx"
17 
18 #include <ColumnStat.hxx>
19 #include <gui_aliview.hxx>
20 #include <macros.hxx>
21 #include <nds.h>
22 #include <TreeCallbacks.hxx>
23 
24 #include <aw_awars.hxx>
25 #include <aw_preset.hxx>
26 #include <aw_msg.hxx>
27 #include <aw_root.hxx>
28 #include <aw_question.hxx>
29 
30 #include <awt.hxx>
31 #include <awt_sel_boxes.hxx>
32 #include <awt_filter.hxx>
33 #include <awt_config_manager.hxx>
34 
35 #include <arb_progress.h>
36 #include <arb_misc.h>
37 #include <arb_defs.h>
38 #include <arb_global_defs.h>
39 
40 #include <ad_cb.h>
41 
42 #include <list>
43 #include <map>
44 #include <mod_rlimit.h>
45 
46 #if defined(DEBUG)
47 # define TESTMENU
48 #endif // DEBUG
49 
50 using namespace std;
51 
53 
54 #define AWAR_COLUMNSTAT_BASE "tmp/pars/colstat"
55 #define AWAR_COLUMNSTAT_NAME AWAR_COLUMNSTAT_BASE "/name"
56 
57 #define AWT_TREE_PARS(ntw) DOWNCAST(AWT_graphic_parsimony*, (ntw)->gfx)
58 
60 
61 inline AWT_graphic_parsimony *global_tree() { return GLOBAL_PARS->get_tree(); }
62 inline AP_pars_root *global_tree_root() { return global_tree()->get_tree_root(); }
63 
64 // waaah more globals :(
65 AP_main *ap_main; // @@@ move into ArbParsimony? or eliminate ArbParsimony
66 
68  ap_assert(!tree); // only call once
69  tree = tree_;
70  ap_main->set_tree_root(tree);
71 }
72 
73 static void set_keep_ghostnodes() {
74  // avoid that saving tree to DB does delete removed nodes
75  // (hack to fix #528)
76  // see ../ARBDB/adtree.cxx@keep_ghostnodes
77  GBDATA *gb_tree = ap_main->get_tree_root()->get_gb_tree();
78  GB_transaction ta(gb_tree);
79  GBDATA *gb_keep = GB_searchOrCreate_int(gb_tree, "keep_ghostnodes", 1);
81 }
82 static void delete_kept_ghostnodes() {
83  if (ap_main->get_graphic_tree()) {
84  GBDATA *gb_tree = ap_main->get_tree_root()->get_gb_tree();
85  GB_transaction ta(gb_tree);
86 
87  GBDATA *gb_keep = GB_entry(gb_tree, "keep_ghostnodes");
88  if (gb_keep) { // e.g. wrong for quick-add species
89  GB_ERROR error = GB_delete(gb_keep);
90  if (!error) {
91  if (ap_main->get_tree_root()->was_saved()) {
92  // if tree was saved, DB may contain ghostnodes
93  // -> save again to delete them
94  error = global_tree()->save_to_DB(GB_get_root(gb_tree), NULp);
95  }
96  }
97  if (error) aw_message(error);
98  }
99  }
100 }
101 
103  AW_root *aw_root = aww->get_root();
104  shutdown_macro_recording(aw_root);
105 
106  ap_main->accept_all();
108 
109  aw_root->unlink_awars_from_DB(ap_main->get_gb_main());
110 #if defined(DEBUG)
111  AWT_browser_forget_db(ap_main->get_gb_main());
112 #endif // DEBUG
113  delete ap_main; // closes DB
114  ap_main = NULp;
115 
116  exit(EXIT_SUCCESS);
117 }
118 
119 static void AP_user_push_cb(AW_window *aww) {
120  ap_main->remember_user_state();
122 }
123 
124 static void AP_user_pop_cb(AW_window *aww, TREE_canvas *ntw) {
125  if (ap_main->get_user_push_counter()<=0) {
126  aw_message("No tree on stack.");
127  return;
128  }
129 
130  AWT_auto_refresh allowed_on(ntw);
131  ap_main->revert_user_state();
132  ntw->request_save();
133 
135  if (ap_main->get_user_push_counter() <= 0) { // last tree was popped => push again
136  AP_user_push_cb(aww);
137  }
138 }
139 
140 class InsertData {
141  bool abort_flag;
142  arb_progress progress;
143 
144 public:
145 
147  InsertData(bool quick, long spec_count)
148  : abort_flag(false),
149  progress(GBS_global_string("Inserting %li species", spec_count), spec_count),
150  quick_add_flag(quick)
151  {}
152 
153  bool aborted() const { return abort_flag; }
154  void set_aborted(bool aborted_) { abort_flag = aborted_; }
155 
156  void inc() {
157  progress.inc();
158  abort_flag = progress.aborted();
159  }
160 
161  arb_progress& get_progress() { return progress; }
162 };
163 
164 
165 static int sort_sequences_by_length(const char*, long leaf0_ptr, const char*, long leaf1_ptr) { // @@@ any chance to make this typesafe?
166  AP_tree_nlen *leaf0 = (AP_tree_nlen*)leaf0_ptr;
167  AP_tree_nlen *leaf1 = (AP_tree_nlen*)leaf1_ptr;
168 
169  AP_FLOAT len0 = leaf0->get_seq()->weighted_base_count();
170  AP_FLOAT len1 = leaf1->get_seq()->weighted_base_count();
171 
172  // longest sequence first
173  if (len0<len1) return 1;
174  if (len0>len1) return -1;
175 
176  // if length equal -> determine order by species name (just to have a defined order!)
177  int cmp = strcmp(leaf1->name, leaf0->name);
178  ap_assert(cmp != 0);
179  return cmp;
180 }
181 
182 static long transform_gbd_to_leaf(const char *key, long val, void *) {
183  if (!val) return val;
184 
185 #if defined(WARN_TODO)
186 #warning use create_linked_leaf() when impl
187 #endif
188 
189  GBDATA *gb_node = (GBDATA *)val;
190  AP_pars_root *troot = ap_main->get_tree_root();
191  AP_tree_nlen *leaf = DOWNCAST(AP_tree_nlen*, troot->makeNode());
192 
193  leaf->forget_origin(); // new leaf is not part of tree yet
194 
195  leaf->gb_node = gb_node;
196  leaf->name = ARB_strdup(key);
197  leaf->markAsLeaf();
198 
199  leaf->set_seq(troot->get_seqTemplate()->dup());
200  GB_ERROR error = leaf->get_seq()->bind_to_species(gb_node);
201  if (!error) {
202  if (leaf->get_seq()->weighted_base_count() < MIN_SEQUENCE_LENGTH) {
203  error = GBS_global_string("Species %s has too short sequence (%f, minimum is %i)",
204  key,
205  leaf->get_seq()->weighted_base_count(),
207  }
208  }
209  if (error) {
210  GBT_message(gb_node, error);
211  destroy(leaf, troot); leaf = NULp;
212  }
213  return (long)leaf;
214 }
215 
216 typedef vector<AP_tree_nlen*> InsertedSpecies;
217 
218 static long toInserted(const char *, long val, void *cd_toInsert) {
219  InsertedSpecies *toInsert = (InsertedSpecies*)cd_toInsert;
220  AP_tree_nlen *node = (AP_tree_nlen*)val;
221 
222  toInsert->push_back(node);
223  return 0;
224 }
225 
226 inline int maxAllowedInsertions(int inTree) {
227  // max. species allowed to insert (in one pass) into a tree with 'inTree' leafs
228  return inTree/2;
229 }
230 inline int calcInsertNow(int toInsert, int inTree) {
231  // calculate number of species added in next pass
232  return std::min(toInsert, maxAllowedInsertions(inTree));
233 }
234 
235 static long calc_steps(int toInsert, int inTree) {
236  ap_assert((toInsert+inTree) >= 2);
237 
238  if (!toInsert) return 0;
239  if (!inTree) return 1 + calc_steps(toInsert-2, 2);
240 
241  int edges = leafs_2_edges(inTree, UNROOTED);
242  int insertNow = calcInsertNow(toInsert, inTree);
243 
244  return (edges+1)*insertNow + calc_steps(toInsert-insertNow, inTree+insertNow); // +1 for final step (=actual insertion of species)
245 }
246 
247 class AP_subtree { // defines a subtree
248  AP_tree_nlen *subNode;
249  AP_tree_nlen *upNode;
250 
251  bool valid() const { return subNode && upNode; }
252 
253 public:
254  AP_subtree() : subNode(NULp), upNode(NULp) {}
255  AP_subtree(AP_tree_edge *e, AP_tree_nlen *sub_node) :
256  subNode(sub_node),
257  upNode(e->otherNode(subNode))
258  {}
259 
260  AP_tree_edge *edgeToSubtree() const { ap_assert(valid()); return upNode->edgeTo(subNode); }
261  AP_tree_nlen *subtreeRoot() const { return subNode; }
262 
263  void setSubtreeRoot(AP_tree_nlen *new_subtree) {
264  ap_assert(upNode->edgeTo(new_subtree));
265  subNode = new_subtree;
266  }
267 };
268 
269 struct EdgeBetween : private AP_subtree {
270  // semantically same as AP_tree_edge, but survives tree-modifications which modify edges (like insert+moveNextTo/moveTo)
271 
273  EdgeBetween(AP_tree_edge *e) : AP_subtree(e, e->sonNode()) {}
274  AP_tree_edge *find() const { return edgeToSubtree(); }
275 };
276 
277 struct BestEdge {
279  EdgeBetween between; // need to store pair of AP_tree_nlen here
280  // (using AP_tree_edge is not stable; may move elsewhere by calls insert() or moveNextTo()!)
281 
282  BestEdge() : pars(-1) {}
283  BestEdge(const EdgeBetween& betw, Mutations p) : pars(p), between(betw) {}
284 
285  AP_tree_edge *edge() const { return between.find(); }
286 };
287 
289  bool operator() (AP_tree_nlen *i, AP_tree_nlen *j) { return strcmp(i->name, j->name)<0; }
290 };
291 
292 typedef InsertedSpecies::const_iterator InsertSpeciesIterator;
293 
295  typedef map<AP_tree_nlen*, BestEdge> BestEdge4Node;
296  BestEdge4Node bestpos;
297 
298  ap_assert(begin != end);
299 
300  {
301  ap_main->remember();
302 
303  EdgeChain chain(rootEdge(), ANY_EDGE, false);
304  ap_assert(chain.size()>0);
305 
306  bool speciesInserted = false;
307 
308  while (chain) {
309  AP_tree_edge *edge = *chain; ++chain;
310  edge->set_root();
311 
312  EdgeBetween betweenNodes(edge);
313 
314  InsertSpeciesIterator curr = begin;
315  AP_tree_nlen *species = *curr++;
316 
317  if (speciesInserted) {
318  species->moveTo(edge);
319  }
320  else {
321  species->insert(edge->sonNode()); // edge is root-edge -> son does not matter
322  speciesInserted = true;
323  }
324 
325  species->set_root(); // => only needs one combine when exchanging species
326 
327  Mutations pars = rootNode()->costs();
328  BestEdge4Node::iterator found = bestpos.find(species);
329  if (found == bestpos.end() || pars<found->second.pars) {
330  bestpos[species] = BestEdge(betweenNodes, pars);
331  }
332  ++progress;
333 
334  AP_tree_nlen *rot_node = rootNode()->get_leftson(); // rot=rest of tree
335  if (rot_node == species) {
336  rot_node = rot_node->get_brother();
337  }
338  ap_assert(rot_node->get_brother() == species);
339 
340  AP_combinableSeq *rot_seq = rot_node->get_seq();
341  Mutations rot_costs = rot_node->stored_costs();
342 
343  ap_assert(species->stored_costs() == 0); // leaf has no mutations
344 
345  while (1) {
346  if (curr == end) break;
347 
348  AP_tree_nlen *nextSpec = *curr++;
349  AP_combinableSeq *nextSeq = nextSpec->get_seq();
350 
351  pars = nextSeq->mutations_if_combined_with(rot_seq) + rot_costs;
352  found = bestpos.find(nextSpec);
353  if (found == bestpos.end() || pars<found->second.pars) {
354  bestpos[nextSpec] = BestEdge(betweenNodes, pars);
355  }
356  ++progress;
357  }
358  }
359 
360  ap_main->revert();
361  }
362 
363  // create insert lists for each used insert position:
364  typedef list<AP_tree_nlen*> NodeList;
365  typedef map<AP_tree_edge*, NodeList> NodesAtEdge;
366 
367  NodesAtEdge atEdge;
368  for (InsertSpeciesIterator s = begin; s != end; ++s) {
369  const BestEdge& best = bestpos[*s];
370  AP_tree_edge *edge = best.edge();
371 
372  ap_assert(edge != NULp);
373 
374  NodesAtEdge::iterator at = atEdge.find(edge);
375  if (at == atEdge.end()) {
376  atEdge[edge] = NodeList(1, *s);
377  }
378  else {
379  at->second.push_back(*s);
380  }
381  }
382 
383 #if defined(DEVEL_RALF)
384  // testcode: test whether all found edges are members of the tree
385  // (got some problem with insert/REMOVE while root is next to inserted/removed node)
386 
387  set<AP_tree_edge*> edgeInTree;
388  {
389  EdgeChain chain(rootEdge(), ANY_EDGE, false);
390  while (chain) {
391  AP_tree_edge *edge = *chain; ++chain;
392  edgeInTree.insert(edge);
393  }
394 
395  for (BestEdge4Node::iterator b = bestpos.begin(); b != bestpos.end(); ++b) {
396  AP_tree_edge *e = b->second.edge();
397 
398  if (edgeInTree.find(e) == edgeInTree.end()) {
399  GBK_terminate("remembered edge has been removed from tree");
400  }
401  }
402  }
403 #endif
404 
405  // build list of edges where insert takes place (value=iterator into 'atEdge')
406  // => insert in determined order
407  typedef list<NodesAtEdge::iterator> InsertOrder;
408  InsertOrder insertOrder;
409  {
410  EdgeChain chain(rootEdge(), ANY_EDGE, false);
411  while (chain) {
412  AP_tree_edge *edge = *chain; ++chain;
413 
414  NodesAtEdge::iterator at = atEdge.find(edge);
415  if (at != atEdge.end()) {
416  insertOrder.push_back(at);
417  }
418  }
419  }
420 
421  typedef list<AP_subtree> OptiList;
422  OptiList optiPos;
423 
424  // insert species to tree according to insert-lists:
425  for (InsertOrder::iterator o = insertOrder.begin(); o != insertOrder.end(); ++o) {
426  NodesAtEdge::iterator e = *o;
427  AP_tree_edge *edge = e->first;
428  NodeList& nodes = e->second;
429 
430  edge->set_root();
431 
432  AP_tree_nlen *brother = edge->sonNode();
433  size_t nodes_size = nodes.size();
434 
435 #if defined(ASSERTION_USED)
436  ap_assert(bestpos[nodes.front()].edge() == edge);
437 #endif
438 
439  if (nodes_size == 1) {
440  nodes.front()->insert(brother);
442  }
443  else {
444  bool atLeaf = brother->is_leaf();
445  if (!atLeaf && edge->is_leaf_edge()) { // at leaf edge -> make sure brother points to leaf node
446  brother = edge->notSonNode();
447  ap_assert(brother->is_leaf());
448  atLeaf = true;
449  }
450 
451 #if defined(UNIT_TESTS)
452  if (RUNNING_TEST()) {
453  // use a determined order to insert multiple species at one position.
454  // Does not produce "better" topologies, just makes result independent from insert order.
455  typedef vector<AP_tree_nlen*> NodeVector;
456 
457  NodeVector toSort(nodes.begin(), nodes.end());
458  sort(toSort.begin(), toSort.end(), NodeInsertOrder());
459  nodes = NodeList(toSort.begin(), toSort.end());
460  }
461 #endif
462 
463  AP_tree_nlen *at = brother;
464  for (NodeList::iterator n = nodes.begin(); n != nodes.end(); ++n) {
465  (*n)->insert(at);
466  at = *n; // only insert 1st node at 'brother', insert following nodes next to previously added nodes
467  }
468 
470 
471  AP_tree_nlen *ourFather = brother->get_father();
472  AP_tree_nlen *addedSubtree = brother->get_brother(); // contains all added species
473  ap_assert(addedSubtree->is_ancestor_of(at));
474 
475  if (atLeaf) {
476  // if inserted at leaf edge -> perform NNI at parent edge (i.e. including the leaf)
477  AP_tree_edge *toRest = ourFather->nextEdge();
478  for (int i = 0; i<2; ++i) {
479  AP_tree_nlen *rest = toRest->otherNode(ourFather);
480  if (rest != brother && rest != addedSubtree) {
481  break;
482  }
483  toRest = ourFather->nextEdge(toRest);
484  }
485 
486  optiPos.push_back(AP_subtree(toRest, ourFather));
487  ap_assert(optiPos.back().subtreeRoot() == ourFather);
488  }
489  else {
490  if (nodes_size>2) { // if inserted at internal edge && only 2 species inserted -> NNI makes no sense
491  // Store (directed) edge to brother (for later optimization of subtree):
492  AP_tree_edge *subEdge = ourFather->edgeTo(addedSubtree);
493  optiPos.push_back(AP_subtree(subEdge, addedSubtree));
494  ap_assert(optiPos.back().subtreeRoot() == addedSubtree);
495  }
496  }
497  }
498  progress.inc_by(nodes_size);
499  }
500 
501  // Optimize all inserts of multiple species at one position:
502  {
503  arb_suppress_progress suppress_child; // suppress implicit progress count caused by nni_rec
504 
505  AP_FLOAT curr_pars = rootNode()->costs();
506  AP_FLOAT prev_pars = curr_pars;
507 
508  int loop = 0;
509 
510  do {
511  ++loop;
512  prev_pars = curr_pars;
513  for (OptiList::iterator op = optiPos.begin(); op != optiPos.end(); ++op) {
514  AP_tree_edge *subtreeEdge = op->edgeToSubtree();
515  AP_tree_nlen *subtreeRoot = op->subtreeRoot();
516 
517  subtreeEdge->set_root();
518  ap_assert(subtreeEdge->isConnectedTo(subtreeRoot));
519  AP_tree_nlen *father = subtreeEdge->otherNode(subtreeRoot);
520 
521  AP_FLOAT this_pars;
522  while (1) {
523  ap_assert(subtreeEdge->isConnectedTo(father)); // otherwise block fails
524  this_pars = subtreeEdge->nni_rec(SKIP_LEAF_EDGES, AP_BL_NNI_ONLY, father, false);
525  if (!(this_pars<curr_pars)) {
526  ap_assert(!(this_pars>curr_pars));
527  break;
528  }
529  curr_pars = this_pars;
530  }
531 
532  ap_assert(subtreeEdge->isConnectedTo(father)); // otherwise next command fails
533  AP_tree_nlen *newSubtreeRoot = subtreeEdge->otherNode(father);
534  if (newSubtreeRoot != subtreeRoot) {
535  op->setSubtreeRoot(newSubtreeRoot);
536  }
537  }
538  }
539  while (curr_pars<prev_pars);
540  }
541 }
542 
544  // inserts all species (from hash) into tree
545 
546  AP_tree_nlen *tree = rootNode();
547 
548  int inTree = tree ? tree->count_leafs() : 0;
549  int toInsert = GBS_hash_elements(hash);
550 
551  ap_assert(toInsert);
552 
553  long steps = calc_steps(toInsert, inTree);
554  arb_progress progress(steps);
555 
556  // move species to insert to a stack
557  InsertedSpecies speciesToInsert;
558  speciesToInsert.reserve(toInsert);
559 
560  if (maxAllowedInsertions(inTree)<toInsert) {
561  // insert longest sequences first
563  }
564  else {
565  // insert all sequences (order should not matter)
566  GBS_hash_do_loop(hash, toInserted, &speciesToInsert);
567  }
568  GBS_free_hash(hash);
569  hash = NULp;
570 
571  ap_assert(toInsert != 2); // @@@ need to test this case
572 
573  InsertSpeciesIterator curr = speciesToInsert.begin();
574  InsertSpeciesIterator end = speciesToInsert.end();
575 
576  AP_tree_edge *oldRootEdge = NULp;
577  if (!tree) { // create initial tree
578  AP_pars_root *troot = ap_main->get_tree_root();
579 
580  AP_tree_nlen *s1 = *curr++;
581  AP_tree_nlen *s2 = *curr++;
582 
583  s1->initial_insert(s2, troot);
584 
585  inTree = 2;
586  toInsert -= 2;
587 
588  ++progress;
589  }
590  else {
591  oldRootEdge = rootEdge();
592  }
593 
595 
596  while (1) {
597  int insertNow = calcInsertNow(toInsert, inTree);
598  ap_assert(insertNow<=toInsert);
599  if (insertNow == toInsert) break;
600 
601  {
602  InsertSpeciesIterator partEnd = curr;
603  advance(partEnd, insertNow);
604 
605  insert_species_into_tree(curr, partEnd, progress);
606  curr = partEnd;
607  }
608 
609  toInsert -= insertNow;
610  inTree += insertNow;
611  }
612 
613  insert_species_into_tree(curr, end, progress);
614 
615  if (oldRootEdge) oldRootEdge->set_root(); // set root back to old position
616 }
617 
618 enum AddWhat {
621 };
622 
623 static void nt_add(AWT_graphic_parsimony *agt, AddWhat what, bool quick) {
624  GB_ERROR error = NULp;
625 
626  AP_tree *oldrootleft = NULp;
627  AP_tree *oldrootright = NULp;
628  {
629  AP_tree_nlen *root = rootNode();
630  if (root) {
631  root->reset_subtree_layout();
632  oldrootleft = root->get_leftson();
633  oldrootright = root->get_rightson();
634  }
635  }
636 
637  GB_HASH *hash = NULp;
638  GBDATA *gb_main = agt->get_gbmain();
639  {
640  GB_transaction ta(gb_main);
641  switch (what) {
642  case NT_ADD_SELECTED: {
643  char *name = GBT_readOrCreate_string(gb_main, AWAR_SPECIES_NAME, "");
644  if (name && strlen(name)) {
645  GBDATA *gb_species = GBT_find_species(gb_main, name);
646  if (gb_species) {
647  hash = GBS_create_hash(1, GB_MIND_CASE);
648  GBS_write_hash(hash, name, (long)gb_species);
649  }
650  else error = GBS_global_string("Selected Species (%s) not found", name);
651  }
652  else error = "Please select a species";
653  free(name);
654  break;
655  }
656  case NT_ADD_MARKED: {
657  hash = GBT_create_marked_species_hash(gb_main);
658  break;
659  }
660  }
661  }
662 
663  if (!error) {
664  ap_assert(hash);
665 
666  arb_progress progress(quick ? "Quick add" : "Add + NNI");
667 
669 
670  size_t species_count = GBS_hash_elements(hash);
671  InsertPerfMeter insertPerf("(quick-)add", species_count);
672 
673  {
674  GB_transaction ta(gb_main);
676  }
677  {
678  size_t skipped = species_count - GBS_hash_elements(hash);
679  if (skipped) {
680  GBT_message(gb_main, GBS_global_string("Skipped %zu species (no data?)", skipped));
681  }
682  }
683  if (GBS_hash_elements(hash)) {
685  }
686  else {
687  GBT_message(gb_main, "No species (left) to insert");
688  }
689 
690  if (rootNode()) {
691  if (oldrootleft) {
692  if (oldrootleft->father == oldrootright) oldrootleft->set_root();
693  else oldrootright->set_root();
694  }
695  else {
696  ARB_edge innermost = rootNode()->get_tree_root()->find_innermost_edge();
697  innermost.set_root();
698  }
699 
700  if (!quick) {
701  arb_suppress_progress quiet; // @@@ use weighted progress (#789) for loop below
702 
703  Mutations pars_prev = rootNode()->costs();
704  rootNode()->compute_tree(); // see AP_tree_edge.cxx@flags_broken_by_moveNextTo
705  progress.subtitle("local optimize (repeated NNI)");
706  while (1) {
708  Mutations pars_curr = rootNode()->costs();
709  if (pars_curr == pars_prev) break;
710  ap_assert(pars_curr<pars_prev);
711  pars_prev = pars_curr;
712  }
713  }
714 
715  {
716  arb_suppress_progress ignore;
717  rootEdge()->calc_branchlengths();
718  }
719 
721  rootNode()->compute_tree();
722  }
723  else {
724  error = "Tree lost (no leafs left)";
725  }
726 
727  insertPerf.dump(stdout);
728  }
729 
730  if (hash) GBS_free_hash(hash);
731  if (error) aw_message(error);
732 
733  // @@@ quick-add w/o NNI should sort according to original tree
735 }
736 
737 // ------------------------------------------
738 // Adding partial sequences to tree
739 
741  GBDATA *gb_species;
742  mutable AP_tree_nlen *self; // self converted to leaf (ready for insertion)
743  const AP_tree_nlen *best_full_match; // full sequence position which matched best
744  long overlap; // size of overlapping region
745  long penalty; // weighted mismatches
746  bool released;
747  bool multi_match;
748  string multi_list; // list of equal-rated insertion-points (not containing self)
749 
750  AP_tree_nlen *get_self() const {
751  if (!self) {
752  ap_assert(!released); // request not possible, because leaf has already been released!
753 
754  self = (AP_tree_nlen*)transform_gbd_to_leaf(GBT_get_name_or_description(gb_species), (long)gb_species, NULp);
755  ap_assert(self);
756  }
757  return self;
758  }
759 
760 public:
761  PartialSequence(GBDATA *gb_species_) :
762  gb_species(gb_species_),
763  self(NULp),
764  best_full_match(NULp),
765  overlap(0),
766  penalty(LONG_MAX),
767  released(false),
768  multi_match(false)
769  {}
771  : gb_species(other.gb_species),
772  self(other.self),
773  best_full_match(other.best_full_match),
774  overlap(other.overlap),
775  penalty(other.penalty),
776  released(other.released),
777  multi_match(other.multi_match),
778  multi_list(other.multi_list)
779  {
780  ap_assert(!self); // copying self not implemented
781  }
784 
785  GBDATA *get_species() const { return gb_species; }
786  const AP_tree_nlen *get_best_match() const { return best_full_match; }
787  AP_FLOAT get_branchlength() const { return AP_FLOAT(penalty)/overlap; }
788  void test_match(const AP_tree_nlen *leaf_full);
789  bool is_multi_match() const { return multi_match; }
790 
791  const char *get_name() const {
792  const char *name = get_self()->name;
793  ap_assert(name);
794  return name;
795  }
796 
797  string get_multilist() const {
798  ap_assert(is_multi_match());
799  return string(best_full_match->name)+multi_list;
800  }
801 
802  AP_tree_nlen *release() {
803  AP_tree_nlen *s = self;
804  self = NULp;
805  released = true;
806  return s;
807  }
808 
809  void dump(const char *whichMatch) const {
810  ap_assert(best_full_match);
811  printf("%s match for '%s' is '%s' (overlap=%li penalty=%li)\n",
812  whichMatch, get_name(), best_full_match->name,
813  overlap, penalty);
814  }
815 
816 };
817 
818 void PartialSequence::test_match(const AP_tree_nlen *leaf_full) {
819  long curr_overlap;
820  long curr_penalty;
821 
822  leaf_full->get_seq()->partial_match(get_self()->get_seq(), &curr_overlap, &curr_penalty);
823 
824  bool better = false;
825 
826  if (curr_overlap > overlap) {
827  better = true;
828  }
829  else if (curr_overlap == overlap) {
830  if (curr_penalty<penalty) {
831  better = true;
832  }
833  else if (curr_penalty == penalty) {
834  // found two equal-rated insertion points -> store data for warning
835 #if defined(DEBUG)
836  if (!multi_match) dump("better");
837  printf("Another equal match is against '%s' (overlap=%li penalty=%li)\n", leaf_full->name, curr_overlap, curr_penalty);
838 #endif // DEBUG
839 
840  multi_match = true;
841  multi_list.append(1, '/');
842  multi_list.append(leaf_full->name);
843  }
844  }
845 
846  if (better) {
847  overlap = curr_overlap;
848  penalty = curr_penalty;
849  best_full_match = leaf_full;
850  multi_match = false;
851  multi_list = "";
852 
853 #if defined(DEBUG)
854  dump("better");
855 #endif
856  }
857 #if defined(DEBUG)
858  else if (!multi_match) {
859  printf("Worse match against '%s' (overlap=%li penalty=%li)\n", leaf_full->name, curr_overlap, curr_penalty);
860  }
861 #endif
862 }
863 
864 static GB_ERROR nt_best_partial_match_rec(list<PartialSequence>& partial, const AP_tree_nlen *tree) {
865  GB_ERROR error = NULp;
866 
867  if (tree) {
868  if (tree->is_leaf() && tree->name) {
869  if (tree->gb_node) {
870  int is_partial = GBT_is_partial(tree->gb_node, 0, true); // marks undef as 'full sequence'
871  if (is_partial == 0) { // do not consider other partial sequences
872  list<PartialSequence>::iterator i = partial.begin();
873  list<PartialSequence>::iterator e = partial.end();
874  for (; i != e; ++i) {
875  i->test_match(tree);
876  }
877  }
878  else if (is_partial == -1) {
879  error = GB_await_error();
880  }
881  }
882  }
883  else {
884  error = nt_best_partial_match_rec(partial, tree->get_leftson());
885  if (!error) error = nt_best_partial_match_rec(partial, tree->get_rightson());
886  }
887  }
888  return error;
889 }
890 
891 static void count_partial_and_full(const AP_tree_nlen *at, int *partial, int *full, int *zombies, int default_value, bool define_if_undef) {
892  if (at->is_leaf()) {
893  if (at->gb_node) {
894  int is_partial = GBT_is_partial(at->gb_node, default_value, define_if_undef);
895  if (is_partial) ++(*partial);
896  else ++(*full);
897  }
898  else {
899  ++(*zombies);
900  }
901  }
902  else {
903  count_partial_and_full(at->get_leftson(), partial, full, zombies, default_value, define_if_undef);
904  count_partial_and_full(at->get_rightson(), partial, full, zombies, default_value, define_if_undef);
905  }
906 }
907 
908 static const AP_tree_nlen *find_least_deep_leaf(const AP_tree_nlen *at, int depth, int *min_depth) {
909  if (depth >= *min_depth) {
910  return NULp; // already found better or equal
911  }
912 
913  if (at->is_leaf()) {
914  if (at->gb_node) {
915  *min_depth = depth;
916  return at;
917  }
918  return NULp;
919  }
920 
921  const AP_tree_nlen *left = find_least_deep_leaf(at->get_leftson(), depth+1, min_depth);
922  const AP_tree_nlen *right = find_least_deep_leaf(at->get_rightson(), depth+1, min_depth);
923 
924  return right ? right : left;
925 }
926 inline AP_tree_nlen *find_least_deep_leaf(AP_tree_nlen *at, int depth, int *min_depth) {
927  return const_cast<AP_tree_nlen*>(find_least_deep_leaf(const_cast<const AP_tree_nlen*>(at), depth, min_depth));
928 }
929 
930 static void push_partial(const char *, long val, void *cd_partial) {
931  list<PartialSequence> *partial = reinterpret_cast<list<PartialSequence> *>(cd_partial);
932  partial->push_back(PartialSequence((GBDATA*)val));
933 }
934 
935 // -------------------------------
936 // Add Partial sequences
937 
939  GB_ERROR error = NULp;
940  GBDATA *gb_main = agt->get_gbmain();
941 
942  GB_begin_transaction(gb_main);
943 
944  int full_marked_sequences = 0;
945 
946  arb_progress part_add_progress("Adding partial sequences");
947 
948  {
949  list<PartialSequence> partial;
950  {
951  GB_HASH *partial_hash = GBS_create_hash(GBT_get_species_count(gb_main), GB_MIND_CASE);
952 
953  int marked_found = 0;
954  int partial_marked_sequences = 0;
955  int no_data = 0; // no data in alignment
956 
957  for (GBDATA *gb_marked = GBT_first_marked_species(gb_main);
958  !error && gb_marked;
959  gb_marked = GBT_next_marked_species(gb_marked))
960  {
961  ++marked_found;
962 
963  if (GBT_find_sequence(gb_marked, ap_main->get_aliname())) { // species has sequence in alignment
964  const char *name = GBT_get_name_or_description(gb_marked);
965 
966  switch (GBT_is_partial(gb_marked, 1, true)) { // marks undef as 'partial sequence'
967  case 0: { // full sequences
968  GBT_message(gb_main, GBS_global_string("'%s' is a full sequence (cannot add partial)", name));
969  ++full_marked_sequences;
970  break;
971  }
972  case 1: // partial sequences
973  ++partial_marked_sequences;
974  GBS_write_hash(partial_hash, name, (long)gb_marked);
975  break;
976  case -1: // error
977  error = GB_await_error();
978  break;
979  default:
980  ap_assert(0);
981  break;
982  }
983  }
984  else {
985  no_data++;
986  }
987  }
988 
989  if (!error && !marked_found) error = "There are no marked species";
990 
991  if (!error) {
992  NT_remove_species_in_tree_from_hash(rootNode(), partial_hash); // skip all species which are in tree
993  GBS_hash_do_const_loop(partial_hash, push_partial, &partial); // build partial list from hash
994 
995  int partials_already_in_tree = partial_marked_sequences - partial.size();
996 
997  if (no_data>0) GBT_message(gb_main, GBS_global_string("%i marked species have no data in '%s'", no_data, ap_main->get_aliname()));
998  if (full_marked_sequences>0) GBT_message(gb_main, GBS_global_string("%i marked species are declared full sequences", full_marked_sequences));
999  if (partials_already_in_tree>0) GBT_message(gb_main, GBS_global_string("%i marked species are already in tree", partials_already_in_tree));
1000 
1001  if (partial.empty()) error = "No species left to add";
1002  }
1003 
1004  GBS_free_hash(partial_hash);
1005  }
1006 
1007  if (!error) error = GBT_add_new_changekey(gb_main, "ARB_partial", GB_INT);
1008 
1009  if (!error) {
1010  rootNode()->reset_subtree_layout();
1011 
1012  // find best matching full sequence for each partial sequence
1013  error = nt_best_partial_match_rec(partial, rootNode());
1014 
1015  list<PartialSequence>::iterator i = partial.begin();
1016  list<PartialSequence>::iterator e = partial.end();
1017 
1018  arb_progress part_insert_progress(partial.size());
1019 
1020 #if defined(DEBUG)
1021  // show results :
1022  for (; i != e; ++i) i->dump("best");
1023  i = partial.begin();
1024 #endif // DEBUG
1025 
1026  for (; i != e && !error; ++i) {
1027  const char *name = i->get_name();
1028 
1029  if (i->is_multi_match()) {
1030  GBT_message(gb_main, GBS_global_string("Insertion of '%s' is ambiguous.\n"
1031  "(took first of equal scored insertion points: %s)",
1032  name, i->get_multilist().c_str()));
1033  }
1034 
1035  AP_tree_nlen *part_leaf = i->release();
1036  AP_tree_nlen *full_seq = const_cast<AP_tree_nlen*>(i->get_best_match());
1037  AP_tree_nlen *brother = full_seq->get_brother();
1038  int is_partial = 0;
1039  AP_tree_nlen *target = NULp;
1040 
1041  if (brother->is_leaf()) {
1042  if (brother->gb_node) {
1043  is_partial = GBT_is_partial(brother->gb_node, 0, true);
1044 
1045  if (is_partial) { // brother is partial sequence
1046  target = brother; // insert as brother of brother
1047  }
1048  else {
1049  target = full_seq; // insert as brother of full_seq
1050  }
1051  }
1052  else {
1053  error = "There are zombies in your tree - please remove them";
1054  }
1055  }
1056  else {
1057  int partial_count = 0;
1058  int full_count = 0;
1059  int zombie_count = 0;
1060 
1061  count_partial_and_full(brother, &partial_count, &full_count, &zombie_count, 0, true);
1062 
1063  if (zombie_count) {
1064  error = "There are zombies in your tree - please remove them";
1065  }
1066  else if (full_count) {
1067  // brother is a subtree containing full sequences
1068  // -> add new brother to full_seq found above
1069  target = full_seq;
1070  }
1071  else { // brother subtree only contains partial sequences
1072  // find one of the least-deep leafs
1073  int depth = INT_MAX;
1074  target = find_least_deep_leaf(brother, 0, &depth);
1075  is_partial = 1;
1076  }
1077  }
1078 
1079 
1080  if (!error) {
1081 #if defined(DEBUG)
1082  printf("inserting '%s'\n", name);
1083 #endif // DEBUG
1084  part_leaf->insert(target);
1085 
1086  // we need to create the sequence of the father node!
1087  AP_tree_nlen *father = part_leaf->get_father();
1088  father->costs();
1089 
1090  // ensure full-sequence is always on top
1091  if (father->rightson == target) {
1092  father->swap_sons();
1093  }
1094 
1095  if (!error) { // now correct the branch lengths modified by insert()
1096  // calc the original branchlen (of target leaf branch)
1097  GBT_LEN orglen = father->get_branchlength()+target->get_branchlength();
1098 
1099  if (is_partial) { // we have a subtree of partial sequences
1100  target->set_branchlength(orglen); // restore original branchlength
1101  father->set_branchlength(0); // all father branches are zero length
1102  }
1103  else { // we have a subtree of one full+one partial sequence
1104  ap_assert(full_seq->get_father() == father);
1105 
1106  father->set_branchlength(orglen); // father branch represents original length (w/o partial seq)
1107  full_seq->set_branchlength(0); // full seq has no sub-branch length
1108  }
1109  part_leaf->set_branchlength(i->get_branchlength());
1110  printf("Adding with branchlength=%f\n", i->get_branchlength());
1111  }
1112  }
1113  else {
1114  destroy(part_leaf);
1115  }
1116 
1117  part_insert_progress.inc_and_check_user_abort(error);
1118  }
1119  }
1120  }
1121 
1122  if (full_marked_sequences) {
1123  GBT_message(gb_main, GBS_global_string("%i marked full sequences were not added", full_marked_sequences));
1124  }
1125 
1126  if (error) {
1127  GBT_message(gb_main, error);
1128  GB_abort_transaction(gb_main);
1129  }
1130  else {
1131  GB_commit_transaction(gb_main);
1132  agt->exports.request_save();
1133  }
1134 }
1135 
1137  AWT_auto_refresh allowed_on(ntw);
1139 }
1140 
1141 // -------------------------------
1142 // add marked / selected
1143 
1144 static void nt_add_and_update(AWT_canvas *ntw, AddWhat what, bool quick) {
1145  AWT_auto_refresh allowed_on(ntw);
1146  nt_add(AWT_TREE_PARS(ntw), what, quick);
1147 }
1148 
1149 static void NT_add_and_NNI(UNFIXED, TREE_canvas *ntw, AddWhat what) { nt_add_and_update(ntw, what, false); }
1150 static void NT_add_quick (UNFIXED, TREE_canvas *ntw, AddWhat what) { nt_add_and_update(ntw, what, true); }
1151 
1152 // ------------------------------------------
1153 // remove and add marked / selected
1154 
1155 static void nt_reAdd(AWT_graphic_parsimony *agt, AddWhat what, bool quick) {
1156  if (agt->get_root_node()) {
1157  ap_assert(what == NT_ADD_MARKED); // code below will misbehave for NT_ADD_SELECTED
1158  agt->get_tree_root()->remove_leafs(AWT_REMOVE_MARKED);
1159  nt_add(agt, what, quick);
1160  }
1161 }
1162 
1163 static void nt_reAdd_and_update(AWT_canvas *ntw, AddWhat what, bool quick) {
1164  AWT_auto_refresh allowed_on(ntw);
1165  nt_reAdd(AWT_TREE_PARS(ntw), what, quick);
1166 }
1167 
1168 static void NT_reAdd_and_NNI(UNFIXED, TREE_canvas *ntw, AddWhat what) { nt_reAdd_and_update(ntw, what, false); }
1169 static void NT_reAdd_quick (UNFIXED, TREE_canvas *ntw, AddWhat what) { nt_reAdd_and_update(ntw, what, true); }
1170 
1171 // --------------------------------------------------------------------------------
1172 
1174  arb_progress progress("Calculating branchlengths");
1175  rootEdge()->calc_branchlengths();
1177 }
1178 
1180  AWT_auto_refresh allowed_on(ntw);
1182 }
1183 
1184 static void NT_bootstrap(AW_window *, TREE_canvas *ntw, bool limit_only) {
1185  arb_progress progress("Calculating bootstrap limit");
1186  AWT_auto_refresh allowed_on(ntw);
1188 
1189  rootEdge()->nni_rec(ANY_EDGE, mode, NULp, true);
1190  AWT_graphic_tree *agt = AWT_TREE(ntw);
1192  agt->set_logical_root_to(agt->get_root_node());
1193 }
1194 
1196  arb_progress progress("Optimizing tree");
1197  agt->get_parsimony().optimize_tree(rootNode(), settings, progress);
1200 }
1201 static void NT_optimize(AW_window *, TREE_canvas *ntw) {
1202  AWT_auto_refresh allowed_on(ntw);
1204 }
1205 
1206 static void recursiveNNI(AWT_graphic_parsimony *agt, EdgeSpec whichEdges) {
1207  arb_progress progress("Recursive NNI");
1208  Mutations orgPars = rootNode()->costs();
1209  Mutations prevPars = orgPars;
1210  progress.subtitle(GBS_global_string("best=%li", orgPars));
1211 
1212  {
1213  arb_suppress_progress quiet; // @@@ use weighted progress (#789) for loop below
1214 
1215  while (!progress.aborted()) {
1216  Mutations currPars = rootEdge()->nni_rec(whichEdges, AP_BL_NNI_ONLY, NULp, true);
1217  if (currPars == prevPars) break; // no improvement -> abort
1218  progress.subtitle(GBS_global_string("best=%li (gain=%li)", currPars, orgPars-currPars));
1219  prevPars = currPars;
1220  }
1222  }
1223 }
1224 
1225 static void NT_recursiveNNI(AW_window *, TREE_canvas *ntw) {
1226  AWT_auto_refresh allowed_on(ntw);
1227  EdgeSpec whichEdges = KL_Settings(ntw->awr).whichEdges;
1228  recursiveNNI(AWT_TREE_PARS(ntw), whichEdges);
1229 }
1230 
1231 static int calculate_default_random_repeat(long leafs) {
1232  double balanced_depth = log10(leafs) / log10(2);
1233  int repeat = int(balanced_depth*2.0 + .5);
1234  if (repeat<1) repeat = 1;
1235  return repeat;
1236 }
1237 
1239  long leafs = agt->get_root_node()->count_leafs();
1240  int repeat = calculate_default_random_repeat(leafs);
1241  awr->awar(AWAR_RAND_REPEAT)->write_int(repeat);
1242 }
1243 
1244 static void mixtree_and_calclengths(AWT_graphic_parsimony *agt, int repeat, int percent, EdgeSpec whichEdges) {
1245  arb_progress progress("Randomizing tree", 2L);
1246 
1247  // @@@ possible candidate for weighted progress (#789)
1248  progress.subtitle("mixing");
1249  rootEdge()->mixTree(repeat, percent, whichEdges);
1250  ++progress;
1251 
1252  progress.subtitle("calculating branchlengths");
1253  rootEdge()->calc_branchlengths();
1254  ++progress;
1255 
1256  agt->exports.request_save();
1257 }
1258 
1259 static void randomMixTree(AW_window *aww, TREE_canvas *ntw) {
1260  AWT_auto_refresh allowed_on(ntw);
1261  AW_root *awr = aww->get_root();
1262 
1264  {
1265  ARB_edge newRootEdge = rootNode()->get_tree_root()->find_innermost_edge();
1266  newRootEdge.son()->set_root();
1267  }
1268  AWT_TREE_PARS(ntw)->reorderTree(BIG_BRANCHES_TO_TOP);
1269 }
1270 
1271 
1273  { AWAR_OPTI_MARKED_ONLY, "marked_only" },
1274  { AWAR_OPTI_SKIP_FOLDED, "skip_folded" },
1275 
1276  // { AWAR_RAND_REPEAT, "rand_repeat" }, // do not store (use treesize-dependent default)
1277  { AWAR_RAND_PERCENT, "rand_percent" },
1278 
1279  { AWAR_KL_MAXDEPTH, "maxdepth" },
1280  { AWAR_KL_INCDEPTH, "incdepth" },
1281 
1282  { AWAR_KL_STATIC_ENABLED, "static" },
1283  { AWAR_KL_STATIC_DEPTH1, "s_depth1" },
1284  { AWAR_KL_STATIC_DEPTH2, "s_depth2" },
1285  { AWAR_KL_STATIC_DEPTH3, "s_depth3" },
1286  { AWAR_KL_STATIC_DEPTH4, "s_depth4" },
1287  { AWAR_KL_STATIC_DEPTH5, "s_depth5" },
1288 
1289  { AWAR_KL_DYNAMIC_ENABLED, "dynamic" },
1290  { AWAR_KL_DYNAMIC_START, "start" },
1291  { AWAR_KL_DYNAMIC_MAXX, "maxx" },
1292  { AWAR_KL_DYNAMIC_MAXY, "maxy" },
1293 
1294  { NULp, NULp }
1295 };
1296 
1298  {
1299  "*minimum_static_reduction",
1300  "Sets paths allowed by static reduction to maximum\n(causing the minimal reduction)",
1301  "s_depth1='8';s_depth2='6';s_depth3='6';s_depth4='6';s_depth5='6';static='1'" // only defines/affects settings related to static path reduction
1302  },
1303  {
1304  "*whole_tree_level8",
1305  "Level-8-optimization of whole tree\n(no path reduction)",
1306  "dynamic='0';incdepth='0';marked_only='0';maxdepth='8';skip_folded='0';static='0'"
1307  },
1308  { NULp, NULp, NULp }
1309 };
1310 
1312  AW_window_simple *aws = new AW_window_simple;
1313  aws->init(aw_root, "TREE_OPTIMIZE", "Tree optimization");
1314  aws->load_xfig("pars/tree_opti.fig");
1315 
1316  aws->at("close");
1317  aws->callback(AW_POPDOWN);
1318  aws->create_button("CLOSE", "CLOSE", "C");
1319 
1320  aws->at("help");
1321  aws->callback(makeHelpCallback("pa_optimizer.hlp"));
1322  aws->create_button("HELP", "HELP", "H");
1323 
1324  aws->at("marked");
1325  aws->label("Only subtrees containing marked species");
1326  aws->create_toggle(AWAR_OPTI_MARKED_ONLY);
1327 
1328  aws->at("folded");
1329  aws->label("Do not modify folded subtrees");
1330  aws->create_toggle(AWAR_OPTI_SKIP_FOLDED);
1331 
1332  aws->button_length(18);
1333 
1334  aws->at("rec_nni");
1335  aws->callback(makeWindowCallback(NT_recursiveNNI, ntw));
1336  aws->create_button("REC_NNI", "Recursive NNI", "N");
1337 
1338  aws->at("heuristic");
1339  aws->callback(makeWindowCallback(NT_optimize, ntw));
1340  aws->create_button("HEURISTIC", "Heuristic\noptimizer", "H");
1341 
1342  aws->at("config");
1343  AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "treeopti", optimizer_config_mapping, NULp, optimizer_predefined_configs);
1344 
1345  aws->at("settings");
1346  aws->callback(makeCreateWindowCallback(create_kernighan_properties_window));
1347  aws->create_button("SETTINGS", "Settings", "S");
1348 
1349  aws->at("randomize");
1350  aws->callback(makeWindowCallback(randomMixTree, ntw));
1351  aws->create_button("RANDOMIZE", "Randomize tree", "R");
1352 
1353  aws->button_length(5);
1354 
1355  aws->at("repeat"); aws->create_input_field(AWAR_RAND_REPEAT);
1356  aws->at("percent"); aws->create_input_field(AWAR_RAND_PERCENT);
1357 
1358  return aws;
1359 }
1360 
1361 // -----------------------
1362 // test functions
1363 
1364 #if defined(TESTMENU)
1365 static void refreshTree(AWT_canvas *ntw) {
1366  GB_transaction ta(ntw->gb_main);
1367  AWT_auto_refresh allowed_on(ntw);
1369 }
1370 
1371 static void setBranchlens(AP_tree_nlen *node, double newLen) {
1372  node->setBranchlen(newLen, newLen);
1373 
1374  if (!node->is_leaf()) {
1375  setBranchlens(node->get_leftson(), newLen);
1376  setBranchlens(node->get_rightson(), newLen);
1377  }
1378 }
1379 
1380 static void TESTMENU_setBranchlen(AW_window *, AWT_canvas *ntw) {
1381  AP_tree_nlen *root = rootNode();
1382 
1383  setBranchlens(root, 1.0);
1384  refreshTree(ntw);
1385 }
1386 
1387 static void TESTMENU_treeStats(AW_window *) {
1388  ARB_tree_info tinfo;
1389  AP_tree_nlen *root = rootNode();
1390 
1391  if (root) {
1392  {
1393  GB_transaction ta(root->get_tree_root()->get_gb_main());
1394  root->calcTreeInfo(tinfo);
1395  }
1396 
1397  puts("Tree stats:");
1398 
1399  printf("nodes =%6zu\n", tinfo.nodes());
1400  printf(" inner =%6zu\n", tinfo.innerNodes);
1401  printf(" groups =%6zu\n", tinfo.groups);
1402  printf(" leafs =%6zu\n", tinfo.leafs);
1403  printf(" unlinked =%6zu (zombies?)\n", tinfo.unlinked);
1404  printf(" linked =%6zu\n", tinfo.linked());
1405  printf(" marked =%6zu\n", tinfo.marked);
1406  }
1407  else {
1408  puts("No tree");
1409  }
1410 }
1411 
1412 static void TESTMENU_sortTreeByName(AW_window *, AWT_canvas *ntw) {
1413  AP_tree_nlen *root = rootNode();
1414 
1415  root->sortByName();
1416  refreshTree(ntw);
1417 }
1418 
1419 static void init_TEST_menu(AW_window_menu_modes *awm, AWT_canvas *ntw) {
1420  awm->create_menu("Test[debug]", "g", AWM_ALL);
1421 
1422  awm->insert_menu_topic("treestat", "Tree statistics", "s", "", AWM_ALL, TESTMENU_treeStats);
1423  awm->insert_menu_topic("setlens", "Set branchlens", "b", "", AWM_ALL, makeWindowCallback(TESTMENU_setBranchlen, ntw));
1424  awm->insert_menu_topic("sorttreebyname", "Sort tree by name", "o", "", AWM_ALL, makeWindowCallback(TESTMENU_sortTreeByName, ntw));
1425 }
1426 #endif // TESTMENU
1427 
1429  GB_ERROR error = NULp;
1430  warning = NULp;
1431 
1432  char *tree_name = awr->awar(AWAR_TREE)->read_string();
1433  char *filter = awr->awar(filterDef->def_filter)->read_string();
1434  long ali_len = 0;
1435 
1436  if (strlen(filter)) {
1437  int i;
1438  for (i=0; filter[i]; i++) {
1439  if (filter[i] != '0') ali_len++;
1440  }
1441  }
1442  else {
1443  char *ali_name = awr->awar(AWAR_ALIGNMENT)->read_string();
1444  ali_len = GBT_get_alignment_len(ap_main->get_gb_main(), ali_name);
1445  if (ali_len<=0) {
1446  error = "Please select a valid alignment";
1447  GB_clear_error();
1448  }
1449  free(ali_name);
1450  }
1451 
1452  if (!error) {
1453  long tree_size = GBT_size_of_tree(ap_main->get_gb_main(), tree_name);
1454  if (tree_size == -1) {
1455  error = "Please select an existing tree";
1456  }
1457  else {
1458  size_t expected_memuse = (ali_len * tree_size * 4 / 1024);
1459  if (expected_memuse > GB_get_usable_memory()) {
1460  warning = GBS_global_string("Estimated memory usage (%s) exceeds physical memory (will swap)\n"
1461  "(did you specify a filter?)",
1462  GBS_readable_size(expected_memuse, "b"));
1463  }
1464  }
1465  }
1466 
1467  free(filter);
1468  free(tree_name);
1469 
1471  return error;
1472 }
1473 
1475  AW_root *awr = aww->get_root();
1477 }
1478 
1480  int leafs; // counts leafs with insufficiant data
1481  int inner; // same for inner nodes
1482 
1483 public:
1484  LowDataCheck() : leafs(0), inner(0) {}
1485 
1486  void count(AP_tree_nlen *node);
1487 
1488  int get_leafs() const { return leafs; }
1489  int get_inner() const { return inner; }
1490 };
1491 
1492 void LowDataCheck::count(AP_tree_nlen *node) {
1493  const AP_combinableSeq *seq = node->get_seq();
1494  AP_FLOAT bases = seq->weighted_base_count();
1495 
1496  if (node->is_leaf()) {
1497  if (bases<MIN_SEQUENCE_LENGTH) ++leafs;
1498  }
1499  else {
1500  if (bases<MIN_SEQUENCE_LENGTH) ++inner;
1501 
1502  count(node->get_leftson());
1503  count(node->get_rightson());
1504  }
1505 }
1506 
1508  AWT_trigger_remote_action(NULp, canvas->gb_main, "ARB_NT:species_info");
1509  nt_mode_event(NULp, canvas, mode);
1510 }
1511 
1512 static void pars_start_cb(AW_window *aw_parent, WeightedFilter *wfilt, const PARS_commands *cmds) {
1513  ModRLimit increase_stacksize(RLIMIT_STACK, TREEDISP_STACKSIZE);
1514 
1515  AW_root *awr = aw_parent->get_root();
1516  GBDATA *gb_main = ap_main->get_gb_main();
1517  GB_begin_transaction(gb_main);
1518  {
1519  GB_ERROR warning;
1520  GB_ERROR error = pars_check_size(awr, warning, wfilt->get_adfiltercbstruct());
1521 
1522  if (warning && !error) {
1523  char *question = GBS_global_string_copy("%s\nDo you want to continue?", warning);
1524  bool cont = aw_ask_sure("swap_warning", question);
1525  free(question);
1526 
1527  if (!cont) error = "User abort";
1528 
1529  }
1530 
1531  if (error) {
1532  aw_message(error);
1533  GB_commit_transaction(gb_main);
1534  return;
1535  }
1536  }
1537 
1538 
1540  awm->init(awr, "ARB_PARSIMONY", "ARB_PARSIMONY", 400, 200);
1541 
1542  GLOBAL_PARS->generate_tree(wfilt);
1543 
1544  TREE_canvas *ntw;
1545  {
1547  global_tree()->set_tree_style(AP_LIST_SIMPLE, NULp); // avoid NDS warnings during startup
1548  ntw = new TREE_canvas(gb_main, awm, awm->get_window_id(), global_tree(), awr->awar(AWAR_TREE));
1549  global_tree()->set_tree_style(prev_style, ntw);
1550  }
1551 
1552  {
1553  GB_ERROR error = NULp;
1554  arb_progress progress("loading tree");
1555  NT_reload_tree_event(awr, ntw, false); // load tree (but do not expose - first zombies need to be removed)
1556  if (!global_tree()->get_root_node()) {
1557  error = "Failed to load the selected tree";
1558  }
1559  else {
1560  AP_tree_edge::initialize(rootNode()); // builds edges
1561  long removed = global_tree_root()->remove_leafs(AWT_REMOVE_ZOMBIES);
1562 
1565 
1566  if (!global_tree()->get_root_node()) {
1567  const char *aliname = global_tree_root()->get_aliview()->get_aliname();
1568  error = GBS_global_string("Less than 2 species contain data in '%s'\n"
1569  "Tree vanished", aliname);
1570  }
1571  else if (removed) {
1572  aw_message(GBS_global_string("Removed %li leafs (zombies or species w/o data in alignment)", removed));
1573  }
1574 
1575  error = GB_end_transaction(ntw->gb_main, error);
1576  if (!error) {
1577  progress.subtitle("Calculating inner nodes");
1578  GLOBAL_PARS->get_root_node()->costs();
1579 
1580  progress.subtitle("Checking amount of data");
1581  LowDataCheck lowData;
1582  lowData.count(GLOBAL_PARS->get_root_node());
1583 
1584  bool warned = false;
1585  if (lowData.get_inner()>0) {
1586  aw_message(GBS_global_string("Inner nodes with insufficient data: %i", lowData.get_inner()));
1587  warned = true;
1588  }
1589  if (lowData.get_leafs()>0) {
1590  aw_message(GBS_global_string("Species with insufficient data: %i", lowData.get_leafs()));
1591  warned = true;
1592  }
1593 #define _STRGIZE(x) #x
1594 #define INT2STR(i) _STRGIZE(i)
1595  if (warned) {
1596  aw_message("Warning: low sequence data (<" INT2STR(MIN_SEQUENCE_LENGTH) " bp) detected! (filter too restrictive?)");
1597  }
1598  }
1599  }
1600  if (error) aw_popup_exit(error);
1601  }
1602 
1603  if (cmds->add_marked) NT_add_quick(NULp, ntw, NT_ADD_MARKED);
1604  if (cmds->add_selected) NT_add_quick(NULp, ntw, NT_ADD_SELECTED);
1606  if (cmds->calc_bootstrap) NT_bootstrap(awm, ntw, 0);
1607  if (cmds->quit) pars_exit(awm);
1608 
1609  GB_transaction ta(ntw->gb_main);
1610 
1611 #if defined(DEBUG)
1612  AWT_create_debug_menu(awm);
1613 #endif // DEBUG
1614 
1615  awm->create_menu("File", "F", AWM_ALL);
1616  {
1617  insert_macro_menu_entry(awm, false);
1618  awm->insert_menu_topic("print_tree", "Print Tree ...", "P", "tree2prt.hlp", AWM_ALL, makeWindowCallback(AWT_popup_print_window, static_cast<AWT_canvas*>(ntw)));
1619  awm->insert_menu_topic("quit", "Quit", "Q", "quit.hlp", AWM_ALL, pars_exit);
1620  }
1621 
1622  awm->create_menu("Species", "S", AWM_ALL);
1623  {
1624  NT_insert_mark_submenus(awm, ntw, 0);
1625 
1626  }
1627  awm->create_menu("Tree", "T", AWM_ALL);
1628  {
1629 
1630  awm->insert_menu_topic("nds", "NDS (Node Display Setup) ...", "N", "props_nds.hlp", AWM_ALL, makeCreateWindowCallback(AWT_create_nds_window, ntw->gb_main));
1631 
1632  awm->sep______________();
1633  awm->insert_menu_topic("tree_print", "Print tree ...", "P", "tree2prt.hlp", AWM_ALL, makeWindowCallback(AWT_popup_print_window, static_cast<AWT_canvas*>(ntw)));
1634  awm->insert_menu_topic("tree_2_xfig", "Export tree to XFIG ...", "F", "tree2file.hlp", AWM_ALL, makeWindowCallback(AWT_popup_tree_export_window, static_cast<AWT_canvas*>(ntw)));
1635  awm->sep______________();
1636  NT_insert_collapse_submenu(awm, ntw);
1637  awm->sep______________();
1638  awm->insert_sub_menu("Remove Species from Tree", "R");
1639  {
1640  awm->insert_menu_topic("tree_remove_deleted", "Remove Zombies", "Z", "trm_del.hlp", AWM_ALL, makeWindowCallback(NT_remove_leafs, ntw, AWT_REMOVE_ZOMBIES));
1641  awm->insert_menu_topic("tree_remove_marked", "Remove Marked", "M", "trm_mrkd.hlp", AWM_ALL, makeWindowCallback(NT_remove_leafs, ntw, AWT_REMOVE_MARKED));
1642  awm->insert_menu_topic("tree_keep_marked", "Keep Marked", "K", "tkeep_mrkd.hlp", AWM_ALL, makeWindowCallback(NT_remove_leafs, ntw, AWT_KEEP_MARKED));
1643  }
1644  awm->close_sub_menu();
1645  awm->insert_sub_menu("Add Species to Tree", "A");
1646  {
1647  awm->insert_menu_topic("add_marked", "Add Marked Species", "M", "pa_quick.hlp", AWM_ALL, makeWindowCallback(NT_add_quick, ntw, NT_ADD_MARKED));
1648  awm->insert_menu_topic("add_marked_nni", "Add Marked Species + Local Optimization (NNI)", "N", "pa_add.hlp", AWM_ALL, makeWindowCallback(NT_add_and_NNI, ntw, NT_ADD_MARKED));
1649  awm->insert_menu_topic("rm_add_marked", "Remove & Add Marked Species", "R", "pa_quick.hlp", AWM_ALL, makeWindowCallback(NT_reAdd_quick, ntw, NT_ADD_MARKED));
1650  awm->insert_menu_topic("rm_add_marked_nni|", "Remove & Add Marked + Local Optimization (NNI)", "L", "pa_add.hlp", AWM_ALL, makeWindowCallback(NT_reAdd_and_NNI, ntw, NT_ADD_MARKED));
1651  awm->sep______________();
1652  awm->insert_menu_topic("add_marked_partial", "Add Marked Partial Species", "P", "pa_partial.hlp", AWM_ALL, makeWindowCallback(NT_add_partial_and_update, ntw));
1653  awm->sep______________();
1654  awm->insert_menu_topic("add_selected", "Add Selected Species", "S", "pa_quick.hlp", AWM_ALL, makeWindowCallback(NT_add_quick, ntw, NT_ADD_SELECTED));
1655  awm->insert_menu_topic("add_selected_nni", "Add Selected Species + Local Optimization (NNI)", "O", "pa_add.hlp", AWM_ALL, makeWindowCallback(NT_add_and_NNI, ntw, NT_ADD_SELECTED));
1656  }
1657  awm->close_sub_menu();
1658  awm->sep______________();
1659  awm->insert_menu_topic("optimize", "Tree Optimization ...", "O", "pa_optimizer.hlp", AWM_ALL, makeCreateWindowCallback(createOptimizeWindow, ntw));
1660  awm->insert_menu_topic("reset", "Reset optimal parsimony", "s", "pa_reset.hlp", AWM_ALL, pars_reset_optimal_parsimony);
1661  awm->sep______________();
1662  awm->insert_menu_topic("beautify_tree", "Beautify Tree", "B", "resorttree.hlp", AWM_ALL, makeWindowCallback(NT_resort_tree_cb, ntw, BIG_BRANCHES_TO_TOP));
1663  awm->insert_menu_topic("calc_branch_lengths", "Calculate Branch Lengths", "L", "pa_branchlengths.hlp", AWM_ALL, makeWindowCallback(NT_calc_branchlengths_reorder_and_update, ntw));
1664  awm->sep______________();
1665  awm->insert_menu_topic("calc_upper_bootstrap_indep", "Calculate Upper Bootstrap Limit (dependent NNI)", "U", "pa_bootstrap.hlp", AWM_ALL, makeWindowCallback(NT_bootstrap, ntw, false));
1666  awm->insert_menu_topic("calc_upper_bootstrap_dep", "Calculate Upper Bootstrap Limit (independent NNI)", "i", "pa_bootstrap.hlp", AWM_ALL, makeWindowCallback(NT_bootstrap, ntw, true));
1667  awm->insert_menu_topic("tree_remove_remark", "Remove bootstrap values", "v", "trm_boot.hlp", AWM_ALL, makeWindowCallback(NT_remove_bootstrap, ntw));
1668  }
1669 
1670 #if defined(TESTMENU)
1671  init_TEST_menu(awm, ntw);
1672 #endif // TESTMENU
1673 
1674  awm->create_menu("Reset", "R", AWM_ALL);
1675  {
1676  awm->insert_menu_topic("reset_logical_zoom", "Logical Zoom", "L", "rst_log_zoom.hlp", AWM_ALL, makeWindowCallback(NT_reset_lzoom_cb, ntw));
1677  awm->insert_menu_topic("reset_physical_zoom", "Physical Zoom", "P", "rst_phys_zoom.hlp", AWM_ALL, makeWindowCallback(NT_reset_pzoom_cb, ntw));
1678  }
1679 
1680  awm->create_menu("Properties", "P", AWM_ALL);
1681  {
1682  awm->insert_menu_topic("props_menu", "Frame settings ...", "F", "props_frame.hlp", AWM_ALL, AW_preset_window);
1683  awm->insert_menu_topic("props_tree2", "Tree options", "o", "nt_tree_settings.hlp", AWM_ALL, TREE_create_settings_window);
1684  awm->insert_menu_topic("props_tree", "Tree colors & fonts", "c", "color_props.hlp", AWM_ALL, makeCreateWindowCallback(AW_create_gc_window, ntw->gc_manager));
1685  awm->insert_menu_topic("props_kl", "Optimizer settings (KL)", "K", "kernlin.hlp", AWM_ALL, makeCreateWindowCallback(create_kernighan_properties_window));
1686  awm->sep______________();
1688  awm->sep______________();
1689  awm->insert_menu_topic("save_props", "Save Defaults (pars.arb)", "D", "savedef.hlp", AWM_ALL, AW_save_properties);
1690  }
1691  awm->button_length(5);
1692 
1693  awm->insert_help_topic("ARB_PARSIMONY help", "P", "arb_pars.hlp", AWM_ALL, makeHelpCallback("arb_pars.hlp"));
1694 
1695  // ----------------------
1696  // mode buttons
1697  //
1698  // keep them synchronized as far as possible with those in ARB_PARSIMONY
1699  // see ../NTREE/NT_extern.cxx@keepModesSynchronized
1700 
1701  awm->create_mode("mode_select.xpm", "mode_select.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_SELECT));
1702  awm->create_mode("mode_mark.xpm", "mode_mark.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_MARK));
1703  awm->create_mode("mode_group.xpm", "mode_group.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_GROUP));
1704  awm->create_mode("mode_zoom.xpm", "mode_pzoom.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_ZOOM));
1705  awm->create_mode("mode_lzoom.xpm", "mode_lzoom.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_LZOOM));
1706 
1707  awm->create_mode("mode_info.xpm", "mode_info.hlp", AWM_ALL, makeWindowCallback(PARS_infomode_cb, ntw, AWT_MODE_INFO));
1708  // reserve mode-locations (to put the modes below at the same position as in ARB_NT)
1709  awm->create_mode("mode_empty.xpm", "mode.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_EMPTY));
1710 
1711  // topology-modification-modes
1712  awm->create_mode("mode_setroot.xpm", "mode_setroot.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_SETROOT));
1713  awm->create_mode("mode_swap.xpm", "mode_swap.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_SWAP));
1714  awm->create_mode("mode_move.xpm", "mode_move.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_MOVE));
1715 
1716  awm->create_mode("mode_nni.xpm", "mode_nni.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_NNI));
1717  awm->create_mode("mode_kernlin.xpm", "mode_kernlin.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_KERNINGHAN));
1718  awm->create_mode("mode_optimize.xpm", "mode_optimize.hlp", AWM_ALL, makeWindowCallback(nt_mode_event, ntw, AWT_MODE_OPTIMIZE));
1719 
1720  awm->at(5, 2);
1721  awm->auto_space(0, -2);
1722  awm->shadow_width(1);
1723 
1724 
1725  int db_treex, db_treey;
1726  awm->get_at_position(&db_treex, &db_treey);
1727  awm->callback(makeHelpCallback("nt_tree_select.hlp"));
1728  awm->button_length(16);
1729  awm->help_text("nt_tree_select.hlp");
1730  awm->create_button(NULp, AWAR_TREE);
1731 
1732 
1733  int db_stackx, db_stacky;
1734  awm->label_length(8);
1735  awm->label("Stored");
1736  awm->get_at_position(&db_stackx, &db_stacky);
1737  awm->button_length(6);
1738  awm->callback(makeHelpCallback("ap_stack.hlp"));
1739  awm->help_text("ap_stack.hlp");
1741 
1742  int db_parsx, db_parsy;
1743  awm->label_length(14);
1744  awm->label("Current Pars:");
1745  awm->get_at_position(&db_parsx, &db_parsy);
1746 
1747  awm->button_length(10);
1748  awm->create_button(NULp, AWAR_PARSIMONY, NULp, "+");
1749 
1750  awm->button_length(0);
1751 
1752  awm->callback(makeWindowCallback(NT_jump_cb, ntw, AP_JUMP_BY_BUTTON));
1753  awm->help_text("tr_jump.hlp");
1754  awm->create_button("JUMP", "Jump");
1755 
1756  awm->callback(makeHelpCallback("arb_pars.hlp"));
1757  awm->help_text("help.hlp");
1758  awm->create_button("HELP", "HELP", "H");
1759 
1760  awm->at_newline();
1761 
1762  awm->button_length(8);
1763  awm->at_x(db_stackx);
1764  awm->callback(makeWindowCallback(AP_user_pop_cb, ntw));
1765  awm->help_text("ap_stack.hlp");
1766  awm->create_button("POP", "RESTORE");
1767 
1768  awm->button_length(6);
1769  awm->callback(AP_user_push_cb);
1770  awm->help_text("ap_stack.hlp");
1771  awm->create_button("PUSH", "STORE");
1772 
1773  awm->at_x(db_parsx);
1774  awm->label_length(14);
1775  awm->label("Optimal Pars:");
1776 
1777  awm->button_length(10);
1779 
1780  awm->button_length(0);
1781  awm->auto_space(0, -2);
1782 
1783  awm->at_x(db_treex);
1784  awm->callback(makeWindowCallback(NT_set_tree_style, ntw, AP_TREE_RADIAL));
1785  awm->help_text("tr_type_radial.hlp");
1786  awm->create_button("RADIAL_TREE", "#radial.xpm");
1787 
1788  awm->callback(makeWindowCallback(NT_set_tree_style, ntw, AP_TREE_NORMAL));
1789  awm->help_text("tr_type_list.hlp");
1790  awm->create_button("LIST_TREE", "#dendro.xpm");
1791 
1792  awm->at_newline();
1793  awm->at(db_treex, awm->get_at_yposition());
1794 
1795  {
1797 
1800  awm->at_newline();
1801  awm->restore_at_from(*maxSize);
1802  }
1803 
1804  awm->get_at_position(&db_treex, &db_treey);
1805  awm->set_info_area_height(db_treey);
1806 
1807  awm->set_bottom_area_height(0);
1808 
1809  aw_parent->hide(); // hide parent
1810  awm->show();
1811 
1813 
1815  AP_user_push_cb(aw_parent); // push initial tree
1816  set_keep_ghostnodes(); // make sure no stacked nodes get deleted
1817 }
1818 
1820  AW_window_simple *aws = new AW_window_simple;
1821  aws->init(awr, "PARS_PROPS", "SET PARSIMONY OPTIONS");
1822  aws->load_xfig("pars/init.fig");
1823 
1824  aws->button_length(10);
1825  aws->label_length(10);
1826 
1827  aws->callback(pars_exit);
1828  aws->at("close");
1829  aws->create_button("ABORT", "ABORT", "A");
1830 
1831  aws->callback(makeHelpCallback("arb_pars_init.hlp"));
1832  aws->at("help");
1833  aws->create_button("HELP", "HELP", "H");
1834 
1835  GBDATA *gb_main = ap_main->get_gb_main();
1836  WeightedFilter *weighted_filter = // do NOT free (bound to callbacks)
1837  new WeightedFilter(gb_main, aws->get_root(), AWAR_FILTER_NAME, AWAR_COLUMNSTAT_NAME, aws->get_root()->awar_string(AWAR_ALIGNMENT));
1838 
1839  aws->at("filter");
1840  aws->callback(makeCreateWindowCallback(awt_create_select_filter_win, weighted_filter->get_adfiltercbstruct()));
1841  aws->create_button("SELECT_FILTER", AWAR_FILTER_NAME);
1842 
1843  aws->at("weights");
1844  aws->callback(makeCreateWindowCallback(COLSTAT_create_selection_window, weighted_filter->get_column_stat()));
1845  aws->sens_mask(AWM_EXP);
1846  aws->create_button("SELECT_CSP", AWAR_COLUMNSTAT_NAME);
1847  aws->sens_mask(AWM_ALL);
1848 
1849  aws->at("alignment");
1850  awt_create_ALI_selection_list(gb_main, aws, AWAR_ALIGNMENT, "*=");
1851 
1852  aws->at("tree");
1853  awt_create_TREE_selection_list(gb_main, aws, AWAR_TREE, true);
1854 
1855  aws->callback(makeWindowCallback(pars_start_cb, weighted_filter, cmds));
1856  aws->at("go");
1857  aws->create_button("GO", "GO", "G");
1858 
1859  return aws;
1860 }
1861 
1863  maxdepth = aw_root->awar(AWAR_KL_MAXDEPTH)->read_int();
1864  incdepth = aw_root->awar(AWAR_KL_INCDEPTH)->read_int();
1865 
1866  Static.enabled = aw_root->awar(AWAR_KL_STATIC_ENABLED)->read_int();
1867  Static.depth[0] = 2; // always test both possibilities at starting edge
1868  Static.depth[1] = aw_root->awar(AWAR_KL_STATIC_DEPTH1)->read_int();
1869  Static.depth[2] = aw_root->awar(AWAR_KL_STATIC_DEPTH2)->read_int();
1870  Static.depth[3] = aw_root->awar(AWAR_KL_STATIC_DEPTH3)->read_int();
1871  Static.depth[4] = aw_root->awar(AWAR_KL_STATIC_DEPTH4)->read_int();
1872  Static.depth[5] = aw_root->awar(AWAR_KL_STATIC_DEPTH5)->read_int();
1873 
1874  Dynamic.enabled = aw_root->awar(AWAR_KL_DYNAMIC_ENABLED)->read_int();
1875  Dynamic.start = aw_root->awar(AWAR_KL_DYNAMIC_START)->read_int();
1876  Dynamic.maxx = aw_root->awar(AWAR_KL_DYNAMIC_MAXX)->read_int();
1877  Dynamic.maxy = aw_root->awar(AWAR_KL_DYNAMIC_MAXY)->read_int();
1878  Dynamic.type = (KL_DYNAMIC_THRESHOLD_TYPE)aw_root->awar(AWAR_KL_FUNCTION_TYPE)->read_int();
1879 
1880  whichEdges = ANY_EDGE;
1881  if (aw_root->awar(AWAR_OPTI_MARKED_ONLY)->read_int()) whichEdges = EdgeSpec(whichEdges|SKIP_UNMARKED_EDGES);
1882  if (aw_root->awar(AWAR_OPTI_SKIP_FOLDED)->read_int()) whichEdges = EdgeSpec(whichEdges|SKIP_FOLDED_EDGES);
1883 }
1884 #if defined(UNIT_TESTS)
1886  // set default values
1887  maxdepth = 15;
1888 
1889  Static.enabled = true;
1890  Static.depth[0] = 2; // always test both possibilities at starting edge
1891  Static.depth[1] = 8;
1892  Static.depth[2] = 6;
1893  Static.depth[3] = 6;
1894  Static.depth[4] = 6;
1895  Static.depth[5] = 6;
1896 
1897  Dynamic.enabled = true;
1898  Dynamic.start = 100;
1899  Dynamic.maxy = 150;
1900  Dynamic.maxx = 6;
1901 
1902  // these values do not seem to have any effect (i.e. are not covered by unit-tests):
1903  incdepth = 4;
1904 
1905  // const setting (not configurable)
1906  Dynamic.type = AP_QUADRAT_START;
1908 }
1909 #endif
1910 
1911 static void create_optimize_vars(AW_root *aw_root, AW_default props) {
1912  // kernighan
1913 
1914  aw_root->awar_int(AWAR_OPTI_MARKED_ONLY, 1, props);
1915  aw_root->awar_int(AWAR_OPTI_SKIP_FOLDED, 1, props);
1916 
1917  aw_root->awar_int(AWAR_KL_MAXDEPTH, 15, props);
1918  aw_root->awar_int(AWAR_KL_INCDEPTH, 4, props);
1919 
1920  aw_root->awar_int(AWAR_KL_STATIC_ENABLED, 1, props);
1921  aw_root->awar_int(AWAR_KL_STATIC_DEPTH1, 5, props)->set_minmax(1, 8);
1922  aw_root->awar_int(AWAR_KL_STATIC_DEPTH2, 3, props)->set_minmax(1, 6);
1923  aw_root->awar_int(AWAR_KL_STATIC_DEPTH3, 2, props)->set_minmax(1, 6);
1924  aw_root->awar_int(AWAR_KL_STATIC_DEPTH4, 2, props)->set_minmax(1, 6);
1925  aw_root->awar_int(AWAR_KL_STATIC_DEPTH5, 1, props)->set_minmax(1, 6);
1926 
1927  aw_root->awar_int(AWAR_KL_DYNAMIC_ENABLED, 1, props);
1928  aw_root->awar_int(AWAR_KL_DYNAMIC_START, 100, props);
1929  aw_root->awar_int(AWAR_KL_DYNAMIC_MAXX, 6, props);
1930  aw_root->awar_int(AWAR_KL_DYNAMIC_MAXY, 150, props);
1931 
1933 }
1934 
1936  awr->awar_string(AWAR_SPECIES_NAME, "", gb_main);
1937  awr->awar_string(AWAR_FOOTER, "", aw_def);
1938 
1939  // copy currently selected alignment to awar:
1940  {
1941  GB_transaction ta(gb_main);
1942  char *dali = GBT_get_default_alignment(gb_main);
1943  awr->awar_string(AWAR_ALIGNMENT, dali, gb_main)->write_string(dali);
1944  free(dali);
1945  }
1946 
1949 
1950  awr->awar_int(AWAR_PARS_TYPE, PARS_WAGNER, gb_main);
1951 
1952  {
1953  GB_transaction ta(gb_main);
1954  GBDATA *gb_tree_name = GB_search(gb_main, AWAR_TREE, GB_STRING);
1955  char *tree_name = GB_read_string(gb_tree_name);
1956 
1957  awr->awar_string(AWAR_TREE, "", aw_def)->write_string(tree_name);
1958  free(tree_name);
1959  }
1960 
1961  awr->awar_int(AWAR_PARSIMONY, 0, aw_def);
1962  awr->awar_int(AWAR_BEST_PARSIMONY, 0, aw_def);
1963  awr->awar_int(AWAR_STACKPOINTER, 0, aw_def);
1964 
1965  awr->awar_int(AWAR_RAND_REPEAT, 1, aw_def)->set_minmax(1, 1000000); // default value is overwritten by update_random_repeat()
1966  awr->awar_int(AWAR_RAND_PERCENT, 50, aw_def)->set_minmax(1, 100);
1967 
1968  create_optimize_vars(awr, aw_def);
1969  create_nds_vars(awr, aw_def, gb_main, false);
1970 
1971  TREE_create_awars(awr, gb_main);
1972 
1973 #if defined(DEBUG)
1974  AWT_create_db_browser_awars(awr, aw_def);
1975 #endif // DEBUG
1976 
1977  GB_ERROR error = ARB_init_global_awars(awr, aw_def, gb_main);
1978  if (error) aw_message(error);
1979 }
1980 
1982 
1983 void PARS_map_viewer(GBDATA *gb_species, AD_MAP_VIEWER_TYPE vtype) {
1984  // Note: sync with ../NTREE/ad_spec.cxx@launch_MapViewer_cb
1985 
1986  if (AD_map_viewer_aw_root &&
1987  gb_species &&
1988  (vtype == ADMVT_SELECT || vtype == ADMVT_INFO))
1989  {
1990  AD_map_viewer_aw_root->awar(AWAR_SPECIES_NAME)->write_string(null2empty(GBT_get_name(gb_species)));
1991  }
1992 }
1993 
1994 int ARB_main(int argc, char *argv[]) {
1995  aw_initstatus();
1996 
1997  GB_shell shell;
1998  AW_root *aw_root = AWT_create_root("pars.arb", "ARB_PARS", need_macro_ability());
1999  AD_map_viewer_aw_root = aw_root;
2000 
2001  ap_main = new AP_main;
2002  GLOBAL_PARS = new ArbParsimony();
2003 
2004  const char *db_server = ":";
2005 
2006  PARS_commands cmds;
2007 
2008  while (argc>=2 && argv[1][0] == '-') {
2009  argc--;
2010  argv++;
2011  if (!strcmp(argv[0], "-quit")) cmds.quit = 1;
2012  else if (!strcmp(argv[0], "-add_marked")) cmds.add_marked = 1;
2013  else if (!strcmp(argv[0], "-add_selected")) cmds.add_selected = 1;
2014  else if (!strcmp(argv[0], "-calc_branchlengths")) cmds.calc_branch_lengths = 1;
2015  else if (!strcmp(argv[0], "-calc_bootstrap")) cmds.calc_bootstrap = 1;
2016  else {
2017  fprintf(stderr, "Unknown option '%s'\n", argv[0]);
2018 
2019  printf(" Options: Meaning:\n"
2020  "\n"
2021  " -add_marked add marked species (without changing topology)\n"
2022  " -add_selected add selected species (without changing topology)\n"
2023  " -calc_branchlengths calculate branch lengths only\n"
2024  " -calc_bootstrap estimate bootstrap values\n"
2025  " -quit quit after performing operations\n"
2026  );
2027 
2028  exit(EXIT_FAILURE);
2029  }
2030  }
2031 
2032 
2033  if (argc==2) db_server = argv[1];
2034 
2035  GB_ERROR error = ap_main->open(db_server);
2036  if (!error) {
2037  GBDATA *gb_main = ap_main->get_gb_main();
2038  error = configure_macro_recording(aw_root, "ARB_PARS", gb_main);
2039 
2040  if (!error) {
2041 #if defined(DEBUG)
2042  AWT_announce_db_to_browser(gb_main, GBS_global_string("ARB-database (%s)", db_server));
2043 #endif // DEBUG
2044 
2045  pars_create_all_awars(aw_root, AW_ROOT_DEFAULT, gb_main);
2046 
2047  AW_window *aww = create_pars_init_window(aw_root, &cmds);
2048  aww->show();
2049 
2051  aw_root->main_loop();
2052  }
2053  }
2054 
2055  if (error) aw_popup_exit(error);
2056  return EXIT_SUCCESS;
2057 }
2058 
2059 
2060 // --------------------------------------------------------------------------------
2061 
2062 #ifdef UNIT_TESTS
2063 #include <arb_file.h>
2064 #include <arb_diff.h>
2065 #include <test_unit.h>
2066 #include <AP_seq_dna.hxx>
2067 #include <AP_seq_protein.hxx>
2068 #include "test_env.h"
2069 
2070 // #define AUTO_UPDATE_IF_CHANGED // uncomment to auto update expected results
2071 
2072 static arb_test::match_expectation topologyEquals(AP_tree_nlen *root_node, const char *treefile_base) {
2073  using namespace arb_test;
2074  expectation_group fulfilled;
2075 
2076  char *outfile = GBS_global_string_copy("pars/%s.tree", treefile_base);
2077  char *expected = GBS_global_string_copy("%s.expected", outfile);
2078  bool update = false;
2079 
2080  {
2081  FILE *out = fopen(outfile, "wt");
2082  fulfilled.add(that(out).does_differ_from_NULL());
2083  char *newick = GBT_tree_2_newick(root_node, NewickFormat(nLENGTH|nWRAP), false);
2084  fputs(newick, out);
2085  free(newick);
2086  fclose(out);
2087  }
2088 
2089  if (GB_is_regularfile(expected)) {
2090  bool match_exp_topo = textfiles_have_difflines(outfile,expected,0);
2091 #if defined(AUTO_UPDATE_IF_CHANGED)
2092  if (!match_exp_topo) update = true;
2093 #endif
2094  if (!update) fulfilled.add(that(match_exp_topo).is_equal_to(true));
2095  }
2096  else {
2097  update = true;
2098  }
2099 
2100  if (update) TEST_COPY_FILE(outfile, expected);
2102 
2103  free(expected);
2104  free(outfile);
2105 
2106  return all().ofgroup(fulfilled);
2107 }
2108 
2109 template<class ENV>
2110 arb_test::match_expectation calcCostsCausesCombines(ENV& env, AP_FLOAT exp_pars, long exp_combines) {
2111  using namespace arb_test;
2112  expectation_group fulfilled;
2113 
2114  long combines_b4_costCalc = env.combines_performed();
2115  fulfilled.add(that(combines_b4_costCalc).is_equal_to(0));
2116 
2117  AP_FLOAT new_pars = env.root_node()->costs();
2118  long combines_by_costCalc = env.combines_performed();
2119 
2120  fulfilled.add(that(new_pars).fulfills(epsilon_similar(0.001), exp_pars));
2121  fulfilled.add(that(combines_by_costCalc).is_equal_to(exp_combines));
2122 
2123  return all().ofgroup(fulfilled);
2124 }
2125 
2126 #define TEST_EXPECT_SAVED_TOPOLOGY(env,exp_topo) TEST_EXPECTATION(topologyEquals(env.root_node(), exp_topo))
2127 #define TEST_EXPECT_SAVED_TOPOLOGY__BROKEN(env,exp_topo,got_topo) TEST_EXPECTATION__BROKEN(topologyEquals(env.root_node(), exp_topo), topologyEquals(env.root_node(), got_topo))
2128 
2129 #define TEST_EXPECT_PARSVAL(env,exp_pars) TEST_EXPECT_EQUAL(env.root_node()->costs(), exp_pars);
2130 #define TEST_EXPECT_ONLY_PARSVAL_COMBINES(env,exp_pars,exp_combines) TEST_EXPECTATION(calcCostsCausesCombines(env, exp_pars, exp_combines))
2131 // use TEST_EXPECT_ONLY_PARSVAL_COMBINES when
2132 // - no combines occurred (or combines were just tested using TEST_EXPECT_COMBINES_PERFORMED) and
2133 // - topology was modified, so that calculation of costs causes new combines.
2134 #define TEST_EXPECT_KNOWN_PARSVAL(env,exp_pars) TEST_EXPECT_ONLY_PARSVAL_COMBINES(env,exp_pars,0)
2135 
2136 enum TopoMod {
2137  MOD_REMOVE_MARKED,
2138 
2139  MOD_QUICK_READD,
2140  MOD_QUICK_ADD,
2141  MOD_READD_NNI,
2142 
2143  MOD_ADD_PARTIAL,
2144 
2145  MOD_CALC_LENS,
2146  MOD_OPTI_NNI,
2147  MOD_OPTI_GLOBAL,
2148 
2149  MOD_MIX_TREE,
2150 };
2151 
2152 template <typename SEQ>
2153 static void modifyTopology(PARSIMONY_testenv<SEQ>& env, TopoMod mod) {
2154  switch (mod) {
2155  case MOD_REMOVE_MARKED:
2156  env.graphic_tree()->get_tree_root()->remove_leafs(AWT_REMOVE_MARKED);
2157  break;
2158 
2159  case MOD_QUICK_READD:
2160  nt_reAdd(env.graphic_tree(), NT_ADD_MARKED, true);
2161  break;
2162 
2163  case MOD_QUICK_ADD:
2164  nt_add(env.graphic_tree(), NT_ADD_MARKED, true);
2165  break;
2166 
2167  case MOD_READD_NNI:
2168  nt_reAdd(env.graphic_tree(), NT_ADD_MARKED, false);
2169  break;
2170 
2171  case MOD_ADD_PARTIAL:
2173  break;
2174 
2175  case MOD_CALC_LENS:
2177  break;
2178 
2179  case MOD_OPTI_NNI: // only marked/unfolded
2181  break;
2182 
2183  case MOD_OPTI_GLOBAL:
2185  break;
2186 
2187  case MOD_MIX_TREE: {
2188  long leafs = rootNode()->count_leafs();
2190  break;
2191  }
2192  }
2193 }
2194 
2195 template <typename SEQ>
2196 static arb_test::match_expectation modifyingTopoResultsIn(TopoMod mod, const char *topo, long pars_expected, PARSIMONY_testenv<SEQ>& env, bool restore) {
2197  using namespace arb_test;
2198  expectation_group fulfilled;
2199 
2201 
2202  Level upc = env.get_user_push_counter();
2203  Level fl = env.get_frame_level();
2204 
2205  if (restore) {
2206  env.push();
2208  }
2209 
2210  AWT_graphic_exports& exports = env.graphic_tree()->exports;
2211  exports.clear_save_request();
2212  modifyTopology(env, mod);
2213  if (topo) {
2214  fulfilled.add(topologyEquals(env.root_node(), topo));
2215  if (mod != MOD_REMOVE_MARKED) { // remove_leafs doesn't request save
2216  fulfilled.add(that(exports.needs_save()).is_equal_to(true));
2217  }
2218  }
2219 
2220  fulfilled.add(that(allBranchlengthsAreDefined(env.root_node())).is_equal_to(true));
2221 
2222  if (pars_expected != -1) {
2223  fulfilled.add(that(env.root_node()->costs()).is_equal_to(pars_expected));
2224  }
2225 
2226  if (restore) {
2229  env.pop();
2230  bool blen_def_after_pop = allBranchlengthsAreDefined(env.root_node());
2231  fulfilled.add(that(blen_def_after_pop).is_equal_to(true));
2232  }
2233 
2236 
2238 
2239  return all().ofgroup(fulfilled);
2240 }
2241 
2242 static arb_test::match_expectation movingRootDoesntAffectCosts(long pars_expected) {
2243  using namespace arb_test;
2244  expectation_group fulfilled;
2245 
2246  long pars_min = LONG_MAX;
2247  long pars_max = LONG_MIN;
2248 
2249  for (int depth_first = 0; depth_first<=1; ++depth_first) {
2250  for (int push_local = 0; push_local<=1; ++push_local) {
2251  EdgeChain chain(rootEdge(), ANY_EDGE, depth_first);
2252 
2253  if (!push_local) ap_main->remember();
2254  while (chain) {
2255  AP_tree_edge *edge = *chain; ++chain;
2256 
2257  if (push_local) ap_main->remember();
2258  edge->set_root();
2259  long pars = rootNode()->costs();
2260  pars_min = std::min(pars, pars_min);
2261  pars_max = std::max(pars, pars_max);
2262  if (push_local) ap_main->revert();
2263  }
2264  if (!push_local) ap_main->revert();
2265  }
2266  }
2267 
2268  fulfilled.add(that(pars_min).is_equal_to(pars_expected));
2269  fulfilled.add(that(pars_max).is_equal_to(pars_expected));
2270 
2271  return all().ofgroup(fulfilled);
2272 }
2273 
2274 static GBDATA *copy_to(GBDATA *gb_species, const char *newShortname) {
2275  GBDATA *gb_species_data = GB_get_father(gb_species);
2276  GBDATA *gb_new_species = GB_create_container(gb_species_data, "species");
2277 
2278  GB_ERROR error = NULp;
2279  if (!gb_new_species) {
2280  error = GB_await_error();
2281  }
2282  else {
2283  error = GB_copy_dropProtectMarksAndTempstate(gb_new_species, gb_species);
2284  if (!error) error = GBT_write_string(gb_new_species, "name", newShortname);
2285  }
2286 
2287  ap_assert(contradicted(gb_new_species, error));
2288  return gb_new_species;
2289 }
2290 
2291 inline void mark_only(GBDATA *gb_species) {
2292  GBDATA *gb_main = GB_get_root(gb_species);
2293  GB_transaction ta(gb_main);
2294  GBT_mark_all(gb_main, 0);
2295  GB_write_flag(gb_species, 1);
2296 }
2297 inline void mark(GBDATA *gb_species) {
2298  GBDATA *gb_main = GB_get_root(gb_species);
2299  GB_transaction ta(gb_main);
2300  GB_write_flag(gb_species, 1);
2301 }
2302 inline void mark_all(GBDATA *gb_main) {
2303  GB_transaction ta(gb_main);
2304  GBT_mark_all(gb_main, 1);
2305 }
2306 
2307 inline int is_partial(GBDATA *gb_species) {
2308  GB_transaction ta(gb_species);
2309  return GBT_is_partial(gb_species, -1, false);
2310 }
2311 
2312 template <typename SEQ>
2313 static arb_test::match_expectation addedAsBrotherOf(const char *name, const char *allowedBrothers, PARSIMONY_testenv<SEQ>& env) {
2314  using namespace arb_test;
2315  expectation_group fulfilled;
2316 
2317  AP_tree_nlen *node_in_tree = env.root_node()->findLeafNamed(name);
2318  ap_assert(node_in_tree);
2319  fulfilled.add(that(node_in_tree).does_differ_from_NULL());
2320 
2321  const char *brother = node_in_tree->get_brother()->name;
2322  ap_assert(brother);
2323  fulfilled.add(that(allowedBrothers).does_contain(brother));
2324 
2325  return all().ofgroup(fulfilled);
2326 }
2327 
2328 template <typename SEQ>
2329 static arb_test::match_expectation addingPartialResultsIn(GBDATA *gb_added_species, const char *allowedBrothers, const char *topo, int pars_expected, PARSIMONY_testenv<SEQ>& env) {
2330  using namespace arb_test;
2331  expectation_group fulfilled;
2332 
2333  mark_only(gb_added_species);
2334  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
2335  fulfilled.add(modifyingTopoResultsIn(MOD_ADD_PARTIAL, topo, pars_expected, env, false));
2336  fulfilled.add(that(is_partial(gb_added_species)).is_equal_to(1));
2337 
2338  const char *name = GBT_get_name_or_description(gb_added_species);
2339  fulfilled.add(addedAsBrotherOf(name, allowedBrothers, env));
2340 
2341  return all().ofgroup(fulfilled);
2342 }
2343 
2344 static int seqDiff(GBDATA *gb_main, const char *aliname, const char *species1, const char *species2, int startPos, int endPos) {
2345  GB_transaction ta(gb_main);
2346 
2347  GBDATA *gb_species1 = GBT_expect_species(gb_main, species1);
2348  GBDATA *gb_species2 = GBT_expect_species(gb_main, species2);
2349  int diffs = -1;
2350 
2351  if (gb_species1 && gb_species2) {
2352  GBDATA *gb_seq1 = GBT_find_sequence(gb_species1, aliname);
2353  GBDATA *gb_seq2 = GBT_find_sequence(gb_species2, aliname);
2354 
2355  if (gb_seq1 && gb_seq2) {
2356  char *seq1 = GB_read_string(gb_seq1);
2357  char *seq2 = GB_read_string(gb_seq2);
2358 
2359  int maxPos1 = strlen(seq1)-1;
2360 #if defined(ASSERTION_USED)
2361  int maxPos2 = strlen(seq2)-1;
2362 #endif
2363  ap_assert(maxPos1 == maxPos2);
2364 
2365  if (endPos>maxPos1) endPos = maxPos1;
2366 
2367  diffs = 0;
2368  for (int p = startPos; p<=endPos; ++p) { // LOOP_ VECTORIZED[!<9.1] // @@@ fails in RELEASE code! // IRRELEVANT_LOOP
2369  diffs += seq1[p] != seq2[p];
2370  }
2371 
2372  free(seq2);
2373  free(seq1);
2374  }
2375  }
2376 
2377  return diffs;
2378 }
2379 
2380 static GBDATA *createPartialSeqFrom(GBDATA *gb_main, const char *aliname, const char *dest_species, const char *source_species, int startPos, int endPos) {
2381  GB_transaction ta(gb_main);
2382 
2383  GBDATA *gb_result = NULp;
2384  GBDATA *gb_source_species = GBT_expect_species(gb_main, source_species);
2385 
2386  if (gb_source_species) {
2387  GBDATA *gb_dest_species = copy_to(gb_source_species, dest_species);
2388  GBDATA *gb_dest_seq = GBT_find_sequence(gb_dest_species, aliname); // =same as source seq
2389  char *seq = GB_read_string(gb_dest_seq);
2390 
2391  if (seq) {
2392  int maxPos = strlen(seq)-1;
2393 
2394  startPos = std::min(startPos, maxPos);
2395  endPos = std::min(endPos, maxPos);
2396 
2397  if (startPos>0) memset(seq, '.', startPos);
2398  if (endPos<maxPos) memset(seq+endPos+1, '.', maxPos-endPos);
2399 
2400  GB_ERROR error = GB_write_string(gb_dest_seq, seq);
2401  if (error) GB_export_error(error);
2402  else {
2403  gb_result = gb_dest_species; // success
2404 #if defined(DEBUG)
2405  fprintf(stderr, "created partial '%s' from '%s' (seq='%s')\n", dest_species, source_species, seq);
2406 #endif
2407  }
2408 
2409  free(seq);
2410  }
2411  }
2412 
2413  return gb_result;
2414 }
2415 
2416 static GB_ERROR modifyOneBase(GBDATA *gb_species, const char *aliname, char cOld, char cNew) {
2417  GB_transaction ta(gb_species);
2418  GB_ERROR error = "failed to modifyOneBase";
2419 
2420  GBDATA *gb_seq = GBT_find_sequence(gb_species, aliname);
2421  if (gb_seq) {
2422  char *seq = GB_read_string(gb_seq);
2423  if (seq) {
2424  char *B = strchr(seq, cOld);
2425  if (!B) {
2426  error = "does not contain base in modifyOneBase";
2427  }
2428  else {
2429  B[0] = cNew;
2430  error = GB_write_string(gb_seq, seq);
2431  }
2432  free(seq);
2433  }
2434  }
2435 
2436  return error;
2437 }
2438 
2439 static long unmark_unwanted(const char *, long cd_gbd, void*) {
2440  GBDATA *gbd = (GBDATA*)cd_gbd;
2441  GB_write_flag(gbd, 0);
2442  return 0;
2443 }
2444 
2445 void TEST_SLOW_nucl_tree_modifications() {
2446  const char *aliname = "ali_5s";
2447 
2448  PARSIMONY_testenv<AP_sequence_parsimony> env("TEST_trees.arb", aliname);
2449  TEST_EXPECT_NO_ERROR(env.load_tree("tree_test"));
2450  TEST_EXPECT_SAVED_TOPOLOGY(env, "nucl-initial");
2451 
2452  const int PARSIMONY_ORG = 302;
2453  TEST_EXPECT_ONLY_PARSVAL_COMBINES(env, PARSIMONY_ORG, 14);
2454 
2455  // [NUCOPTI] opposed to protein tests below the initial tree here is NOT optimized! compare .@PROTOPTI
2456  // -> removing and adding species produces a better tree (for add+NNI)
2457  //
2458  // diff initial->removed : http://bugs.arb-home.de/changeset/HEAD/branches/pars/UNIT_TESTER/run/pars/nucl-removed.tree.expected?old=HEAD&old_path=branches%2Fpars%2FUNIT_TESTER%2Frun%2Fpars%2Fnucl-initial.tree.expected
2459  // diff initial->add-quick: http://bugs.arb-home.de/changeset/HEAD/branches/pars/UNIT_TESTER/run/pars/nucl-add-quick.tree.expected?old=HEAD&old_path=branches%2Fpars%2FUNIT_TESTER%2Frun%2Fpars%2Fnucl-initial.tree.expected
2460  // diff initial->add-NNI: http://bugs.arb-home.de/changeset/HEAD/branches/pars/UNIT_TESTER/run/pars/nucl-add-NNI.tree.expected?old=HEAD&old_path=branches%2Fpars%2FUNIT_TESTER%2Frun%2Fpars%2Fnucl-initial.tree.expected
2461 
2462  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_REMOVE_MARKED, "nucl-removed", PARSIMONY_ORG-94, env, true)); // test remove-marked only (same code as part of nt_reAdd)
2464 
2465  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_READD, "nucl-add-quick", PARSIMONY_ORG-18, env, true)); // test quick-add
2467 
2468  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_READD_NNI, "nucl-add-NNI", PARSIMONY_ORG-20, env, true)); // test add + NNI
2470 
2471  // test partial-add
2472  {
2473  GBDATA *gb_main = env.gbmain();
2474 
2475  // create 2 non-overlapping partial species
2476  const int SPLIT = 55;
2477  GBDATA *CorGlutP = createPartialSeqFrom(gb_main, aliname, "CorGlutP", "CorGluta", 0, SPLIT);
2478  GBDATA *CloButyP = createPartialSeqFrom(gb_main, aliname, "CloButyP", "CloButyr", SPLIT+1, INT_MAX);
2479  GBDATA *CloButyM = createPartialSeqFrom(gb_main, aliname, "CloButyM", "CloButyr", SPLIT+1, INT_MAX);
2480  TEST_EXPECT_NO_ERROR(modifyOneBase(CloButyM, aliname, 'G', 'C')); // change first 'G' into 'C'
2481 
2482  TEST_VALIDITY(env.all_available_pops_will_produce_valid_trees()); // no push yet (does nothing)
2483 
2484  // test partials differ from full:
2485  TEST_REJECT_ZERO(seqDiff(gb_main, aliname, "CorGlutP", "CorGluta", 0, INT_MAX));
2486  TEST_REJECT_ZERO(seqDiff(gb_main, aliname, "CloButyP", "CloButyr", 0, INT_MAX));
2487  TEST_REJECT_ZERO(seqDiff(gb_main, aliname, "CloButyM", "CloButyr", 0, INT_MAX));
2488  // test partials created from CloButyr differ in partial range:
2489  TEST_REJECT_ZERO(seqDiff(gb_main, aliname, "CloButyM", "CloButyP", SPLIT+1, INT_MAX));
2490 
2491  // test condition that "CloButyr and CloButy2 do NOT differ in seq-range of partial" (otherwise test below makes no sense!)
2492  TEST_EXPECT_ZERO(seqDiff(gb_main, aliname, "CloButyr", "CloButy2", SPLIT+1, INT_MAX));
2493 
2494  // test that "CloButyr and CloButy2 DO differ in whole seq-range" (otherwise inserting into tree is non-deterministic)
2495  TEST_REJECT_ZERO(seqDiff(gb_main, aliname, "CloButyr", "CloButy2", 0, INT_MAX));
2496 
2497  // add CloButyP (and undo)
2498  {
2499  env.push();
2500 
2501  // CloButyr and CloButy2 do not differ in seq-range of partial -> any of both may be chosen as brother.
2502  // behavior should be changed with #605
2503  TEST_EXPECTATION(addingPartialResultsIn(CloButyP, "CloButyr;CloButy2", "nucl-addPart-CloButyP", PARSIMONY_ORG, env));
2505  env.pop();
2506  }
2507 
2508  {
2509  env.push();
2510  TEST_EXPECTATION(addingPartialResultsIn(CorGlutP, "CorGluta", "nucl-addPart-CorGlutP", PARSIMONY_ORG, env)); // add CorGlutP
2511  TEST_EXPECT_COMBINES_PERFORMED(env, 5); // @@@ partial-add should not perform combines at all (maybe caused by cost-recalc?)
2512  TEST_EXPECTATION(addingPartialResultsIn(CloButyP, "CloButyr;CloButy2", "nucl-addPart-CorGlutP-CloButyP", PARSIMONY_ORG, env)); // also add CloButyP
2514  env.pop();
2515  }
2516 
2517  // now add CorGlutP as full, then CloButyP and CloButyM as partials
2518  {
2519  env.push();
2520 
2521  mark_only(CorGlutP);
2522  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
2523  {
2524  GB_transaction ta(gb_main);
2525  TEST_EXPECT_NO_ERROR(GBT_write_int(CorGlutP, "ARB_partial", 0)); // revert species to "full"
2526  }
2527 
2528  const int PARSIMONY_ADDED = PARSIMONY_ORG; // value after adding CorGlutP (as full-length sequence)
2529 
2530  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_READD, "nucl-addPartialAsFull-CorGlutP", PARSIMONY_ADDED, env, false));
2532  TEST_EXPECT_EQUAL(is_partial(CorGlutP), 0); // check CorGlutP was added as full sequence
2533  TEST_EXPECTATION(addedAsBrotherOf("CorGlutP", "CorGluta", env)); // partial created from CorGluta gets inserted next to CorGluta
2534 
2535  // add CloButyP as partial.
2536  // as expected it is placed next to matching full sequences (does not differ in partial range)
2537  TEST_EXPECTATION(addingPartialResultsIn(CloButyP, "CloButyr;CloButy2", NULp, PARSIMONY_ADDED, env));
2539 
2540  // CloButyM differs slightly in overlap with CloButyr/CloButy2, but has no overlap with CorGlutP
2541  // shows bug described in #609 is fixed:
2542  TEST_EXPECTATION(addingPartialResultsIn(CloButyM, "CloButyP", "nucl-addPart-bug609",
2543  PARSIMONY_ADDED+1, // @@@ known bug - partial should not affect parsimony value; possibly related to ../HELP_SOURCE/oldhelp/pa_partial.hlp@WARNINGS
2544  env));
2546  env.pop();
2547  }
2548  }
2549 
2550  TEST_EXPECT_SAVED_TOPOLOGY(env, "nucl-initial");
2551 
2552  const int PARSIMONY_NNI_MARKED = PARSIMONY_ORG-18;
2553  const int PARSIMONY_NNI_ALL = PARSIMONY_ORG-18;
2554  const int PARSIMONY_OPTI_MARKED = PARSIMONY_ORG-25;
2555  const int PARSIMONY_OPTI_VISIBLE = PARSIMONY_ORG-26;
2556  const int PARSIMONY_OPTI_ALL = PARSIMONY_ORG-36;
2557 
2558  {
2559  env.push();
2560  TEST_EXPECTATION(movingRootDoesntAffectCosts(PARSIMONY_ORG));
2562  env.pop();
2563  }
2564 
2565  // ------------------------------
2566  // test optimize (some)
2567 
2568  // mark initially marked species
2569  {
2570  GB_transaction ta(env.gbmain());
2571  GBT_restore_marked_species(env.gbmain(), "CorAquat;CorGluta;CurCitre;CloButyr;CloButy2;CytAquat");
2572  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
2573  }
2574 
2575  TEST_EXPECT_KNOWN_PARSVAL(env, PARSIMONY_ORG);
2576 
2577  // test branchlength calculation
2578  // (optimizations below implicitely recalculates branchlengths)
2579  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_CALC_LENS, "nucl-calclength", PARSIMONY_ORG, env, false));
2581 
2582  // test whether branchlength calculation depends on root-position
2583  {
2584  AP_tree_edge *orgRootEdge = rootEdge();
2585 
2586  env.push();
2587 
2588  const char *tested_roots[] = {
2589  "CloButyr",
2590  "CloTyro4",
2591  "CloTyrob",
2592  "CloInnoc",
2593  };
2594 
2595  for (size_t r = 0; r<ARRAY_ELEMS(tested_roots); ++r) {
2596  const char *leafName = tested_roots[r];
2597  env.root_node()->findLeafNamed(leafName)->set_root();
2599  orgRootEdge->set_root();
2601 
2602  TEST_EXPECT_SAVED_TOPOLOGY(env, "nucl-calclength");
2603  }
2605 
2606  env.pop();
2607  }
2608 
2609  // test optimize (some)
2610  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_NNI, "nucl-opti-NNI", PARSIMONY_NNI_MARKED, env, true)); // test recursive NNI
2612 
2613  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_GLOBAL, "nucl-opti-marked-global", PARSIMONY_OPTI_MARKED, env, true)); // test recursive NNI+KL
2614  TEST_EXPECT_COMBINES_PERFORMED(env, 18518);
2615 
2616  {
2617  KL_Settings& KL = env.get_KL_settings();
2618  LocallyModify<EdgeSpec> target(KL.whichEdges, EdgeSpec(KL.whichEdges&~SKIP_UNMARKED_EDGES)); // ignore marks; skip folded
2619 
2620  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_GLOBAL, "nucl-opti-visible-global", PARSIMONY_OPTI_VISIBLE, env, true)); // same result as if all species marked (see below)
2621  TEST_EXPECT_COMBINES_PERFORMED(env, 34925);
2622 
2623  KL.whichEdges = EdgeSpec(KL.whichEdges&~SKIP_FOLDED_EDGES); // ignore marks and folding
2624 
2625  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_GLOBAL, "nucl-opti-global", PARSIMONY_OPTI_ALL, env, true)); // same result as if all species marked and all groups unfolded (see below)
2626  TEST_EXPECT_COMBINES_PERFORMED(env, 124811);
2627  }
2628 
2629  // -----------------------------
2630  // test optimize (all)
2631 
2632  // mark all species
2633  mark_all(env.gbmain());
2634  // unmark species not in tree
2635  {
2636  GB_transaction ta(env.gbmain());
2637  GB_HASH *markedNotInTree = GBT_create_marked_species_hash(env.gbmain());
2638  NT_remove_species_in_tree_from_hash(env.root_node(), markedNotInTree);
2639  GBS_hash_do_loop(markedNotInTree, unmark_unwanted, NULp);
2640  GBS_free_hash(markedNotInTree);
2641  }
2642  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
2644 
2645  TEST_EXPECT_KNOWN_PARSVAL(env, PARSIMONY_ORG);
2646 
2647  // test branchlength calculation
2648  // (optimizations below implicitely recalculates branchlengths)
2649  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_CALC_LENS, "nucl-calclength", PARSIMONY_ORG, env, false));
2651 
2652  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_NNI, "nucl-opti-all-NNI", PARSIMONY_NNI_ALL, env, true)); // test recursive NNI
2654 
2655  {
2656  env.push();
2657  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_GLOBAL, "nucl-opti-visible-global", PARSIMONY_OPTI_VISIBLE, env, false)); // test recursive NNI+KL
2658  TEST_EXPECT_COMBINES_PERFORMED(env, 34925);
2659 
2660  TEST_EXPECTATION(movingRootDoesntAffectCosts(PARSIMONY_OPTI_VISIBLE));
2662  env.pop();
2663  }
2664 
2665  // unfold groups
2666  {
2667  AP_tree_nlen *CloTyrob = env.root_node()->findLeafNamed("CloTyrob");
2668  AP_tree_nlen *group = CloTyrob->get_father();
2669  ap_assert(group->gr.grouped);
2670  group->gr.grouped = false; // unfold the only folded group
2671 
2672  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_GLOBAL, "nucl-opti-global", PARSIMONY_OPTI_ALL, env, true)); // test recursive NNI+KL
2673  TEST_EXPECT_COMBINES_PERFORMED(env, 124811);
2674  }
2675 
2676  // test re-add all (i.e. test "create tree from scratch")
2677  // Note: trees generated below are NO LONGER better than optimized trees! (see also r13651)
2678 
2679  // quick add:
2680  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_READD, "nucl-readdall-quick", PARSIMONY_ORG-7, env, true));
2682 
2683  // quick add + NNI:
2684  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_READD_NNI, "nucl-readdall-NNI", PARSIMONY_ORG-8, env, true));
2686 
2687  // test adding a too short sequence
2688  // (has to be last test, because it modifies seq data) << ------------ !!!!!
2689  {
2690  env.push();
2691 
2692  AP_tree_nlen *CloTyrob = env.root_node()->findLeafNamed("CloTyrob");
2693  mark_only(CloTyrob->gb_node);
2694  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
2695 
2696  // modify sequence of CloTyrob (keep only some bases)
2697  {
2698  GB_transaction ta(env.gbmain());
2699  GBDATA *gb_seq = GBT_find_sequence(CloTyrob->gb_node, aliname);
2700 
2701  char *seq = GB_read_string(gb_seq);
2702  int keep_bases = MIN_SEQUENCE_LENGTH-1;
2703 
2704  for (int i = 0; seq[i]; ++i) {
2705  if (!GAP::is_std_gap(seq[i])) {
2706  if (keep_bases) --keep_bases;
2707  else seq[i] = '.';
2708  }
2709  }
2710 
2711  GB_topSecurityLevel unsecured(gb_seq);
2712  TEST_EXPECT_NO_ERROR(GB_write_string(gb_seq, seq));
2713  free(seq);
2714  }
2715 
2716  // remove CloTyrob
2717  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_REMOVE_MARKED, NULp, PARSIMONY_ORG-1, env, false));
2719  TEST_EXPECT_EQUAL(env.root_node()->count_leafs(), 14);
2720 
2721  // attempt to add CloTyrob (should fail because sequence too short) and CorGluta (should stay, because already in tree)
2722  TEST_REJECT_NULL(env.root_node()->findLeafNamed("CorGluta")); // has to be in tree
2723  {
2724  GB_transaction ta(env.gbmain());
2725  GBT_restore_marked_species(env.gbmain(), "CloTyrob;CorGluta");
2726  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
2727  }
2728 
2729  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_ADD, NULp, PARSIMONY_ORG-1, env, false));
2730  TEST_EXPECT_COMBINES_PERFORMED(env, 110); // @@@ why does this perform combines at all?
2731  TEST_EXPECT_EQUAL(env.root_node()->count_leafs(), 14); // ok, CloTyrob was not added
2732  TEST_REJECT_NULL(env.root_node()->findLeafNamed("CorGluta")); // has to be in tree
2733 
2734  env.pop();
2735  }
2736 }
2737 
2738 void TEST_SLOW_prot_tree_modifications() {
2739  const char *aliname = "ali_tuf_pro";
2740 
2741  PARSIMONY_testenv<AP_sequence_protein> env("TEST_prot.arb", aliname);
2742  TEST_EXPECT_NO_ERROR(env.load_tree("tree_prot_opti"));
2743  TEST_EXPECT_SAVED_TOPOLOGY(env, "prot-initial");
2744 
2745  const int PARSIMONY_ORG = 1081;
2746  TEST_EXPECT_ONLY_PARSVAL_COMBINES(env, PARSIMONY_ORG, 10);
2747 
2748  // [PROTOPTI] opposed to nucleid tests above the initial tree here is already optimized! compare .@NUCOPTI
2749  // -> adding species approximately reproduces initial topology
2750  //
2751  // diff initial->add-quick: http://bugs.arb-home.de/changeset/HEAD/branches/pars/UNIT_TESTER/run/pars/prot-add-quick.tree.expected?old=HEAD&old_path=branches%2Fpars%2FUNIT_TESTER%2Frun%2Fpars%2Fprot-initial.tree.expected
2752  // diff initial->add-NNI: http://bugs.arb-home.de/changeset/HEAD/branches/pars/UNIT_TESTER/run/pars/prot-add-NNI.tree.expected?old=HEAD&old_path=branches%2Fpars%2FUNIT_TESTER%2Frun%2Fpars%2Fprot-initial.tree.expected
2753  //
2754  // Note: comparing these two diffs also demonstrates why quick-adding w/o NNI suffers
2755 
2756  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_REMOVE_MARKED, "prot-removed", PARSIMONY_ORG-146, env, true)); // test remove-marked only (same code as part of nt_reAdd)
2758 
2759  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_READD, "prot-add-quick", PARSIMONY_ORG, env, true)); // test quick-add
2761 
2762  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_READD_NNI, "prot-add-NNI", PARSIMONY_ORG, env, true)); // test add + NNI
2764 
2765  // test partial-add
2766  {
2767  GBDATA *gb_main = env.gbmain();
2768 
2769  // create 2 non-overlapping partial species
2770  GBDATA *MucRaceP = createPartialSeqFrom(gb_main, aliname, "MucRaceP", "MucRacem", 0, 60+4); // (+4 = dots inserted into DB at left end)
2771  GBDATA *StrCoelP = createPartialSeqFrom(gb_main, aliname, "StrCoelP", "StrCoel9", 66-1+4, 184-1+4);
2772  GBDATA *StrCoelM = createPartialSeqFrom(gb_main, aliname, "StrCoelM", "StrCoel9", 66-1+4, 184-1+4);
2773  TEST_EXPECT_NO_ERROR(modifyOneBase(StrCoelM, aliname, 'Y', 'H')); // change first 'Y' into 'H'
2774 
2775  // add StrCoelP (and undo)
2776  {
2777  env.push();
2778  // StrCoel9 and StrRamo3 do not differ in seq-range of partial -> any of both may be chosen as brother.
2779  // behavior should be changed with #605
2780  TEST_EXPECTATION(addingPartialResultsIn(StrCoelP, "StrCoel9;StrRamo3", "prot-addPart-StrCoelP", PARSIMONY_ORG, env));
2782  env.pop();
2783  }
2784 
2785  {
2786  env.push();
2787  TEST_EXPECTATION(addingPartialResultsIn(MucRaceP, "MucRacem", "prot-addPart-MucRaceP", PARSIMONY_ORG, env)); // add MucRaceP
2789  TEST_EXPECTATION(addingPartialResultsIn(StrCoelP, "StrCoel9;StrRamo3", "prot-addPart-MucRaceP-StrCoelP", PARSIMONY_ORG, env)); // also add StrCoelP
2791  env.pop();
2792  }
2793 
2794  // now add MucRaceP as full, then StrCoelP and StrCoelM as partials
2795  {
2796  env.push();
2797 
2798  mark_only(MucRaceP);
2799  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
2800  {
2801  GB_transaction ta(gb_main);
2802  TEST_EXPECT_NO_ERROR(GBT_write_int(MucRaceP, "ARB_partial", 0)); // revert species to "full"
2803  }
2804 
2805  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_READD, "prot-addPartialAsFull-MucRaceP", PARSIMONY_ORG, env, false));
2807  TEST_EXPECT_EQUAL(is_partial(MucRaceP), 0); // check MucRaceP was added as full sequence
2808  TEST_EXPECTATION(addedAsBrotherOf("MucRaceP", "Eukarya EF-Tu", env)); // partial created from MucRacem gets inserted next to this group
2809  // Note: looks ok. group contains MucRacem, AbdGlauc and 4 other species
2810 
2811  // add StrCoelP as partial.
2812  // as expected it is placed next to matching full sequences (does not differ in partial range)
2813  TEST_EXPECTATION(addingPartialResultsIn(StrCoelP, "StrCoel9;StrRamo3", NULp, PARSIMONY_ORG, env));
2815 
2816  // StrCoelM differs slightly in overlap with StrCoel9/StrRamo3, but has no overlap with MucRaceP
2817  // shows bug described in #609 is fixed:
2818  TEST_EXPECTATION(addingPartialResultsIn(StrCoelM, "StrCoelP", "prot-addPart-bug609",
2819  PARSIMONY_ORG+1, // @@@ known bug - partial should not affect parsimony value; possibly related to ../HELP_SOURCE/oldhelp/pa_partial.hlp@WARNINGS
2820  env));
2822  env.pop();
2823  }
2824  }
2825 
2826  TEST_EXPECT_SAVED_TOPOLOGY(env, "prot-initial");
2827 
2828  const unsigned mixseed = 8164724;
2829 
2830  const long PARSIMONY_MIXED = PARSIMONY_ORG + 1519;
2831  const long PARSIMONY_NNI_MARKED = PARSIMONY_ORG + 1053;
2832  const long PARSIMONY_NNI_ALL = PARSIMONY_ORG;
2833  const long PARSIMONY_OPTI_MARKED = PARSIMONY_ORG;
2834  const long PARSIMONY_OPTI_ALL = PARSIMONY_ORG; // no gain (initial tree already is optimized)
2835 
2836  // ------------------------------------------------------
2837  // mix tree (original tree already is optimized)
2838 
2839  GB_random_seed(mixseed);
2840  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_MIX_TREE, "prot-mixed", PARSIMONY_MIXED, env, false));
2842 
2843  {
2844  env.push();
2845  TEST_EXPECTATION(movingRootDoesntAffectCosts(PARSIMONY_MIXED));
2847  env.pop();
2848  }
2849 
2850  // ------------------------------
2851  // test optimize (some)
2852 
2853  // mark initially marked species
2854  {
2855  GB_transaction ta(env.gbmain());
2856 
2857  GBT_restore_marked_species(env.gbmain(), "CytLyti6;StrRamo3;MucRace2;SacCere5");
2858  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
2859  }
2860 
2861  TEST_EXPECT_KNOWN_PARSVAL(env, PARSIMONY_MIXED);
2862 
2863  // test branchlength calculation
2864  // (optimizations below implicitely recalculates branchlengths)
2865  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_CALC_LENS, "prot-calclength", PARSIMONY_MIXED, env, false));
2867 
2868  // test whether branchlength calculation depends on root-position
2869  {
2870  AP_tree_edge *orgRootEdge = rootEdge();
2871 
2872  env.push();
2873 
2874  const char *tested_roots[] = {
2875  // "CytLyti6", // no effect on branchlengths
2876  "TaxOcell",
2877  "MucRace3",
2878  "StrCoel9",
2879  };
2880 
2881  for (size_t r = 0; r<ARRAY_ELEMS(tested_roots); ++r) {
2882  TEST_ANNOTATE(tested_roots[r]);
2883  const char *leafName = tested_roots[r];
2884  env.root_node()->findLeafNamed(leafName)->set_root();
2886  orgRootEdge->set_root();
2888 
2889  TEST_EXPECT_SAVED_TOPOLOGY(env, "prot-calclength");
2890  }
2892 
2893  env.pop();
2894  }
2895 
2896  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_NNI, "prot-opti-NNI", PARSIMONY_NNI_MARKED, env, true)); // test recursive NNI
2898 
2899  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_GLOBAL, "prot-opti-marked-global", PARSIMONY_OPTI_MARKED, env, true)); // test recursive NNI+KL
2900  TEST_EXPECT_COMBINES_PERFORMED(env, 2810);
2901 
2902  // -----------------------------
2903  // test optimize (all)
2904 
2905  // mark all species
2906  mark_all(env.gbmain());
2907  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
2909 
2910  TEST_EXPECT_KNOWN_PARSVAL(env, PARSIMONY_MIXED);
2911 
2912  // test branchlength calculation
2913  // (optimizations below implicitely recalculates branchlengths)
2914  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_CALC_LENS, "prot-calclength", PARSIMONY_MIXED, env, false));
2916 
2917  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_NNI, "prot-opti-all-NNI", PARSIMONY_NNI_ALL, env, true)); // test recursive NNI
2919 
2920  {
2921  env.push();
2922  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_OPTI_GLOBAL, "prot-opti-global", PARSIMONY_OPTI_ALL, env, false)); // test recursive NNI+KL
2923  TEST_EXPECT_COMBINES_PERFORMED(env, 1690);
2924 
2925  TEST_EXPECTATION(movingRootDoesntAffectCosts(PARSIMONY_OPTI_ALL));
2927  env.pop();
2928  }
2929 }
2930 
2931 void TEST_node_stack() {
2932  // test was used to fix #620
2933 
2934  const char *aliname = "ali_5s";
2935  PARSIMONY_testenv<AP_sequence_parsimony> env("TEST_trees.arb", aliname);
2936  TEST_EXPECT_NO_ERROR(env.load_tree("tree_test"));
2937  TEST_EXPECT_SAVED_TOPOLOGY(env, "nucl-initial");
2938 
2939  const int PARSIMONY_ORG = 302;
2940  TEST_EXPECT_ONLY_PARSVAL_COMBINES(env, PARSIMONY_ORG, 14);
2941 
2942  TEST_VALIDITY(env.root_node()->sequence_state_valid());
2943  TEST_EXPECT(env.root_node()->has_valid_root_remarks());
2944 
2945  // test set root to CytAquat + pop (works)
2946  {
2947  env.push();
2948  env.root_node()->findLeafNamed("CytAquat")->set_root();
2949  TEST_VALIDITY(env.root_node()->sequence_state_valid());
2950  env.pop();
2951  TEST_VALIDITY(env.root_node()->sequence_state_valid());
2952  }
2953 
2954  TEST_EXPECT(env.root_node()->has_valid_root_remarks());
2955 
2956  // test set root to CloButyr + pop (works)
2957  {
2958  env.push();
2959  env.root_node()->findLeafNamed("CloButyr")->set_root();
2960  TEST_VALIDITY(env.root_node()->sequence_state_valid());
2961  env.pop();
2962  TEST_VALIDITY(env.root_node()->sequence_state_valid());
2963  }
2964 
2965  TEST_EXPECT(env.root_node()->has_valid_root_remarks());
2966 
2967  // test set root to CloBifer + set root to CloTyrob + pop (works)
2968  // Note: both species are in same subtree (of root)
2969  {
2970  env.push();
2971 
2972  env.root_node()->findLeafNamed("CloBifer")->set_root();
2973  env.root_node()->findLeafNamed("CloTyrob")->set_root();
2974 
2975  TEST_VALIDITY(env.root_node()->sequence_state_valid());
2976  env.pop();
2977  TEST_VALIDITY(env.root_node()->sequence_state_valid());
2978  }
2979 
2980  TEST_EXPECT(env.root_node()->has_valid_root_remarks());
2981 
2982  // test set root to CytAquat + set root to CloButyr + pop (failed, fixed by [13138])
2984  for (int calcCostsBetween = 0; calcCostsBetween<2; ++calcCostsBetween) {
2985  TEST_ANNOTATE(GBS_global_string("calcCostsBetween=%i", calcCostsBetween));
2986 
2987  TEST_EXPECT_PARSVAL(env, PARSIMONY_ORG);
2988 
2989  env.push();
2990 
2991  env.root_node()->findLeafNamed("CytAquat")->set_root();
2992 
2993  if (calcCostsBetween) {
2994  TEST_EXPECT_ONLY_PARSVAL_COMBINES(env, PARSIMONY_ORG, 2);
2995  }
2996 
2997  env.root_node()->findLeafNamed("CloButyr")->set_root();
2998 
2999  TEST_VALIDITY(env.root_node()->sequence_state_valid());
3000  TEST_EXPECT_ONLY_PARSVAL_COMBINES(env, PARSIMONY_ORG, 6);
3001 
3002  env.pop();
3003 
3004  TEST_VALIDITY(env.root_node()->sequence_state_valid());
3005  TEST_EXPECT_KNOWN_PARSVAL(env, PARSIMONY_ORG);
3007  }
3008 
3009  {
3010  env.push();
3011  {
3012  env.push();
3013 
3014  env.root_node()->findLeafNamed("CloInnoc")->moveNextTo(env.root_node()->findLeafNamed("CytAquat"), 0.5);
3016  env.root_node()->findLeafNamed("CloInnoc")->set_root();
3018  env.root_node()->findLeafNamed("CytAquat")->moveNextTo(env.root_node()->findLeafNamed("CloPaste"), 0.5);
3020  env.root_node()->findLeafNamed("CloPaste")->set_root();
3022  env.root_node()->findLeafNamed("CloPaste")->moveNextTo(env.root_node()->findLeafNamed("CloInnoc"), 0.5);
3024 
3025  {
3026  AP_tree_nlen *son_of_brother;
3027  AP_tree_nlen *brother_of_father;
3028 
3029  // COVER1: son of root -> grandson of root
3030  {
3031  AP_tree_nlen *son_of_root = env.root_node()->get_leftson();
3032  ap_assert(son_of_root);
3033 
3034  son_of_brother = son_of_root->get_brother()->get_leftson();
3035  son_of_root->moveNextTo(son_of_brother, 0.5);
3037  }
3038 
3039  // COVER2: grandson of root -> son of brother
3040  {
3041  AP_tree_nlen *son_of_root = env.root_node()->get_leftson();
3042  AP_tree_nlen *grandson_of_root = son_of_root->get_brother()->get_rightson();
3043  ap_assert(grandson_of_root);
3044 
3045  son_of_brother = grandson_of_root->get_brother()->get_leftson();
3046  grandson_of_root->moveNextTo(son_of_brother, 0.5);
3048  }
3049 
3050  AP_tree_nlen *some_leaf = env.root_node()->findLeafNamed("CloBifer");
3051  ap_assert(some_leaf);
3052 
3053  // COVER3: some leaf -> son of brother
3054  son_of_brother = some_leaf->get_brother()->get_leftson();
3055  some_leaf->moveNextTo(son_of_brother, 0.5);
3057 
3058  // COVER4: some leaf -> son of brother
3059  brother_of_father = some_leaf->get_father()->get_brother();
3060  some_leaf->moveNextTo(brother_of_father, 0.5);
3062 
3063  // test forbidden moves:
3064  TEST_EXPECT_ERROR_CONTAINS(some_leaf->cantMoveNextTo(some_leaf->get_father()), "Already there");
3065  TEST_EXPECT_ERROR_CONTAINS(some_leaf->cantMoveNextTo(some_leaf->get_brother()), "Already there");
3066  }
3067 
3068  TEST_EXPECT_ONLY_PARSVAL_COMBINES(env, PARSIMONY_ORG+5, 6);
3069 
3070  env.pop();
3072  }
3073  env.pop();
3074 
3075  TEST_EXPECT_KNOWN_PARSVAL(env, PARSIMONY_ORG);
3077  }
3078 
3079  // remove + quick add marked + pop() both works
3080  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_READD, "nucl-add-quick", PARSIMONY_ORG-18, env, true)); // test quick-add
3082 
3083  TEST_EXPECT(env.root_node()->has_valid_root_remarks());
3084 
3085  // remove + quick-add marked + pop() quick-add -> corrupts tree
3086  // (root-edge is lost)
3087  {
3088  env.push();
3090  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_REMOVE_MARKED, NULp, -1, env, false)); // test remove-marked only (same code as part of nt_reAdd)
3093 
3095 
3096  env.push();
3098  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_READD, NULp, -1, env, false)); // test quick-add (same code as part of nt_reAdd)
3102  env.pop();
3103 
3104  TEST_VALIDITY(env.root_node()->has_valid_edges());
3105 
3106  env.pop();
3109  }
3110 
3111  // same as above, but with only 1 species marked
3112  const char *testSingle[] = {
3113  "CytAquat", // CytAquat is the only grandson of root (CytAquat located in lower subtree)
3114  "CloBifer", // two father nodes between CloBifer and root (CloBifer located in upper subtree)
3115  "CloPaste", // two father nodes between CloPaste and root (CloPaste located in upper subtree)
3116  "CorGluta", // three father nodes between CorGluta and root (CorGluta located in lower subtree)
3117  "CelBiazo", // two father nodes between CelBiazo and root
3118  NULp
3119  };
3120 
3121  for (int i = 0; testSingle[i]; ++i) {
3122  for (int swapped = 0; swapped<2; ++swapped) {
3123  TEST_ANNOTATE(GBS_global_string("single=%s swapped=%i", testSingle[i], swapped));
3124 
3125  env.push();
3127  {
3128  AP_tree_nlen *old_rightson = env.root_node()->get_rightson();
3129  env.root_node()->get_leftson()->get_rightson()->set_root();
3130  old_rightson->get_leftson()->set_root();
3131  old_rightson->set_root();
3132 
3133  ap_assert(env.root_node()->get_rightson() == old_rightson);
3134  }
3136 
3137  mark_only(env.root_node()->findLeafNamed(testSingle[i])->gb_node);
3138  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
3139 
3140  env.push();
3141  if (swapped) {
3142  env.root_node()->swap_sons();
3143  }
3144 
3146  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_REMOVE_MARKED, NULp, -1, env, false)); // test remove-marked only (same code as part of nt_reAdd)
3148 
3149  env.push();
3151  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_READD, NULp, -1, env, false)); // test quick-add (same code as part of nt_reAdd)
3153  env.pop();
3154 
3156  env.pop();
3158  env.pop();
3160  }
3161  }
3162  TEST_EXPECT_COMBINES_PERFORMED(env, 2120);
3163 
3164  // similar to above (remove+add a grandson of root; here grandson is a subtree with 4 species)
3165 
3166  for (int remove_from_lower_subtree = 0; remove_from_lower_subtree<2; ++remove_from_lower_subtree) {
3167  TEST_ANNOTATE(GBS_global_string("remove_from_lower_subtree=%i", remove_from_lower_subtree));
3168 
3169  // mark a complete subtree (which - as a whole - forms a grandson of root). subtree is located in upper part of the tree
3170  mark_only(env.root_node()->findLeafNamed("CloButy2")->gb_node);
3171  mark(env.root_node()->findLeafNamed("CloButyr")->gb_node);
3172  mark(env.root_node()->findLeafNamed("CloCarni")->gb_node);
3173  mark(env.root_node()->findLeafNamed("CloPaste")->gb_node);
3174  env.compute_tree(); // species marks affect order of node-chain (used in nni_rec)
3175 
3176  env.push();
3177  if (remove_from_lower_subtree) {
3178  env.root_node()->swap_sons();
3179  }
3181  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_REMOVE_MARKED, NULp, -1, env, false)); // test remove-marked only (same code as part of nt_reAdd)
3183 
3184  env.push();
3186  TEST_EXPECTATION(modifyingTopoResultsIn(MOD_QUICK_READD, NULp, -1, env, false)); // test quick-add (same code as part of nt_reAdd)
3188  env.pop();
3189 
3190  TEST_VALIDITY(env.root_node()->has_valid_edges()); // now always valid
3191 
3192  env.pop();
3194  }
3196 }
3197 
3198 void TEST_node_edge_resources() {
3199  const char *aliname = "ali_5s";
3200 
3201  // document memsize of nodes and edges:
3202 
3203 #define STATE_STACK_SIZE sizeof(StateStack) // 8 (Cxx11) or 16 (older C++); maybe 4/8 in 32bit
3204 
3205 #if defined(ARB_64)
3206  TEST_EXPECT_EQUAL(sizeof(AP_tree_nlen), 184 + STATE_STACK_SIZE);
3207  TEST_EXPECT_EQUAL(sizeof(AP_tree), 136);
3208  TEST_EXPECT_EQUAL(sizeof(ARB_seqtree), 88);
3209  TEST_EXPECT_EQUAL(sizeof(TreeNode), 80);
3210 #else // !defined(ARB_64)
3211  TEST_EXPECT_EQUAL(sizeof(AP_tree_nlen), 112 + STATE_STACK_SIZE);
3212  TEST_EXPECT_EQUAL(sizeof(AP_tree), 84);
3213  TEST_EXPECT_EQUAL(sizeof(ARB_seqtree), 48);
3214  TEST_EXPECT_EQUAL(sizeof(TreeNode), 44);
3215 #endif
3216 
3217 
3218 #if defined(ARB_64)
3219  TEST_EXPECT_EQUAL(sizeof(AP_tree_edge), 64);
3220 #else // !defined(ARB_64)
3221  TEST_EXPECT_EQUAL(sizeof(AP_tree_edge), 32);
3222 #endif
3223 
3224  PARSIMONY_testenv<AP_sequence_parsimony> env("TEST_trees.arb", aliname);
3225  TEST_EXPECT_NO_ERROR(env.load_tree("tree_test"));
3226 
3227  const int PARSIMONY_ORG = 302;
3228  TEST_EXPECT_ONLY_PARSVAL_COMBINES(env, PARSIMONY_ORG, 14);
3229 
3230  AP_tree_nlen *CloButyr = env.root_node()->findLeafNamed("CloButyr");
3231  AP_tree_nlen *CloButy2 = env.root_node()->findLeafNamed("CloButy2");
3232  TEST_EXPECT_EQUAL(CloButyr->get_brother()->name, CloButy2->name); // test they are brothers
3233 
3234  AP_tree_nlen *CorAquat = env.root_node()->findLeafNamed("CorAquat");
3235  AP_tree_nlen *CurCitre = env.root_node()->findLeafNamed("CurCitre");
3236  TEST_EXPECT_EQUAL(CorAquat->get_brother()->name, CurCitre->name); // test they are brothers
3237 
3238  CorAquat->REMOVE();
3239 
3240  for (int test = 1; test<=8; ++test) {
3241  // test == 1 -> provokes common nodes+edges in revert+accept
3242  // test == 2 -> provokes common nodes+edges in revert+accept
3243  // test == 3 -> provokes common nodes+edges in revert+accept
3244  // tests 4-7 do not provoke common nodes or edges
3245 
3246  for (int mode = 0; mode<=3; ++mode) {
3247  bool accept_outer = mode&2;
3248  bool accept_inner = mode&1;
3249 
3250  TEST_ANNOTATE(GBS_global_string("accept_outer=%i accept_inner=%i (mode=%i, test=%i)", accept_outer, accept_inner, mode, test));
3251 
3252  TEST_EXPECT_NULL(CorAquat->get_father());
3253  TEST_EXPECT(CloButyr->get_brother() == CloButy2);
3255 
3256  env.push();
3257 
3258  switch (test) {
3259  case 1: CorAquat->insert(CurCitre); break;
3260  case 2: CorAquat->insert(CurCitre); break;
3261  case 3: break;
3262  case 4: CloButyr->REMOVE(); break;
3263  case 5: CloButyr->REMOVE(); break;
3264  case 6: break;
3265  case 7: CloButyr->moveNextTo(CurCitre, 0.5); break;
3266  case 8: break;
3267  default: ap_assert(0); break;
3268  }
3270 
3271  {
3272  env.push();
3273 
3274  switch (test) {
3275  case 1: CorAquat->REMOVE(); break;
3276  case 2: break;
3277  case 3: CorAquat->insert(CurCitre); break;
3278  case 4: CloButyr->insert(CloButy2); break;
3279  case 5: break;
3280  case 6: CloButyr->REMOVE(); break;
3281  case 7: CloButyr->moveNextTo(CloButy2, 0.5); break;
3282  case 8: CorAquat->insert(CurCitre); CorAquat->REMOVE(); break;
3283  default: ap_assert(0); break;
3284  }
3286 
3287  env.accept_if(accept_inner);
3288  }
3289 
3290  switch (test) {
3291  case 1: break;
3292  case 2: CorAquat->REMOVE(); break;
3293  case 3: if (CorAquat->father) CorAquat->REMOVE(); break;
3294  case 4: break;
3295  case 5: CloButyr->insert(CloButy2); break;
3296  case 6: if (!CloButyr->father) CloButyr->insert(CloButy2); break;
3297  case 7: CloButyr->REMOVE(); break;
3298  case 8: break;
3299  default: ap_assert(0); break;
3300  }
3302 
3303  env.accept_if(accept_outer);
3304 
3305  // manually revert changes (outside any stack frame)
3306  if (CorAquat->father) CorAquat->REMOVE();
3307  if (!CloButyr->father) CloButyr->insert(CloButy2);
3308  }
3309  }
3310 
3311  CorAquat->insert(CurCitre);
3312 
3313  TEST_EXPECT_PARSVAL(env, PARSIMONY_ORG);
3314  env.combines_performed(); // accept any no of combines
3315 }
3316 
3317 #endif // UNIT_TESTS
3318 
3319 // --------------------------------------------------------------------------------
3320 
bool isConnectedTo(const AP_tree_nlen *n) const
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2516
void reorderTree(TreeOrder mode)
static void recursiveNNI(AWT_graphic_parsimony *agt, EdgeSpec whichEdges)
Definition: PARS_main.cxx:1206
#define TEST_EXPECT_COMBINES_PERFORMED(env, expComb)
Definition: test_env.h:150
GB_HASH * GBT_create_marked_species_hash(GBDATA *gb_main)
Definition: adhashtools.cxx:40
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
Definition: arbdb.cxx:2144
void set_aborted(bool aborted_)
Definition: PARS_main.cxx:154
void awt_create_filter_awars(AW_root *aw_root, AW_default aw_def, const char *awar_filtername, const char *awar_mapto_alignment)
Definition: AWT_filter.cxx:193
#define AWT_TREE(ntw)
Definition: TreeDisplay.hxx:80
bool aborted() const
Definition: PARS_main.cxx:153
const char * GB_ERROR
Definition: arb_core.h:25
bool allBranchlengthsAreDefined(AP_tree_nlen *tree)
void get_at_position(int *x, int *y) const
Definition: AW_at.cxx:291
ColumnStat * get_column_stat()
Definition: gui_aliview.hxx:42
BestEdge(const EdgeBetween &betw, Mutations p)
Definition: PARS_main.cxx:283
GB_ERROR GB_commit_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2539
void AWT_popup_tree_export_window(AW_window *parent_win, AWT_canvas *scr)
Definition: AWT_canio.cxx:765
size_t marked
Definition: ARB_Tree.hxx:109
adfiltercbstruct * get_adfiltercbstruct()
Definition: gui_aliview.hxx:41
void button_length(int length)
Definition: AW_at.cxx:283
group_matcher all()
Definition: test_unit.h:1000
AP_subtree(AP_tree_edge *e, AP_tree_nlen *sub_node)
Definition: PARS_main.cxx:255
#define AWAR_KL_DYNAMIC_MAXY
Definition: pars_awars.h:43
GBDATA * GBT_first_marked_species(GBDATA *gb_main)
Definition: aditem.cxx:113
AWT_COMMAND_MODE
Definition: awt_canvas.hxx:25
void NT_remove_leafs(UNFIXED, TREE_canvas *ntw, AWT_RemoveType mode)
static void mixtree_and_calclengths(AWT_graphic_parsimony *agt, int repeat, int percent, EdgeSpec whichEdges)
Definition: PARS_main.cxx:1244
static void pars_reset_optimal_parsimony(AW_window *aww)
Definition: PARS_main.cxx:1474
static void nt_reAdd_and_update(AWT_canvas *ntw, AddWhat what, bool quick)
Definition: PARS_main.cxx:1163
void nt_mode_event(UNFIXED, TREE_canvas *ntw, AWT_COMMAND_MODE mode)
__ATTR__USERESULT_TODO GB_ERROR ARB_init_global_awars(AW_root *aw_root, AW_default aw_def, GBDATA *gb_main)
Definition: aw_root.hxx:198
size_t nodes() const
Definition: ARB_Tree.hxx:114
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
Definition: adhash.cxx:457
return string(buffer, length)
static AW_window * createOptimizeWindow(AW_root *aw_root, TREE_canvas *ntw)
Definition: PARS_main.cxx:1311
void insert_menu_topic(const char *id, const char *name, const char *mnemonic, const char *help_text_, AW_active mask, const WindowCallback &wcb)
Definition: AW_window.cxx:592
void set_tree(AWT_graphic_parsimony *tree_)
Definition: PARS_main.cxx:67
const char * name() const OVERRIDE
Definition: test_unit.h:803
void NT_remove_species_in_tree_from_hash(AP_tree *tree, GB_HASH *hash)
GB_ERROR GBT_restore_marked_species(GBDATA *gb_main, const char *stored_marked)
Definition: aditem.cxx:428
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
Definition: arbdb.cxx:1385
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:717
const char * get_window_id() const
Definition: aw_window.hxx:364
void set_logical_root_to(AP_tree *node)
AP_BL_MODE
#define AWAR_COLUMNSTAT_NAME
Definition: PARS_main.cxx:55
#define AWAR_KL_DYNAMIC_MAXX
Definition: pars_awars.h:42
virtual void set_root()
Definition: TreeNode.cxx:206
#define TEST_REJECT_ZERO(cond)
Definition: test_unit.h:1076
#define ASSERT_NO_ERROR(errorExpr)
Definition: arb_assert.h:360
void at_x(int x)
Definition: AW_at.cxx:98
static AWT_config_mapping_def optimizer_config_mapping[]
Definition: PARS_main.cxx:1272
void accept_if(bool cond)
Definition: test_env.h:115
bool is_multi_match() const
Definition: PARS_main.cxx:789
#define AWT_TREE_PARS(ntw)
Definition: PARS_main.cxx:57
#define AWAR_KL_STATIC_DEPTH4
Definition: pars_awars.h:37
static void AP_user_pop_cb(AW_window *aww, TREE_canvas *ntw)
Definition: PARS_main.cxx:124
AW_window * COLSTAT_create_selection_window(AW_root *aw_root, ColumnStat *column_stat)
Definition: ColumnStat.cxx:373
Mutations nni_rec(EdgeSpec whichEdges, AP_BL_MODE mode, AP_tree_nlen *skipNode, bool includeStartEdge)
static void pars_create_all_awars(AW_root *awr, AW_default aw_def, GBDATA *gb_main)
Definition: PARS_main.cxx:1935
size_t groups
Definition: ARB_Tree.hxx:107
void NT_remove_bootstrap(UNFIXED, TREE_canvas *ntw)
char * GBT_tree_2_newick(const TreeNode *tree, NewickFormat format, bool compact)
Definition: adtree.cxx:1353
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2549
void at(int x, int y)
Definition: AW_at.cxx:93
long
Definition: AW_awar.cxx:154
POS_TREE1 * get_father() const
Definition: probe_tree.h:211
void aw_initstatus()
Definition: AW_status.cxx:766
void PARS_map_viewer(GBDATA *gb_species, AD_MAP_VIEWER_TYPE vtype)
Definition: PARS_main.cxx:1983
void NT_reset_pzoom_cb(UNFIXED, TREE_canvas *ntw)
size_t unlinked
Definition: ARB_Tree.hxx:108
static void nt_add(AWT_graphic_parsimony *agt, AddWhat what, bool quick)
Definition: PARS_main.cxx:623
static void insert_all_species_into_tree(GB_HASH *&hash)
Definition: PARS_main.cxx:543
AWT_graphic_parsimony * graphic_tree()
Definition: test_env.h:125
void request_save()
Definition: awt_canvas.hxx:366
GB_ERROR save_to_DB(GBDATA *gb_main, const char *name) FINAL_OVERRIDE __ATTR__USERESULT
long combines_performed()
Definition: test_env.h:129
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
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)
void remember_user_state()
Definition: AP_main.cxx:27
#define AWAR_ALIGNMENT
Definition: ap_main.hxx:22
long read_int() const
Definition: AW_awar.cxx:187
AP_tree_nlen * get_root_node()
Definition: pars_dtree.hxx:36
AD_MAP_VIEWER_TYPE
AP_tree_nlen * release()
Definition: PARS_main.cxx:802
AW_awar * set_minmax(float min, float max)
Definition: AW_awar.cxx:532
Validity all_available_pops_will_produce_valid_trees()
Definition: test_env.h:119
AP_tree_nlen * sonNode() const
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
void warning(int warning_num, const char *warning_message)
Definition: util.cxx:61
AW_root * awr
Definition: awt_canvas.hxx:338
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:718
static void insert_species_into_tree(const InsertSpeciesIterator begin, const InsertSpeciesIterator end, arb_progress &progress)
Definition: PARS_main.cxx:294
bool GB_have_error()
Definition: arb_msg.cxx:349
GBDATA * get_gb_main() const
STL namespace.
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
Mutations pars
Definition: PARS_main.cxx:278
static void NT_add_quick(UNFIXED, TREE_canvas *ntw, AddWhat what)
Definition: PARS_main.cxx:1150
void AW_insert_common_property_menu_entries(AW_window_menu_modes *awmm)
Definition: AW_preset.cxx:1445
const AP_tree_nlen * get_best_match() const
Definition: PARS_main.cxx:786
static long calc_steps(int toInsert, int inTree)
Definition: PARS_main.cxx:235
void GBS_free_hash(GB_HASH *hs)
Definition: adhash.cxx:541
int GBT_is_partial(GBDATA *gb_species, int default_value, bool define_if_undef)
Definition: adali.cxx:646
static GB_ERROR nt_best_partial_match_rec(list< PartialSequence > &partial, const AP_tree_nlen *tree)
Definition: PARS_main.cxx:864
GBDATA * get_gbmain() const
#define EXIT_SUCCESS
Definition: arb_a2ps.c:154
int GB_unlink(const char *path)
Definition: arb_file.cxx:188
TreeNode * son() const
Definition: TreeNode.h:730
PartialSequence(const PartialSequence &other)
Definition: PARS_main.cxx:770
__ATTR__USERESULT GB_ERROR configure_macro_recording(AW_root *aw_root, const char *client_id, GBDATA *gb_main)
Definition: trackers.cxx:454
#define AWAR_FOOTER_MAX_LEN
int get_leafs() const
Definition: PARS_main.cxx:1488
ARB_edge rootEdge(TreeRoot *root)
Definition: TreeNode.h:858
GB_ERROR GBT_add_new_changekey(GBDATA *gb_main, const char *name, int type)
void dump(FILE *out) const
Definition: PerfMeter.h:104
static long transform_gbd_to_leaf(const char *key, long val, void *)
Definition: PARS_main.cxx:182
size_t get_user_push_counter() const
#define ARRAY_ELEMS(array)
Definition: arb_defs.h:19
size_t size() const
GBDATA * GB_get_father(GBDATA *gbd)
Definition: arbdb.cxx:1720
static void delete_kept_ghostnodes()
Definition: PARS_main.cxx:82
FILE * seq
Definition: rns.c:46
bool calc_bootstrap
Definition: ap_main.hxx:39
#define DOWNCAST(totype, expr)
Definition: downcast.h:141
double AP_FLOAT
Definition: AP_matrix.hxx:30
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1904
struct Unfixed_cb_parameter * UNFIXED
Definition: cb_base.h:15
KL_DYNAMIC_THRESHOLD_TYPE
Definition: pars_awars.h:52
AP_FLOAT get_branchlength() const
Definition: PARS_main.cxx:787
size_t leafs
Definition: ARB_Tree.hxx:105
AP_tree_nlen * root_node()
Definition: test_env.h:88
void setSubtreeRoot(AP_tree_nlen *new_subtree)
Definition: PARS_main.cxx:263
Level get_frame_level()
Definition: test_env.h:122
void set_tree_style(AP_tree_display_style style, AWT_canvas *ntw)
POS_TREE1 * father
Definition: probe_tree.h:39
static void count_partial_and_full(const AP_tree_nlen *at, int *partial, int *full, int *zombies, int default_value, bool define_if_undef)
Definition: PARS_main.cxx:891
void set_root()
Definition: TreeNode.h:837
GB_ERROR GB_export_error(const char *error)
Definition: arb_msg.cxx:259
int create_mode(const char *pixmap, const char *help_text_, AW_active mask, const WindowCallback &cb)
Definition: AW_window.cxx:2958
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:353
#define AWAR_PARSIMONY
Definition: ap_main.hxx:24
static ArbParsimony * GLOBAL_PARS
Definition: PARS_main.cxx:59
void show()
Definition: AW_window.cxx:1658
bool needs_save() const
Definition: awt_canvas.hxx:163
void revert_user_state()
Definition: AP_main.cxx:32
GBDATA * GB_create_container(GBDATA *father, const char *key)
Definition: arbdb.cxx:1827
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
#define TEST_EXPECT(cond)
Definition: test_unit.h:1313
static void NT_add_and_NNI(UNFIXED, TREE_canvas *ntw, AddWhat what)
Definition: PARS_main.cxx:1149
#define AWAR_FOOTER
void GB_random_seed(unsigned seed)
Definition: admath.cxx:80
void inc()
Definition: PARS_main.cxx:156
void NT_insert_collapse_submenu(AW_window_menu_modes *awm, TREE_canvas *ntw)
#define MIN_SEQUENCE_LENGTH
Definition: pars_main.hxx:18
#define AWAR_FILTER_NAME
Definition: ap_main.hxx:23
#define AWAR_KL_INCDEPTH
Definition: pars_awars.h:31
GBDATA * gb_species_data
Definition: adname.cxx:34
AWT_RemoveType
Definition: AP_Tree.hxx:35
void GBS_hash_do_const_loop(const GB_HASH *hs, gb_hash_const_loop_type func, void *client_data)
Definition: adhash.cxx:562
static SearchSettings * settings[SEARCH_PATTERNS]
Definition: ED4_search.cxx:628
Generic smart pointer.
Definition: smartptr.h:149
bool aborted()
Definition: arb_progress.h:277
void GBK_terminate(const char *error) __ATTR__NORETURN
Definition: arb_msg.cxx:463
static void calc_branchlengths_and_reorder(AWT_graphic_parsimony *agt)
Definition: PARS_main.cxx:1173
static void nt_reAdd(AWT_graphic_parsimony *agt, AddWhat what, bool quick)
Definition: PARS_main.cxx:1155
GB_ERROR load_tree(const char *tree_name)
Definition: test_env.h:95
int get_inner() const
Definition: PARS_main.cxx:1489
CONSTEXPR_INLINE int leafs_2_edges(int leafs, TreeModel model)
Definition: arbdbt.h:61
AP_main * ap_main
Definition: PARS_main.cxx:65
static int group[MAXN+1]
Definition: ClustalV.cxx:65
void AW_save_properties(AW_window *aw)
Definition: AW_preset.cxx:1452
AWT_graphic_parsimony * get_tree() const
Definition: pars_main.hxx:31
void GB_clear_error()
Definition: arb_msg.cxx:365
#define DECLARE_ASSIGNMENT_OPERATOR(T)
Definition: arbtools.h:61
static void nt_add_and_update(AWT_canvas *ntw, AddWhat what, bool quick)
Definition: PARS_main.cxx:1144
#define false
Definition: ureadseq.h:13
Level get_user_push_counter()
Definition: test_env.h:123
bool is_leaf_edge() const
void generate_tree(WeightedFilter *pars_weighted_filter)
Definition: PARS_dtree.cxx:295
size_t innerNodes
Definition: ARB_Tree.hxx:106
void create_menu(const char *name, const char *mnemonic, AW_active mask=AWM_ALL)
Definition: AW_window.cxx:469
const char * GBS_readable_size(unsigned long long size, const char *unit_suffix)
Definition: arb_misc.cxx:23
GBDATA * GBT_expect_species(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:146
int ARB_main(int argc, char *argv[])
Definition: PARS_main.cxx:1994
AW_window * AW_create_gc_window(AW_root *aw_root, AW_gc_manager *gcman)
Definition: AW_preset.cxx:1373
AddWhat
Definition: PARS_main.cxx:618
void help_text(const char *id)
Definition: AW_window.cxx:113
#define TEST_REJECT_NULL(n)
Definition: test_unit.h:1310
long Mutations
Definition: AP_sequence.hxx:99
EdgeBetween between
Definition: PARS_main.cxx:279
void NT_jump_cb(UNFIXED, TREE_canvas *ntw, AP_tree_jump_type jumpType)
TreeNode * father
Definition: TreeNode.h:131
static void error(const char *msg)
Definition: mkptypes.cxx:96
GBDATA * GB_get_root(GBDATA *gbd)
Definition: arbdb.cxx:1738
GB_ERROR GB_abort_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2527
void init(AW_root *root, const char *wid, const char *windowname, int width, int height)
Definition: AW_window.cxx:2374
char * GBT_readOrCreate_string(GBDATA *gb_container, const char *fieldpath, const char *default_value)
Definition: adtools.cxx:371
void restore_at_from(const AW_at_storage &stored)
Definition: aw_window.hxx:549
AW_window * AW_preset_window(AW_root *root)
Definition: AW_preset.cxx:1920
expectation_group & add(const expectation &e)
Definition: test_unit.h:801
AP_tree_edge * edgeToSubtree() const
Definition: PARS_main.cxx:260
GBDATA * GBT_next_marked_species(GBDATA *gb_species)
Definition: aditem.cxx:116
#define AWAR_TREE
GBDATA * GB_searchOrCreate_int(GBDATA *gb_container, const char *fieldpath, long default_value)
Definition: adquery.cxx:569
void label(const char *label)
Definition: AW_window.cxx:102
void GBS_hash_do_sorted_loop(GB_HASH *hs, gb_hash_loop_type func, gbs_hash_compare_function sorter, void *client_data)
Definition: adhash.cxx:632
void insert_help_topic(const char *labeli, const char *mnemonic, const char *helpText, AW_active mask, const WindowCallback &cb)
Definition: AW_window.cxx:566
size_t GBS_hash_elements(const GB_HASH *hs)
Definition: adhash.cxx:573
#define that(thing)
Definition: test_unit.h:1032
#define TEST_EXPECT_VALID_TREE(tree)
Definition: TreeNode.h:620
void remember()
Definition: AP_main.cxx:50
EdgeSpec whichEdges
Definition: pars_awars.h:82
#define AWAR_KL_STATIC_DEPTH1
Definition: pars_awars.h:34
static void nt_add_partial(AWT_graphic_parsimony *agt)
Definition: PARS_main.cxx:938
AP_tree_nlen * subtreeRoot() const
Definition: PARS_main.cxx:261
#define AWAR_SPECIES_NAME
AW_window * awt_create_select_filter_win(AW_root *aw_root, adfiltercbstruct *acbs)
Definition: AWT_filter.cxx:364
#define TEST_EXPECT_ZERO_OR_SHOW_ERRNO(iocond)
Definition: test_unit.h:1079
const char * get_name() const
Definition: PARS_main.cxx:791
static int calculate_default_random_repeat(long leafs)
Definition: PARS_main.cxx:1231
#define cmp(h1, h2)
Definition: admap.cxx:50
void optimize_tree(AP_tree_nlen *at, const KL_Settings &settings, arb_progress &progress)
Definition: PARS_dtree.cxx:190
static void pars_start_cb(AW_window *aw_parent, WeightedFilter *wfilt, const PARS_commands *cmds)
Definition: PARS_main.cxx:1512
static AW_root * AD_map_viewer_aw_root
Definition: PARS_main.cxx:1981
void count(AP_tree_nlen *node)
Definition: PARS_main.cxx:1492
static void push_partial(const char *, long val, void *cd_partial)
Definition: PARS_main.cxx:930
#define ap_assert(cond)
AP_tree_display_style get_tree_style() const
static const AP_tree_nlen * find_least_deep_leaf(const AP_tree_nlen *at, int depth, int *min_depth)
Definition: PARS_main.cxx:908
AWT_graphic_parsimony * get_graphic_tree()
long GBT_size_of_tree(GBDATA *gb_main, const char *tree_name)
Definition: adtree.cxx:1111
UserActionTracker * need_macro_ability()
Definition: trackers.cxx:450
char * read_string() const
Definition: AW_awar.cxx:201
static void NT_reAdd_quick(UNFIXED, TREE_canvas *ntw, AddWhat what)
Definition: PARS_main.cxx:1169
AP_tree_nlen * rootNode()
Definition: ap_main.hxx:54
NewickFormat
Definition: arbdb_base.h:68
CONSTEXPR_INLINE bool valid(SpeciesCreationMode m)
Definition: ed4_class.hxx:2246
FILE * topo
Definition: rns.c:46
AP_tree_edge * edge() const
Definition: PARS_main.cxx:285
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
#define RUNNING_TEST()
Definition: arb_assert.h:278
void insert_sub_menu(const char *name, const char *mnemonic, AW_active mask=AWM_ALL)
Definition: AW_window.cxx:642
#define does_differ_from_NULL()
Definition: test_unit.h:1018
static long toInserted(const char *, long val, void *cd_toInsert)
Definition: PARS_main.cxx:218
GB_ERROR open(const char *db_server)
Definition: AP_main.cxx:20
AP_pars_root * get_tree_root()
Definition: pars_dtree.hxx:39
#define AWAR_PARS_TYPE
Definition: ap_main.hxx:28
InsertedSpecies::const_iterator InsertSpeciesIterator
Definition: PARS_main.cxx:292
void NT_set_tree_style(UNFIXED, TREE_canvas *ntw, AP_tree_display_style style)
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
Definition: adali.cxx:682
void test_match(const AP_tree_nlen *leaf_full)
Definition: PARS_main.cxx:818
void create_nds_vars(AW_root *aw_root, AW_default awdef, GBDATA *gb_main, bool force_reinit)
Definition: nds.cxx:205
#define EXIT_FAILURE
Definition: arb_a2ps.c:157
static __ATTR__NORETURN void pars_exit(AW_window *aww)
Definition: PARS_main.cxx:102
static AW_window_menu_modes_opengl * awm
#define is_equal_to(val)
Definition: test_unit.h:1014
void GBS_hash_do_loop(GB_HASH *hs, gb_hash_loop_type func, void *client_data)
Definition: adhash.cxx:548
#define AWAR_KL_DYNAMIC_START
Definition: pars_awars.h:41
long GBT_count_marked_species(GBDATA *gb_main)
Definition: aditem.cxx:353
#define TEST_EXPECT_ZERO(cond)
Definition: test_unit.h:1074
void NT_insert_mark_submenus(AW_window_menu_modes *awm, TREE_canvas *ntw, int insert_as_submenu)
static AW_at_storage * make(AW_window *aww, AW_at_storage_type type)
Definition: AW_at.cxx:444
void unlink_awars_from_DB(GBDATA *gb_main)
Definition: AW_root.cxx:635
#define AWAR_OPTI_SKIP_FOLDED
Definition: pars_awars.h:25
#define AW_HEADER_MAIN
Definition: aw_window.hxx:36
AP_tree_edge * find() const
Definition: PARS_main.cxx:274
void awt_set_awar_to_valid_filter_good_for_tree_methods(GBDATA *gb_main, AW_root *awr, const char *awar_name)
Definition: AWT_filter.cxx:313
AW_DB_selection * awt_create_ALI_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, const char *ali_type_match)
#define TEST_EXPECTATION(EXPCTN)
Definition: test_unit.h:1037
GB_ERROR GB_set_temporary(GBDATA *gbd) __ATTR__USERESULT
Definition: arbdb.cxx:2274
#define does_contain(val)
Definition: test_unit.h:1029
bool aw_ask_sure(const char *unique_id, const char *msg)
void main_loop()
Definition: AW_root.cxx:625
AW_root * AWT_create_root(const char *properties, const char *program, UserActionTracker *user_tracker)
void set_info_area_height(int height)
Definition: AW_window.cxx:793
AW_window * AWT_create_nds_window(AW_root *aw_root, GBDATA *gb_main)
Definition: nds.cxx:500
AW_DB_selection * awt_create_TREE_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, bool fallback2default)
fputs(TRACE_PREFIX, stderr)
GB_ULONG GB_get_usable_memory(void)
Definition: adsocket.cxx:833
string get_multilist() const
Definition: PARS_main.cxx:797
#define textfiles_have_difflines(f1, f2, ed)
Definition: test_unit.h:1409
static void create_optimize_vars(AW_root *aw_root, AW_default props)
Definition: PARS_main.cxx:1911
void AWT_trigger_remote_action(UNFIXED, GBDATA *gb_main, const char *remote_action_spec)
void set_bottom_area_height(int height)
Definition: AW_window.cxx:798
AWT_graphic_parsimony * global_tree()
Definition: PARS_main.cxx:61
static void AP_user_push_cb(AW_window *aww)
Definition: PARS_main.cxx:119
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 NT_resort_tree_cb(UNFIXED, TREE_canvas *ntw, TreeOrder order)
AW_window * create_kernighan_properties_window(AW_root *aw_root)
static void randomMixTree(AW_window *aww, TREE_canvas *ntw)
Definition: PARS_main.cxx:1259
void request_save_and_zoom_reset()
Definition: awt_canvas.hxx:368
KL_Settings & get_KL_settings()
Definition: test_env.h:137
void auto_space(int xspace, int yspace)
Definition: AW_at.cxx:259
#define TEST_EXPECT_NULL(n)
Definition: test_unit.h:1307
#define AWAR_KL_STATIC_DEPTH2
Definition: pars_awars.h:35
GBDATA * gbmain() const
Definition: test_env.h:127
void GB_write_flag(GBDATA *gbd, long flag)
Definition: arbdb.cxx:2761
int maxAllowedInsertions(int inTree)
Definition: PARS_main.cxx:226
static void NT_add_partial_and_update(UNFIXED, TREE_canvas *ntw)
Definition: PARS_main.cxx:1136
#define AWAR_RAND_PERCENT
Definition: pars_awars.h:28
#define fulfills(pred, arg)
Definition: test_unit.h:1026
KL_Settings(AW_root *aw_root)
Definition: PARS_main.cxx:1862
void compute_tree()
Definition: test_env.h:135
#define AWAR_BEST_PARSIMONY
Definition: ap_main.hxx:25
GB_ERROR GBT_write_string(GBDATA *gb_container, const char *fieldpath, const char *content)
Definition: adtools.cxx:451
AW_gc_manager * gc_manager
Definition: awt_canvas.hxx:341
static void NT_reAdd_and_NNI(UNFIXED, TREE_canvas *ntw, AddWhat what)
Definition: PARS_main.cxx:1168
static void NT_bootstrap(AW_window *, TREE_canvas *ntw, bool limit_only)
Definition: PARS_main.cxx:1184
AP_pars_root * get_tree_root() const
AP_tree_display_style
Definition: TreeDisplay.hxx:82
vector< AP_tree_nlen * > InsertedSpecies
Definition: PARS_main.cxx:216
#define AWAR_OPTI_MARKED_ONLY
Definition: pars_awars.h:24
bool calc_branch_lengths
Definition: ap_main.hxx:38
static AW_window * create_pars_init_window(AW_root *awr, const PARS_commands *cmds)
Definition: PARS_main.cxx:1819
AP_tree * get_root_node()
bool add_selected
Definition: ap_main.hxx:37
void subtitle(const char *stitle)
Definition: arb_progress.h:263
void AWT_popup_print_window(AW_window *parent_win, AWT_canvas *scr)
Definition: AWT_canio.cxx:865
char * GB_read_string(GBDATA *gbd)
Definition: arbdb.cxx:903
AWT_graphic_exports exports
Definition: awt_canvas.hxx:249
int calcInsertNow(int toInsert, int inTree)
Definition: PARS_main.cxx:230
AP_tree_nlen * otherNode(const AP_tree_nlen *n) const
void PARS_tree_init(AWT_graphic_parsimony *agt)
Definition: PARS_dtree.cxx:59
void close_sub_menu()
Definition: AW_window.cxx:483
void GBT_message(GBDATA *gb_main, const char *msg)
Definition: adtools.cxx:238
AW_window * TREE_create_settings_window(AW_root *aw_root)
#define TREEDISP_STACKSIZE
Definition: TreeDisplay.hxx:32
void revert()
Definition: AP_main.cxx:66
#define TEST_EXPECT_NO_ERROR(call)
Definition: test_unit.h:1107
#define AWAR_KL_STATIC_DEPTH5
Definition: pars_awars.h:38
void aw_message(const char *msg)
Definition: AW_status.cxx:932
void hide()
Definition: AW_window.cxx:1807
AP_FLOAT weighted_base_count() const
void insert_macro_menu_entry(AW_window *awm, bool prepend_separator)
Definition: macro_gui.cxx:171
static void initialize(AP_tree_nlen *root)
AW_root * get_root()
Definition: aw_window.hxx:348
float GBT_LEN
Definition: arbdb_base.h:34
#define AWAR_STACKPOINTER
Definition: ap_main.hxx:26
__ATTR__NORETURN void aw_popup_exit(const char *msg)
bool is_std_gap(const char c)
void shutdown_macro_recording(AW_root *aw_root)
Definition: trackers.cxx:470
#define NULp
Definition: cxxforward.h:97
bool GB_is_regularfile(const char *path)
Definition: arb_file.cxx:76
size_t linked() const
Definition: ARB_Tree.hxx:115
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:1103
Validity pop_will_produce_valid_tree()
Definition: test_env.h:118
bool add_marked
Definition: ap_main.hxx:36
InsertData(bool quick, long spec_count)
Definition: PARS_main.cxx:147
#define INT2STR(i)
static AWT_predefined_config optimizer_predefined_configs[]
Definition: PARS_main.cxx:1297
#define AWAR_KL_FUNCTION_TYPE
Definition: pars_awars.h:45
#define __ATTR__NORETURN
Definition: attributes.h:56
#define TEST_VALIDITY(valid)
Definition: test_unit.h:1319
GB_ERROR write_string(const char *aw_string)
ArbParsimony & get_parsimony()
Definition: pars_dtree.hxx:40
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:687
static void optimizeTree(AWT_graphic_parsimony *agt, const KL_Settings &settings)
Definition: PARS_main.cxx:1195
const char * GBT_get_name(GBDATA *gb_item)
Definition: aditem.cxx:450
void sep______________()
Definition: AW_window.cxx:750
static void set_keep_ghostnodes()
Definition: PARS_main.cxx:73
arb_progress & get_progress()
Definition: PARS_main.cxx:161
void GBT_mark_all(GBDATA *gb_main, int flag)
Definition: aditem.cxx:295
void inc_by(PINT count)
Definition: arb_progress.h:303
void AWT_install_cb_guards()
PartialSequence(GBDATA *gb_species_)
Definition: PARS_main.cxx:761
EdgeSpec
Definition: pars_awars.h:57
static int sort_sequences_by_length(const char *, long leaf0_ptr, const char *, long leaf1_ptr)
Definition: PARS_main.cxx:165
long GBT_get_species_count(GBDATA *gb_main)
Definition: aditem.cxx:207
void accept_all()
bool quick_add_flag
Definition: PARS_main.cxx:146
GB_transaction ta(gb_var)
GB_ERROR GBT_write_int(GBDATA *gb_container, const char *fieldpath, long content)
Definition: adtools.cxx:471
void callback(const WindowCallback &cb)
Definition: AW_window.cxx:130
void set_tree_root(AWT_graphic_parsimony *agt_)
Definition: AP_main.cxx:299
void destroy(TreeNode *that)
Definition: TreeNode.h:560
#define AWAR_KL_MAXDEPTH
Definition: pars_awars.h:30
AP_pars_root * global_tree_root()
Definition: PARS_main.cxx:62
int get_at_yposition() const
Definition: AW_at.cxx:300
GBDATA * gb_main
Definition: adname.cxx:33
const char * get_aliname() const
Definition: AP_main.cxx:304
#define ASSERT_VALID_TREE(tree)
Definition: TreeNode.h:607
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
static GB_ERROR pars_check_size(AW_root *awr, GB_ERROR &warning, const adfiltercbstruct *filterDef)
Definition: PARS_main.cxx:1428
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
Definition: aditem.cxx:441
void shadow_width(int shadow_thickness)
Definition: AW_window.cxx:1075
#define AWAR_RAND_REPEAT
Definition: pars_awars.h:27
#define min(a, b)
Definition: f2c.h:153
void label_length(int length)
Definition: AW_at.cxx:279
void at_newline()
Definition: AW_at.cxx:119
void dump(const char *whichMatch) const
Definition: PARS_main.cxx:809
static void PARS_infomode_cb(UNFIXED, TREE_canvas *canvas, AWT_COMMAND_MODE mode)
Definition: PARS_main.cxx:1507
void TREE_create_awars(AW_root *aw_root, AW_default db)
virtual Mutations mutations_if_combined_with(const AP_combinableSeq *other)=0
static void NT_calc_branchlengths_reorder_and_update(AW_window *, TREE_canvas *ntw)
Definition: PARS_main.cxx:1179
GBDATA * get_species() const
Definition: PARS_main.cxx:785
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
#define TEST_EXPECT_EQUAL(expr, want)
Definition: test_unit.h:1283
GB_ERROR write_int(long aw_int)
void NT_reset_lzoom_cb(UNFIXED, TREE_canvas *ntw)
EdgeBetween(AP_tree_edge *e)
Definition: PARS_main.cxx:273
static void NT_recursiveNNI(AW_window *, TREE_canvas *ntw)
Definition: PARS_main.cxx:1225
static void update_random_repeat(AW_root *awr, AWT_graphic_parsimony *agt)
Definition: PARS_main.cxx:1238
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
static void NT_optimize(AW_window *, TREE_canvas *ntw)
Definition: PARS_main.cxx:1201
void TREE_install_update_callbacks(TREE_canvas *ntw)
#define AWAR_KL_DYNAMIC_ENABLED
Definition: pars_awars.h:40
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:195
AP_tree_nlen * notSonNode() const
unsigned long Level
Definition: AP_buffer.hxx:126
GBDATA * gb_main
Definition: awt_canvas.hxx:336
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)
Definition: adhash.cxx:253
void create_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, const char *color=NULp)
Definition: AW_button.cxx:446
#define AWAR_KL_STATIC_ENABLED
Definition: pars_awars.h:33
Definition: arbdb.h:66
#define AWAR_KL_STATIC_DEPTH3
Definition: pars_awars.h:36
void NT_reload_tree_event(AW_root *, TREE_canvas *ntw, bool unzoom_and_expose)
#define max(a, b)
Definition: f2c.h:154
GB_write_int const char s
Definition: AW_awar.cxx:156