]> git.donarmstrong.com Git - mothur.git/blob - sharedmorisitahorn.cpp
added logfile feature
[mothur.git] / sharedmorisitahorn.cpp
1 /*
2  *  sharedmorisitahorn.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 3/24/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "sharedmorisitahorn.h"
11
12 /***********************************************************************/
13 EstOutput MorHorn::getValues(vector<SharedRAbundVector*> shared) {
14         try {   
15                 data.resize(1,0);
16                 
17                 int Atotal, Btotal, tempA, tempB;
18                 Atotal = 0; Btotal = 0; 
19                 float  morhorn, sumSharedA, sumSharedB, a, b, d;
20                 morhorn = 0.0; sumSharedA = 0.0; sumSharedB = 0.0; a = 0.0; b = 0.0; d = 0.0;
21                 
22                 //get the total values we need to calculate the theta denominator sums
23                 for (int i = 0; i < shared[0]->size(); i++) {
24                         //store in temps to avoid multiple repetitive function calls
25                         Atotal += shared[0]->getAbundance(i);
26                         Btotal += shared[1]->getAbundance(i);
27                 }
28                 
29                 //calculate the theta denominator sums
30                 for (int j = 0; j < shared[0]->size(); j++) {
31                         //store in temps to avoid multiple repetitive function calls
32                         tempA = shared[0]->getAbundance(j);
33                         tempB = shared[1]->getAbundance(j);
34                         
35                         a += tempA * tempA;
36                         b += tempB * tempB;
37                         d += tempA * tempB;
38                 }
39
40                 a /= double(Atotal * Atotal);
41                 b /= double(Btotal * Btotal);
42                 d /= double(Atotal * Btotal);
43                 
44                 morhorn = (2 * d) / (a + b);
45                 
46                 if (isnan(morhorn) || isinf(morhorn)) { morhorn = 0; }
47                 
48                 data[0] = morhorn;
49                 
50                 return data;
51         }
52         catch(exception& e) {
53                 errorOut(e, "MorHorn", "getValues");
54                 exit(1);
55         }
56 }
57
58 /***********************************************************************/