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