X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=catchallcommand.cpp;h=7b298ef87345ea7b9ce497ac6d0b2e6d2d94759d;hb=af27acb766f6947c45e1eb65438d878c7ea48ef3;hp=d6264db3309bd867696ee0b89041b9e34d3b6556;hpb=8bc3e5b38c2317a1715f53be22fa96455868c281;p=mothur.git diff --git a/catchallcommand.cpp b/catchallcommand.cpp index d6264db..7b298ef 100644 --- a/catchallcommand.cpp +++ b/catchallcommand.cpp @@ -26,8 +26,9 @@ vector CatchAllCommand::getValidParameters(){ CatchAllCommand::CatchAllCommand(){ try { //initialize outputTypes - - //need to determine outputFIles and types + vector tempOutNames; + outputTypes["csv"] = tempOutNames; + outputTypes["summary"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "CatchAllCommand", "CatchAllCommand"); @@ -62,7 +63,7 @@ CatchAllCommand::CatchAllCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; - allLines = 0; + allLines = 1; //allow user to run help if(option == "help") { help(); abort = true; } @@ -83,10 +84,10 @@ CatchAllCommand::CatchAllCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - //initialize outputTypes - //need to determine outputFIles and types - + vector tempOutNames; + outputTypes["csv"] = tempOutNames; + outputTypes["summary"] = tempOutNames; //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); @@ -117,7 +118,7 @@ CatchAllCommand::CatchAllCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter - outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = "./"; } + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(sabundfile); } } } @@ -130,9 +131,10 @@ CatchAllCommand::CatchAllCommand(string option) { void CatchAllCommand::help(){ try { - m->mothurOut("The catchall command interfaces mothur with the catchall program written by ...citation goes here...\n"); - m->mothurOut("For more information about clearcut refer to http://catchall.cac.cornell.edu/ \n"); + m->mothurOut("The catchall command interfaces mothur with the catchall program written by Linda Woodard, Sean Connolly and John Bunge.\n"); + m->mothurOut("For more information about catchall refer to http://www.northeastern.edu/catchall/index.html \n"); m->mothurOut("The catchall executable must be in a folder called catchall in the same folder as your mothur executable, similar to mothur's requirements for using blast. \n"); + m->mothurOut("If you are a MAC or Linux user you must also have installed mono, a link to mono is on the webpage. \n"); m->mothurOut("The catchall command parameters are sabund and label, sabund is required. \n"); m->mothurOut("The label parameter is used to analyze specific labels in your input.\n"); m->mothurOut("The catchall command should be in the following format: \n"); @@ -156,7 +158,7 @@ int CatchAllCommand::execute() { //get location of catchall GlobalData* globaldata = GlobalData::getInstance(); - string path = globaldata->argv; + path = globaldata->argv; path = path.substr(0, (path.find_last_of('m'))); path = m->getFullPathName(path); @@ -177,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))) { @@ -184,26 +195,28 @@ int CatchAllCommand::execute() { if(allLines == 1 || labels.count(sabund->getLabel()) == 1){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); - //create list of output files catchall will make - //datasetname_Analysis.csv - //datasetname_BestModelsAnalysis.csv - //datasetname_BestModelsFits.csv - //datasetname_BubblePlot.csv - //datasetname_Poisson_fits.csv - //datasetname_SingleExp_fits.csv - //datasetname_ThreeMixedExp_fits.csv - //datasetname_TwoMixedExp_fits.csv - //create catchall input file from mothur's inputfile string filename = process(sabund); - sabund->print(cout); + string outputPath = m->getPathName(filename); + //create system command - string catchAllCommand = catchAllCommandExe + filename + " " + path; -cout << catchAllCommand << endl; + string catchAllCommand = catchAllCommandExe + filename + " " + outputPath + " 1"; + //run catchall system(catchAllCommand.c_str()); + + remove(filename.c_str()); + + filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra . + + outputNames.push_back(filename + "_Analysis.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv"); + outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv"); + 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(), out); - if (m->control_pressed) { 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()); @@ -217,27 +230,29 @@ cout << catchAllCommand << endl; m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); - //create list of output files catchall will make - //datasetname_Analysis.csv - //datasetname_BestModelsAnalysis.csv - //datasetname_BestModelsFits.csv - //datasetname_BubblePlot.csv - //datasetname_Poisson_fits.csv - //datasetname_SingleExp_fits.csv - //datasetname_ThreeMixedExp_fits.csv - //datasetname_TwoMixedExp_fits.csv - //create catchall input file from mothur's inputfile string filename = process(sabund); - + string outputPath = m->getPathName(filename); + //create system command - string catchAllCommand = catchAllCommandExe + filename + " " + path; -cout << catchAllCommand << endl; + string catchAllCommand = catchAllCommandExe + filename + " " + outputPath + " 1"; + //run catchall system(catchAllCommand.c_str()); - - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; delete sabund; return 0; } + + remove(filename.c_str()); + + filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra . + + outputNames.push_back(filename + "_Analysis.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv"); + outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv"); + 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(), out); + + 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()); @@ -272,32 +287,37 @@ cout << catchAllCommand << endl; sabund = (input->getSAbundVector(lastLabel)); m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); - //create list of output files catchall will make - //datasetname_Analysis.csv - //datasetname_BestModelsAnalysis.csv - //datasetname_BestModelsFits.csv - //datasetname_BubblePlot.csv - //datasetname_Poisson_fits.csv - //datasetname_SingleExp_fits.csv - //datasetname_ThreeMixedExp_fits.csv - //datasetname_TwoMixedExp_fits.csv - + //create catchall input file from mothur's inputfile string filename = process(sabund); - + string outputPath = m->getPathName(filename); + //create system command - string catchAllCommand = catchAllCommandExe + filename + " " + path; -cout << catchAllCommand << endl; + string catchAllCommand = catchAllCommandExe + filename + " " + outputPath + " 1"; + //run catchall system(catchAllCommand.c_str()); - + + remove(filename.c_str()); + + filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra . + + outputNames.push_back(filename + "_Analysis.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv"); + outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv"); + 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(), out); delete sabund; } - + + out.close(); delete read; delete input; globaldata->ginput = NULL; + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str()); } return 0; } + m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } @@ -314,7 +334,7 @@ cout << catchAllCommand << endl; //********************************************************************************************************************** string CatchAllCommand::process(SAbundVector* sabund) { try { - string filename = outputDir + m->getRootName(m->getSimpleName(sabundfile)) + sabund->getLabel() + ".catchall"; + string filename = outputDir + m->getRootName(m->getSimpleName(sabundfile)) + sabund->getLabel() + ".csv"; filename = m->getFullPathName(filename); ofstream out; @@ -337,6 +357,75 @@ string CatchAllCommand::process(SAbundVector* sabund) { exit(1); } } +//********************************************************************************************************************** +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 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); + } +} /**************************************************************************************/