X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=getlabelcommand.cpp;h=03bf7ad991829e2afc693db3d15560d66e597a91;hp=971feb4b33f70f44bcfbabdf6de55caf17bda3cd;hb=615301e57c25e241356a9c2380648d117709458d;hpb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6 diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp index 971feb4..03bf7ad 100644 --- a/getlabelcommand.cpp +++ b/getlabelcommand.cpp @@ -9,75 +9,175 @@ #include "getlabelcommand.h" -//********************************************************************************************************************** -GetlabelCommand::GetlabelCommand(string option) { +//********************************************************************************************************************** +vector GetlabelCommand::setParameters(){ try { - globaldata = GlobalData::getInstance(); - abort = false; + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false, true); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false, true); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false, true); parameters.push_back(psabund); + 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 ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund or rabund before you can use the get.label command."); m->mothurOutEndLine(); abort = true; } - } - + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } + return myArray; } catch(exception& e) { - m->errorOut(e, "GetlabelCommand", "GetlabelCommand"); + m->errorOut(e, "GetlabelCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** - -void GetlabelCommand::help(){ +GetlabelCommand::GetlabelCommand(){ try { - m->mothurOut("The get.label command can only be executed after a successful read.otu command.\n"); - m->mothurOut("You may not use any parameters with the get.label command.\n"); - m->mothurOut("The get.label command should be in the following format: \n"); - m->mothurOut("get.label()\n"); - m->mothurOut("Example get.label().\n"); + abort = true; calledHelp = true; + setParameters(); } catch(exception& e) { - m->errorOut(e, "GetlabelCommand", "help"); + m->errorOut(e, "GetlabelCommand", "CollectCommand"); exit(1); } } - //********************************************************************************************************************** - -GetlabelCommand::~GetlabelCommand(){ +string GetlabelCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The get.label command parameters are list, sabund and rabund file. \n"; + helpString += "The get.label command should be in the following format: \n"; + helpString += "get.label()\n"; + helpString += "Example get.label().\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "GetlabelCommand", "getHelpString"); + exit(1); + } } +//********************************************************************************************************************** +GetlabelCommand::GetlabelCommand(string option) { + try { + abort = false; calledHelp = false; + + //allow user to run help + if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} + + else { + 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 (it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } + } + + //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("rabund"); + //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["rabund"] = inputDir + it->second; } + } + + it = parameters.find("sabund"); + //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["sabund"] = inputDir + it->second; } + } + + it = parameters.find("list"); + //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["list"] = inputDir + it->second; } + } + } + + //check for required parameters + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { listfile = ""; abort = true; } + else if (listfile == "not found") { listfile = ""; } + else { format = "list"; inputfile = listfile; m->setListFile(listfile); } + + sabundfile = validParameter.validFile(parameters, "sabund", true); + if (sabundfile == "not open") { sabundfile = ""; abort = true; } + else if (sabundfile == "not found") { sabundfile = ""; } + else { format = "sabund"; inputfile = sabundfile; m->setSabundFile(sabundfile); } + + rabundfile = validParameter.validFile(parameters, "rabund", true); + if (rabundfile == "not open") { rabundfile = ""; abort = true; } + else if (rabundfile == "not found") { rabundfile = ""; } + else { format = "rabund"; inputfile = rabundfile; m->setRabundFile(rabundfile); } + + if ((listfile == "") && (rabundfile == "") && (sabundfile == "")) { + //is there are current file available for any of these? + //give priority to list, then rabund, then sabund + //if there is a current shared file, use it + + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + rabundfile = m->getRabundFile(); + if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } + else { + sabundfile = m->getSabundFile(); + if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list, sabund or rabund file."); m->mothurOutEndLine(); + abort = true; + } + } + } + } + } + + } + catch(exception& e) { + m->errorOut(e, "GetlabelCommand", "GetlabelCommand"); + exit(1); + } +} //********************************************************************************************************************** int GetlabelCommand::execute(){ try { - if (abort == true) { return 0; } + if (abort == true) { if (calledHelp) { return 0; } return 2; } + + InputData* input = new InputData(inputfile, format); + OrderVector* order = input->getOrderVector(); + string label = order->getLabel(); - filename = globaldata->inputFileName; - ifstream in; - m->openInputFile(filename, in); - string label; - int numBins = 0; - int count = -1; - while(in.good()) { + while (order != NULL) { - if (m->control_pressed) { in.close(); return 0; } + if (m->control_pressed) { delete input; delete order; return 0; } - if(count > numBins) - count = 0; - if(count == 0) { - m->mothurOut(label); m->mothurOutEndLine(); - in >> numBins; - } - in >> label; - count++; - } + label = order->getLabel(); + + m->mothurOut(label); m->mothurOutEndLine(); + + delete order; + order = input->getOrderVector(); + } + + delete input; - in.close(); return 0; } @@ -86,4 +186,6 @@ int GetlabelCommand::execute(){ exit(1); } } +//********************************************************************************************************************** +