numNodes = 2*numLeaves - 1;
tree.resize(numNodes);
-
+
//initialize groupNodeInfo
for (int i = 0; i < globaldata->gTreemap->namesOfGroups.size(); i++) {
groupNodeInfo[globaldata->gTreemap->namesOfGroups[i]].resize(0);
}
-
+
//initialize tree with correct number of nodes, name and group info.
for (int i = 0; i < numNodes; i++) {
//initialize leaf nodes
//save group info
string group = globaldata->gTreemap->getGroup(globaldata->Treenames[i]);
+
vector<string> tempGroups; tempGroups.push_back(group);
tree[i].setGroup(tempGroups);
groupNodeInfo[group].push_back(i);
tree[i].setGroup(tempGroups);
}
}
+
}
catch(exception& e) {
m->errorOut(e, "Tree", "Tree");
copy->tree[i].setParent(grandparent);
copy->tree[i].setBranchLength((copy->tree[i].getBranchLength()+copy->tree[parent].getBranchLength()));
- copy->tree[grandparent].setChildren(grandparentLC, grandparentRC);
+ if (grandparent != -1) {
+ copy->tree[grandparent].setChildren(grandparentLC, grandparentRC);
+ }
removedLeaves.insert(sibIndex);
}
}else{
copy->tree[sibIndex].setParent(grandparent);
copy->tree[sibIndex].setBranchLength((copy->tree[sibIndex].getBranchLength()+copy->tree[parent].getBranchLength()));
- copy->tree[grandparent].setChildren(grandparentLC, grandparentRC);
+ if (grandparent != -1) {
+ copy->tree[grandparent].setChildren(grandparentLC, grandparentRC);
+ }
removedLeaves.insert(i);
}else{
//neither of us are, so we want to eliminate ourselves and our parent
int parentsSibIndex;
if (grandparent != -1) {
int greatgrandparent = copy->tree[grandparent].getParent();
- int greatgrandparentLC = copy->tree[greatgrandparent].getLChild();
- int greatgrandparentRC = copy->tree[greatgrandparent].getRChild();
+ int greatgrandparentLC, greatgrandparentRC;
+ if (greatgrandparent != -1) {
+ greatgrandparentLC = copy->tree[greatgrandparent].getLChild();
+ greatgrandparentRC = copy->tree[greatgrandparent].getRChild();
+ }
int grandparentLC = copy->tree[grandparent].getLChild();
int grandparentRC = copy->tree[grandparent].getRChild();
copy->tree[parentsSibIndex].setParent(greatgrandparent);
copy->tree[parentsSibIndex].setBranchLength((copy->tree[parentsSibIndex].getBranchLength()+copy->tree[grandparent].getBranchLength()));
- copy->tree[greatgrandparent].setChildren(greatgrandparentLC, greatgrandparentRC);
+ if (greatgrandparent != -1) {
+ copy->tree[greatgrandparent].setChildren(greatgrandparentLC, greatgrandparentRC);
+ }
}else{
- copy->tree[parent].setChildren(-1, -1);
- cout << "issues with making subtree" << endl;
+ copy->tree[parent].setParent(-1);
+ //cout << "issues with making subtree" << endl;
}
removedLeaves.insert(sibIndex);
removedLeaves.insert(i);
int nextSpot = numLeaves;
populateNewTree(copy->tree, root, nextSpot);
-
}
catch(exception& e) {
m->errorOut(e, "Tree", "getCopy");