]> git.donarmstrong.com Git - mothur.git/blob - sharedmorisitahorn.cpp
removed "shared" from some of the calculator names and classes
[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(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
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 < shared1->size(); i++) {
24                         //store in temps to avoid multiple repetitive function calls
25                         Atotal += shared1->getAbundance(i);
26                         Btotal += shared2->getAbundance(i);
27                 }
28                 
29                 //calculate the theta denominator sums
30                 for (int j = 0; j < shared1->size(); j++) {
31                         //store in temps to avoid multiple repetitive function calls
32                         tempA = shared1->getAbundance(j);
33                         tempB = shared2->getAbundance(j);
34                         
35                         //they are shared
36                         if ((tempA != 0) && (tempB != 0)) {
37                                 if (Atotal != 0)        { sumSharedA = (tempA / (float)Atotal); }
38                                 if (Btotal != 0)        { sumSharedB = (tempB / (float)Btotal); }
39                         
40                                 a += sumSharedA * sumSharedA;
41                                 b += sumSharedB * sumSharedB;
42                                 d += sumSharedA * sumSharedB;
43                         }
44                 }
45
46                 morhorn = (2 * d) / (float) (a + b);
47                 
48                 if (isnan(morhorn) || isinf(morhorn)) { morhorn = 0; }
49                 
50                 data[0] = morhorn;
51                 
52                 return data;
53         }
54         catch(exception& e) {
55                 cout << "Standard Error: " << e.what() << " has occurred in the MorHorn class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
56                 exit(1);
57         }
58         catch(...) {
59                 cout << "An unknown error has occurred in the MorHorn class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
60                 exit(1);
61         }       
62 }
63
64 /***********************************************************************/