+ if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want
+ itout = outputStrings.find(group+rareAbund);
+ if (itout == outputStrings.end()) {
+ outputStrings[group+rareAbund] = names[i] + '\t' + names[i];
+ }else { outputStrings[group+rareAbund] += "," + names[i]; }
+ }else if(group == "not found") {
+ m->mothurOut(names[i] + " is not in your groupfile. Ignoring."); m->mothurOutEndLine();
+ }
+ }
+
+ for (itout = outputStrings.begin(); itout != outputStrings.end(); itout++) { *(filehandles[itout->first]) << itout->second << endl; }
+ }
+
+
+ for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
+ (*(filehandles[it3->first])).close();
+ outputNames.push_back(fileroot + it3->first + ".names");
+ delete it3->second;
+ }
+ }
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SplitAbundCommand", "writeNames");
+ exit(1);
+ }
+}
+/**********************************************************************************************************************/
+//just write the unique names - if a namesfile is given
+int SplitAbundCommand::writeAccnos(string tag) {
+ try {
+
+ map<string, ofstream*> filehandles;
+
+ if (Groups.size() == 0) {
+ ofstream aout;
+ ofstream rout;
+
+
+ string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare.accnos";
+ m->openOutputFile(rare, rout);
+ outputNames.push_back(rare);
+
+ for (set<string>::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) {
+ rout << (*itRare) << endl;
+ }
+ rout.close();
+
+ string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund.accnos";
+ m->openOutputFile(abund, aout);
+ outputNames.push_back(abund);
+
+ for (set<string>::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) {
+ aout << (*itAbund) << endl;
+ }
+ aout.close();
+
+ }else{ //parse names by abundance and group
+ string fileroot = outputDir + m->getRootName(m->getSimpleName(inputFile));
+ ofstream* temp;
+ ofstream* temp2;
+ map<string, ofstream*> filehandles;
+ map<string, ofstream*>::iterator it3;
+
+ for (int i=0; i<Groups.size(); i++) {
+ temp = new ofstream;
+ filehandles[Groups[i]+".rare"] = temp;
+ temp2 = new ofstream;
+ filehandles[Groups[i]+".abund"] = temp2;
+
+ m->openOutputFile(fileroot + tag + Groups[i] + ".rare.accnos", *(filehandles[Groups[i]+".rare"]));
+ m->openOutputFile(fileroot + tag + Groups[i] + ".abund.accnos", *(filehandles[Groups[i]+".abund"]));
+ }
+
+ //write rare
+ for (set<string>::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) {
+ string group = groupMap->getGroup(*itRare);