X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getgroupcommand.cpp;h=ab3ccfa36f3f2d4e6a7e1f5af6a38434640f3105;hb=a4f05f09c250323132a4b9427f41a3ededaec634;hp=3fc67d11612bccfdced922b1a8276b90cfc5b023;hpb=3117b1c3109121dff476997d3c5db5b47a77729b;p=mothur.git diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index 3fc67d1..ab3ccfa 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -9,23 +9,119 @@ #include "getgroupcommand.h" - -GetgroupCommand::GetgroupCommand(){ +//********************************************************************************************************************** +vector GetgroupCommand::getValidParameters(){ try { - globaldata = GlobalData::getInstance(); - groupMap = globaldata->gGroupmap; - outputFile = globaldata->inputFileName + ".bootGroups"; - openOutputFile(outputFile, out); + string Array[] = {"outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function GetgroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "GetgroupCommand", "getValidParameters"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the GetgroupCommand class function GetgroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +//********************************************************************************************************************** +GetgroupCommand::GetgroupCommand(){ + try { + abort = true; calledHelp = true; + vector tempOutNames; + outputTypes["bootgroup"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); exit(1); - } + } +} +//********************************************************************************************************************** +vector GetgroupCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetgroupCommand::getRequiredFiles(){ + try { + string Array[] = {"shared"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +GetgroupCommand::GetgroupCommand(string option) { + try { + globaldata = GlobalData::getInstance(); + abort = false; calledHelp = false; + + //allow user to run help + if(option == "help") { help(); abort = true; calledHelp = true; } + + else { + //valid paramters for this command + string Array[] = {"outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + OptionParser parser(option); + map parameters = parser.getParameters(); + + ValidParameters validParameter; + //check to make sure all parameters are valid for command + for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } + } + + //initialize outputTypes + vector tempOutNames; + outputTypes["bootgroup"] = tempOutNames; + + //if the user changes the output directory command factory will send this info to us in the output parameter + string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } + + if ((globaldata->getSharedFile() == "")) { m->mothurOut("You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command."); m->mothurOutEndLine(); abort = true; } + + if (abort == false) { + //open shared file + sharedfile = globaldata->getSharedFile(); + m->openInputFile(sharedfile, in); + + //open output file + if (outputDir == "") { outputDir += m->hasPath(sharedfile); } + outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "bootGroups"; + m->openOutputFile(outputFile, out); + + } + } + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); + exit(1); + } +} +//********************************************************************************************************************** + +void GetgroupCommand::help(){ + try { + m->mothurOut("The get.group command can only be executed after a successful read.otu command.\n"); + //m->mothurOut("The get.group command outputs a .bootGroups file to you can use in addition to the tree file generated by the bootstrap.shared command to run the consensus command.\n"); + m->mothurOut("You may not use any parameters with the get.group command.\n"); + m->mothurOut("The get.group command should be in the following format: \n"); + m->mothurOut("get.group()\n"); + m->mothurOut("Example get.group().\n"); + + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "help"); + exit(1); + } } //********************************************************************************************************************** @@ -37,23 +133,66 @@ GetgroupCommand::~GetgroupCommand(){ int GetgroupCommand::execute(){ try { - vector groupNames = groupMap->namesOfGroups; - for(int i = 0; i < groupNames.size(); i++) { - cout << groupNames[i] << "\n"; - out << groupNames[i] << "\t" << groupNames[i] << "\n"; + + if (abort == true) { if (calledHelp) { return 0; } return 2; } + + int num, inputData, count; + count = 0; + string holdLabel, nextLabel, groupN, label; + + //read in first row since you know there is at least 1 group. + in >> label >> groupN >> num; + holdLabel = label; + + //output first group + m->mothurOut(groupN); m->mothurOutEndLine(); + out << groupN << '\t' << groupN << endl; + + //get rest of line + for(int i=0;i> inputData; } + + if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); remove(outputFile.c_str()); return 0; } + + if (in.eof() != true) { in >> nextLabel; } + + //read the rest of the groups info in + while ((nextLabel == holdLabel) && (in.eof() != true)) { + if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); remove(outputFile.c_str()); return 0; } + + in >> groupN >> num; + count++; + + //output next group + m->mothurOut(groupN); m->mothurOutEndLine(); + out << groupN << '\t' << groupN << endl; + + //fill vector. + for(int i=0;i> inputData; + } + + if (in.eof() != true) { in >> nextLabel; } + } + + in.close(); out.close(); + + if (m->control_pressed) { remove(outputFile.c_str()); return 0; } + + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outputFile); m->mothurOutEndLine(); outputNames.push_back(outputFile); outputTypes["bootgroup"].push_back(outputFile); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "GetgroupCommand", "execute"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the GetgroupCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } }