X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getgroupcommand.cpp;h=cf47661bb6a8084740262d8a6b4b157181a2b0ab;hb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6;hp=9014031d5a58556493b712282fbf4bfc5535d5e2;hpb=92dde9a6d6c638fcbbd5dbaa5c79167564f90e49;p=mothur.git diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index 9014031..cf47661 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -10,7 +10,7 @@ #include "getgroupcommand.h" //********************************************************************************************************************** -GetgroupCommand::GetgroupCommand(string option){ +GetgroupCommand::GetgroupCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -19,24 +19,39 @@ GetgroupCommand::GetgroupCommand(string option){ if(option == "help") { help(); abort = true; } else { - if (option != "") { mothurOut("There are no valid parameters for the get.group command."); mothurOutEndLine(); abort = true; } + //valid paramters for this command + string Array[] = {"outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - 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; } + 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; } + } + + //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(); - openInputFile(sharedfile, in); + m->openInputFile(sharedfile, in); //open output file - outputFile = getRootName(sharedfile) + "bootGroups"; - openOutputFile(outputFile, out); + if (outputDir == "") { outputDir += m->hasPath(sharedfile); } + outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "bootGroups"; + m->openOutputFile(outputFile, out); } } } catch(exception& e) { - errorOut(e, "GetgroupCommand", "GetgroupCommand"); + m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); exit(1); } } @@ -44,16 +59,16 @@ GetgroupCommand::GetgroupCommand(string option){ void GetgroupCommand::help(){ 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 consensus 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"); + 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) { - errorOut(e, "GetgroupCommand", "help"); + m->errorOut(e, "GetgroupCommand", "help"); exit(1); } } @@ -79,7 +94,7 @@ int GetgroupCommand::execute(){ holdLabel = label; //output first group - mothurOut(groupN); mothurOutEndLine(); + m->mothurOut(groupN); m->mothurOutEndLine(); out << groupN << '\t' << groupN << endl; //get rest of line @@ -87,15 +102,19 @@ int GetgroupCommand::execute(){ in >> inputData; } + if (m->control_pressed) { 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) { in.close(); out.close(); remove(outputFile.c_str()); return 0; } + in >> groupN >> num; count++; //output next group - mothurOut(groupN); mothurOutEndLine(); + m->mothurOut(groupN); m->mothurOutEndLine(); out << groupN << '\t' << groupN << endl; //fill vector. @@ -108,11 +127,19 @@ int GetgroupCommand::execute(){ 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(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "GetgroupCommand", "execute"); + m->errorOut(e, "GetgroupCommand", "execute"); exit(1); } }