5 * Created by Thomas Ryabin on 3/13/09.
6 * Copyright 2009 __MyCompanyName__. All rights reserved.
10 #include "sharedbdiversity.h"
11 #include "calculator.h"
13 /***********************************************************************/
15 double SharedBDiversity::whitt(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
16 double nz1 = (double)shared1->numNZ();
17 double nz2 = (double)shared2->numNZ();
19 for(int i = 1; i < shared1->size(); i++)
21 if(shared1->get(i).abundance == 0 && shared2->get(i).abundance != 0)
24 return 2*sum/(nz1+nz2)-1;
27 /***********************************************************************/
29 double SharedBDiversity::ms(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
33 for(int i = 1; i < shared1->size(); i++)
35 int abund1 = shared1->get(i).abundance;
36 int abund2 = shared2->get(i).abundance;
38 if(abund1 > 0 && abund2 > 0)
40 else if(abund1 > 0 && abund2 == 0)
42 else if(abund1 == 0 && abund2 > 0)
48 /***********************************************************************/
50 double SharedBDiversity::sor(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
54 for(int i = 1; i < shared1->size(); i++)
56 int abund1 = shared1->get(i).abundance;
57 int abund2 = shared2->get(i).abundance;
66 return 2*sum/(asum+bsum);
69 /***********************************************************************/
71 double SharedBDiversity::mor(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
77 for(int i = 1; i < shared1->size(); i++)
79 double abund1 = (double)shared1->get(i).abundance;
80 double abund2 = (double)shared2->get(i).abundance;
81 multSum += abund1*abund2;
82 powSum1 += pow(abund1, 2);
83 powSum2 += pow(abund2, 2);
87 return 2*multSum / ((powSum1/pow(ind1, 2) + powSum2/pow(ind2, 2)) * (ind1*ind2));
89 /***********************************************************************/
91 EstOutput SharedBDiversity::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
95 double whitt1 = whitt(shared1, shared2);
96 double jac1 = 1-ms(shared1, shared2);
97 double sor1 = sor(shared1, shared2);
98 double mor1 = mor(shared1, shared2);
99 /*cout << "Whittaker's Measure: " << whitt1 << "\n";
100 cout << "Marczewski-Steinhaus distance: " << jac1 << "\n";
101 cout << "Sorensen index: " << sor1 << "\n";
102 cout << "Morisita-Horn index: " << mor1 << "\n";*/
108 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
109 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
110 if (isnan(data[2]) || isinf(data[0])) { data[2] = 0; }
111 if (isnan(data[3]) || isinf(data[1])) { data[3] = 0; }
116 catch(exception& e) {
117 cout << "Standard Error: " << e.what() << " has occurred in the NPShannon class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 cout << "An unknown error has occurred in the NPShannon class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 /***********************************************************************/