+map<string,int> Tree::mergeGcounts(int position) {
+ try{
+ map<string,int>::iterator pos;
+
+ int lc = tree[position].getLChild();
+ int rc = tree[position].getRChild();
+
+ map<string,int> sum = tree[lc].pcount;
+
+ for(it=tree[rc].pcount.begin();it!=tree[rc].pcount.end();it++){
+ sum[it->first] += it->second;
+ }
+ return sum;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function mergeGcounts. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the Tree class function mergeGcounts. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+
+void Tree::randomLabels() {
+ try {
+ for(int i=numLeaves-1;i>=0;i--){
+ if(tree[i].pGroups.size() == 0){
+ continue;
+ }
+
+ int escape = 1;
+ int z;
+
+ while(escape == 1){
+ z = int((float)(i+1) * (float)(rand()) / ((float)RAND_MAX+1.0));
+
+ if(tree[z].pGroups.size() != 0){
+ escape = 0;
+ }
+ }
+
+
+ map<string,int> lib_hold = tree[z].pGroups;
+ tree[z].pGroups = (tree[i].pGroups);
+ tree[i].pGroups = (lib_hold);
+
+ tree[z].setGroup(tree[z].pGroups.begin()->first);
+ tree[i].setGroup(tree[i].pGroups.begin()->first);
+
+ map<string,int> gcount_hold = tree[z].pcount;
+ tree[z].pcount = (tree[i].pcount);
+ tree[i].pcount = (gcount_hold);
+ }
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function randomLabels. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the Tree class function randomLabels. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+
+void Tree::randomBlengths() {
+ try {
+ for(int i=numNodes-1;i>=0;i--){
+ int z = int((float)(i+1) * (float)(rand()) / ((float)RAND_MAX+1.0));
+
+ float bl_hold = tree[z].getBranchLength();
+ tree[z].setBranchLength(tree[i].getBranchLength());
+ tree[i].setBranchLength(bl_hold);
+ }
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function randomBlengths. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the Tree class function randomBlengths. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/*************************************************************************************************/
+void Tree::assembleRandomUnifracTree() {
+ randomLabels();
+ assembleTree();
+}
+
+/*************************************************************************************************/
+//for now it's just random topology but may become random labels as well later that why this is such a simple function now...
+void Tree::assembleRandomTree() {
+ randomTopology();
+ assembleTree();
+}
+/**************************************************************************************************/
+
+void Tree::randomTopology() {
+ try {
+ for(int i=0;i<numNodes;i++){
+ tree[i].setParent(-1);
+ }
+ for(int i=numLeaves;i<numNodes;i++){
+ tree[i].setChildren(-1, -1);
+ }
+
+ for(int i=numLeaves;i<numNodes;i++){
+ int escape =0;
+ int rnd_index1, rnd_index2;
+ while(escape == 0){
+ rnd_index1 = (int)(((double)rand() / (double) RAND_MAX)*i);
+ if(tree[rnd_index1].getParent() == -1){escape = 1;}
+ }
+
+ escape = 0;
+ while(escape == 0){
+ rnd_index2 = (int)(((double)rand() / (double) RAND_MAX)*i);
+ if(rnd_index2 != rnd_index1 && tree[rnd_index2].getParent() == -1){
+ escape = 1;
+ }
+ }
+
+ tree[i].setChildren(rnd_index1,rnd_index2);
+ tree[i].setParent(-1);
+ tree[rnd_index1].setParent(i);
+ tree[rnd_index2].setParent(i);
+ }
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function randomTopology. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the Tree class function randomTopology. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}