X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=getgroupcommand.cpp;h=529ed934d5b194d1a1d82869c44053ca4f7bbaf2;hp=95baec8e72a5ea9202261790279fc5080e0ca3ad;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=510b1cfc25cd79391d6973ca20c5ec25fb1bb3b2 diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index 95baec8..529ed93 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -8,113 +8,135 @@ */ #include "getgroupcommand.h" +#include "inputdata.h" //********************************************************************************************************************** -GetgroupCommand::GetgroupCommand(string option){ +vector GetgroupCommand::setParameters(){ try { - globaldata = GlobalData::getInstance(); - abort = false; + CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none","",false,true, true); parameters.push_back(pshared); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); - //allow user to run help - if(option == "help") { help(); abort = true; } - - else { - if (option != "") { mothurOut("There are no valid parameters for the get.group command."); mothurOutEndLine(); abort = true; } - - if ((globaldata->getSharedFile() == "")) { mothurOut("You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command."); mothurOutEndLine(); abort = true; } - - if (abort == false) { - //open shared file - sharedfile = globaldata->getSharedFile(); - openInputFile(sharedfile, in); - - //open output file - outputFile = getRootName(sharedfile) + "bootGroups"; - openOutputFile(outputFile, out); - - } - } + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } + return myArray; } catch(exception& e) { - errorOut(e, "GetgroupCommand", "GetgroupCommand"); + m->errorOut(e, "GetgroupCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** - -void GetgroupCommand::help(){ +string GetgroupCommand::getHelpString(){ try { - mothurOut("The get.group command can only be executed after a successful read.otu command.\n"); - //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 concensus command.\n"); - mothurOut("You may not use any parameters with the get.group command.\n"); - mothurOut("The get.group command should be in the following format: \n"); - mothurOut("get.group()\n"); - mothurOut("Example get.group().\n"); - + string helpString = ""; + helpString += "The get.group command parameter is shared and it's required if you have no valid current file.\n"; + helpString += "You may not use any parameters with the get.group command.\n"; + helpString += "The get.group command should be in the following format: \n"; + helpString += "get.group()\n"; + helpString += "Example get.group().\n"; + return helpString; } catch(exception& e) { - errorOut(e, "GetgroupCommand", "help"); + m->errorOut(e, "GetgroupCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** - -GetgroupCommand::~GetgroupCommand(){ +GetgroupCommand::GetgroupCommand(){ + try { + abort = true; calledHelp = true; + setParameters(); + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); + exit(1); + } } - //********************************************************************************************************************** - -int GetgroupCommand::execute(){ +GetgroupCommand::GetgroupCommand(string option) { try { - - if (abort == true) { return 0; } - - int num, inputData, count; - count = 0; - string holdLabel, nextLabel, groupN, label; + abort = false; calledHelp = false; - //read in first row since you know there is at least 1 group. - in >> label >> groupN >> num; - holdLabel = label; + //allow user to run help + if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} - //output first group - mothurOut(groupN); mothurOutEndLine(); - out << groupN << '\t' << groupN << endl; + else { + vector myArray = setParameters(); - //get rest of line - for(int i=0;i> inputData; - } - - if (in.eof() != true) { in >> nextLabel; } - - //read the rest of the groups info in - while ((nextLabel == holdLabel) && (in.eof() != true)) { - in >> groupN >> num; - count++; + OptionParser parser(option); + map parameters = parser.getParameters(); + map::iterator it; - //output next group - mothurOut(groupN); mothurOutEndLine(); - out << groupN << '\t' << groupN << endl; + ValidParameters validParameter; + //check to make sure all parameters are valid for command + for (it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } + } - //fill vector. - for(int i=0;i> inputData; + //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); + if (inputDir == "not found"){ inputDir = ""; } + else { + string path; + it = parameters.find("shared"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["shared"] = inputDir + it->second; } + } } - if (in.eof() != true) { in >> nextLabel; } + //get shared file + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { m->setSharedFile(sharedfile); } + + + //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 = m->hasPath(sharedfile); } } + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); + exit(1); + } +} +//********************************************************************************************************************** + +int GetgroupCommand::execute(){ + try { + + if (abort == true) { if (calledHelp) { return 0; } return 2; } + + InputData input(sharedfile, "sharedfile"); + vector lookup = input.getSharedRAbundVectors(); + + for (int i = 0; i < lookup.size(); i++) { + m->mothurOut(lookup[i]->getGroup()); m->mothurOutEndLine(); + delete lookup[i]; + } + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + m->mothurOutEndLine(); - in.close(); - out.close(); return 0; } catch(exception& e) { - errorOut(e, "GetgroupCommand", "execute"); + m->errorOut(e, "GetgroupCommand", "execute"); exit(1); } } +//**********************************************************************************************************************