From: westcott Date: Mon, 6 Dec 2010 12:47:44 +0000 (+0000) Subject: added summary output to catchall command X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=af27acb766f6947c45e1eb65438d878c7ea48ef3 added summary output to catchall command --- diff --git a/catchallcommand.cpp b/catchallcommand.cpp index efe99b0..7b298ef 100644 --- a/catchallcommand.cpp +++ b/catchallcommand.cpp @@ -179,6 +179,15 @@ int CatchAllCommand::execute() { set processedLabels; set userLabels = labels; + string summaryfilename = outputDir + m->getRootName(m->getSimpleName(sabundfile)) + "catchall.summary"; + summaryfilename = m->getFullPathName(summaryfilename); + outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename); + + ofstream out; + m->openOutputFile(summaryfilename, out); + + out << "label\tmodel\testimate\tlci\tuci" << endl; + //for each label the user selected while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { @@ -205,9 +214,9 @@ int CatchAllCommand::execute() { outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv"); outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv"); - createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel()); + createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str()); } delete read; delete input; globaldata->ginput = NULL; delete sabund; return 0; } + if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str()); } delete read; delete input; globaldata->ginput = NULL; delete sabund; return 0; } processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); @@ -241,9 +250,9 @@ int CatchAllCommand::execute() { outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv"); outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv"); - createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel()); + createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str()); } delete read; delete input; globaldata->ginput = NULL; delete sabund; return 0; } + if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str()); } delete read; delete input; globaldata->ginput = NULL; delete sabund; return 0; } processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); @@ -298,11 +307,12 @@ int CatchAllCommand::execute() { outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv"); outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv"); - createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel()); + createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out); delete sabund; } - + + out.close(); delete read; delete input; globaldata->ginput = NULL; @@ -348,16 +358,8 @@ string CatchAllCommand::process(SAbundVector* sabund) { } } //********************************************************************************************************************** -string CatchAllCommand::createSummaryFile(string file1, string label) { +int CatchAllCommand::createSummaryFile(string file1, string label, ofstream& out) { try { - string filename = outputDir + m->getRootName(m->getSimpleName(sabundfile)) + label + ".catchall.summary"; - filename = m->getFullPathName(filename); - outputNames.push_back(filename); outputTypes["summary"].push_back(filename); - - ofstream out; - m->openOutputFile(filename, out); - - out << "group\tmodel\testimate\tlci\tuci" << endl; ifstream in; m->openInputFile(file1, in); @@ -367,28 +369,56 @@ string CatchAllCommand::createSummaryFile(string file1, string label) { string header = m->getline(in); m->gobble(in); int pos = header.find("Total Number of Observed Species ="); - cout << pos << '\t' << header.length() << endl; exit(1); + 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]; - string numString = ""; 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 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); - int numOtus; convert(numString, numOtus); - cout << numOtus << endl; + 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(); - out.close(); - return filename; + return 0; } catch(exception& e) { diff --git a/catchallcommand.h b/catchallcommand.h index 8795cd7..4406361 100644 --- a/catchallcommand.h +++ b/catchallcommand.h @@ -48,7 +48,7 @@ private: map< string, vector > outputTypes; string process(SAbundVector*); - string createSummaryFile(string, string); + int createSummaryFile(string, string, ofstream&); }; /****************************************************************************/ diff --git a/mothur b/mothur index a9ab78c..3f9ed5f 100755 Binary files a/mothur and b/mothur differ diff --git a/mothurout.cpp b/mothurout.cpp index b30ee3c..e041582 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -1221,17 +1221,6 @@ void MothurOut::splitAtChar(string& estim, vector& container, char symbo } container.push_back(individual); - /* - - while (estim.find_first_of(symbol) != -1) { - individual = estim.substr(0,estim.find_first_of(symbol)); - if ((estim.find_first_of(symbol)+1) <= estim.length()) { //checks to make sure you don't have dash at end of string - estim = estim.substr(estim.find_first_of(symbol)+1, estim.length()); - container.push_back(individual); - } - } - //get last one - container.push_back(estim); */ } catch(exception& e) { errorOut(e, "MothurOut", "splitAtChar");