X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getgroupcommand.cpp;h=b39fb645154f97252e7d928c9862cde01553ab6b;hb=1c898913f53fe4c6574102896b967d9347d1b42a;hp=2847db149ac5e40defdbfdedfd9d99ae3df5d583;hpb=191ae1be0679d5cf4eda950b3b1bf26fb7dd503d;p=mothur.git diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index 2847db1..b39fb64 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -10,73 +10,70 @@ #include "getgroupcommand.h" //********************************************************************************************************************** -vector GetgroupCommand::getValidParameters(){ +vector GetgroupCommand::setParameters(){ try { - string Array[] = {"outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none",false,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); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetgroupCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -GetgroupCommand::GetgroupCommand(){ - try { - abort = true; - //initialize outputTypes - vector tempOutNames; - outputTypes["bootgroup"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); + m->errorOut(e, "GetgroupCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector GetgroupCommand::getRequiredParameters(){ +string GetgroupCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The get.group command parameter is shared and it's required if you have no valid current file.\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"); + 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) { - m->errorOut(e, "GetgroupCommand", "getRequiredParameters"); + m->errorOut(e, "GetgroupCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector GetgroupCommand::getRequiredFiles(){ +GetgroupCommand::GetgroupCommand(){ try { - string Array[] = {"shared"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["bootgroup"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "GetgroupCommand", "getRequiredFiles"); + m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); exit(1); } } //********************************************************************************************************************** GetgroupCommand::GetgroupCommand(string option) { try { - globaldata = GlobalData::getInstance(); - abort = false; + abort = false; calledHelp = false; //allow user to run help - if(option == "help") { help(); abort = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { - //valid paramters for this command - string Array[] = {"outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } @@ -84,22 +81,33 @@ GetgroupCommand::GetgroupCommand(string option) { 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 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 ((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); - + //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; } } + + + //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) { @@ -109,34 +117,18 @@ GetgroupCommand::GetgroupCommand(string option) { } //********************************************************************************************************************** -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); - } -} - -//********************************************************************************************************************** - -GetgroupCommand::~GetgroupCommand(){ -} - -//********************************************************************************************************************** - int GetgroupCommand::execute(){ try { - if (abort == true) { return 0; } - + if (abort == true) { if (calledHelp) { return 0; } return 2; } + + //open shared file + m->openInputFile(sharedfile, in); + + //open output file + outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "bootGroups"; + m->openOutputFile(outputFile, out); + int num, inputData, count; count = 0; string holdLabel, nextLabel, groupN, label;