]> git.donarmstrong.com Git - mothur.git/blobdiff - groupmap.cpp
fixes while testing 1.33.0
[mothur.git] / groupmap.cpp
index 8e2139db771010d1b372ccfdc0a6a0523c6e4849..9b8aa3f8abc87ef9ff93520a80b3da9169d406f4 100644 (file)
@@ -372,6 +372,22 @@ bool GroupMap::isValidGroup(string groupname) {
        }
 }
 /************************************************************/
+int GroupMap::getCopy(GroupMap* g) {
+       try {
+        vector<string> 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<string, string>::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<string, string>::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<string> userGroups) {
+       try {
+               
+               for (map<string, string>::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<string> GroupMap::getNamesSeqs(){
        try {