X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=groupmap.cpp;h=9b8aa3f8abc87ef9ff93520a80b3da9169d406f4;hp=8e2139db771010d1b372ccfdc0a6a0523c6e4849;hb=b206f634aae1b4ce13978d203247fb64757d5482;hpb=79ca496859f48f1c38803c0f7c603faac348fe4c diff --git a/groupmap.cpp b/groupmap.cpp index 8e2139d..9b8aa3f 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -372,6 +372,22 @@ bool GroupMap::isValidGroup(string groupname) { } } /************************************************************/ +int GroupMap::getCopy(GroupMap* g) { + try { + vector names = g->getNamesSeqs(); + for (int i = 0; i < names.size(); i++) { + if (m->control_pressed) { break; } + string group = g->getGroup(names[i]); + setGroup(names[i], group); + } + return names.size(); + } + catch(exception& e) { + m->errorOut(e, "GroupMap", "getCopy"); + exit(1); + } +} +/************************************************************/ int GroupMap::getNumSeqs(string group) { try { @@ -389,7 +405,66 @@ int GroupMap::getNumSeqs(string group) { exit(1); } } - +/************************************************************/ +int GroupMap::renameSeq(string oldName, string newName) { + try { + + map::iterator itName; + + itName = groupmap.find(oldName); + + if (itName == groupmap.end()) { + m->mothurOut("[ERROR]: cannot find " + toString(oldName) + " in group file"); + m->control_pressed = true; + return 0; + }else { + string group = itName->second; + groupmap.erase(itName); + groupmap[newName] = group; + } + + return 0; + + } + catch(exception& e) { + m->errorOut(e, "GroupMap", "renameSeq"); + exit(1); + } +} +/************************************************************/ +int GroupMap::print(ofstream& out) { + try { + + for (map::iterator itName = groupmap.begin(); itName != groupmap.end(); itName++) { + out << itName->first << '\t' << itName->second << endl; + } + + return 0; + + } + catch(exception& e) { + m->errorOut(e, "GroupMap", "print"); + exit(1); + } +} +/************************************************************/ +int GroupMap::print(ofstream& out, vector userGroups) { + try { + + for (map::iterator itName = groupmap.begin(); itName != groupmap.end(); itName++) { + if (m->inUsersGroups(itName->second, userGroups)) { + out << itName->first << '\t' << itName->second << endl; + } + } + + return 0; + + } + catch(exception& e) { + m->errorOut(e, "GroupMap", "print"); + exit(1); + } +} /************************************************************/ vector GroupMap::getNamesSeqs(){ try {