5 * Created by Sarah Westcott on 1/8/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "sharedchao1.h"
12 /***********************************************************************/
13 EstOutput SharedChao1::getValues(SharedRAbundVector* sharedA, SharedRAbundVector* sharedB){
17 int f11, f1A, f2A, f1B, f2B, S12, tempA, tempB;
18 f11 = 0; f1A = 0; f2A = 0; f1B = 0; f2B = 0; S12 = 0;
19 float ChaoAB, part1, part2, part3;
21 /* f11 = number of shared OTUs with one observed individual in A and B
22 f1A, f2A = number of shared OTUs with one or two individuals observed in A
23 f1B, f2B = number of shared OTUs with one or two individuals observed in B
24 S12 = number of shared OTUs in A and B */
26 //loop through vectors calculating the f11, f1A, f2A, f1B, f2B, S12 values
27 for (int i = 0; i< sharedA->size(); i++) {
28 tempA = sharedA->getAbundance(i); //store in temps to avoid calling getAbundance multiple times
29 tempB = sharedB->getAbundance(i);
30 if ((tempA != 0) && (tempB != 0)) {//they are shared
31 S12++; //they are shared
32 //do both A and B have one
33 if ((tempA == 1) && (tempB == 1)) { f11++; }
35 //does A have one or two
36 if (tempA == 1) { f1A++; }
37 else if (tempA == 2) { f2A++; }
39 //does B have one or two
40 if (tempB == 1) { f1B++; }
41 else if (tempB == 2) { f2B++; }
45 //checks for divide by zero error
46 if ((f2A == 0) || (f2B == 0)) {
47 part1 = ((float)(f1A*f1B)/(float)(4*(f2A+1)*(f2B+1)));
48 part2 = ((float)(f1A*(f1A-1))/(float)(2*f2A+2));
49 part3 = ((float)(f1B*(f1B-1))/(float)(2*f2B+2));
51 part1 = ((float)(f1A*f1B)/(float)(4*f2A*f2B));
52 part2 = ((float)(f1A*f1A)/(float)(2*f2A));
53 part3 = ((float)(f1B*f1B)/(float)(2*f2B));
56 ChaoAB = (float)S12 + (float)(f11*part1) + part2 + part3;
62 cout << "Standard Error: " << e.what() << " has occurred in the SharedChao1 class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
66 cout << "An unknown error has occurred in the SharedChao1 class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
72 /***********************************************************************/