]> git.donarmstrong.com Git - mothur.git/blobdiff - gower.cpp
Revert to previous commit
[mothur.git] / gower.cpp
diff --git a/gower.cpp b/gower.cpp
new file mode 100644 (file)
index 0000000..5f0bf68
--- /dev/null
+++ b/gower.cpp
@@ -0,0 +1,56 @@
+/*
+ *  gower.cpp
+ *  Mothur
+ *
+ *  Created by westcott on 12/17/10.
+ *  Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "gower.h"
+
+/***********************************************************************/
+EstOutput Gower::getValues(vector<SharedRAbundVector*> shared) {
+       try {
+               data.resize(1,0);
+               
+               vector<int> maxOtus; maxOtus.resize(shared[0]->getNumBins());
+               vector<int> minOtus; minOtus.resize(shared[0]->getNumBins());
+               //for each otu
+               for (int i = 0; i < shared[0]->getNumBins(); i++) {
+                       
+                       //set otus min and max to first one
+                       minOtus[i] = shared[0]->getAbundance(i);
+                       maxOtus[i] = shared[0]->getAbundance(i);
+                       
+                       //for each group
+                       for (int j = 1; j < shared.size(); j++) { 
+                               maxOtus[i] = max(shared[j]->getAbundance(i), maxOtus[i]);
+                               minOtus[i] = min(shared[j]->getAbundance(i), minOtus[i]);
+                       }
+               }
+               
+               double sum = 0.0;
+               for (int i = 0; i < shared[0]->getNumBins(); i++) {
+                       int A = shared[0]->getAbundance(i);
+                       int B = shared[1]->getAbundance(i);
+                       
+                       double numerator = abs(A - B);
+                       double denominator = maxOtus[i] - minOtus[i];
+                               
+                       if (denominator != 0) { sum += (numerator / denominator); }
+               }
+               
+               data[0] = sum;
+               
+               if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
+               
+               return data;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "Gower", "getValues");
+               exit(1);
+       }
+}
+/***********************************************************************/
+