]> git.donarmstrong.com Git - mothur.git/blob - sharedsorclass.cpp
changes while testing
[mothur.git] / sharedsorclass.cpp
1 /*
2  *  sharedsorclass.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 "sharedsorclass.h"
11
12 /***********************************************************************/
13
14 EstOutput SorClass::getValues(vector<SharedRAbundVector*> shared) {
15         try {
16                 double S1, S2, S12, tempA, tempB;
17                 S1 = 0; S2 = 0; S12 = 0; tempA = 0; tempB = 0; 
18                 
19                 /*S1, S2 = number of OTUs observed or estimated in A and B 
20                 S12=number of OTUs shared between A and B */
21
22                 data.resize(1,0);
23                 
24                 for (int i = 0; i < shared[0]->getNumBins(); i++) {
25                         //store in temps to avoid multiple repetitive function calls
26                         tempA = shared[0]->getAbundance(i);
27                         tempB = shared[1]->getAbundance(i);
28
29                         //find number of bins in shared1 and shared2
30                         if (tempA != 0) { S1++; }
31                         if (tempB != 0) { S2++; } 
32                         
33                         //they are shared
34                         if ((tempA != 0) && (tempB != 0)) {     S12++; }
35                 }
36                 
37                 data[0] = 1.0-(2 * S12) / (float)(S1 + S2);
38                 
39                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
40                 
41                 return data;
42         }
43         catch(exception& e) {
44                 m->errorOut(e, "SorClass", "getValues");
45                 exit(1);
46         }
47 }
48
49 /***********************************************************************/