]> git.donarmstrong.com Git - mothur.git/blob - averagelinkage.cpp
changes while testing
[mothur.git] / averagelinkage.cpp
1 #ifndef AVERAGE_H
2 #define AVERAGE_H
3
4 //test
5 #include "mothur.h"
6 #include "cluster.hpp"
7 #include "rabundvector.hpp"
8 #include "sparsedistancematrix.h"
9
10 /* This class implements the average UPGMA, average neighbor clustering algorithm */
11
12 /***********************************************************************/
13
14 AverageLinkage::AverageLinkage(RAbundVector* rav, ListVector* lv, SparseDistanceMatrix* dm, float c, string s, float a) :
15 Cluster(rav, lv, dm, c, s, a)
16 {
17         saveRow = -1;
18         saveCol = -1;
19 }
20
21
22 /***********************************************************************/
23 //This function returns the tag of the method.
24 string AverageLinkage::getTag() {
25         return("an");
26 }
27
28
29 /***********************************************************************/
30 //This function updates the distance based on the average linkage method.
31 bool AverageLinkage::updateDistance(PDistCell& colCell, PDistCell& 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                 //cout << "colcell.dist = " << colCell.dist << '\t' << smallRow << '\t' << smallCol << '\t' << rowCell.dist << endl;
41                 colCell.dist = (colBin * colCell.dist + rowBin * rowCell.dist) / totalBin;
42         
43                 return(true);
44         }
45         catch(exception& e) {
46                 m->errorOut(e, "AverageLinkage", "updateDistance");
47                 exit(1);
48         }
49 }
50
51 /***********************************************************************/
52
53
54 /***********************************************************************/
55
56 #endif