+ }
+
+ for (itout = outputStrings.begin(); itout != outputStrings.end(); itout++) {
+ *(filehandles[itout->first]) << itout->second << endl;
+ wroteFile[itout->first] = true;
+ }
+ }
+
+
+ for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
+ (*(filehandles[it3->first])).close();
+ if (wroteFile[it3->first] == true) { outputNames.push_back(fileroot + it3->first + ".names"); }
+ else { remove((it3->first).c_str()); }
+ 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;
+
+ if (rareNames.size() != 0) {
+ string rare = outputDir + getRootName(getSimpleName(inputFile)) + tag + "rare.accnos";
+ openOutputFile(rare, rout);
+ outputNames.push_back(rare);
+
+ for (set<string>::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) {
+ rout << (*itRare) << endl;
+ }
+ rout.close();
+ }
+
+ if (abundNames.size() != 0) {
+ string abund = outputDir + getRootName(getSimpleName(inputFile)) + tag + "abund.accnos";
+ 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 + getRootName(getSimpleName(inputFile));
+ ofstream* temp;
+ ofstream* temp2;
+ map<string, bool> wroteFile;
+ 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;
+
+ openOutputFile(fileroot + tag + Groups[i] + ".rare.accnos", *(filehandles[Groups[i]+".rare"]));
+ openOutputFile(fileroot + tag + Groups[i] + ".abund.accnos", *(filehandles[Groups[i]+".abund"]));
+
+ wroteFile[Groups[i] + ".rare"] = false;
+ wroteFile[Groups[i] + ".abund"] = false;
+ }
+
+ //write rare
+ for (set<string>::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) {
+ string group = groupMap->getGroup(*itRare);