+//**********************************************************************************************************************
+RareFactCommand::RareFactCommand(string option) {
+ try {
+ abort = false; calledHelp = false;
+ allLines = 1;
+
+ //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; }
+ }
+
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["rarefaction"] = tempOutNames;
+ outputTypes["r_chao"] = tempOutNames;
+ outputTypes["r_ace"] = tempOutNames;
+ outputTypes["r_jack"] = tempOutNames;
+ outputTypes["r_shannon"] = tempOutNames;
+ outputTypes["r_shannoneven"] = tempOutNames;
+ outputTypes["r_heip"] = tempOutNames;
+ outputTypes["r_smithwilson"] = tempOutNames;
+ outputTypes["r_npshannon"] = tempOutNames;
+ outputTypes["r_simpson"] = tempOutNames;
+ outputTypes["r_simpsoneven"] = tempOutNames;
+ outputTypes["r_invsimpson"] = tempOutNames;
+ outputTypes["r_bootstrap"] = tempOutNames;
+ outputTypes["r_coverage"] = tempOutNames;
+ outputTypes["r_nseqs"] = tempOutNames;
+
+ //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; }
+ }
+
+ 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); }
+
+ sharedfile = validParameter.validFile(parameters, "shared", true);
+ if (sharedfile == "not open") { sharedfile = ""; abort = true; }
+ else if (sharedfile == "not found") { sharedfile = ""; }
+ else { format = "sharedfile"; inputfile = sharedfile; m->setSharedFile(sharedfile); }
+
+ if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) {
+ //is there are current file available for any of these?
+ //give priority to shared, then list, then rabund, then sabund
+ //if there is a current shared file, use it
+ sharedfile = m->getSharedFile();
+ if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
+ else {
+ 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, rabund or shared file before you can use the collect.single command."); 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(inputfile); }