+ m->errorOut(e, "SharedChao1", "getValues");
+ exit(1);
+ }
+}
+
+/***********************************************************************/
+//builds trees structure with n leaf nodes initialized to 0.
+void SharedChao1::initialTree(int n) {
+ try {
+ // (2^n) / 2. Divide by 2 because each leaf node contains 2 values. One for + and one for 1 or 2.
+ numLeaves = pow(2, (float)n) / 2;
+ numNodes = 2*numLeaves - 1;
+ int countleft = 0;
+ int countright = 1;
+
+ f1leaves.resize(numNodes);
+ f2leaves.resize(numNodes);
+
+ //initialize leaf values
+ for (int i = 0; i < numLeaves; i++) {
+ f1leaves[i] = new IntNode(0, 0, NULL, NULL);
+ f2leaves[i] = new IntNode(0, 0, NULL, NULL);
+ }
+
+ //set pointers to children
+ for (int j = numLeaves; j < numNodes; j++) {
+ f1leaves[j] = new IntNode();
+ f1leaves[j]->left = f1leaves[countleft];
+ f1leaves[j]->right = f1leaves[countright];
+
+ f2leaves[j] = new IntNode();
+ f2leaves[j]->left = f2leaves[countleft];
+ f2leaves[j]->right =f2leaves[countright];
+
+ countleft = countleft + 2;
+ countright = countright + 2;
+ }
+
+ //point to root
+ f1root = f1leaves[numNodes-1];
+
+ //point to root
+ f2root = f2leaves[numNodes-1];
+
+ //set coeffients
+ setCoef(f2root, 0);
+ }
+ catch(exception& e) {
+ if ((toString(e.what()) == "vector::_M_fill_insert") || (toString(e.what()) == "St9bad_alloc")) { m->mothurOut("You are using " + toString(n) + " groups which creates 2^" + toString(n+1) + " nodes. Try reducing the number of groups you selected. "); m->mothurOutEndLine(); exit(1); }
+ m->errorOut(e, "SharedChao1", "initialTree");
+ exit(1);
+ }
+}
+
+/***********************************************************************/
+//take vector containing the abundance info. for a bin and updates trees.
+void SharedChao1::updateTree(vector<int> bin) {
+ try {
+ updateBranchf1(f1root, bin, 0);
+ updateBranchf2(f2root, bin, 0);
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SharedChao1", "updateTree");
+ exit(1);
+ }
+}
+
+/***********************************************************************/
+void SharedChao1::updateBranchf1(IntNode* node, vector<int> bin, int index) {
+ try {
+ //if you have more than one group
+ if (index == (bin.size()-1)) {
+ if (bin[index] == 1) { node->lvalue++; node->rvalue++; }
+ else { node->rvalue++; }
+ }else {
+ if (bin[index] == 1) {
+ //follow path as if you are 1
+ updateBranchf1(node->left, bin, index+1);
+ }
+ //follow path as if you are +
+ updateBranchf1(node->right, bin, index+1);
+ }
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SharedChao1", "updateBranchf1");