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