+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<string> myArray = setParameters();
+
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+ map<string,string>::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);
+ }
+}