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(vector<SharedRAbundVector*> shared) {
18 double sumSharedA, sumSharedB, sumSharedAB, tempA, tempB;
19 sumSharedA = 0; sumSharedB = 0; sumSharedAB = 0;
21 /*Xi, Yi = abundance of the ith shared OTU in A and B
22 sumSharedA = the number of otus in A
23 sumSharedB = the sum of all shared otus in B
24 sumSharedAB = the sum of the minimum otus int all shared otus in AB.
27 for (int i = 0; i < shared[0]->getNumBins(); i++) {
28 //store in temps to avoid multiple repetitive function calls
29 tempA = shared[0]->getAbundance(i);
30 tempB = shared[1]->getAbundance(i);
35 //sum the min of tempA and tempB
36 if (tempA < tempB) { sumSharedAB += tempA; }
37 else { sumSharedAB += tempB; }
40 data[0] = 1.0 - (2 * sumSharedAB) / (float)( sumSharedA + sumSharedB);
42 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
47 m->errorOut(e, "BrayCurtis", "getValues");
52 /***********************************************************************/