+//**********************************************************************************************************************
+int CatchAllCommand::createSummaryFile(string file1, string label, ofstream& out) {
+ try {
+
+ ifstream in;
+ m->openInputFile(file1, in);
+
+ 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);
+ }
+}