]> git.donarmstrong.com Git - mothur.git/blob - cluster.cpp
Initial revision
[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 <exception>
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                 cout << "Standard Error: " << e.what() << " has occurred in the Cluster class Function getRowColCells. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
60                 exit(1);
61         }
62         catch(...) {
63                 cout << "An unknown error has occurred in the Cluster class function getRowColCells. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
64                 exit(1);
65         }       
66 }
67
68 /***********************************************************************/
69
70 void Cluster::clusterBins(){
71         try {
72         //      cout << smallCol << '\t' << smallRow << '\t' << smallDist << '\t' << rabund->get(smallRow) << '\t' << rabund->get(smallCol);
73
74                 rabund->set(smallCol, rabund->get(smallRow)+rabund->get(smallCol));     
75                 rabund->set(smallRow, 0);       
76                 rabund->setLabel(toString(smallDist));
77
78         //      cout << '\t' << rabund->get(smallRow) << '\t' << rabund->get(smallCol) << endl;
79         }
80         catch(exception& e) {
81                 cout << "Standard Error: " << e.what() << " has occurred in the Cluster class Function clusterBins. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82                 exit(1);
83         }
84         catch(...) {
85                 cout << "An unknown error has occurred in the Cluster class function clusterBins. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
86                 exit(1);
87         }       
88
89
90 }
91
92 /***********************************************************************/
93
94 void Cluster::clusterNames(){
95         try {
96         //      cout << smallCol << '\t' << smallRow << '\t' << smallDist << '\t' << list->get(smallRow) << '\t' << list->get(smallCol);
97
98                 list->set(smallCol, list->get(smallRow)+','+list->get(smallCol));
99                 list->set(smallRow, "");        
100                 list->setLabel(toString(smallDist));
101         
102         //      cout << '\t' << list->get(smallRow) << '\t' << list->get(smallCol) << endl;
103     }
104         catch(exception& e) {
105                 cout << "Standard Error: " << e.what() << " has occurred in the Cluster class Function clusterNames. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106                 exit(1);
107         }
108         catch(...) {
109                 cout << "An unknown error has occurred in the Cluster class function clusterNames. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
110                 exit(1);
111         }       
112 }
113
114 /***********************************************************************/
115