+//remove group
+int CountTable::removeGroup(string groupName) {
+ try {
+ if (hasGroups) {
+ //save for later in case removing a group means we need to remove a seq.
+ map<int, string> reverse;
+ for (map<string, int>::iterator it = indexNameMap.begin(); it !=indexNameMap.end(); it++) { reverse[it->second] = it->first; }
+
+ map<string, int>::iterator it = indexGroupMap.find(groupName);
+ if (it == indexGroupMap.end()) {
+ m->mothurOut("[ERROR]: " + groupName + " is not in your count table. Please correct.\n"); m->control_pressed = true;
+ }else {
+ int indexOfGroupToRemove = it->second;
+ map<string, int> currentGroupIndex = indexGroupMap;
+ vector<string> newGroups;
+ for (int i = 0; i < groups.size(); i++) {
+ if (groups[i] != groupName) {
+ newGroups.push_back(groups[i]);
+ indexGroupMap[groups[i]] = newGroups.size()-1;
+ }
+ }
+ indexGroupMap.erase(groupName);
+ groups = newGroups;
+ totalGroups.erase(totalGroups.begin()+indexOfGroupToRemove);
+
+ int thisIndex = 0;
+ map<string, int> newIndexNameMap;
+ for (int i = 0; i < counts.size(); i++) {
+ int num = counts[i][indexOfGroupToRemove];
+ counts[i].erase(counts[i].begin()+indexOfGroupToRemove);
+ totals[i] -= num;
+ total -= num;
+ if (totals[i] == 0) { //your sequences are only from the group we want to remove, then remove you.
+ counts.erase(counts.begin()+i);
+ totals.erase(totals.begin()+i);
+ uniques--;
+ i--;
+ }
+ newIndexNameMap[reverse[thisIndex]] = i;
+ thisIndex++;
+ }
+ indexNameMap = newIndexNameMap;
+
+ if (groups.size() == 0) { hasGroups = false; }
+ }
+ }else { m->mothurOut("[ERROR]: your count table does not contain group information, can not remove group " + groupName + ".\n"); m->control_pressed = true; }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "CountTable", "removeGroup");
+ exit(1);
+ }
+}
+/************************************************************/