]> git.donarmstrong.com Git - mothur.git/blobdiff - sparsematrix.cpp
changes while testing
[mothur.git] / sparsematrix.cpp
index 7f1c3c8564d29c6b1c551f7ee9bd16b58636af0a..3a0ec6521720c1f89eb7c54ce47f60a2f81d364a 100644 (file)
@@ -2,11 +2,10 @@
 #include "sparsematrix.hpp"
 #include "listvector.hpp"
 
-typedef list<PCell>::iterator MatData;
 
 /***********************************************************************/
 
-SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){}
+SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){  m = MothurOut::getInstance();  }
 
 /***********************************************************************/
 
@@ -22,20 +21,20 @@ float SparseMatrix::getSmallDist(){
 
 /***********************************************************************/
 
-void SparseMatrix::rmCell(MatData data){
+MatData SparseMatrix::rmCell(MatData data){
        try {
                if(data->vectorMap != NULL ){
                        *(data->vectorMap) = NULL;
                        data->vectorMap = NULL;
                }
-               matrix.erase(data);             
+               data = matrix.erase(data);              
                numNodes--;
-       
+               return(data);
        //  seems like i should be updating smallDist here, but the only time we remove cells is when
        //  clustering and the clustering algorithm updates smallDist
        }
        catch(exception& e) {
-               errorOut(e, "SparseMatrix", "rmCell");
+               m->errorOut(e, "SparseMatrix", "rmCell");
                exit(1);
        }
 }
@@ -51,7 +50,7 @@ void SparseMatrix::addCell(PCell value){
                }
        }
        catch(exception& e) {
-               errorOut(e, "SparseMatrix", "addCell");
+               m->errorOut(e, "SparseMatrix", "addCell");
                exit(1);
        }
 }
@@ -67,7 +66,7 @@ void SparseMatrix::clear(){
                smallDist = 1e6;
        }
        catch(exception& e) {
-               errorOut(e, "SparseMatrix", "clear");
+               m->errorOut(e, "SparseMatrix", "clear");
                exit(1);
        }
 }
@@ -89,18 +88,16 @@ MatData SparseMatrix::end(){
 void SparseMatrix::print(){
        try {
                int index = 0;
-               
-               mothurOutEndLine();
-               mothurOut("Index\tRow\tColumn\tDistance");
-               mothurOutEndLine();
+       
+               cout << endl << "Index\tRow\tColumn\tDistance" << endl;
        
                for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
-                       mothurOut(toString(index) + "\t" + toString(currentCell->row)  + "\t" + toString(currentCell->column) + "\t" + toString(currentCell->dist)); mothurOutEndLine();
+                       cout << index << '\t' << currentCell->row  << '\t' << currentCell->column << '\t' << currentCell->dist << endl;
                        index++;
                }
        }
        catch(exception& e) {
-               errorOut(e, "SparseMatrix", "print");
+               m->errorOut(e, "SparseMatrix", "print");
                exit(1);
        }
 }
@@ -111,18 +108,15 @@ void SparseMatrix::print(ListVector* list){
        try {
                int index = 0;
        
-               mothurOutEndLine();
-               mothurOut("Index\tRow\tColumn\tDistance");
-               mothurOutEndLine();
-
+               m->mothurOutEndLine(); m->mothurOut("Index\tRow\tColumn\tDistance"); m->mothurOutEndLine();
        
                for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
-                       mothurOut(toString(index) + "\t" + toString(list->get(currentCell->row))  + "\t" + toString(list->get(currentCell->column)) + "\t" + toString(currentCell->dist)); mothurOutEndLine();
+                       m->mothurOut(toString(index) + "\t" + toString(list->get(currentCell->row))  + "\t" + toString(list->get(currentCell->column)) + "\t" + toString(currentCell->dist)); m->mothurOutEndLine();
                        index++;
                }
        }
        catch(exception& e) {
-               errorOut(e, "SparseMatrix", "print");
+               m->errorOut(e, "SparseMatrix", "print");
                exit(1);
        }
 }
@@ -142,7 +136,7 @@ PCell* SparseMatrix::getSmallestCell(){
        //      if the mins vector is empty go here...
                if(mins.empty()){               
                        mins.clear();
-               
+       
                        smallDist = begin()->dist;  //set the first candidate small distance
                
                        for(MatData currentCell=begin();currentCell!=end();currentCell++){
@@ -174,7 +168,7 @@ PCell* SparseMatrix::getSmallestCell(){
                return smallCell;
        }
        catch(exception& e) {
-               errorOut(e, "SparseMatrix", "getSmallestCell");
+               m->errorOut(e, "SparseMatrix", "getSmallestCell");
                exit(1);
        }
 }