X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=bstick.cpp;h=67507a9967ef82effe923662298960ecf00618b8;hp=3a0e0e91a873f6692b585463ec324e33d3b2cd82;hb=050a3ff02473a3d4c0980964e1a9ebe52e55d6b8;hpb=eb1c88346fb246e95a6b38935b103f95e38b82ca diff --git a/bstick.cpp b/bstick.cpp index 3a0e0e9..67507a9 100644 --- a/bstick.cpp +++ b/bstick.cpp @@ -3,12 +3,12 @@ * Mothur * * Created by Thomas Ryabin on 3/6/09. - * Copyright 2009 __MyCompanyName__. All rights reserved. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. * */ #include "bstick.h" -#include "calculator.h" + /***********************************************************************/ double BStick::invSum(int index, double numSpec) @@ -18,16 +18,15 @@ double BStick::invSum(int index, double numSpec) sum += 1/(double)i; return sum; } - +/***********************************************************************/ RAbundVector BStick::getRAbundVector(SAbundVector* rank){ vector rData; int mr = 1; int nb = 0; int ns = 0; - for(int i = rank->size()-1; i > 0; i--) - { - int cur = rank->get(i); + for(int i = rank->size()-1; i > 0; i--) { + double cur = rank->get(i); if(mr == 1 && cur > 0) mr = i; nb += cur; @@ -46,7 +45,7 @@ RAbundVector BStick::getRAbundVector(SAbundVector* rank){ /***************************************************************************/ EstOutput BStick::getValues(SAbundVector* rank){ try { - data.resize(2,0); + data.resize(3,0); rdata = getRAbundVector(rank); double numInd = (double)rdata.getNumSeqs(); double numSpec = (double)rdata.getNumBins(); @@ -55,8 +54,7 @@ EstOutput BStick::getValues(SAbundVector* rank){ double sumObs = 0; double maxDiff = 0; - for(int i = 0; i < rdata.size(); i++) - { + for(int i = 0; i < rdata.size(); i++) { sumObs += rdata.get(i); sumExp += numInd/numSpec*invSum(i+1,numSpec); double diff = fabs(sumObs-sumExp); @@ -64,38 +62,25 @@ EstOutput BStick::getValues(SAbundVector* rank){ maxDiff = diff; } - double DStatistic = maxDiff/numInd; - double critVal = 0; - /*cout << "BStick:\n"; - cout << "D-Statistic = " << DStatistic << "\n"; - cout << "Critical value for 95% confidence interval = ";*/ - if(rdata.size() > 20) - { - critVal = .886/sqrt(rdata.size()); - } - else - { - KOSTable table; - critVal = table.getConfLimit(numSpec); - } - /*cout << critVal << "\n"; - cout << "If D-Statistic is less than the critical value then the data fits the Broken Stick model w/ 95% confidence.\n\n";*/ + + data[0] = maxDiff/numInd; + data[1] = 0.886/sqrt(rdata.size()); + data[2] = 1.031/sqrt(rdata.size()); + + /*m->mothurOut(critVal); m->mothurOutEndLine(); + m->mothurOut("If D-Statistic is less than the critical value then the data fits the Broken Stick model w/ 95% confidence.\n");*/ - data[0] = DStatistic; - data[1] = critVal; + if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; } + if (isnan(data[2]) || isinf(data[2])) { data[2] = 0; } return data; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the NPShannon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "BStick", "getValues"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the NPShannon class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/