18 #ifndef _GLIBCXX_ALGORITHM
22 #define rt_assert(cond) arb_assert(cond)
24 #if defined(DEBUG) || defined(UNIT_TESTS) // UT_DIFF
25 # define PROVIDE_TREE_STRUCTURE_TESTS
27 #if defined(DEVEL_RALF) && defined(PROVIDE_TREE_STRUCTURE_TESTS)
28 # define AUTO_CHECK_TREE_STRUCTURE // Note: dramatically slows down most tree operations
49 #define DEFINE_READ_ACCESSORS(TYPE, ACCESS, MEMBER) \
50 TYPE ACCESS() { return MEMBER; } \
51 const TYPE ACCESS() const { return MEMBER; }
56 bool seenBootstrapDuringLoad;
69 deleteWithNodes(deleteWithNodes_),
70 seenBootstrapDuringLoad(
false)
95 if (deleteWithNodes) {
102 return seenBootstrapDuringLoad;
105 seenBootstrapDuringLoad = seen;
123 const char *end =
NULp;
124 bootstrap = strtod(remark, (
char**)&end);
126 bool is_bootstrap = end[0] ==
'%' && end[1] == 0;
147 const char *end =
NULp;
148 bootstrap = strtod(label, (
char**)&end);
150 bool is_bootstrap = end !=
label;
154 bootstrap = bootstrap/100.0;
156 is_bootstrap = end[0] ==
':' || !end[0];
159 case ':': label = end+1;
break;
160 case 0: label =
NULp;
break;
161 default: is_bootstrap =
false;
break;
168 #define KEELED_INDICATOR '!' // prefixed to names of "keeled groups" (not meant to be changed)
181 SmartCharPtr remark_branch;
186 const GBT_LEN& length_ref()
const {
return const_cast<TreeNode*
>(
this)->length_ref(); }
203 if (father->keeledOver) {
225 return father == Father &&
231 return father->
leftson ==
this;
239 return this == subtree || (father &&
get_father()->is_inside(subtree));
262 length_ref() = newlen;
304 return parse_remark(remark_branch.content(), bootstrap);
309 return remark_branch.content();
313 return remark_branch;
318 remark_branch = newRemark;
330 #if defined(ASSERTION_USED) || defined(PROVIDE_TREE_STRUCTURE_TESTS)
351 return !father || !father->
father;
355 rt_assert(tree_root->get_root_node() ==
this);
358 root->TreeRoot::change_root(
this,
NULp);
376 #if defined(ASSERTION_USED)
386 leftlen(0.0), rightlen(0.0),
424 if (!tree_root)
return NULp;
426 const TreeNode *root = tree_root->get_root_node();
446 return gb_node &&
name;
449 return (
has_group_info() && keeledOver) ? (inverseLeft ? get_leftson() : get_rightson()) :
NULp;
463 return keeledOver ? (inverseLeft ? 1 : 2) : 0;
466 keeledOver = keeledState;
467 inverseLeft = keeledState == 1;
499 if (!skipKeeledBrothers)
break;
502 if (!keeled || keeled == child)
break;
507 parent = child->get_father();
558 inverseLeft = !inverseLeft;
578 : bootstrap(bootstrap_),
579 branchlength(branchlength_),
580 applyAtLeafs(applyAtLeafs_)
583 class LengthCollector;
590 void eliminate_and_collect(
const multifurc_limits& below, LengthCollector& collect);
593 #if defined(PROVIDE_TREE_STRUCTURE_TESTS)
595 #endif // PROVIDE_TREE_STRUCTURE_TESTS
610 #define DEFINE_TREE_ROOT_ACCESSORS(RootType, TreeType) \
611 DEFINE_DOWNCAST_ACCESSORS(TreeType, get_root_node, TreeRoot::get_root_node())
613 #define DEFINE_TREE_RELATIVES_ACCESSORS(TreeType) \
614 DEFINE_DOWNCAST_ACCESSORS(TreeType, get_father, father); \
615 DEFINE_DOWNCAST_ACCESSORS(TreeType, get_leftson, leftson); \
616 DEFINE_DOWNCAST_ACCESSORS(TreeType, get_rightson, rightson); \
617 DEFINE_DOWNCAST_ACCESSORS(TreeType, get_brother, TreeNode::get_brother()); \
618 DEFINE_DOWNCAST_ACCESSORS(TreeType, get_root_node, TreeNode::get_root_node()); \
619 TreeType *findLeafNamed(const char *wantedName) { return DOWNCAST(TreeType*, TreeNode::findLeafNamed(wantedName)); }
621 #define DEFINE_TREE_ACCESSORS(RootType, TreeType) \
622 DEFINE_DOWNCAST_ACCESSORS(RootType, get_tree_root, TreeNode::get_tree_root()); \
623 DEFINE_TREE_RELATIVES_ACCESSORS(TreeType)
629 #if defined(PROVIDE_TREE_STRUCTURE_TESTS)
630 template <
typename TREE>
631 inline Validity tree_is_valid(
const TREE *
tree,
bool acceptNULL) {
632 if (tree)
return tree->is_valid();
633 return Validity(acceptNULL,
"NULp tree");
635 template <
typename TREE>
636 inline bool tree_is_valid_or_dump(
const TREE *
tree,
bool acceptNULL) {
638 if (!valid) fprintf(stderr,
"\ntree is NOT valid (Reason: %s)\n", valid.
why_not());
643 #if defined(AUTO_CHECK_TREE_STRUCTURE)
644 #define ASSERT_VALID_TREE(tree) rt_assert(tree_is_valid_or_dump(tree, false))
645 #define ASSERT_VALID_TREE_OR_NULL(tree) rt_assert(tree_is_valid_or_dump(tree, true))
647 #define ASSERT_VALID_TREE(tree)
648 #define ASSERT_VALID_TREE_OR_NULL(tree)
649 #endif // AUTO_CHECK_TREE_STRUCTURE
651 #if defined(PROVIDE_TREE_STRUCTURE_TESTS) && defined(UNIT_TESTS)
653 #define TEST_EXPECT_VALID_TREE(tree) TEST_VALIDITY(tree_is_valid(tree, false))
654 #define TEST_EXPECT_VALID_TREE_OR_NULL(tree) TEST_VALIDITY(tree_is_valid(tree, true))
655 #define TEST_EXPECT_VALID_TREE__BROKEN(tree,why) TEST_VALIDITY__BROKEN(tree_is_valid(tree, false), why)
656 #define TEST_EXPECT_VALID_TREE_OR_NULL__BROKEN(tree,why) TEST_VALIDITY__BROKEN(tree_is_valid(tree, true), why)
660 #define TEST_EXPECT_VALID_TREE(tree)
661 #define TEST_EXPECT_VALID_TREE_OR_NULL(tree)
662 #define TEST_EXPECT_VALID_TREE__BROKEN(tree)
663 #define TEST_EXPECT_VALID_TREE_OR_NULL__BROKEN(tree)
724 GBT_LEN adjacent_distance()
const;
725 GBT_LEN length_or_adjacent_distance()
const {
728 if (len>0.0)
return len;
730 return adjacent_distance();
739 #if defined(UNIT_TESTS) // UT_DIFF
740 friend void TEST_edges();
757 from(otherEdge.from),
808 TreeNode *father = to->get_father();
819 TreeNode *father = from->get_father();
831 TreeNode *father = to->get_father();
842 TreeNode *father = from->get_father();
858 return from == otherEdge.from && to == otherEdge.to;
887 TreeNode *father = son->get_father();
899 TreeNode *root_node = root->get_root_node();
904 #error TreeNode.h included twice
ARB_edge(const ARB_edge &otherEdge)
void set_bootstrap(double bootstrap)
void set_branchlength_unrooted(GBT_LEN newlen)
void compute_tree() OVERRIDE
DECLARE_ASSIGNMENT_OPERATOR(ARB_edge)
ARB_edge(TreeNode *From, TreeNode *To)
void destroyNode(TreeNode *node) const OVERRIDE
void virtually_distribute_length(GBT_LEN len, TreeNode::LengthCollector &collect) const
void bootstrap2branchlen()
bool operator==(const ARB_edge &otherEdge) const
TreeNode * makeNode() const OVERRIDE
GBT_RemarkType parse_bootstrap(double &bootstrap) const
#define implicated(hypothesis, conclusion)
TreeNode * findLeafNamed(const char *wantedName)
MARK_NONFINAL_METHOD(TreeRoot, change_root,(TreeNode *, TreeNode *))
int calc_clade_level() const
const TreeNode * get_root_node() const
TreeNode * find_parent_clade()
bool has_group_info() const
void unlink_from_father()
const char * why_not() const
GBT_LEN get_branchlength_unrooted() const
virtual void compute_tree()=0
bool is_edge_from_leaf() const
ARB_edge_type get_type() const
void setKeeledState(int keeledState)
TreeRoot * get_tree_root() const
GBT_LEN reset_length_and_bootstrap()
TreeNode * ancestor_common_with(TreeNode *other)
ARB_edge previous() const
bool operator!=(const ARB_edge &otherEdge) const
const TreeNode * find_parent_with_groupInfo(bool skipKeeledBrothers=false) const
ARB_edge rootEdge(TreeRoot *root)
void use_as_remark(const SmartCharPtr &newRemark)
multifurc_limits(double bootstrap_, double branchlength_, bool applyAtLeafs_)
void destroy(TreeRoot *viaRoot)
bool keelsDownGroup(const TreeNode *toSon) const
void reset_branchlengths()
#define DOWNCAST(totype, expr)
SimpleTree(SimpleRoot *sroot)
bool has_valid_root_remarks() const
ARB_edge parentEdge(TreeNode *son)
GBT_RemarkType parse_remark(const char *remark, double &bootstrap)
const TreeNode * get_brother() const
POS_TREE1 * get_father() const
void branchlen2bootstrap()
ARB_edge(TreeNode *From, TreeNode *To, ARB_edge_type Type)
static void destroy(TreeNode *that, TreeRoot *root)
const TreeNode * keelTarget() const
bool in_other_branch_than(const TreeNode *other) const
bool is_son_of_root() const
const TreeNode * ancestor_common_with(const TreeNode *other) const
virtual TreeNode * makeNode() const =0
void swap_node_info(TreeNode *other, bool ofKeeledGroups)
bool parse_treelabel(const char *&label, double &bootstrap)
int keeledStateInfo() const
CONSTEXPR_INLINE int leafs_2_edges(int leafs, TreeModel model)
ARB_edge leafEdge(TreeNode *leaf)
DEFINE_READ_ACCESSORS(TreeNode *, get_father, father)
bool is_root_node() const
CONSTEXPR_INLINE_Cxx14 void swap(unsigned char &c1, unsigned char &c2)
bool is_keeled_group() const
bool in_same_branch_as(const TreeNode *other) const
TreeNode * get_root_node()
ARB_edge counter_previous() const
static void destroy(TreeNode *that)
void multifurcate_whole_tree(const multifurc_limits &below)
virtual unsigned get_leaf_count() const =0
bool is_son_of(const TreeNode *Father) const
CONSTEXPR_INLINE bool valid(SpeciesCreationMode m)
TreeRoot(bool deleteWithNodes_)
TreeNode * find_parent_with_groupInfo(bool skipKeeledBrothers=false)
bool is_ancestor_of(const TreeNode *descendant) const
void reorder_tree(TreeOrder mode)
bool knownNonNull(const void *nonnull)
GBT_LEN root_distance() const
bool has_no_remark() const
bool has_bootstrap() const
bool is_edge_to_leaf() const
void set_branchlength_preserving(GBT_LEN new_len)
TreeNode * fixDeletedSon()
GBT_LEN intree_distance_to(const TreeNode *other) const
bool is_inner_node_with_remark() const
bool is_inside(const TreeNode *subtree) const
DEFINE_READ_ACCESSORS(TreeNode *, get_root_node, rootNode)
void announce_tree_constructed()
void fixKeeledOrientation()
void scale_branchlengths(double factor)
void set_branchlength(GBT_LEN newlen)
void set_tree_root(TreeRoot *new_root)
void set_remark(const char *newRemark)
GBT_LEN sum_child_lengths() const
ARB_edge counter_next() const
bool is_inner_edge() const
GB_ERROR apply_aci_to_remarks(const char *aci, const GBL_call_env &callEnv)
ARB_edge find_innermost_edge()
GBT_LEN get_branchlength() const
virtual void destroyNode(TreeNode *node) const =0
void destroy(TreeNode *that)
virtual void change_root(TreeNode *old, TreeNode *newroot)
void set_length(GBT_LEN len)
const char * get_remark() const
const TreeNode * find_parent_clade() const
const SmartCharPtr & get_remark_ptr() const
void set_bootstrap_seen(bool seen)
const char * get_group_name() const
unsigned get_leaf_count() const OVERRIDE
bool is_normal_group() const
char * GBS_global_string_copy(const char *templat,...)
TreeNode * source() const
static int iteration_count(int leafs_in_tree)