]> git.donarmstrong.com Git - mothur.git/blob - sharedsorest.cpp
removed "shared" from some of the calculator names and classes
[mothur.git] / sharedsorest.cpp
1 /*
2  *  sharedsorest.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 "sharedsorest.h"
11 #include "chao1.h"
12 #include "sharedchao1.h"
13
14 /***********************************************************************/
15
16 EstOutput SorEst::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
17         try {
18                 EstOutput S1, S2, S12;
19                 S12.resize(1,0);
20                 S1.resize(3,0);
21                 S2.resize(3,0); 
22                 
23                 /*S1, S2 = number of OTUs estimated in A and B using the Chao estimator
24                 S12 = estimated number of OTUs shared between A and B using the SharedChao estimator*/
25
26                 data.resize(1,0);
27                 
28                 SharedChao1* sharedChao = new SharedChao1();
29                 Chao1* chaoS1 = new Chao1();
30                 Chao1* chaoS2 = new Chao1();
31                 SAbundVector* chaoS1Sabund = new SAbundVector();
32                 SAbundVector* chaoS2Sabund = new SAbundVector();
33                 
34                 *chaoS1Sabund = shared1->getSAbundVector();
35                 *chaoS2Sabund = shared2->getSAbundVector();
36                 
37                 S12 = sharedChao->getValues(shared1, shared2);
38                 S1 = chaoS1->getValues(chaoS1Sabund);
39                 S2 = chaoS2->getValues(chaoS2Sabund);
40                 
41                 data[0] = (2 * S12[0]) / (float)(S1[0] + S2[0]);
42                  
43                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
44                 
45                 return data;
46         }
47         catch(exception& e) {
48                 cout << "Standard Error: " << e.what() << " has occurred in the SorEst class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
49                 exit(1);
50         }
51         catch(...) {
52                 cout << "An unknown error has occurred in the SorEst class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53                 exit(1);
54         }       
55 }
56
57 /***********************************************************************/