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