X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=sparsematrix.cpp;h=3a0ec6521720c1f89eb7c54ce47f60a2f81d364a;hp=fc10d27e4193dfcce4ecde200416157876c9ad14;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=c5c7502f435e1413c19e373dab1dfebcaa67588d diff --git a/sparsematrix.cpp b/sparsematrix.cpp index fc10d27..3a0ec65 100644 --- a/sparsematrix.cpp +++ b/sparsematrix.cpp @@ -2,13 +2,10 @@ #include "sparsematrix.hpp" #include "listvector.hpp" -using namespace std; - -typedef list::iterator MatData; /***********************************************************************/ -SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){}; +SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){ m = MothurOut::getInstance(); } /***********************************************************************/ @@ -24,26 +21,22 @@ 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) { - cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SparseMatrix", "rmCell"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SparseMatrix class function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -57,13 +50,9 @@ void SparseMatrix::addCell(PCell value){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SparseMatrix", "addCell"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SparseMatrix class function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -77,13 +66,9 @@ void SparseMatrix::clear(){ smallDist = 1e6; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SparseMatrix", "clear"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SparseMatrix class function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -112,13 +97,9 @@ void SparseMatrix::print(){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SparseMatrix", "print"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -127,21 +108,17 @@ void SparseMatrix::print(ListVector* list){ try { int index = 0; - cout << endl << "Index\tRow\tColumn\tDistance" << endl; + m->mothurOutEndLine(); m->mothurOut("Index\tRow\tColumn\tDistance"); m->mothurOutEndLine(); for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){ - cout << index << '\t' << list->get(currentCell->row) << '\t' << list->get(currentCell->column) << '\t' << currentCell->dist << endl; + 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) { - cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SparseMatrix", "print"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -159,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++){ @@ -191,13 +168,9 @@ PCell* SparseMatrix::getSmallestCell(){ return smallCell; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SparseMatrix", "getSmallestCell"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SparseMatrix class function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/