55 double midpointDist = 0.0;
58 double dToNewParent = 0, dToNewChild = 0;
67 if (oldTree.
size() == 0) {
78 midpointDist = dmax/2.0;
80 while (cursor1.
is_valid() && dToEnd1 < midpointDist) {
81 dToEnd1 += cursor1->distance;
83 cursor1 = tmpTree.
parent(cursor2);
93 item =
SeqItem(
"New Root", -1, dToEnd1-midpointDist);
96 if (dToEnd1 == midpointDist) {
97 newTreeRoot = cursor1;
98 cursor1 = tmpTree.
parent(newTreeRoot);
108 cursor2 = newTreeRoot;
109 dToNewParent = cursor2->distance;
110 cursor2->distance = 0.0;
116 dToNewChild = cursor1->distance;
117 cursor1->distance = dToNewParent;
118 dToNewParent = dToNewChild;
120 cursor1 = tmpTree.
parent(cursor2);
125 tmpTreeCursor = cursor2.
begin();
126 while (tmpTreeCursor != tmpSibling) {
129 tmpTreeCursor->distance += cursor2->distance;
151 if (nTopLevelNodes == 2) {
157 cursor1 = tmpTree.
end();
160 cursor1->distance += dToNewParent;
161 }
else if (nTopLevelNodes > 2) {
163 dToNewChild = cursor2->distance;
169 if (nTopLevelNodes > 2) {
174 newTreeCursor =
newTree.begin();
175 while (!found && newTreeCursor !=
newTree.end()) {
176 if (*newTreeCursor == item) {
177 sit = newTreeCursor.
begin();
178 while (sit != newTreeCursor.
end()) {
179 if (*sit == nullItem) {
180 sit->distance = dToNewParent;
185 found = (
count == 1) ?
true :
false;
207 double rootDMax = 0.0, d1 = 0.0, d2 = 0.0;
209 if (atree.
size() < 2) {
237 while (it != atree.
end() && foundCount < 2) {
238 if (rootEnd1.
is_valid() && *it == *rootEnd1) {
241 }
else if (rootEnd2.is_valid() && *it == *rootEnd2) {
249 if (foundCount < 2) {
256 if (
result && rootEnd1 != rootEnd2 && rootDMax > 0) {
277 double localMax, localBranch1, localBranch2;
281 assert(dBranch1 >= dBranch2);
292 double sibDist, testDist;
296 while (
result && sibCursor != cursor.
end()) {
297 sibDist = sibCursor->distance;
303 result =
GetMaxPath(sibCursor, localMax, localBranch1, localEnd1, localBranch2, localEnd2);
305 testDist = localBranch1 + sibDist + dBranch1;
307 if (localMax > dMax && localMax > testDist) {
312 dBranch1 = localBranch1 + sibDist;
313 dBranch2 = localBranch2 + sibDist;
315 }
else if (testDist >= localMax && testDist > dMax) {
318 if (localBranch1 + sibDist > dBranch1) {
322 dBranch1 = localBranch1 + sibDist;
325 dBranch2 = localBranch1 + sibDist;
328 }
else if (dMax >= localMax && dMax >= testDist) {
static const Rootedness DEF_ROOTED
bool useMidpointRooting()
void midpointRootIfNeeded()
static const string NO_NAME
sibling_iterator end() const
unsigned int number_of_children() const
sibling_iterator begin() const
pre_order_iterator iterator
sibling_iterator previous_sibling(const iterator_base &) const
sibling_iterator next_sibling(const iterator_base &) const
iter append_child(iter position)
tree reroot(iterator newRoot)
pre_order_iterator begin() const
iter insert(iter position, const T &x)
unsigned int number_of_children(const iterator_base &) const
iter reparent(iter position, sibling_iterator begin, sibling_iterator end)
unsigned int number_of_siblings(const iterator_base &) const
pre_order_iterator end() const
bool GetMaxPath(const SeqTree &atree, double &dMax, SeqTree::iterator &end1, SeqTree::iterator &end2)
void MidpointRootSeqTree(const SeqTree &oldTree, SeqTree &newTree)
const double RESET_WITH_TINY_DISTANCE
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.