/***********************************************************************/
EstOutput SharedChao1::getValues(vector<SharedRAbundVector*> shared){
try {
- data.resize(1,0);
-
+ data.resize(1,0);
vector<int> temp;
int numGroups = shared.size();
float Chao = 0.0; float leftvalue, rightvalue;
//they are shared
if (sharedByAll == true) {
-
- // cout << "temp = ";
- // for (int h = 0; h < temp.size(); h++) { cout << temp[h] << " "; } cout << endl;
//find f1 and f2values
updateTree(temp);
}
}
- //cout << "Entering " << endl;
//calculate chao1, (numleaves-1) because numleaves contains the ++ values.
- for (int i = 0; i < numLeaves; i++) {
- //divide by zero error
- if (f2leaves[i]->lvalue == 0) { f2leaves[i]->lvalue++; }
- if (f2leaves[i]->rvalue == 0) { f2leaves[i]->rvalue++; }
-
- //cout << "f2 leaves ";
- //cout << f2leaves[i]->lvalue << f2leaves[i]->rvalue << endl;
-
- // cout << "f2 leaf coef ";
- //cout << f2leaves[i]->lcoef << '\t' << f2leaves[i]->rcoef << endl;
-
- // cout << "f1 leaves ";
- // cout << f1leaves[i]->lvalue << f1leaves[i]->rvalue << endl;
-
+ bool bias;
+ for(int i=0;i<numLeaves;i++){
+ if (f2leaves[i]->lvalue == 0) { bias = true;}// break;}
+ }
+
+ if(bias){
+ for (int i = 0; i < numLeaves; i++) {
+
+ leftvalue = (float)(f1leaves[i]->lvalue * (f1leaves[i]->lvalue - 1)) / (float)((pow(2, (float)f2leaves[i]->lcoef)) * (f2leaves[i]->lvalue + 1));
+ if (i != (numLeaves-1)) {
+ rightvalue = (float)(f1leaves[i]->rvalue * (f1leaves[i]->rvalue - 1)) / (float)((pow(2, (float)f2leaves[i]->rcoef)) * (f2leaves[i]->rvalue + 1));
+ }else{
+ rightvalue = (float)(f1leaves[i]->rvalue);
+ }
+ Chao += leftvalue + rightvalue;
+ }
+ }
+ else{
- leftvalue = (float)(f1leaves[i]->lvalue * f1leaves[i]->lvalue) / (float)((pow(2, (float)f2leaves[i]->lcoef)) * f2leaves[i]->lvalue);
- if (i != (numLeaves-1)) {
- rightvalue = (float)(f1leaves[i]->rvalue * f1leaves[i]->rvalue) / (float)((pow(2, (float)f2leaves[i]->rcoef)) * f2leaves[i]->rvalue);
- }else{
- rightvalue = (float)(f1leaves[i]->rvalue);
+ for (int i = 0; i < numLeaves; i++) {
+
+ leftvalue = (float)(f1leaves[i]->lvalue * f1leaves[i]->lvalue) / (float)((pow(2, (float)f2leaves[i]->lcoef)) * f2leaves[i]->lvalue);
+ if (i != (numLeaves-1)) {
+ rightvalue = (float)(f1leaves[i]->rvalue * f1leaves[i]->rvalue) / (float)((pow(2, (float)f2leaves[i]->rcoef)) * f2leaves[i]->rvalue);
+ }else{
+ rightvalue = (float)(f1leaves[i]->rvalue);
+ }
+ Chao += leftvalue + rightvalue;
}
- //cout << "left = " << leftvalue << " right = " << rightvalue << endl;
- Chao += leftvalue + rightvalue;
}
for (int i = 0; i < numNodes; i++) {
delete f2leaves[i];
}
- // cout << "exiting " << endl;
+
data[0] = Chao;
return data;
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedChao1 class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ errorOut(e, "SharedChao1", "getValues");
exit(1);
}
- catch(...) {
- cout << "An unknown error has occurred in the SharedChao1 class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
}
/***********************************************************************/
setCoef(f2root, 0);
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedChao1 class Function initialTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ errorOut(e, "SharedChao1", "initialTree");
exit(1);
}
- catch(...) {
- cout << "An unknown error has occurred in the SharedChao1 class function initialTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
}
/***********************************************************************/
updateBranchf2(f2root, bin, 0);
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedChao1 class Function updateTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ errorOut(e, "SharedChao1", "updateTree");
exit(1);
}
- catch(...) {
- cout << "An unknown error has occurred in the SharedChao1 class function updateTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
}
/***********************************************************************/
}
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedChao1 class Function updateBranchf1. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ errorOut(e, "SharedChao1", "updateBranchf1");
exit(1);
}
- catch(...) {
- cout << "An unknown error has occurred in the SharedChao1 class function updateBranchf1. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
}
/***********************************************************************/
}
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedChao1 class Function updateBranchf2. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ errorOut(e, "SharedChao1", "updateBranchf2");
exit(1);
}
- catch(...) {
- cout << "An unknown error has occurred in the SharedChao1 class function updateBranchf2. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
}
/***********************************************************************/
}
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SharedChao1 class Function getCoef. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ errorOut(e, "SharedChao1", "setCoef");
exit(1);
}
- catch(...) {
- cout << "An unknown error has occurred in the SharedChao1 class function getCoef. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
}
/***********************************************************************/
//for debugging purposes
void SharedChao1::printTree() {
- cout << "F1 leaves" << endl;
+ mothurOut("F1 leaves"); mothurOutEndLine();
printBranch(f1root);
- cout << "F2 leaves" << endl;
+ mothurOut("F2 leaves"); mothurOutEndLine();
printBranch(f2root);
printBranch(node->left);
printBranch(node->right);
}else { //you are a leaf
- cout << node->lvalue << endl;
- cout << node->rvalue << endl;
+ mothurOut(toString(node->lvalue)); mothurOutEndLine();
+ mothurOut(toString(node->rvalue)); mothurOutEndLine();
}
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function printBranch. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ errorOut(e, "SharedChao1", "printBranch");
exit(1);
}
- catch(...) {
- cout << "An unknown error has occurred in the Tree class function printBranch. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
}
/*****************************************************************/