X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=sharedchao1.cpp;h=8d47ad2fca1d307bd150a985224b1099e492626a;hp=cbb519241bd98e85823ef1fc25f33701dbeb84e9;hb=050a3ff02473a3d4c0980964e1a9ebe52e55d6b8;hpb=9a339a6b007b23c39b7eb20cc777af66dd2cebef diff --git a/sharedchao1.cpp b/sharedchao1.cpp index cbb5192..8d47ad2 100644 --- a/sharedchao1.cpp +++ b/sharedchao1.cpp @@ -27,10 +27,9 @@ EstOutput SharedChao1::getValues(vector shared){ // the coeffient is 2. Note: we only set the coeffient in f2 values. //create and initialize trees to 0. - initialTree(numGroups); + initialTree(numGroups); - - for (int i = 0; i < shared[0]->size(); i++) { + for (int i = 0; i < shared[0]->getNumBins(); i++) { //get bin values and calc shared bool sharedByAll = true; temp.clear(); @@ -46,9 +45,9 @@ EstOutput SharedChao1::getValues(vector shared){ } } - + //calculate chao1, (numleaves-1) because numleaves contains the ++ values. - bool bias; + bool bias = false; for(int i=0;ilvalue == 0 || f2leaves[i]->rvalue == 0) { bias = true;}// break;} } @@ -91,7 +90,7 @@ EstOutput SharedChao1::getValues(vector shared){ return data; } catch(exception& e) { - errorOut(e, "SharedChao1", "getValues"); + m->errorOut(e, "SharedChao1", "getValues"); exit(1); } } @@ -108,39 +107,30 @@ void SharedChao1::initialTree(int n) { f1leaves.resize(numNodes); f2leaves.resize(numNodes); - + //initialize leaf values for (int i = 0; i < numLeaves; i++) { - f1leaves[i] = new IntNode; - f1leaves[i]->lvalue = 0; - f1leaves[i]->rvalue = 0; - f1leaves[i]->left = NULL; - f1leaves[i]->right = NULL; - - f2leaves[i] = new IntNode; - f2leaves[i]->lvalue = 0; - f2leaves[i]->rvalue = 0; - f2leaves[i]->left = NULL; - f2leaves[i]->right = NULL; + 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] = new IntNode(); f1leaves[j]->left = f1leaves[countleft]; f1leaves[j]->right = f1leaves[countright]; - f2leaves[j] = new IntNode; + 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]; @@ -148,7 +138,8 @@ void SharedChao1::initialTree(int n) { setCoef(f2root, 0); } catch(exception& e) { - errorOut(e, "SharedChao1", "initialTree"); + 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); } } @@ -161,7 +152,7 @@ void SharedChao1::updateTree(vector bin) { updateBranchf2(f2root, bin, 0); } catch(exception& e) { - errorOut(e, "SharedChao1", "updateTree"); + m->errorOut(e, "SharedChao1", "updateTree"); exit(1); } } @@ -183,7 +174,7 @@ void SharedChao1::updateBranchf1(IntNode* node, vector bin, int index) { } } catch(exception& e) { - errorOut(e, "SharedChao1", "updateBranchf1"); + m->errorOut(e, "SharedChao1", "updateBranchf1"); exit(1); } } @@ -205,7 +196,7 @@ void SharedChao1::updateBranchf2(IntNode* node, vector bin, int index) { } } catch(exception& e) { - errorOut(e, "SharedChao1", "updateBranchf2"); + m->errorOut(e, "SharedChao1", "updateBranchf2"); exit(1); } } @@ -222,7 +213,7 @@ void SharedChao1::setCoef(IntNode* node, int coef) { } } catch(exception& e) { - errorOut(e, "SharedChao1", "setCoef"); + m->errorOut(e, "SharedChao1", "setCoef"); exit(1); } } @@ -231,10 +222,10 @@ void SharedChao1::setCoef(IntNode* node, int coef) { //for debugging purposes void SharedChao1::printTree() { - mothurOut("F1 leaves"); mothurOutEndLine(); + m->mothurOut("F1 leaves"); m->mothurOutEndLine(); printBranch(f1root); - mothurOut("F2 leaves"); mothurOutEndLine(); + m->mothurOut("F2 leaves"); m->mothurOutEndLine(); printBranch(f2root); @@ -248,13 +239,13 @@ void SharedChao1::printBranch(IntNode* node) { printBranch(node->left); printBranch(node->right); }else { //you are a leaf - mothurOut(toString(node->lvalue)); mothurOutEndLine(); - mothurOut(toString(node->rvalue)); mothurOutEndLine(); + m->mothurOut(toString(node->lvalue)); m->mothurOutEndLine(); + m->mothurOut(toString(node->rvalue)); m->mothurOutEndLine(); } } catch(exception& e) { - errorOut(e, "SharedChao1", "printBranch"); + m->errorOut(e, "SharedChao1", "printBranch"); exit(1); } }