]> git.donarmstrong.com Git - mothur.git/blob - cluster.cpp
added mothur.h and fixed includes in many files
[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
14 /***********************************************************************/
15
16 Cluster::Cluster(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
17 rabund(rav), list(lv), dMatrix(dm)
18 {
19 }
20
21 /***********************************************************************/
22
23 void Cluster::getRowColCells(){
24         try {
25                 PCell* smallCell = dMatrix->getSmallestCell();  //find the smallest cell - this routine should probably not be in the SpMat class
26         
27                 smallRow = smallCell->row;              //get its row
28                 smallCol = smallCell->column;   //get its column
29                 smallDist = smallCell->dist;    //get the smallest distance
30         
31                 rowCells.clear();
32                 colCells.clear();
33                 
34                 for(MatData currentCell=dMatrix->begin();currentCell!=dMatrix->end();currentCell++){
35                 
36                         if(&*currentCell == smallCell){                         //put the smallest cell first
37                                 rowCells.insert(rowCells.begin(), currentCell);
38                                 colCells.insert(colCells.begin(), currentCell);
39                         }
40                         else if(currentCell->row == smallRow){
41                                 rowCells.push_back(currentCell);
42                         }
43                         else if(currentCell->column == smallRow){
44                                 rowCells.push_back(currentCell);
45                         }
46                         else if(currentCell->row == smallCol){
47                                 colCells.push_back(currentCell);
48                         }
49                         else if(currentCell->column == smallCol){
50                                 colCells.push_back(currentCell);
51                         }
52                 }
53         
54                 nRowCells = rowCells.size();
55                 nColCells = colCells.size();
56         }
57         catch(exception& e) {
58                 cout << "Standard Error: " << e.what() << " has occurred in the Cluster class Function getRowColCells. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
59                 exit(1);
60         }
61         catch(...) {
62                 cout << "An unknown error has occurred in the Cluster class function getRowColCells. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63                 exit(1);
64         }       
65 }
66
67 /***********************************************************************/
68
69 void Cluster::clusterBins(){
70         try {
71         //      cout << smallCol << '\t' << smallRow << '\t' << smallDist << '\t' << rabund->get(smallRow) << '\t' << rabund->get(smallCol);
72
73                 rabund->set(smallCol, rabund->get(smallRow)+rabund->get(smallCol));     
74                 rabund->set(smallRow, 0);       
75                 rabund->setLabel(toString(smallDist));
76
77         //      cout << '\t' << rabund->get(smallRow) << '\t' << rabund->get(smallCol) << endl;
78         }
79         catch(exception& e) {
80                 cout << "Standard Error: " << e.what() << " has occurred in the Cluster class Function clusterBins. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
81                 exit(1);
82         }
83         catch(...) {
84                 cout << "An unknown error has occurred in the Cluster class function clusterBins. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
85                 exit(1);
86         }       
87
88
89 }
90
91 /***********************************************************************/
92
93 void Cluster::clusterNames(){
94         try {
95         //      cout << smallCol << '\t' << smallRow << '\t' << smallDist << '\t' << list->get(smallRow) << '\t' << list->get(smallCol);
96
97                 list->set(smallCol, list->get(smallRow)+','+list->get(smallCol));
98                 list->set(smallRow, "");        
99                 list->setLabel(toString(smallDist));
100         
101         //      cout << '\t' << list->get(smallRow) << '\t' << list->get(smallCol) << endl;
102     }
103         catch(exception& e) {
104                 cout << "Standard Error: " << e.what() << " has occurred in the Cluster class Function clusterNames. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
105                 exit(1);
106         }
107         catch(...) {
108                 cout << "An unknown error has occurred in the Cluster class function clusterNames. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
109                 exit(1);
110         }       
111 }
112
113 /***********************************************************************/
114