]> git.donarmstrong.com Git - mothur.git/blob - cluster.cpp
added logfile feature
[mothur.git] / cluster.cpp
1 /*
2  *  cluster.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 8/14/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "cluster.hpp"
11 #include "rabundvector.hpp"
12 #include "listvector.hpp"
13 #include "sparsematrix.hpp"
14
15 /***********************************************************************/
16
17 Cluster::Cluster(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
18 rabund(rav), list(lv), dMatrix(dm)
19 {
20 }
21
22 /***********************************************************************/
23
24 void Cluster::getRowColCells(){
25         try {
26                 PCell* smallCell = dMatrix->getSmallestCell();  //find the smallest cell - this routine should probably not be in the SpMat class
27         
28                 smallRow = smallCell->row;              //get its row
29                 smallCol = smallCell->column;   //get its column
30                 smallDist = smallCell->dist;    //get the smallest distance
31         
32                 rowCells.clear();
33                 colCells.clear();
34                 
35                 for(MatData currentCell=dMatrix->begin();currentCell!=dMatrix->end();currentCell++){
36                 
37                         if(&*currentCell == smallCell){                         //put the smallest cell first
38                                 rowCells.insert(rowCells.begin(), currentCell);
39                                 colCells.insert(colCells.begin(), currentCell);
40                         }
41                         else if(currentCell->row == smallRow){
42                                 rowCells.push_back(currentCell);
43                         }
44                         else if(currentCell->column == smallRow){
45                                 rowCells.push_back(currentCell);
46                         }
47                         else if(currentCell->row == smallCol){
48                                 colCells.push_back(currentCell);
49                         }
50                         else if(currentCell->column == smallCol){
51                                 colCells.push_back(currentCell);
52                         }
53                 }
54         
55                 nRowCells = rowCells.size();
56                 nColCells = colCells.size();
57         }
58         catch(exception& e) {
59                 errorOut(e, "Cluster", "getRowColCells");
60                 exit(1);
61         }
62 }
63
64 /***********************************************************************/
65
66 void Cluster::clusterBins(){
67         try {
68         
69                 rabund->set(smallCol, rabund->get(smallRow)+rabund->get(smallCol));     
70                 rabund->set(smallRow, 0);       
71                 rabund->setLabel(toString(smallDist));
72
73         }
74         catch(exception& e) {
75                 errorOut(e, "Cluster", "clusterBins");
76                 exit(1);
77         }
78 }
79
80 /***********************************************************************/
81
82 void Cluster::clusterNames(){
83         try {
84         
85                 list->set(smallCol, list->get(smallRow)+','+list->get(smallCol));
86                 list->set(smallRow, "");        
87                 list->setLabel(toString(smallDist));
88         
89     }
90         catch(exception& e) {
91                 errorOut(e, "Cluster", "clusterNames");
92                 exit(1);
93         }
94 }
95
96 /***********************************************************************/
97