+ 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;
+ m->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 (m->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 += m->hasPath(listfile); }
+ string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + label + ".rep.fasta";
+ m->openOutputFile(outputFileName, out);
+ vector<repStruct> reps;
+ outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName);
+
+ ofstream out2;
+ string tempNameFile = filename + ".temp";
+ m->openOutputFile(tempNameFile, out2);
+
+ ifstream in;
+ m->openInputFile(filename, in);
+
+ int i = 0;
+ while (!in.eof()) {
+ string rep, binnames;
+ in >> i >> rep >> binnames; m->gobble(in);
+ out2 << rep << '\t' << binnames << endl;
+
+ vector<string> names;
+ m->splitAtComma(binnames, names);
+ int binsize = names.size();
+
+ //if you have a groupfile
+ string group = "";
+ if (groupfile != "") {
+ map<string, string> groups;
+ map<string, string>::iterator groupIt;
+
+ //find the groups that are in this bin
+ for (size_t i = 0; i < names.size(); i++) {
+ string groupName = groupMap->getGroup(names[i]);
+ if (groupName == "not found") {
+ m->mothurOut(names[i] + " is missing from your group file. Please correct. "); m->mothurOutEndLine();
+ groupError = true;
+ } else {
+ groups[groupName] = groupName;
+ }
+ }
+
+ //turn the groups into a string
+ for (groupIt = groups.begin(); groupIt != groups.end(); groupIt++) {
+ group += groupIt->first + "-";
+ }
+ //rip off last dash
+ group = group.substr(0, group.length()-1);
+ }else{ group = ""; }