5 * Created by Thomas Ryabin on 3/13/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "sharedbdiversity.h"
12 /***********************************************************************/
14 double BDiversity::whitt(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
15 double nz1 = (double)shared1->numNZ();
16 double nz2 = (double)shared2->numNZ();
18 for(int i = 1; i < shared1->size(); i++)
20 if(shared1->get(i).abundance == 0 && shared2->get(i).abundance != 0)
23 return 2*sum/(nz1+nz2)-1;
26 /***********************************************************************/
28 double BDiversity::ms(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
32 for(int i = 1; i < shared1->size(); i++)
34 int abund1 = shared1->get(i).abundance;
35 int abund2 = shared2->get(i).abundance;
37 if(abund1 > 0 && abund2 > 0)
39 else if(abund1 > 0 && abund2 == 0)
41 else if(abund1 == 0 && abund2 > 0)
47 /***********************************************************************/
49 double BDiversity::sor(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
53 for(int i = 1; i < shared1->size(); i++)
55 int abund1 = shared1->get(i).abundance;
56 int abund2 = shared2->get(i).abundance;
65 return 2*sum/(asum+bsum);
68 /***********************************************************************/
70 double BDiversity::mor(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
76 for(int i = 1; i < shared1->size(); i++)
78 double abund1 = (double)shared1->get(i).abundance;
79 double abund2 = (double)shared2->get(i).abundance;
80 multSum += abund1*abund2;
81 powSum1 += pow(abund1, 2);
82 powSum2 += pow(abund2, 2);
86 return 2*multSum / ((powSum1/pow(ind1, 2) + powSum2/pow(ind2, 2)) * (ind1*ind2));
88 /***********************************************************************/
90 EstOutput BDiversity::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
94 double whitt1 = whitt(shared1, shared2);
95 double jac1 = 1-ms(shared1, shared2);
96 double sor1 = sor(shared1, shared2);
97 double mor1 = mor(shared1, shared2);
98 /*cout << "Whittaker's Measure: " << whitt1 << "\n";
99 cout << "Marczewski-Steinhaus distance: " << jac1 << "\n";
100 cout << "Sorensen index: " << sor1 << "\n";
101 cout << "Morisita-Horn index: " << mor1 << "\n";*/
107 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
108 if (isnan(data[1]) || isinf(data[1])) { data[1] = 0; }
109 if (isnan(data[2]) || isinf(data[0])) { data[2] = 0; }
110 if (isnan(data[3]) || isinf(data[1])) { data[3] = 0; }
115 catch(exception& e) {
116 cout << "Standard Error: " << e.what() << " has occurred in the BDiversity class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
120 cout << "An unknown error has occurred in the BDiversity class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 /***********************************************************************/