]> git.donarmstrong.com Git - mothur.git/blob - weightedlinkage.cpp
Revert to previous commit
[mothur.git] / weightedlinkage.cpp
1 #ifndef WEIGHTEDLINKAGE_H
2 #define WEIGHTEDLINKAGE_H
3
4
5 #include "mothur.h"
6 #include "cluster.hpp"
7 #include "rabundvector.hpp"
8 #include "sparsematrix.hpp"
9
10 /* This class implements the WPGMA, weighted average neighbor clustering algorithm */
11
12 /***********************************************************************/
13
14 WeightedLinkage::WeightedLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm, float c, string s) :
15         Cluster(rav, lv, dm, c, s)
16 {
17         saveRow = -1;
18         saveCol = -1;
19 }
20
21
22 /***********************************************************************/
23 //This function returns the tag of the method.
24 string WeightedLinkage::getTag() {
25         return("wn");
26 }
27
28
29 /***********************************************************************/
30 //This function updates the distance based on the average linkage method.
31 bool WeightedLinkage::updateDistance(MatData& colCell, MatData& rowCell) {
32         try {
33                 if ((saveRow != smallRow) || (saveCol != smallCol)) {
34 //                      rowBin = rabund->get(smallRow);
35 //                      colBin = rabund->get(smallCol);
36 //                      totalBin = rowBin + colBin;
37                         saveRow = smallRow;
38                         saveCol = smallCol;
39                 }
40                 
41                 colCell->dist = (colCell->dist + rowCell->dist) / 2.0;
42                 
43                 return(true);
44         }
45         catch(exception& e) {
46                 m->errorOut(e, "WeightedLinkage", "updateDistance");
47                 exit(1);
48         }
49 }
50
51 /***********************************************************************/
52
53
54 /***********************************************************************/
55
56 #endif