X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedkstest.cpp;h=f65f271abbf39224b6eb052a3d83d2142968d141;hb=786d5631d9cd5baa6ed6ef16f8b4b384cbc7470f;hp=897432d57a20973cae256a14839b56a209c5ab0d;hpb=29351fe29c017d2225366418973ed0e000ce5293;p=mothur.git diff --git a/sharedkstest.cpp b/sharedkstest.cpp index 897432d..f65f271 100644 --- a/sharedkstest.cpp +++ b/sharedkstest.cpp @@ -3,38 +3,36 @@ * 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 "sharedkstest.h" -#include "calculator.h" -#include /***********************************************************************/ -EstOutput SharedKSTest::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2){ +EstOutput KSTest::getValues(vector shared){ try { - data.resize(2,0); - + data.resize(3,0); + //Must return shared1 and shared2 to original order at conclusion of kstest - vector initData1 = shared1->getData(); - vector initData2 = shared2->getData(); - shared1->sortD(); - shared2->sortD(); + vector initData1 = shared[0]->getData(); + vector initData2 = shared[1]->getData(); + shared[0]->sortD(); + shared[1]->sortD(); - int numNZ1 = shared1->numNZ(); - int numNZ2 = shared2->numNZ(); - double numInd1 = (double)shared1->getNumSeqs(); - double numInd2 = (double)shared2->getNumSeqs(); + int numNZ1 = shared[0]->numNZ(); + int numNZ2 = shared[1]->numNZ(); + double numInd1 = (double)shared[0]->getNumSeqs(); + double numInd2 = (double)shared[1]->getNumSeqs(); double maxDiff = -1; double sum1 = 0; double sum2 = 0; - for(int i = 1; i < shared1->getNumBins(); i++) + for(int i = 1; i < shared[0]->getNumBins(); i++) { - sum1 += shared1->get(i).abundance; - sum2 += shared2->get(i).abundance; + sum1 += shared[0]->get(i).abundance; + sum2 += shared[1]->get(i).abundance; double diff = fabs((double)sum1/numInd1 - (double)sum2/numInd2); if(diff > maxDiff) maxDiff = diff; @@ -56,22 +54,24 @@ EstOutput SharedKSTest::getValues(SharedRAbundVector* shared1, SharedRAbundVecto cout << "If D-Statistic is greater than the critical value then the data sets are significantly different at the 95% confidence level.\n\n"; }*/ - shared1->setData(initData1); - shared2->setData(initData2); + shared[0]->setData(initData1); + shared[1]->setData(initData2); data[0] = DStatistic; data[1] = critVal; + data[2] = 0; + if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } if (isnan(data[1]) || isinf(data[1])) { data[1] = 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"; + cout << "Standard Error: " << e.what() << " has occurred in the KSTest class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; 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"; + cout << "An unknown error has occurred in the KSTest class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } }