X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=treemap.cpp;h=dcef7f7c19174f1aaf6a1435931c9005f986f638;hb=8f7164a88df624fd0a8d1eddbb3d744463cc9ecb;hp=5880b0c593fdd0dc96808e485921d96871e865d6;hpb=c5c7502f435e1413c19e373dab1dfebcaa67588d;p=mothur.git diff --git a/treemap.cpp b/treemap.cpp index 5880b0c..dcef7f7 100644 --- a/treemap.cpp +++ b/treemap.cpp @@ -17,7 +17,7 @@ } /************************************************************/ - TreeMap::~TreeMap(){}; + TreeMap::~TreeMap(){} /************************************************************/ void TreeMap::readMap() { @@ -26,10 +26,10 @@ void TreeMap::readMap() { while(fileHandle){ fileHandle >> seqName; //read from first column fileHandle >> seqGroup; //read from second column - + namesOfSeqs.push_back(seqName); setNamesOfGroups(seqGroup); - + treemap[seqName].groupname = seqGroup; //store data in map it2 = seqsPerGroup.find(seqGroup); @@ -44,6 +44,25 @@ void TreeMap::readMap() { fileHandle.close(); } /************************************************************/ +void TreeMap::removeSeq(string seqName) { + + //erase name from namesOfSeqs + for (int i = 0; i < namesOfSeqs.size(); i++) { + if (namesOfSeqs[i] == seqName) { + namesOfSeqs.erase(namesOfSeqs.begin()+i); + break; + } + } + + //decrement sequences in this group + string group = treemap[seqName].groupname; + seqsPerGroup[group]--; + + //remove seq from treemap + it = treemap.find(seqName); + treemap.erase(it); +} +/************************************************************/ int TreeMap::getNumGroups() { @@ -116,11 +135,7 @@ bool TreeMap::isValidGroup(string groupname) { return false; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the TreeMap class function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "TreeMap", "isValidGroup"); exit(1); } } @@ -134,11 +149,7 @@ void TreeMap::print(ostream& output){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the TreeMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "TreeMap", "print"); exit(1); } } @@ -152,7 +163,7 @@ void TreeMap::makeSim(GroupMap* groupmap) { //set names of seqs to names of groups namesOfSeqs = groupmap->namesOfGroups; - // make map where key and value are both the group name since that what the tree.groups command wants + // make map where key and value are both the group name since that what the tree.shared command wants for (int i = 0; i < namesOfGroups.size(); i++) { treemap[namesOfGroups[i]].groupname = namesOfGroups[i]; seqsPerGroup[namesOfGroups[i]] = 1; @@ -162,13 +173,36 @@ void TreeMap::makeSim(GroupMap* groupmap) { } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function make. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "TreeMap", "makeSim"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the TreeMap class function make. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +/************************************************************/ +void TreeMap::makeSim(ListVector* list) { + try { + //set names of groups + namesOfGroups.clear(); + for(int i = 0; i < list->size(); i++) { + namesOfGroups.push_back(list->get(i)); + } + + //set names of seqs to names of groups + namesOfSeqs = namesOfGroups; + + // make map where key and value are both the group name since that what the tree.shared command wants + for (int i = 0; i < namesOfGroups.size(); i++) { + treemap[namesOfGroups[i]].groupname = namesOfGroups[i]; + seqsPerGroup[namesOfGroups[i]] = 1; + } + + numGroups = namesOfGroups.size(); + + } + catch(exception& e) { + m->errorOut(e, "TreeMap", "makeSim"); exit(1); } } + /************************************************************/