84 a = (startx - maxy) / (maxx * maxx);
89 a = - maxy / ((maxDepth - maxx) * (maxDepth - maxx));
91 c = maxy + a * maxx * maxx;
98 AP_tree_nlen *oldrootleft = get_root_node()->get_leftson();
99 AP_tree_nlen *oldrootright = get_root_node()->get_rightson();
100 Mutations pars_curr = get_root_node()->costs();
120 AP_tree_nlen *skipNode =
NULp;
121 bool skipStartEdge =
true;
125 skipStartEdge =
false;
127 else if (at->is_son_of_root()) {
132 skipNode = at->get_father();
133 startEdge = at->edgeTo(skipNode);
140 if (pars_global_start) {
149 while (chain && !progress.aborted()) {
157 bool better_tree_found = edge->
kl_rec(KL, 0, pars_curr);
159 if (better_tree_found) {
161 Mutations pars_new = get_root_node()->costs();
163 pars_curr = pars_new;
164 if (pars_global_start) {
165 progress.subtitle(
GBS_global_string(
"best=%li (gain=%li, KL=%li)", pars_curr, *pars_global_start-pars_curr, pars_org-pars_curr));
168 progress.subtitle(
GBS_global_string(
"best=%li (gain=%li)", pars_curr, pars_org-pars_curr));
179 if (dumpPerf) performance.
dump(stdout, pars_curr);
181 if (oldrootleft->father == oldrootright) {
182 oldrootleft->set_root();
185 oldrootright->set_root();
192 AP_tree_nlen *oldrootleft = get_root_node()->get_leftson();
193 AP_tree_nlen *oldrootright = get_root_node()->get_rightson();
194 const Mutations org_pars = get_root_node()->costs();
206 NO_FURTHER_HEURISTIC,
207 HEURISTIC_COUNT = NO_FURTHER_HEURISTIC,
208 } heuristic = RECURSIVE_NNI;
216 } heuristic_setting[HEURISTIC_COUNT] = {
217 {
"recursive NNIs",
NULp,
true, CUSTOM_KL, CUSTOM_KL },
218 {
"KL-optimizer", &
settings,
false, RECURSIVE_NNI, NO_FURTHER_HEURISTIC },
224 #if defined(ASSERTION_USED)
231 while (heuristic != NO_FURTHER_HEURISTIC && !progress.
aborted()) {
232 const H_Settings& hset = heuristic_setting[heuristic];
241 this_pars = get_root_node()->costs();
251 bool dumpOverall =
false;
252 Heuristic nextHeuristic = heuristic;
253 if (this_pars<prev_pars) {
254 prev_pars = this_pars;
257 nextHeuristic = hset.onImprove;
258 dumpOverall = heuristic == CUSTOM_KL;
262 nextHeuristic = this_pars<heu_start_pars ? hset.onImprove : hset.onFailure;
265 if (nextHeuristic != heuristic) {
266 heuristic = nextHeuristic;
267 heu_start_pars = this_pars;
269 heuPerf->
dump(stdout, this_pars);
270 delete heuPerf; heuPerf =
NULp;
272 if (dumpOverall) overallPerf.
dumpCustom(stdout, this_pars,
"overall (so far)");
276 if (oldrootleft->father == oldrootright) {
277 oldrootleft->set_root();
280 oldrootright->set_root();
283 overallPerf.
dump(stdout, prev_pars);
288 parsimony(parsimony_)
292 return new AP_pars_root(aliview, seq_prototype, insert_delete_cbs, &
groupScale);
305 if (is_aa) seq_templ =
new AP_sequence_protein(aliview);
306 else seq_templ =
new AP_sequence_parsimony(aliview);
310 new_tree->
init(aliview, seq_templ,
true,
false);
330 "Branch remarks$#DBE994",
331 "+-Bootstrap$#DBE994",
"-B.(limited)$white",
334 "Some marked$#eeee88",
336 "Zombies etc.$#cc5924",
347 void AWT_graphic_parsimony::show(
AW_device *device) {
348 AP_tree_nlen *root_node = parsimony.get_root_node();
352 long parsval = root_node ? root_node->costs() : 0;
355 long best_pars = awar_best->
read_int();
356 if (parsval < best_pars || 0==best_pars) awar_best->
write_int(parsval);
363 bool recalc_branchlengths_on_structure_change =
true;
365 switch (event.
cmd()) {
369 const char *what =
NULp;
370 const char *where =
NULp;
372 switch (event.
cmd()) {
379 AP_tree_nlen *startNode =
NULp;
380 bool repeatOpti =
true;
388 startNode =
DOWNCAST(AP_tree_nlen*, clicked.node());
408 switch (event.
cmd()) {
425 repeatOpti = repeatOpti && curr_pars<prev_pars;
426 }
while (repeatOpti);
435 recalc_branchlengths_on_structure_change =
false;
457 template<
typename SEQTYPE>
472 if (!filter.is_invalid()) {
482 void TEST_basic_tree_modifications() {
487 AP_tree_nlen *root = env.root_node();
503 root->compute_tree();
508 #define B1_TOP "(((((CloTyro3:1.046,CloTyro4:.061):.026,CloTyro2:.017):.017,CloTyrob:.009):.274,CloInnoc:.371):.057,CloBifer:.388):.124"
509 #define B1_BOT "(CloBifer:.388,(CloInnoc:.371,(CloTyrob:.009,(CloTyro2:.017,(CloTyro3:1.046,CloTyro4:.061):.026):.017):.274):.057):.124"
510 #define B2_TOP "(((CloButy2:.009,CloButyr:0):.564,CloCarni:.12):.01,CloPaste:.179):.131"
511 #define B2_BOT "(CloPaste:.179,(CloCarni:.12,(CloButy2:.009,CloButyr:0):.564):.01):.131"
514 #define B3_LEFT_TOP_SONS "(((CorAquat:.084,CurCitre:.058):.103,CorGluta:.522):.053,CelBiazo:.059)"
515 #define B3_TOP_SONS B3_LEFT_TOP_SONS ":.207,CytAquat:.711"
516 #define B3_TOP_SONS_CCR "((CorAquat:.187,CorGluta:.522):.053,CelBiazo:.059):.207,CytAquat:.711" // CCR = CurCitre removed
517 #define B3_TOP "(" B3_TOP_SONS "):.081"
518 #define B3_BOT "(CytAquat:.711,(CelBiazo:.059,(CorGluta:.522,(CorAquat:.084,CurCitre:.058):.103):.053):.207):.081"
521 const char *top_topo =
"((" B1_TOP
"," B2_TOP
"):.081," B3_TOP
");";
522 const char *edge_topo =
"((" B1_TOP
"," B2_BOT
"):.081," B3_BOT
");";
523 const char *bottom_topo =
"(" B3_BOT
",(" B2_BOT
"," B1_BOT
"):.081);";
525 const char *radial_topo =
526 "(((CloPaste:.179,((CloButy2:.009,CloButyr:0):.564,CloCarni:.12):.01):.131,"
527 "((CloInnoc:.371,((CloTyro2:.017,(CloTyro3:1.046,CloTyro4:.061):.026):.017,CloTyrob:.009):.274):.057,CloBifer:.388):.124):.081,"
528 "((CelBiazo:.059,((CorAquat:.084,CurCitre:.058):.103,CorGluta:.522):.053):.207,CytAquat:.711):.081);";
529 const char *radial_topo2 =
530 "(((CloBifer:.388,(CloInnoc:.371,(((CloTyro3:1.046,CloTyro4:.061):.026,CloTyro2:.017):.017,CloTyrob:.009):.274):.057):.124," B2_TOP
"):.081,"
531 "(CytAquat:.711," B3_LEFT_TOP_SONS
":.207):.081);";
560 AP_tree_nlen *CloTyrob = root->findLeafNamed(
"CloTyrob");
568 const char *rootAtCloTyrob_topo =
570 "(((CloTyro3:1.046,CloTyro4:.061):.026,CloTyro2:.017):.017,"
571 "((((" B3_TOP_SONS
"):.162," B2_TOP
"):.124,CloBifer:.388):.057,CloInnoc:.371):.274):.004);";
578 AP_tree_nlen *CelBiazoFather = root->findLeafNamed(
"CelBiazo")->get_father();
580 CelBiazoFather->set_root();
582 const char *rootAtCelBiazoFather_topo =
"(" B3_LEFT_TOP_SONS
":.104,((" B1_TOP
"," B2_TOP
"):.162,CytAquat:.711):.104);";
588 DOWNCAST(AP_tree_nlen*,oldRootEdge.son())->set_root();
590 const char *rootSetBack_topo = top_topo;
597 AP_tree_nlen *CurCitre = root->findLeafNamed(
"CurCitre");
602 const char *CurCitre_removed_topo =
"((" B1_TOP
"," B2_TOP
"):.081,(" B3_TOP_SONS_CCR
"):.081);";
610 root->compute_tree();
618 AP_tree_nlen *CloCarni = root->findLeafNamed(
"CloCarni");
620 CurCitre->insert(CloCarni);
622 const char *CurCitre_inserted_topo =
"((" B1_TOP
",(((CloButy2:.009,CloButyr:0):.564,(CurCitre:.06,CloCarni:.06):.06):.01,CloPaste:.179):.131):.081,(" B3_TOP_SONS_CCR
"):.081);";
637 void TEST_calc_bootstraps() {
641 const char *bs_origi_topo =
"(((((((CloTyro3,CloTyro4)'40%',CloTyro2)'0%',CloTyrob)'97%',CloInnoc)'0%',CloBifer)'53%',(((CloButy2,CloButyr),CloCarni)'33%',CloPaste)'97%'),((((CorAquat,CurCitre),CorGluta)'17%',CelBiazo)'40%',CytAquat));";
642 const char *bs_limit_topo =
"(((((((CloTyro3,CloTyro4)'87%',CloTyro2)'0%',CloTyrob),CloInnoc)'87%',CloBifer)'83%',(((CloButy2,CloButyr)'99%',CloCarni)'17%',CloPaste)'56%')'61%',((((CorAquat,CurCitre)'78%',CorGluta)'0%',CelBiazo)'59%',CytAquat)'61%');";
643 const char *bs_estim_topo =
"(((((((CloTyro3,CloTyro4)'75%',CloTyro2)'0%',CloTyrob),CloInnoc)'75%',CloBifer)'78%',(((CloButy2,CloButyr)'99%',CloCarni)'13%',CloPaste)'32%')'53%',((((CorAquat,CurCitre)'74%',CorGluta)'0%',CelBiazo)'56%',CytAquat)'53%');";
646 AP_tree_nlen *root = env.root_node();
670 void TEST_tree_remove_add_all() {
676 AP_tree_nlen *leaf[LEAFS];
677 const char *name[LEAFS] = {
686 AP_tree_nlen *root = env.root_node();
688 for (
int i = 0; i<LEAFS; ++i) {
689 leaf[i] = root->findLeafNamed(name[i]);
695 AP_pars_root *troot = leaf[0]->get_tree_root();
698 for (
int i = 0; i<LEAFS-1; ++i) {
707 leaf[0]->initial_insert(leaf[1], troot);
708 for (
int i = 2; i<LEAFS; ++i) {
711 leaf[i]->insert(leaf[i-1]);
void reorderTree(TreeOrder mode)
#define TEST_EXPECT_COMBINES_PERFORMED(env, expComb)
AP_tree * get_logical_root()
const char * get_aliname() const
#define TEST_EXPECT_SIMILAR(expr, want, epsilon)
#define implicated(hypothesis, conclusion)
void dump(FILE *out, Mutations end_pars) const
void set_tree(AWT_graphic_parsimony *tree_)
void set_logical_root_to(AP_tree *node)
void dumpCustom(FILE *out, Mutations end_pars, const char *label) const
long GBT_mark_all(GBDATA *gb_main, int flag)
Mutations nni_rec(EdgeSpec whichEdges, AP_BL_MODE mode, AP_tree_nlen *skipNode, bool includeStartEdge)
static void AWT_graphic_parsimony_root_changed(void *cd, AP_tree *old, AP_tree *newroot)
void PARS_map_viewer(GBDATA *gb_species, AD_MAP_VIEWER_TYPE vtype)
AP_tree_nlen * get_root_node()
const char * GBS_global_string(const char *templat,...)
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
GBDATA * get_gb_main() const
const AW_clicked_element * best_click(AW_device_click::ClickPreference prefer=AW_device_click::PREFER_NEARER)
AWT_graphic_parsimony(ArbParsimony &parsimony_, GBDATA *gb_main_, AD_map_viewer_cb map_viewer_cb_)
void TREE_GC_changed_cb(GcChange whatChanged, AWT_canvas *ntw)
AW_MouseButton button() const
ARB_edge rootEdge(TreeRoot *root)
bool GBT_is_alignment_protein(GBDATA *gb_main, const char *alignment_name)
AW_gc_manager * AW_manage_GC(AW_window *aww, const char *gc_base_name, AW_device *device, int base_drag, AW_GCM_AREA area, const GcChangedCallback &changecb, const char *default_background_color,...)
void set_visited(bool vis)
int rec_width[CUSTOM_DEPTHS]
void AW_init_color_group_defaults(const char *for_program)
#define DOWNCAST(totype, expr)
void change_parsimony_start(Mutations offset)
KL_DYNAMIC_THRESHOLD_TYPE
void(* AD_map_viewer_cb)(GBDATA *gbd, AD_MAP_VIEWER_TYPE type)
#define TEST_EXPECT(cond)
char * GBT_read_string(GBDATA *gb_container, const char *fieldpath)
#define TEST_EXPECT_NEWICK(format, tree, expected_newick)
const char * get_gc_base_name() const
AW_root * get_root() const
static SearchSettings * settings[SEARCH_PATTERNS]
static int weights[MAX_BASETYPES][MAX_BASETYPES]
bool is_leaf_edge() const
void generate_tree(WeightedFilter *pars_weighted_filter)
#define TEST_REJECT_NULL(n)
static void error(const char *msg)
#define TEST_EXPECT_VALID_TREE(tree)
GBDATA * get_gb_main() const
void handle_command(AW_device *device, AWT_graphic_event &event) OVERRIDE
void optimize_tree(AP_tree_nlen *at, const KL_Settings &settings, arb_progress &progress)
AWT_graphic_parsimony * get_graphic_tree()
AP_tree_nlen * rootNode()
AW_awar * awar(const char *awar)
AP_pars_root * get_tree_root()
bool next_to_folded_group() const
static AliView * pars_generate_aliview(WeightedFilter *pars_weighted_filter)
KL_RECURSION_TYPE rec_type
QuadraticThreshold thresFunctor
AliView * create_aliview(const char *aliname, GB_ERROR &error) const
void kernighan_optimize_tree(AP_tree_nlen *at, const KL_Settings &settings, const Mutations *pars_global_start, bool dumpPerf)
#define AWAR_BEST_PARSIMONY
AWT_COMMAND_MODE cmd() const
struct KL_Settings::@15 Static
void subtitle(const char *stitle)
AWT_graphic_exports exports
AP_tree_nlen * otherNode(const AP_tree_nlen *n) const
void PARS_tree_init(AWT_graphic_parsimony *agt)
#define TEST_EXPECT_NO_ERROR(call)
AW_event_type type() const
__ATTR__NORETURN void aw_popup_exit(const char *msg)
#define TEST_EXPECT_DIFFERENT(expr, want)
KL_DYNAMIC_THRESHOLD_TYPE type
void init(AliView *aliview, AP_sequence *seq_prototype, bool link_to_database_, bool insert_delete_cbs)
GB_transaction ta(gb_var)
const char * get_aliname() const
#define ASSERT_VALID_TREE(tree)
bool kl_rec(const KL_params &KL, const int rec_depth, Mutations pars_best)
#define TEST_EXPECT_EQUAL(expr, want)
GBDATA * get_gb_main() const
GB_ERROR write_int(long aw_int)
struct KL_Settings::@16 Dynamic
void show(AW_device *device) OVERRIDE
TreeNode * source() const
PARSIMONY_testenv(const char *dbname)