]> git.donarmstrong.com Git - mothur.git/blob - canberra.cpp
working on pam
[mothur.git] / canberra.cpp
1 /*
2  *  canberra.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 12/14/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "canberra.h"
11
12 /***********************************************************************/
13
14 EstOutput Canberra::getValues(vector<SharedRAbundVector*> shared) {
15         try {
16                 data.resize(1,0);
17                 
18                 int numSharedOTUS = 0;
19                 
20                 double sum = 0.0;
21                 
22                 for (int i = 0; i < shared[0]->getNumBins(); i++) { 
23                         
24                         int Aij = shared[0]->getAbundance(i);
25                         int Bij = shared[1]->getAbundance(i);
26                         
27                         //is this otu shared
28                         if ((Aij != 0) && (Bij != 0)) { numSharedOTUS++; }
29                         
30                         if ((Aij + Bij) != 0) { 
31                                 sum += ((abs(Aij - Bij)) / (float) (Aij + Bij));
32                         }
33                 }
34                 
35                 data[0] = (1 / (float) shared[0]->getNumBins()) * sum;
36                 
37                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
38                 
39                 return data;
40         }
41         catch(exception& e) {
42                 m->errorOut(e, "Canberra", "getValues");
43                 exit(1);
44         }
45 }
46
47 /***********************************************************************/