]> git.donarmstrong.com Git - mothur.git/blob - sharedlennon.cpp
added sharedbraycurtis, sharedmorisirahorn, sharedkulczynski, sharedkulczynskicody...
[mothur.git] / sharedlennon.cpp
1 /*
2  *  sharedlennon.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 "sharedlennon.h"
11
12 /***********************************************************************/
13
14 EstOutput SharedLennon::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
15         try {
16                 int S1, S2, S12, tempA, tempB, min;
17                 S1 = 0; S2 = 0; S12 = 0; tempA = 0; tempB = 0; min = 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 < shared1->size(); i++) {
25                         //store in temps to avoid multiple repetitive function calls
26                         tempA = shared1->getAbundance(i);
27                         tempB = shared2->getAbundance(i);
28                         
29                         if (tempA != 0) { S1++; }
30                         if (tempB != 0) { S2++; } 
31
32                         //they are shared
33                         if ((tempA != 0) && (tempB != 0)) {     S12++; }
34                 }
35                 
36                 
37                 tempA = S1 - S12;  tempB = S2 - S12;
38                 
39                 if (tempA < tempB) { min = tempA; }
40                 else { min = tempB; }
41                 
42                 data[0] = S12 / (float)(S12 + min);
43                 
44                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
45                 
46                 return data;
47         }
48         catch(exception& e) {
49                 cout << "Standard Error: " << e.what() << " has occurred in the SharedLennon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
50                 exit(1);
51         }
52         catch(...) {
53                 cout << "An unknown error has occurred in the SharedLennon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54                 exit(1);
55         }       
56 }
57
58 /***********************************************************************/