+ m->openInputFile(countfile, in);
+
+ bool wroteSomething = false;
+ int removedCount = 0;
+
+ string headers = m->getline(in); m->gobble(in);
+ vector<string> columnHeaders = m->splitWhiteSpace(headers);
+
+ vector<string> groups;
+ map<int, string> originalGroupIndexes;
+ map<string, int> GroupIndexes;
+ set<int> indexOfGroupsChosen;
+ for (int i = 2; i < columnHeaders.size(); i++) { groups.push_back(columnHeaders[i]); originalGroupIndexes[i-2] = columnHeaders[i]; }
+ //sort groups to keep consistent with how we store the groups in groupmap
+ sort(groups.begin(), groups.end());
+ for (int i = 0; i < groups.size(); i++) { GroupIndexes[groups[i]] = i; }
+
+ vector<string> groupsToKeep;
+ for (int i = 0; i < groups.size(); i++) {
+ if (!m->inUsersGroups(groups[i], Groups)) { groupsToKeep.push_back(groups[i]); }
+ }
+ sort(groupsToKeep.begin(), groupsToKeep.end());
+ out << "Representative_Sequence\ttotal\t";
+ for (int i = 0; i < groupsToKeep.size(); i++) { out << groupsToKeep[i] << '\t'; indexOfGroupsChosen.insert(GroupIndexes[groupsToKeep[i]]); }
+ out << endl;
+
+ string name; int oldTotal;
+ while (!in.eof()) {
+
+ if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
+
+ in >> name; m->gobble(in); in >> oldTotal; m->gobble(in);
+ if (m->debug) { m->mothurOut("[DEBUG]: " + name + '\t' + toString(oldTotal) + "\n"); }
+
+ if (names.count(name) == 0) {
+ //if group info, then read it
+ vector<int> selectedCounts; int thisTotal = 0; int temp;
+ for (int i = 0; i < groups.size(); i++) {
+ int thisIndex = GroupIndexes[originalGroupIndexes[i]];
+ in >> temp; m->gobble(in);
+ if (indexOfGroupsChosen.count(thisIndex) != 0) { //we want this group
+ selectedCounts.push_back(temp); thisTotal += temp;
+ }
+ }
+
+ out << name << '\t' << thisTotal << '\t';
+ for (int i = 0; i < selectedCounts.size(); i++) { out << selectedCounts[i] << '\t'; }
+ out << endl;
+
+ wroteSomething = true;
+ removedCount+= (oldTotal - thisTotal);
+ }else { m->getline(in); removedCount += oldTotal; }
+
+ m->gobble(in);
+ }
+ in.close();
+ out.close();
+
+ if (wroteSomething == false) { m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine(); }
+ outputTypes["count"].push_back(outputFileName); outputNames.push_back(outputFileName);
+
+ m->mothurOut("Removed " + toString(removedCount) + " sequences from your count file."); m->mothurOutEndLine();
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveGroupsCommand", "readCount");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int RemoveGroupsCommand::readDesign(){
+ try {
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(designfile); }
+ string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + getOutputFileNameTag("design", designfile);
+
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+
+ ifstream in;
+ m->openInputFile(designfile, in);
+ string name, group;