83 a = (startx - maxy) / (maxx * maxx);
88 a = - maxy / ((maxDepth - maxx) * (maxDepth - maxx));
90 c = maxy + a * maxx * maxx;
97 AP_tree_nlen *oldrootleft = get_root_node()->get_leftson();
98 AP_tree_nlen *oldrootright = get_root_node()->get_rightson();
99 Mutations pars_curr = get_root_node()->costs();
119 AP_tree_nlen *skipNode =
NULp;
120 bool skipStartEdge =
true;
124 skipStartEdge =
false;
126 else if (at->is_son_of_root()) {
131 skipNode = at->get_father();
132 startEdge = at->edgeTo(skipNode);
139 if (pars_global_start) {
148 while (chain && !progress.aborted()) {
156 bool better_tree_found = edge->
kl_rec(KL, 0, pars_curr);
158 if (better_tree_found) {
160 Mutations pars_new = get_root_node()->costs();
162 pars_curr = pars_new;
163 if (pars_global_start) {
164 progress.subtitle(
GBS_global_string(
"best=%li (gain=%li, KL=%li)", pars_curr, *pars_global_start-pars_curr, pars_org-pars_curr));
167 progress.subtitle(
GBS_global_string(
"best=%li (gain=%li)", pars_curr, pars_org-pars_curr));
178 if (dumpPerf) performance.
dump(stdout, pars_curr);
180 if (oldrootleft->father == oldrootright) {
181 oldrootleft->set_root();
184 oldrootright->set_root();
191 AP_tree_nlen *oldrootleft = get_root_node()->get_leftson();
192 AP_tree_nlen *oldrootright = get_root_node()->get_rightson();
193 const Mutations org_pars = get_root_node()->costs();
205 NO_FURTHER_HEURISTIC,
206 HEURISTIC_COUNT = NO_FURTHER_HEURISTIC,
207 } heuristic = RECURSIVE_NNI;
215 } heuristic_setting[HEURISTIC_COUNT] = {
216 {
"recursive NNIs",
NULp,
true, CUSTOM_KL, CUSTOM_KL },
217 {
"KL-optimizer", &
settings,
false, RECURSIVE_NNI, NO_FURTHER_HEURISTIC },
223 #if defined(ASSERTION_USED)
230 while (heuristic != NO_FURTHER_HEURISTIC && !progress.
aborted()) {
231 const H_Settings& hset = heuristic_setting[heuristic];
240 this_pars = get_root_node()->costs();
250 bool dumpOverall =
false;
251 Heuristic nextHeuristic = heuristic;
252 if (this_pars<prev_pars) {
253 prev_pars = this_pars;
256 nextHeuristic = hset.onImprove;
257 dumpOverall = heuristic == CUSTOM_KL;
261 nextHeuristic = this_pars<heu_start_pars ? hset.onImprove : hset.onFailure;
264 if (nextHeuristic != heuristic) {
265 heuristic = nextHeuristic;
266 heu_start_pars = this_pars;
268 heuPerf->
dump(stdout, this_pars);
269 delete heuPerf; heuPerf =
NULp;
271 if (dumpOverall) overallPerf.
dumpCustom(stdout, this_pars,
"overall (so far)");
275 if (oldrootleft->father == oldrootright) {
276 oldrootleft->set_root();
279 oldrootright->set_root();
282 overallPerf.
dump(stdout, prev_pars);
287 parsimony(parsimony_)
291 return new AP_pars_root(aliview, seq_prototype, insert_delete_cbs, &
groupScale);
304 if (is_aa) seq_templ =
new AP_sequence_protein(aliview);
305 else seq_templ =
new AP_sequence_parsimony(aliview);
309 new_tree->
init(aliview, seq_templ,
true,
false);
329 "Branch remarks$#DBE994",
330 "+-Bootstrap$#DBE994",
"-B.(limited)$white",
333 "Some marked$#eeee88",
335 "Zombies etc.$#cc5924",
346 void AWT_graphic_parsimony::show(
AW_device *device) {
347 AP_tree_nlen *root_node = parsimony.get_root_node();
351 long parsval = root_node ? root_node->costs() : 0;
354 long best_pars = awar_best->
read_int();
355 if (parsval < best_pars || 0==best_pars) awar_best->
write_int(parsval);
362 bool recalc_branchlengths_on_structure_change =
true;
364 switch (event.
cmd()) {
368 const char *what =
NULp;
369 const char *where =
NULp;
371 switch (event.
cmd()) {
378 AP_tree_nlen *startNode =
NULp;
379 bool repeatOpti =
true;
387 startNode =
DOWNCAST(AP_tree_nlen*, clicked.node());
407 switch (event.
cmd()) {
424 repeatOpti = repeatOpti && curr_pars<prev_pars;
425 }
while (repeatOpti);
434 recalc_branchlengths_on_structure_change =
false;
456 template<
typename SEQTYPE>
471 if (!filter.is_invalid()) {
481 void TEST_basic_tree_modifications() {
486 AP_tree_nlen *root = env.root_node();
502 root->compute_tree();
507 #define B1_TOP "(((((CloTyro3:1.046,CloTyro4:0.061):0.026,CloTyro2:0.017):0.017,CloTyrob:0.009):0.274,CloInnoc:0.371):0.057,CloBifer:0.388):0.124"
508 #define B1_BOT "(CloBifer:0.388,(CloInnoc:0.371,(CloTyrob:0.009,(CloTyro2:0.017,(CloTyro3:1.046,CloTyro4:0.061):0.026):0.017):0.274):0.057):0.124"
509 #define B2_TOP "(((CloButy2:0.009,CloButyr:0.000):0.564,CloCarni:0.120):0.010,CloPaste:0.179):0.131"
510 #define B2_BOT "(CloPaste:0.179,(CloCarni:0.120,(CloButy2:0.009,CloButyr:0.000):0.564):0.010):0.131"
513 #define B3_LEFT_TOP_SONS "(((CorAquat:0.084,CurCitre:0.058):0.103,CorGluta:0.522):0.053,CelBiazo:0.059)"
514 #define B3_TOP_SONS B3_LEFT_TOP_SONS ":0.207,CytAquat:0.711"
515 #define B3_TOP_SONS_CCR "((CorAquat:0.187,CorGluta:0.522):0.053,CelBiazo:0.059):0.207,CytAquat:0.711" // CCR = CurCitre removed
516 #define B3_TOP "(" B3_TOP_SONS "):0.081"
517 #define B3_BOT "(CytAquat:0.711,(CelBiazo:0.059,(CorGluta:0.522,(CorAquat:0.084,CurCitre:0.058):0.103):0.053):0.207):0.081"
520 const char *top_topo =
"((" B1_TOP
"," B2_TOP
"):0.081," B3_TOP
");";
521 const char *edge_topo =
"((" B1_TOP
"," B2_BOT
"):0.081," B3_BOT
");";
522 const char *bottom_topo =
"(" B3_BOT
",(" B2_BOT
"," B1_BOT
"):0.081);";
524 const char *radial_topo =
525 "(((CloPaste:0.179,((CloButy2:0.009,CloButyr:0.000):0.564,CloCarni:0.120):0.010):0.131,"
526 "((CloInnoc:0.371,((CloTyro2:0.017,(CloTyro3:1.046,CloTyro4:0.061):0.026):0.017,CloTyrob:0.009):0.274):0.057,CloBifer:0.388):0.124):0.081,"
527 "((CelBiazo:0.059,((CorAquat:0.084,CurCitre:0.058):0.103,CorGluta:0.522):0.053):0.207,CytAquat:0.711):0.081);";
528 const char *radial_topo2 =
529 "(((CloBifer:0.388,(CloInnoc:0.371,(((CloTyro3:1.046,CloTyro4:0.061):0.026,CloTyro2:0.017):0.017,CloTyrob:0.009):0.274):0.057):0.124," B2_TOP
"):0.081,"
530 "(CytAquat:0.711," B3_LEFT_TOP_SONS
":0.207):0.081);";
559 AP_tree_nlen *CloTyrob = root->findLeafNamed(
"CloTyrob");
567 const char *rootAtCloTyrob_topo =
569 "(((CloTyro3:1.046,CloTyro4:0.061):0.026,CloTyro2:0.017):0.017,"
570 "((((" B3_TOP_SONS
"):0.162," B2_TOP
"):0.124,CloBifer:0.388):0.057,CloInnoc:0.371):0.274):0.004);";
577 AP_tree_nlen *CelBiazoFather = root->findLeafNamed(
"CelBiazo")->get_father();
579 CelBiazoFather->set_root();
581 const char *rootAtCelBiazoFather_topo =
"(" B3_LEFT_TOP_SONS
":0.104,((" B1_TOP
"," B2_TOP
"):0.162,CytAquat:0.711):0.104);";
587 DOWNCAST(AP_tree_nlen*,oldRootEdge.son())->set_root();
589 const char *rootSetBack_topo = top_topo;
596 AP_tree_nlen *CurCitre = root->findLeafNamed(
"CurCitre");
601 const char *CurCitre_removed_topo =
"((" B1_TOP
"," B2_TOP
"):0.081,(" B3_TOP_SONS_CCR
"):0.081);";
609 root->compute_tree();
617 AP_tree_nlen *CloCarni = root->findLeafNamed(
"CloCarni");
619 CurCitre->insert(CloCarni);
621 const char *CurCitre_inserted_topo =
"((" B1_TOP
",(((CloButy2:0.009,CloButyr:0.000):0.564,(CurCitre:0.060,CloCarni:0.060):0.060):0.010,CloPaste:0.179):0.131):0.081,(" B3_TOP_SONS_CCR
"):0.081);";
636 void TEST_calc_bootstraps() {
640 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));";
641 const char *bs_limit_topo =
"(((((((CloTyro3,CloTyro4)'87%',CloTyro2)'0%',CloTyrob)'100%',CloInnoc)'87%',CloBifer)'83%',(((CloButy2,CloButyr)'99%',CloCarni)'17%',CloPaste)'56%')'61%',((((CorAquat,CurCitre)'78%',CorGluta)'0%',CelBiazo)'59%',CytAquat)'61%');";
642 const char *bs_estim_topo =
"(((((((CloTyro3,CloTyro4)'75%',CloTyro2)'0%',CloTyrob)'100%',CloInnoc)'75%',CloBifer)'78%',(((CloButy2,CloButyr)'99%',CloCarni)'13%',CloPaste)'32%')'53%',((((CorAquat,CurCitre)'74%',CorGluta)'0%',CelBiazo)'56%',CytAquat)'53%');";
645 AP_tree_nlen *root = env.root_node();
669 void TEST_tree_remove_add_all() {
675 AP_tree_nlen *leaf[LEAFS];
676 const char *name[LEAFS] = {
685 AP_tree_nlen *root = env.root_node();
687 for (
int i = 0; i<LEAFS; ++i) {
688 leaf[i] = root->findLeafNamed(name[i]);
694 AP_pars_root *troot = leaf[0]->get_tree_root();
697 for (
int i = 0; i<LEAFS-1; ++i) {
706 leaf[0]->initial_insert(leaf[1], troot);
707 for (
int i = 2; i<LEAFS; ++i) {
710 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)