+
+ ofstream newNamesOutput;
+ string outputNamesFile;
+ map<string, ofstream*> filehandles;
+
+ if (Groups.size() == 0) { //you don't want to use groups
+ outputNamesFile = outputDir + getRootName(getSimpleName(listfile)) + processList->getLabel() + ".rep.names";
+ openOutputFile(outputNamesFile, newNamesOutput);
+ outputNames.push_back(outputNamesFile);
+ outputNameFiles[outputNamesFile] = processList->getLabel();
+ }else{ //you want to use groups
+ ofstream* temp;
+ for (int i=0; i<Groups.size(); i++) {
+ temp = new ofstream;
+ filehandles[Groups[i]] = temp;
+ outputNamesFile = outputDir + getRootName(getSimpleName(listfile)) + processList->getLabel() + "." + Groups[i] + ".rep.names";
+
+ openOutputFile(outputNamesFile, *(temp));
+ outputNames.push_back(outputNamesFile);
+ outputNameFiles[outputNamesFile] = processList->getLabel() + "." + Groups[i];
+ }
+ }
+
+ //for each bin in the list vector
+ for (int i = 0; i < processList->size(); i++) {
+ if (m->control_pressed) {
+ out.close();
+ if (Groups.size() == 0) { //you don't want to use groups
+ newNamesOutput.close();
+ }else{
+ for (int j=0; j<Groups.size(); j++) {
+ (*(filehandles[Groups[j]])).close();
+ delete filehandles[Groups[j]];
+ }
+ }
+ return 0;
+ }
+
+ 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;
+ }
+ }
+ }
+ }
+
+ if (Groups.size() == 0) { //you don't want to use groups
+ newNamesOutput.close();
+ }else{
+ for (int i=0; i<Groups.size(); i++) {
+ (*(filehandles[Groups[i]])).close();
+ delete filehandles[Groups[i]];
+ }
+ }
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetOTURepCommand", "process");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int GetOTURepCommand::processNames(string filename, string label) {
+ try{
+
+ //create output file
+ if (outputDir == "") { outputDir += hasPath(listfile); }
+ string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + label + ".rep.fasta";