]> git.donarmstrong.com Git - mothur.git/blob - completelinkage.cpp
Initial revision
[mothur.git] / completelinkage.cpp
1
2 #include "cluster.hpp"
3 #include <exception>
4
5 /***********************************************************************/
6
7 CompleteLinkage::CompleteLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
8 Cluster(rav, lv, dm)
9 {}
10
11 /***********************************************************************/
12 //This function clusters based on the furthest neighbor method.
13 void CompleteLinkage::update(){
14         try {
15                 getRowColCells();       
16         
17                 vector<int> found(nColCells, 0);
18         
19                 for(int i=1;i<nRowCells;i++){
20                 
21                         int search;
22                 
23                         if(rowCells[i]->row == smallRow){
24                                 search = rowCells[i]->column;
25                         }
26                         else{
27                                 search = rowCells[i]->row;
28                         }
29                 
30                         for(int j=1;j<nColCells;j++){
31                         
32                                 if(colCells[j]->row == search || colCells[j]->column == search){
33                                 
34                                         if(colCells[j]->dist < rowCells[i]->dist){
35                                                 colCells[j]->dist = rowCells[i]->dist;
36                                         
37                                                 if(colCells[j]->vectorMap != NULL){
38                                                         *(colCells[j]->vectorMap) = NULL;
39                                                         colCells[j]->vectorMap = NULL;
40                                                 }
41                                         
42                                         }
43                                 
44                                         found[j] = 1;
45                                         break;
46                                 }
47                         }
48                         dMatrix->rmCell(rowCells[i]);
49                 
50                 }       
51                 clusterBins();
52                 clusterNames();
53         
54                 for(int i=0;i<nColCells;i++){
55                         if(found[i] == 0){
56                                 dMatrix->rmCell(colCells[i]);
57                         }
58                 }
59         }
60         catch(exception& e) {
61                 cout << "Standard Error: " << e.what() << " has occurred in the CompleteLinkage class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62                 exit(1);
63         }
64         catch(...) {
65                 cout << "An unknown error has occurred in the CompleteLinkage class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
66                 exit(1);
67         }
68
69 }
70
71 /***********************************************************************/