#include "sharedthetayc.h"
#include "sharedthetan.h"
#include "sharedmorisitahorn.h"
+#include "sharedbraycurtis.h"
//**********************************************************************************************************************
treeCalculators.push_back(new ThetaN());
}else if (globaldata->Estimators[i] == "morisitahorn") {
treeCalculators.push_back(new MorHorn());
+ }else if (globaldata->Estimators[i] == "braycurtis") {
+ treeCalculators.push_back(new BrayCurtis());
}
}
}
#include "sharedbraycurtis.h"
/***********************************************************************/
-//This is used by SharedJAbund and SharedSorAbund
+
EstOutput BrayCurtis::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
try {
- EstOutput data;
data.resize(1,0);
int sumSharedA, sumSharedB, sumSharedAB, tempA, tempB;
sumSharedA = 0; sumSharedB = 0; sumSharedAB = 0;
/*Xi, Yi = abundance of the ith shared OTU in A and B
- sumSharedA = the sum of all shared otus in A
+ sumSharedA = the number of otus in A
sumSharedB = the sum of all shared otus in B
sumSharedAB = the sum of the minimum otus int all shared otus in AB.
*/
//store in temps to avoid multiple repetitive function calls
tempA = shared1->getAbundance(i);
tempB = shared2->getAbundance(i);
-
- if ((tempA != 0) && (tempB != 0)) {//they are shared
- sumSharedA += tempA;
- sumSharedB += tempB;
+ sumSharedA += tempA;
+ sumSharedB += tempB;
- //sum the min of tempA and tempB
- if (tempA < tempB) { sumSharedAB += tempA; }
- else { sumSharedAB += tempB; }
- }
+ //sum the min of tempA and tempB
+ if (tempA < tempB) { sumSharedAB += tempA; }
+ else { sumSharedAB += tempB; }
}
data[0] = (2 * sumSharedAB) / (float)( sumSharedA + sumSharedB);
tempA = shared1->getAbundance(j);
tempB = shared2->getAbundance(j);
- //they are shared
- if ((tempA != 0) && (tempB != 0)) {
- if (Atotal != 0) { sumSharedA = (tempA / (float)Atotal); }
- if (Btotal != 0) { sumSharedB = (tempB / (float)Btotal); }
-
- a += sumSharedA * sumSharedA;
- b += sumSharedB * sumSharedB;
- d += sumSharedA * sumSharedB;
- }
+ a += tempA * tempA;
+ b += tempB * tempB;
+ d += tempA * tempB;
}
- morhorn = (2 * d) / (float) (a + b);
+ a /= double(Atotal * Atotal);
+ b /= double(Btotal * Btotal);
+ d /= double(Atotal * Btotal);
+
+ morhorn = (2 * d) / (a + b);
if (isnan(morhorn) || isinf(morhorn)) { morhorn = 0; }
try {
data.resize(1,0);
- int Atotal, Btotal, tempA, tempB;
- Atotal = 0; Btotal = 0;
- float thetaYC, sumSharedA, sumSharedB, a, b, d;
- thetaYC = 0.0; sumSharedA = 0.0; sumSharedB = 0.0; a = 0.0; b = 0.0; d = 0.0;
+ int Atotal = 0;
+ int Btotal = 0;
+ float thetaYC = 0;
+ float relA = 0;
+ float relB = 0;
+ float a = 0;
+ float b = 0;
//get the total values we need to calculate the theta denominator sums
for (int i = 0; i < shared1->size(); i++) {
//calculate the theta denominator sums
for (int j = 0; j < shared1->size(); j++) {
//store in temps to avoid multiple repetitive function calls
- tempA = shared1->getAbundance(j);
- tempB = shared2->getAbundance(j);
-
- //they are shared
- if ((tempA != 0) && (tempB != 0)) {
- if (Atotal != 0) { sumSharedA = (tempA / (float)Atotal); }
- if (Btotal != 0) { sumSharedB = (tempB / (float)Btotal); }
-
- a += sumSharedA * sumSharedA;
- b += sumSharedB * sumSharedB;
- d += sumSharedA * sumSharedB;
- }
+ relA = shared1->getAbundance(j) / (float)Atotal;
+ relB = shared2->getAbundance(j) / (float)Btotal;
+
+ a += relA * relB;
+ b += pow((relA-relB),2);
}
- thetaYC = d / (float) (a + b - d);
+ thetaYC = a / (float) (b+a);
if (isnan(thetaYC) || isinf(thetaYC)) { thetaYC = 0; }
sumCalculators.push_back(new MorHorn());
}else if (globaldata->Estimators[i] == "braycurtis") {
sumCalculators.push_back(new BrayCurtis());
- }
- else if (globaldata->Estimators[i] == "whittaker") {
+ }else if (globaldata->Estimators[i] == "whittaker") {
sumCalculators.push_back(new Whittaker());
}
#include "sharedthetayc.h"
#include "sharedthetan.h"
#include "sharedmorisitahorn.h"
+#include "sharedbraycurtis.h"
//**********************************************************************************************************************
treeCalculators.push_back(new ThetaN());
}else if (globaldata->Estimators[i] == "morisitahorn") {
treeCalculators.push_back(new MorHorn());
+ }else if (globaldata->Estimators[i] == "braycurtis") {
+ treeCalculators.push_back(new BrayCurtis());
}
}
}
treegroup["thetayc"] = "thetayc";
treegroup["thetan"] = "thetan";
treegroup["morisitahorn"] = "morisitahorn";
+ treegroup["braycurtis"] = "braycurtis";
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialTreeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
boot["thetayc"] = "thetayc";
boot["thetan"] = "thetan";
boot["morisitahorn"] = "morisitahorn";
+ boot["braycurtis"] = "braycurtis";
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialBoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";