5 * Created by Sarah Westcott on 3/24/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "sharedbraycurtis.h"
12 /***********************************************************************/
13 //This is used by SharedJAbund and SharedSorAbund
14 EstOutput BrayCurtis::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
19 int sumSharedA, sumSharedB, sumSharedAB, tempA, tempB;
20 sumSharedA = 0; sumSharedB = 0; sumSharedAB = 0;
22 /*Xi, Yi = abundance of the ith shared OTU in A and B
23 sumSharedA = the sum of all shared otus in A
24 sumSharedB = the sum of all shared otus in B
25 sumSharedAB = the sum of the minimum otus int all shared otus in AB.
28 for (int i = 0; i < shared1->size(); i++) {
29 //store in temps to avoid multiple repetitive function calls
30 tempA = shared1->getAbundance(i);
31 tempB = shared2->getAbundance(i);
34 if ((tempA != 0) && (tempB != 0)) {//they are shared
38 //sum the min of tempA and tempB
39 if (tempA < tempB) { sumSharedAB += tempA; }
40 else { sumSharedAB += tempB; }
44 data[0] = (2 * sumSharedAB) / (float)( sumSharedA + sumSharedB);
46 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
51 cout << "Standard Error: " << e.what() << " has occurred in the BrayCurtis class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55 cout << "An unknown error has occurred in the BrayCurtis class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62 /***********************************************************************/