]> git.donarmstrong.com Git - mothur.git/blob - singlelinkage.cpp
added logfile feature
[mothur.git] / singlelinkage.cpp
1
2 #include "mothur.h"
3 #include "cluster.hpp"
4
5
6 /***********************************************************************/
7
8 SingleLinkage::SingleLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
9 Cluster(rav, lv, dm)
10 {}
11
12 /***********************************************************************/
13 //This function clusters based on nearest method.
14 void SingleLinkage::update(){
15         try {
16                 getRowColCells();               
17         
18                 for(int i=1;i<nRowCells;i++){
19                 
20                         int search;
21                 
22                         if(rowCells[i]->row == smallRow){
23                                 search = rowCells[i]->column;
24                         }
25                         else{
26                                 search = rowCells[i]->row;
27                         }
28                 
29                         for(int j=1;j<nColCells;j++){
30                         
31                                 if(colCells[j]->row == search || colCells[j]->column == search){
32                                 
33                                         if(colCells[j]->dist > rowCells[i]->dist){
34                                                 colCells[j]->dist = rowCells[i]->dist;
35                                         
36                                                 if(colCells[j]->vectorMap != NULL){
37                                                         *(colCells[j]->vectorMap) = NULL;
38                                                         colCells[j]->vectorMap = NULL;
39                                                 }
40                                         
41                                         }
42                                         dMatrix->rmCell(rowCells[i]);
43                                         break;
44                                 }
45                         }                       
46                 
47                         if(search < smallCol){
48                                 rowCells[i]->row = smallCol;
49                                 rowCells[i]->column = search;
50                         }
51                         else{
52                                 rowCells[i]->row = search;
53                                 rowCells[i]->column = smallCol;
54                         }
55                 
56                 }       
57                 clusterBins();
58                 clusterNames();
59                 dMatrix->rmCell(rowCells[0]);
60         }
61         catch(exception& e) {
62                 errorOut(e, "SingleLinkage", "update");
63                 exit(1);
64         }
65 }
66
67 /***********************************************************************/