+ string temp = processList->get(i);
+ vector<string> namesInBin;
+ splitAtComma(temp, namesInBin);
+
+ if (Groups.size() == 0) {
+ nameRep = findRep(namesInBin);
+ newNamesOutput << i << '\t' << nameRep << '\t' << processList->get(i) << endl;
+ }else{
+ map<string, vector<string> > NamesInGroup;
+ for (int j=0; j<Groups.size(); j++) { //initialize groups
+ NamesInGroup[Groups[j]].resize(0);
+ }
+
+ for (int j=0; j<namesInBin.size(); j++) {
+ string thisgroup = groupMap->getGroup(namesInBin[j]);
+
+ if (thisgroup == "not found") { m->mothurOut(namesInBin[j] + " is not in your groupfile, please correct."); m->mothurOutEndLine(); m->control_pressed = true; }
+
+ if (inUsersGroups(thisgroup, Groups)) { //add this name to correct group
+ NamesInGroup[thisgroup].push_back(namesInBin[j]);
+ }
+ }
+
+ //get rep for each group in otu
+ for (int j=0; j<Groups.size(); j++) {
+ if (NamesInGroup[Groups[j]].size() != 0) { //are there members from this group in this otu?
+ //get rep for each group
+ nameRep = findRep(NamesInGroup[Groups[j]]);
+
+ //output group rep and other members of this group
+ (*(filehandles[Groups[j]])) << i << '\t' << nameRep << '\t';
+
+ for (int k=0; k<NamesInGroup[Groups[j]].size()-1; k++) {//output list of names in this otu from this group
+ (*(filehandles[Groups[j]])) << NamesInGroup[Groups[j]][k] << ",";
+ }
+ //output last name
+ (*(filehandles[Groups[j]])) << NamesInGroup[Groups[j]][NamesInGroup[Groups[j]].size()-1] << endl;
+ }
+ }
+ }