+//*********************************************************************************************************************
+string CatchAllCommand::combineSummmary(vector<string>& outputNames) {
+ try {
+
+ ofstream out;
+ map<string, string> variables;
+ variables["[filename]"] = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile));
+ string combineFileName = getOutputFileName("summary", variables);
+
+ //open combined file
+ m->openOutputFile(combineFileName, out);
+
+ out << "label\tgroup\tmodel\testimate\tlci\tuci" << endl;
+
+ //open each groups summary file
+ string newLabel = "";
+ int numLines = 0;
+ map<string, vector<string> > files;
+ for (int i=0; i<outputNames.size(); i++) {
+ vector<string> thisFilesLines;
+
+ ifstream temp;
+ m->openInputFile(outputNames[i], temp);
+
+ //read through first line - labels
+ m->getline(temp);
+ m->gobble(temp);
+
+ //for each label
+ while (!temp.eof()) {
+
+ string thisLine = "";
+ string tempLabel;
+
+ for (int j = 0; j < 5; j++) {
+ temp >> tempLabel;
+
+ //save for later
+ if (j == 1) { thisLine += groups[i] + "\t" + tempLabel + "\t"; }
+ else{ thisLine += tempLabel + "\t"; }
+ }
+
+ thisLine += "\n";
+
+ thisFilesLines.push_back(thisLine);
+
+ m->gobble(temp);
+ }
+
+ files[outputNames[i]] = thisFilesLines;
+
+ numLines = thisFilesLines.size();
+
+ temp.close();
+ m->mothurRemove(outputNames[i]);
+ }
+
+ //for each label
+ for (int k = 0; k < numLines; k++) {
+
+ //grab summary data for each group
+ for (int i=0; i<outputNames.size(); i++) {
+ out << files[outputNames[i]][k];
+ }
+ }
+
+
+ out.close();
+
+ //return combine file name
+ return combineFileName;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "CatchAllCommand", "combineSummmary");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int CatchAllCommand::createSummaryFile(string file1, string label, ofstream& out) {
+ try {
+
+ ifstream in;
+ int able = m->openInputFile(file1, in, "noerror");
+
+ if (able == 1) { m->mothurOut("[ERROR]: the catchall program did not run properly. Please check to make sure it is located in the same folder as your mothur executable.");m->mothurOutEndLine(); m->control_pressed = true; return 0; }
+
+ if (!in.eof()) {
+
+ string header = m->getline(in); m->gobble(in);
+
+ int pos = header.find("Total Number of Observed Species =");
+ string numString = "";
+
+
+ if (pos == string::npos) { m->mothurOut("[ERROR]: cannot parse " + file1); m->mothurOutEndLine(); }
+ else {
+ //pos will be the position of the T in total, so we want to count to the position of =
+ pos += 34;
+ char c=header[pos];
+ while (c != ','){
+ if (c != ' ') {
+ numString += c;
+ }
+ pos++;
+ c=header[pos];
+
+ //sanity check
+ if (pos > header.length()) { m->mothurOut("Cannot find number of OTUs in " + file1); m->mothurOutEndLine(); in.close(); return 0; }
+ }
+ }
+
+ string firstline = m->getline(in); m->gobble(in);
+ vector<string> values;
+ m->splitAtComma(firstline, values);
+
+ values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
+
+ if (values.size() == 1) { //grab next line if firstline didn't have what you wanted
+ string secondline = m->getline(in); m->gobble(in);
+ values.clear();
+ m->splitAtComma(secondline, values);
+
+ values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
+ }
+
+ if (values.size() == 1) { //still not what we wanted fill values with numOTUs
+ values.resize(8, "");
+ values[1] = "Sobs";
+ values[4] = numString;
+ values[6] = numString;
+ values[7] = numString;
+ }
+
+ if (values.size() < 8) { values.resize(8, ""); }
+
+ out << label << '\t' << values[1] << '\t' << values[4] << '\t' << values[6] << '\t' << values[7] << endl;
+ }
+
+ in.close();
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "CatchAllCommand", "createSummaryFile");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> CatchAllCommand::parseSharedFile(string filename) {
+ try {
+ vector<string> filenames;
+
+ //read first line
+ InputData input(filename, "sharedfile");
+ vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
+
+ string sharedFileRoot = outputDir + m->getRootName(m->getSimpleName(filename));
+
+ //clears file before we start to write to it below
+ for (int i=0; i<lookup.size(); i++) {
+ m->mothurRemove((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
+ filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
+ groups.push_back(lookup[i]->getGroup());
+ }
+
+ while(lookup[0] != NULL) {
+
+ for (int i = 0; i < lookup.size(); i++) {
+ SAbundVector sav = lookup[i]->getSAbundVector();
+ ofstream out;
+ m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".sabund", out);
+ sav.print(out);
+ out.close();
+ }
+
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+ lookup = input.getSharedRAbundVectors();
+ }
+
+ return filenames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "CatchAllCommand", "parseSharedFile");
+ exit(1);
+ }
+}