+ 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++) {
+ if (groupfile != "") {
+ 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; }
+
+ //add this name to correct group
+ if (m->inUsersGroups(thisgroup, Groups)) { NamesInGroup[thisgroup].push_back(namesInBin[j]); }
+ }else {
+ vector<string> thisSeqsGroups = ct.getGroups(namesInBin[j]);
+ for (int k = 0; k < thisSeqsGroups.size(); k++) {
+ if (m->inUsersGroups(thisSeqsGroups[k], Groups)) { NamesInGroup[thisSeqsGroups[k]].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]], 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::processFastaNames(string filename, string label) {
+ try{
+
+ //create output file
+ if (outputDir == "") { outputDir += m->hasPath(listfile); }
+ string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + label + "." + getOutputFileNameTag("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;
+ string tempGroup = "";
+ in >> tempGroup; m->gobble(in);
+
+ CountTable thisCt;
+ if (countfile != "") {
+ thisCt.readTable(countfile);
+ if (tempGroup != "noGroup") { out2 << "Representative_Sequence\ttotal\t" << tempGroup << endl; }
+ }
+
+ int thistotal = 0;
+ while (!in.eof()) {
+ string rep, binnames;
+ in >> i >> rep >> binnames; m->gobble(in);
+
+ vector<string> names;
+ m->splitAtComma(binnames, names);
+ int binsize = names.size();
+
+ if (countfile == "") { out2 << rep << '\t' << binnames << endl; }
+ else {
+ if (tempGroup == "noGroup") {
+ for (int j = 0; j < names.size(); j++) {
+ if (names[j] != rep) { thisCt.mergeCounts(rep, names[j]); }
+ }
+ binsize = thisCt.getNumSeqs(rep);
+ }else {
+ int total = 0;
+ for (int j = 0; j < names.size(); j++) { total += thisCt.getGroupCount(names[j], tempGroup); }
+ out2 << rep << '\t' << total << '\t' << total << endl;
+ binsize = total;
+ }
+ }
+ thistotal += binsize;
+ //if you have a groupfile
+ string group = "";
+ map<string, string> groups;
+ map<string, string>::iterator groupIt;
+ if (groupfile != "") {
+ //find the groups that are in this bin
+ for (int 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 if (hasGroups) {
+ map<string, string> groups;
+ for (int i = 0; i < names.size(); i++) {
+ vector<string> thisSeqsGroups = ct.getGroups(names[i]);
+ for (int j = 0; j < thisSeqsGroups.size(); j++) { groups[thisSeqsGroups[j]] = thisSeqsGroups[j]; }
+ }
+ //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);
+ //cout << group << endl;
+ }
+ else{ group = ""; }