X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedlistvector.cpp;h=a113ebe7e82e93f135541b0bfa0ffc7a3b1d33b1;hb=d2fc851cdaf57874b3ac8261b220fad35750daad;hp=81dd7281893a36667f4314f268fe9571c6bade61;hpb=09a01fb51eea9e81409d367410c831394193fd86;p=mothur.git diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 81dd728..a113ebe 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -7,26 +7,20 @@ * */ - -using namespace std; - -#include -#include #include "sabundvector.hpp" #include "rabundvector.hpp" #include "ordervector.hpp" -#include "datavector.hpp" -#include "utilities.hpp" #include "sharedlistvector.h" #include "sharedordervector.h" +#include "sharedutilities.h" /***********************************************************************/ -SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}; +SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; } /***********************************************************************/ -SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){}; +SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; } /***********************************************************************/ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { @@ -50,11 +44,7 @@ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numB } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function SharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function SharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "SharedListVector"); exit(1); } } @@ -73,11 +63,7 @@ void SharedListVector::set(int binNumber, string seqNames){ numSeqs += (nNames_new - nNames_old); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "set"); exit(1); } } @@ -102,11 +88,7 @@ void SharedListVector::push_back(string seqNames){ numSeqs += nNames; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "push_back"); exit(1); } } @@ -146,11 +128,7 @@ void SharedListVector::print(ostream& output){ output << endl; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "print"); exit(1); } } @@ -181,11 +159,7 @@ RAbundVector SharedListVector::getRAbundVector(){ return rav; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "getRAbundVector"); exit(1); } } @@ -206,11 +180,7 @@ SAbundVector SharedListVector::getSAbundVector(){ return sav; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "getSAbundVector"); exit(1); } } @@ -230,24 +200,26 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){ name = names.substr(0,names.find_first_of(',')); names = names.substr(names.find_first_of(',')+1, names.length()); groupName = groupmap->getGroup(name); + + if(groupName == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + order->push_back(i, binSize, groupName); //i represents what bin you are in } //get last name groupName = groupmap->getGroup(names); + if(groupName == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } order->push_back(i, binSize, groupName); } + random_shuffle(order->begin(), order->end()); + order->updateStats(); + return order; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "getSharedOrderVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - } /***********************************************************************/ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { @@ -261,6 +233,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { name = names.substr(0,names.find_first_of(',')); names = names.substr(names.find_first_of(',')+1, names.length()); group = groupmap->getGroup(name); + if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } if (group == groupName) { //this name is in the group you want the vector for. rav.set(i, rav.getAbundance(i) + 1, group); //i represents what bin you are in } @@ -268,6 +241,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { //get last name groupName = groupmap->getGroup(names); + if(groupName == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } if (group == groupName) { //this name is in the group you want the vector for. rav.set(i, rav.getAbundance(i) + 1, group); //i represents what bin you are in } @@ -275,15 +249,59 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { rav.setLabel(label); rav.setGroup(groupName); + return rav; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "getSharedRAbundVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +/***********************************************************************/ +vector SharedListVector::getSharedRAbundVector() { + try { + SharedUtil* util; + util = new SharedUtil(); + vector lookup; + map finder; + string group, names, name; + + util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); + + delete util; + + for (int i = 0; i < globaldata->Groups.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(data.size()); + finder[globaldata->Groups[i]] = temp; + finder[globaldata->Groups[i]]->setLabel(label); + finder[globaldata->Groups[i]]->setGroup(globaldata->Groups[i]); + //*temp = getSharedRAbundVector(globaldata->Groups[i]); + lookup.push_back(finder[globaldata->Groups[i]]); + } + + //fill vectors + for(int i=0;igetGroup(name); + if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in + } + + //get last name + group = groupmap->getGroup(names); + if(group == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in + + } + + return lookup; + } + catch(exception& e) { + errorOut(e, "SharedListVector", "getSharedRAbundVector"); exit(1); } } @@ -300,11 +318,7 @@ SharedSAbundVector SharedListVector::getSharedSAbundVector(string groupName) { return sav; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "getSharedSAbundVector"); exit(1); } } @@ -345,7 +359,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ } else{ if(orderMap->count(seqName) == 0){ - cerr << seqName << " not found, check *.names file\n"; + mothurOut(seqName + " not found, check *.names file\n"); exit(1); } @@ -355,7 +369,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ } if(orderMap->count(seqName) == 0){ - cerr << seqName << " not found, check *.names file\n"; + mothurOut(seqName + " not found, check *.names file\n"); exit(1); } ov.set((*orderMap)[seqName], i); @@ -368,11 +382,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SharedListVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "SharedListVector", "getOrderVector"); exit(1); } }