X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=summarycommand.cpp;h=5ad1ee6432bf17220e3b8fd2187734ba4a7a098a;hb=aa9238c0a9e6e7aa0ed8b8b606b08ad4fd7dcfe3;hp=afb4758a29b3831cd7958583344aa223fec3e223;hpb=92f998cc7debc4bf3e8594848586b8153d96db16;p=mothur.git diff --git a/summarycommand.cpp b/summarycommand.cpp index afb4758..5ad1ee6 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -31,7 +31,7 @@ //********************************************************************************************************************** -SummaryCommand::SummaryCommand(string option){ +SummaryCommand::SummaryCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -44,7 +44,7 @@ SummaryCommand::SummaryCommand(string option){ else { //valid paramters for this command - string Array[] = {"label","calc","abund","size"}; + string Array[] = {"label","calc","abund","size","outputdir","inputdir"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -58,8 +58,14 @@ SummaryCommand::SummaryCommand(string option){ } //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund, rabund or shared file before you can use the summary.single command."); mothurOutEndLine(); abort = true; } - + if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund, rabund or shared file before you can use the summary.single command."); m->mothurOutEndLine(); abort = true; } + + //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 += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... label = validParameter.validFile(parameters, "label", false); @@ -92,7 +98,7 @@ SummaryCommand::SummaryCommand(string option){ } } catch(exception& e) { - errorOut(e, "SummaryCommand", "SummaryCommand"); + m->errorOut(e, "SummaryCommand", "SummaryCommand"); exit(1); } } @@ -100,19 +106,19 @@ SummaryCommand::SummaryCommand(string option){ void SummaryCommand::help(){ try { - mothurOut("The summary.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n"); - mothurOut("The summary.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster.\n"); - mothurOut("The summary.single command parameters are label, calc, abund. No parameters are required.\n"); - mothurOut("The summary.single command should be in the following format: \n"); - mothurOut("summary.single(label=yourLabel, calc=yourEstimators).\n"); - mothurOut("Example summary.single(label=unique-.01-.03, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson).\n"); + m->mothurOut("The summary.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n"); + m->mothurOut("The summary.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster.\n"); + m->mothurOut("The summary.single command parameters are label, calc, abund. No parameters are required.\n"); + m->mothurOut("The summary.single command should be in the following format: \n"); + m->mothurOut("summary.single(label=yourLabel, calc=yourEstimators).\n"); + m->mothurOut("Example summary.single(label=unique-.01-.03, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson).\n"); validCalculator->printCalc("summary", cout); - mothurOut("The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson\n"); - mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n"); + m->mothurOut("The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson\n"); + m->mothurOut("The label parameter is used to analyze specific labels in your input.\n"); + m->mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n"); } catch(exception& e) { - errorOut(e, "SummaryCommand", "help"); + m->errorOut(e, "SummaryCommand", "help"); exit(1); } } @@ -128,18 +134,24 @@ int SummaryCommand::execute(){ if (abort == true) { return 0; } + vector outputNames; + if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } else { inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } + if (m->control_pressed) { return 0; } + for (int p = 0; p < inputFileNames.size(); p++) { - string fileNameRoot = getRootName(inputFileNames[p]) + "summary"; + string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])) + "summary"; globaldata->inputFileName = inputFileNames[p]; + outputNames.push_back(fileNameRoot); if (inputFileNames.size() > 1) { - mothurOutEndLine(); mothurOut("Processing group " + groups[p]); mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); } + sumCalculators.clear(); validCalculator = new ValidCalculators(); @@ -219,17 +231,24 @@ int SummaryCommand::execute(){ set processedLabels; set userLabels = labels; + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + if(allLines == 1 || labels.count(sabund->getLabel()) == 1){ - mothurOut(sabund->getLabel()); mothurOutEndLine(); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); outputFileHandle << sabund->getLabel(); for(int i=0;i data = sumCalculators[i]->getValues(sabund); + + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + outputFileHandle << '\t'; sumCalculators[i]->print(outputFileHandle); } @@ -242,13 +261,16 @@ int SummaryCommand::execute(){ delete sabund; sabund = input->getSAbundVector(lastLabel); - mothurOut(sabund->getLabel()); mothurOutEndLine(); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); outputFileHandle << sabund->getLabel(); for(int i=0;i data = sumCalculators[i]->getValues(sabund); + + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + outputFileHandle << '\t'; sumCalculators[i]->print(outputFileHandle); } @@ -264,16 +286,18 @@ int SummaryCommand::execute(){ sabund = input->getSAbundVector(); } + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;iginput = NULL; return 0; } + //output error messages about any remaining user labels set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -282,10 +306,13 @@ int SummaryCommand::execute(){ if (sabund != NULL) { delete sabund; } sabund = input->getSAbundVector(lastLabel); - mothurOut(sabund->getLabel()); mothurOutEndLine(); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); outputFileHandle << sabund->getLabel(); for(int i=0;i data = sumCalculators[i]->getValues(sabund); + + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + outputFileHandle << '\t'; sumCalculators[i]->print(outputFileHandle); } @@ -295,16 +322,27 @@ int SummaryCommand::execute(){ outputFileHandle.close(); + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;iginput = NULL; return 0; } + + delete input; globaldata->ginput = NULL; delete read; delete validCalculator; globaldata->sabund = NULL; + for(int i=0;icontrol_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(); } + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "SummaryCommand", "execute"); + m->errorOut(e, "SummaryCommand", "execute"); exit(1); } } @@ -363,7 +401,7 @@ vector SummaryCommand::parseSharedFile(string filename) { return filenames; } catch(exception& e) { - errorOut(e, "SummaryCommand", "parseSharedFile"); + m->errorOut(e, "SummaryCommand", "parseSharedFile"); exit(1); } }