1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/*
* getgroupcommand.cpp
* Mothur
*
* Created by Thomas Ryabin on 2/2/09.
* Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
*
*/
#include "getgroupcommand.h"
#include "inputdata.h"
//**********************************************************************************************************************
vector<string> GetgroupCommand::setParameters(){
try {
CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none","",false,true, true); parameters.push_back(pshared);
CommandParameter pseed("seed", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pseed);
CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
abort = false; calledHelp = false;
vector<string> myArray;
for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
return myArray;
}
catch(exception& e) {
m->errorOut(e, "GetgroupCommand", "setParameters");
exit(1);
}
}
//**********************************************************************************************************************
string GetgroupCommand::getHelpString(){
try {
string helpString = "";
helpString += "The get.group command parameter is shared and it's required if you have no valid current file.\n";
helpString += "You may not use any parameters with the get.group command.\n";
helpString += "The get.group command should be in the following format: \n";
helpString += "get.group()\n";
helpString += "Example get.group().\n";
return helpString;
}
catch(exception& e) {
m->errorOut(e, "GetgroupCommand", "getHelpString");
exit(1);
}
}
//**********************************************************************************************************************
GetgroupCommand::GetgroupCommand(string option) : Command() {
try {
//allow user to run help
if(option == "help") { help(); abort = true; calledHelp = true; }
else if(option == "citation") { citation(); abort = true; calledHelp = true;}
else if(option == "category") { abort = true; calledHelp = true; }
else {
OptionParser parser(option, setParameters());
map<string,string> parameters = parser.getParameters();
map<string,string>::iterator it;
ValidParameters validParameter;
//get shared file
sharedfile = validParameter.validFile(parameters, "shared");
if (sharedfile == "not open") { sharedfile = ""; abort = true; }
else if (sharedfile == "not found") {
//if there is a current shared file, use it
sharedfile = current->getSharedFile();
if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter.\n"); }
else { m->mothurOut("You have no current sharedfile and the shared parameter is required.\n"); abort = true; }
}else { current->setSharedFile(sharedfile); }
if (outputdir == ""){ outputdir = util.hasPath(sharedfile); }
}
}
catch(exception& e) {
m->errorOut(e, "GetgroupCommand", "GetgroupCommand");
exit(1);
}
}
//**********************************************************************************************************************
int GetgroupCommand::execute(){
try {
if (abort) { if (calledHelp) { return 0; } return 2; }
InputData input(sharedfile, "sharedfile", nullVector);
SharedRAbundVectors* lookup = input.getSharedRAbundVectors();
vector<string> namesOfGroups = lookup->getNamesGroups();
delete lookup;
for (int i = 0; i < namesOfGroups.size(); i++) {
m->mothurOut(namesOfGroups[i]); m->mothurOutEndLine();
}
m->mothurOut("\nOutput File Names: \n\n");
return 0;
}
catch(exception& e) {
m->errorOut(e, "GetgroupCommand", "execute");
exit(1);
}
}
//**********************************************************************************************************************
|