]> git.donarmstrong.com Git - mothur.git/blobdiff - averagelinkage.cpp
Revert to previous commit
[mothur.git] / averagelinkage.cpp
diff --git a/averagelinkage.cpp b/averagelinkage.cpp
new file mode 100644 (file)
index 0000000..c430c88
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef AVERAGE_H
+#define AVERAGE_H
+
+//test
+#include "mothur.h"
+#include "cluster.hpp"
+#include "rabundvector.hpp"
+#include "sparsematrix.hpp"
+
+/* This class implements the average UPGMA, average neighbor clustering algorithm */
+
+/***********************************************************************/
+
+AverageLinkage::AverageLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm, float c, string s) :
+       Cluster(rav, lv, dm, c, s)
+{
+       saveRow = -1;
+       saveCol = -1;
+}
+
+
+/***********************************************************************/
+//This function returns the tag of the method.
+string AverageLinkage::getTag() {
+       return("an");
+}
+
+
+/***********************************************************************/
+//This function updates the distance based on the average linkage method.
+bool AverageLinkage::updateDistance(MatData& colCell, MatData& rowCell) {
+       try {
+               if ((saveRow != smallRow) || (saveCol != smallCol)) {
+                       rowBin = rabund->get(smallRow);
+                       colBin = rabund->get(smallCol);
+                       totalBin = rowBin + colBin;
+                       saveRow = smallRow;
+                       saveCol = smallCol;
+               }
+               
+               colCell->dist = (colBin * colCell->dist + rowBin * rowCell->dist) / totalBin;
+               
+               return(true);
+       }
+       catch(exception& e) {
+               m->errorOut(e, "AverageLinkage", "updateDistance");
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+
+/***********************************************************************/
+
+#endif