X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=groupmap.cpp;h=9b8aa3f8abc87ef9ff93520a80b3da9169d406f4;hb=250e3b11b1c9c1e1ad458ab6c7e71ac2e67e11d9;hp=e5d8427200aed0a61aaf04a0e7084ed0e17a0a78;hpb=4b54ce99af7db8019ea907cd7c2edf789369ada9;p=mothur.git diff --git a/groupmap.cpp b/groupmap.cpp index e5d8427..9b8aa3f 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -317,6 +317,10 @@ string GroupMap::getGroup(string sequenceName) { if (it != groupmap.end()) { //sequence name was in group file return it->second; }else { + //look for it in names of groups to see if the user accidently used the wrong file + if (m->inUsersGroups(sequenceName, namesOfGroups)) { + m->mothurOut("[WARNING]: Your group or design file contains a group named " + sequenceName + ". Perhaps you are used a group file instead of a design file? A common cause of this is using a tree file that relates your groups (created by the tree.shared command) with a group file that assigns sequences to a group."); m->mothurOutEndLine(); + } return "not found"; } } @@ -368,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 { @@ -385,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 {