X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedlistvector.cpp;h=6dfcb97f0aff013d15c1c641e93a24b0d7b229a3;hb=e0ce7cbc93d7d2fbb753ca694182db092a0ea0e7;hp=b5624508ac792aa82d367ed04ed1fbaf571d4cd6;hpb=d59f91eb1230d2c7867a92cb86138b7003100ab4;p=mothur.git diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index b562450..6dfcb97 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -7,10 +7,6 @@ * */ - -using namespace std; - - #include "sabundvector.hpp" #include "rabundvector.hpp" #include "ordervector.hpp" @@ -20,39 +16,33 @@ using namespace std; /***********************************************************************/ -SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}; +SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){ 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){ groupmap = NULL; } /***********************************************************************/ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { - globaldata = GlobalData::getInstance(); - //set up groupmap for later. - groupmap = new GroupMap(globaldata->getGroupFile()); - groupmap->readMap(); + groupmap = new GroupMap(m->getGroupFile()); + groupmap->readMap(); int hold; string inputData; f >> label >> hold; data.assign(hold, ""); - + for(int i=0;i> inputData; set(i, inputData); } - + } 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"; + m->errorOut(e, "SharedListVector", "SharedListVector"); exit(1); } } @@ -60,22 +50,20 @@ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numB /***********************************************************************/ void SharedListVector::set(int binNumber, string seqNames){ try { - int nNames_old = getNumNames(data[binNumber]); + int nNames_old = m->getNumNames(data[binNumber]); data[binNumber] = seqNames; - int nNames_new = getNumNames(seqNames); + int nNames_new = m->getNumNames(seqNames); if(nNames_old == 0) { numBins++; } if(nNames_new == 0) { numBins--; } if(nNames_new > maxRank) { maxRank = nNames_new; } 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"; + m->errorOut(e, "SharedListVector", "set"); exit(1); } } @@ -91,7 +79,7 @@ string SharedListVector::get(int index){ void SharedListVector::push_back(string seqNames){ try { data.push_back(seqNames); - int nNames = getNumNames(seqNames); + int nNames = m->getNumNames(seqNames); numBins++; @@ -100,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"; + m->errorOut(e, "SharedListVector", "push_back"); exit(1); } } @@ -144,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"; + m->errorOut(e, "SharedListVector", "print"); exit(1); } } @@ -161,7 +141,7 @@ RAbundVector SharedListVector::getRAbundVector(){ RAbundVector rav; for(int i=0;igetNumNames(data[i]); rav.push_back(binSize); } @@ -179,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"; + m->errorOut(e, "SharedListVector", "getRAbundVector"); exit(1); } } @@ -195,7 +171,7 @@ SAbundVector SharedListVector::getSAbundVector(){ SAbundVector sav(maxRank+1); for(int i=0;igetNumNames(data[i]); sav.set(binSize, sav.get(binSize) + 1); } sav.set(0, 0); @@ -204,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"; + m->errorOut(e, "SharedListVector", "getSAbundVector"); exit(1); } } @@ -222,30 +194,32 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){ order->setLabel(label); for(int i=0;igetNumNames(get(i)); //find number of individual in given bin names = get(i); while (names.find_first_of(',') != -1) { 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") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->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") { m->mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); m->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"; + m->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) { @@ -259,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") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->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 } @@ -266,6 +241,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { //get last name groupName = groupmap->getGroup(names); + if(groupName == "not found") { m->mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); m->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 } @@ -273,15 +249,12 @@ 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"; - 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"; + m->errorOut(e, "SharedListVector", "getSharedRAbundVector"); exit(1); } } @@ -290,22 +263,71 @@ vector SharedListVector::getSharedRAbundVector() { try { SharedUtil* util; util = new SharedUtil(); - vector lookup; - - util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); - util->getSharedVectors(globaldata->Groups, lookup, this->getSharedOrderVector()); + vector lookup; //contains just the groups the user selected + map finder; //contains all groups in groupmap + string group, names, name; + vector Groups = m->getGroups(); + vector allGroups = groupmap->getNamesOfGroups(); + util->setGroups(Groups, allGroups); + m->setGroups(Groups); + delete util; + + for (int i = 0; i < allGroups.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(data.size()); + finder[allGroups[i]] = temp; + finder[allGroups[i]]->setLabel(label); + finder[allGroups[i]]->setGroup(allGroups[i]); + if (m->inUsersGroups(allGroups[i], m->getGroups())) { //if this group is in user groups + lookup.push_back(finder[allGroups[i]]); + } + } + + //fill vectors + for(int i=0;igetGroup(seqName); + if(group == "not found") { m->mothurOut("Error: Sequence '" + seqName + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } + finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in + + seqName = ""; + } + else{ + seqName += names[j]; + } + } + group = groupmap->getGroup(seqName); + if(group == "not found") { m->mothurOut("Error: Sequence '" + seqName + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } + finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in + + + +// while (names.find_first_of(',') != -1) { +// 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") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->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") { m->mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); m->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) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->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"; - exit(1); - } - } /***********************************************************************/ @@ -320,11 +342,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"; + m->errorOut(e, "SharedListVector", "getSharedSAbundVector"); exit(1); } } @@ -337,7 +355,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ OrderVector ov; for(int i=0;igetNumNames(data[i]); for(int j=0;j* orderMap = NULL){ } else{ if(orderMap->count(seqName) == 0){ - cerr << seqName << " not found, check *.names file\n"; + m->mothurOut(seqName + " not found, check *.names file\n"); exit(1); } @@ -375,7 +393,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ } if(orderMap->count(seqName) == 0){ - cerr << seqName << " not found, check *.names file\n"; + m->mothurOut(seqName + " not found, check *.names file\n"); exit(1); } ov.set((*orderMap)[seqName], i); @@ -388,11 +406,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"; + m->errorOut(e, "SharedListVector", "getOrderVector"); exit(1); } }