From fd00cd216d3a38ccea22eae258e601df64218b05 Mon Sep 17 00:00:00 2001 From: pschloss Date: Fri, 24 Apr 2009 21:58:56 +0000 Subject: [PATCH] This is mothur v 1.2.0 - the April ~24, 2009 release --- bootstrapsharedcommand.cpp | 3 +++ sharedbraycurtis.cpp | 18 +++++++----------- sharedmorisitahorn.cpp | 18 ++++++++---------- sharedthetayc.cpp | 30 +++++++++++++----------------- summarysharedcommand.cpp | 3 +-- treegroupscommand.cpp | 3 +++ validcalculator.cpp | 2 ++ 7 files changed, 37 insertions(+), 40 deletions(-) diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index 5c2e171..9051dd8 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -17,6 +17,7 @@ #include "sharedthetayc.h" #include "sharedthetan.h" #include "sharedmorisitahorn.h" +#include "sharedbraycurtis.h" //********************************************************************************************************************** @@ -51,6 +52,8 @@ BootSharedCommand::BootSharedCommand(){ 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()); } } } diff --git a/sharedbraycurtis.cpp b/sharedbraycurtis.cpp index 0f29b23..d1b401e 100644 --- a/sharedbraycurtis.cpp +++ b/sharedbraycurtis.cpp @@ -10,17 +10,16 @@ #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. */ @@ -29,16 +28,13 @@ EstOutput BrayCurtis::getValues(SharedRAbundVector* shared1, SharedRAbundVector* //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); diff --git a/sharedmorisitahorn.cpp b/sharedmorisitahorn.cpp index 579f56a..8c5cf92 100644 --- a/sharedmorisitahorn.cpp +++ b/sharedmorisitahorn.cpp @@ -32,18 +32,16 @@ EstOutput MorHorn::getValues(SharedRAbundVector* shared1, SharedRAbundVector* sh 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; } diff --git a/sharedthetayc.cpp b/sharedthetayc.cpp index 1357cb6..2567110 100644 --- a/sharedthetayc.cpp +++ b/sharedthetayc.cpp @@ -14,10 +14,13 @@ EstOutput ThetaYC::getValues(SharedRAbundVector* shared1, SharedRAbundVector* sh 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++) { @@ -29,21 +32,14 @@ EstOutput ThetaYC::getValues(SharedRAbundVector* shared1, SharedRAbundVector* sh //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; } diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index e6a7d9a..eca2033 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -85,8 +85,7 @@ SummarySharedCommand::SummarySharedCommand(){ 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()); } diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index 7791d5e..e50fbaa 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -17,6 +17,7 @@ #include "sharedthetayc.h" #include "sharedthetan.h" #include "sharedmorisitahorn.h" +#include "sharedbraycurtis.h" //********************************************************************************************************************** @@ -49,6 +50,8 @@ TreeGroupCommand::TreeGroupCommand(){ 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()); } } } diff --git a/validcalculator.cpp b/validcalculator.cpp index 72d4041..70299cb 100644 --- a/validcalculator.cpp +++ b/validcalculator.cpp @@ -398,6 +398,7 @@ void ValidCalculators::initialTreeGroups() { 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"; @@ -420,6 +421,7 @@ void ValidCalculators::initialBoot() { 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"; -- 2.39.2