+//**********************************************************************************************************************
+CollectCommand::CollectCommand(){
+ try {
+ abort = true; calledHelp = true;
+ setParameters();
+ vector<string> tempOutNames;
+ outputTypes["sobs"] = tempOutNames;
+ outputTypes["chao"] = tempOutNames;
+ outputTypes["nseqs"] = tempOutNames;
+ outputTypes["coverage"] = tempOutNames;
+ outputTypes["ace"] = tempOutNames;
+ outputTypes["jack"] = tempOutNames;
+ outputTypes["shannon"] = tempOutNames;
+ outputTypes["shannoneven"] = tempOutNames;
+ outputTypes["npshannon"] = tempOutNames;
+ outputTypes["heip"] = tempOutNames;
+ outputTypes["smithwilson"] = tempOutNames;
+ outputTypes["simpson"] = tempOutNames;
+ outputTypes["simpsoneven"] = tempOutNames;
+ outputTypes["invsimpson"] = tempOutNames;
+ outputTypes["bootstrap"] = tempOutNames;
+ outputTypes["geometric"] = tempOutNames;
+ outputTypes["qstat"] = tempOutNames;
+ outputTypes["logseries"] = tempOutNames;
+ outputTypes["bergerparker"] = tempOutNames;
+ outputTypes["bstick"] = tempOutNames;
+ outputTypes["goodscoverage"] = tempOutNames;
+ outputTypes["efron"] = tempOutNames;
+ outputTypes["boneh"] = tempOutNames;
+ outputTypes["solow"] = tempOutNames;
+ outputTypes["shen"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "CollectCommand", "CollectCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+CollectCommand::CollectCommand(string option) {
+ try {
+ abort = false; calledHelp = false;
+ allLines = 1;
+
+ //allow user to run help
+ if(option == "help") { help(); calledHelp = true; abort = 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["sobs"] = tempOutNames;
+ outputTypes["chao"] = tempOutNames;
+ outputTypes["nseqs"] = tempOutNames;
+ outputTypes["coverage"] = tempOutNames;
+ outputTypes["ace"] = tempOutNames;
+ outputTypes["jack"] = tempOutNames;
+ outputTypes["shannon"] = tempOutNames;
+ outputTypes["shannoneven"] = tempOutNames;
+ outputTypes["npshannon"] = tempOutNames;
+ outputTypes["heip"] = tempOutNames;
+ outputTypes["smithwilson"] = tempOutNames;
+ outputTypes["simpson"] = tempOutNames;
+ outputTypes["simpsoneven"] = tempOutNames;
+ outputTypes["invsimpson"] = tempOutNames;
+ outputTypes["bootstrap"] = tempOutNames;
+ outputTypes["geometric"] = tempOutNames;
+ outputTypes["qstat"] = tempOutNames;
+ outputTypes["logseries"] = tempOutNames;
+ outputTypes["bergerparker"] = tempOutNames;
+ outputTypes["bstick"] = tempOutNames;
+ outputTypes["goodscoverage"] = tempOutNames;
+ outputTypes["efron"] = tempOutNames;
+ outputTypes["boneh"] = tempOutNames;
+ outputTypes["solow"] = tempOutNames;
+ outputTypes["shen"] = 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 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 = ""; }
+
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ //check for optional parameter and set defaults
+ // ...at some point should added some additional type checking...
+ label = validParameter.validFile(parameters, "label", false);
+ if (label == "not found") { label = ""; }
+ else {
+ if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
+ else { allLines = 1; }
+ }
+
+ //NOTE: if you add new calc options, don't forget to add them to the parameter initialize in setParameters or the gui won't be able to use them
+ calc = validParameter.validFile(parameters, "calc", false);
+ if (calc == "not found") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
+ else {
+ if (calc == "default") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
+ }
+ m->splitAtDash(calc, Estimators);
+ if (m->inUsersGroups("citation", Estimators)) {
+ ValidCalculators validCalc; validCalc.printCitations(Estimators);
+ //remove citation from list of calcs
+ for (int i = 0; i < Estimators.size(); i++) { if (Estimators[i] == "citation") { Estimators.erase(Estimators.begin()+i); break; } }
+ }