5 * Created by Thomas Ryabin on 2/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "getgroupcommand.h"
11 #include "inputdata.h"
13 //**********************************************************************************************************************
14 vector<string> GetgroupCommand::setParameters(){
16 CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none",false,true); parameters.push_back(pshared);
17 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
18 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
20 vector<string> myArray;
21 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
25 m->errorOut(e, "GetgroupCommand", "setParameters");
29 //**********************************************************************************************************************
30 string GetgroupCommand::getHelpString(){
32 string helpString = "";
33 helpString += "The get.group command parameter is shared and it's required if you have no valid current file.\n";
34 helpString += "You may not use any parameters with the get.group command.\n";
35 helpString += "The get.group command should be in the following format: \n";
36 helpString += "get.group()\n";
37 helpString += "Example get.group().\n";
41 m->errorOut(e, "GetgroupCommand", "getHelpString");
46 //**********************************************************************************************************************
47 GetgroupCommand::GetgroupCommand(){
49 abort = true; calledHelp = true;
53 m->errorOut(e, "GetgroupCommand", "GetgroupCommand");
57 //**********************************************************************************************************************
58 GetgroupCommand::GetgroupCommand(string option) {
60 abort = false; calledHelp = false;
62 //allow user to run help
63 if(option == "help") { help(); abort = true; calledHelp = true; }
64 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
67 vector<string> myArray = setParameters();
69 OptionParser parser(option);
70 map<string,string> parameters = parser.getParameters();
71 map<string,string>::iterator it;
73 ValidParameters validParameter;
74 //check to make sure all parameters are valid for command
75 for (it = parameters.begin(); it != parameters.end(); it++) {
76 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
79 //if the user changes the input directory command factory will send this info to us in the output parameter
80 string inputDir = validParameter.validFile(parameters, "inputdir", false);
81 if (inputDir == "not found"){ inputDir = ""; }
84 it = parameters.find("shared");
85 //user has given a template file
86 if(it != parameters.end()){
87 path = m->hasPath(it->second);
88 //if the user has not given a path then, add inputdir. else leave path alone.
89 if (path == "") { parameters["shared"] = inputDir + it->second; }
94 sharedfile = validParameter.validFile(parameters, "shared", true);
95 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
96 else if (sharedfile == "not found") {
97 //if there is a current shared file, use it
98 sharedfile = m->getSharedFile();
99 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
100 else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; }
101 }else { m->setSharedFile(sharedfile); }
104 //if the user changes the output directory command factory will send this info to us in the output parameter
105 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(sharedfile); }
108 catch(exception& e) {
109 m->errorOut(e, "GetgroupCommand", "GetgroupCommand");
113 //**********************************************************************************************************************
115 int GetgroupCommand::execute(){
118 if (abort == true) { if (calledHelp) { return 0; } return 2; }
120 InputData input(sharedfile, "sharedfile");
121 vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
123 for (int i = 0; i < lookup.size(); i++) {
124 m->mothurOut(lookup[i]->getGroup()); m->mothurOutEndLine();
128 m->mothurOutEndLine();
129 m->mothurOut("Output File Name: "); m->mothurOutEndLine();
130 m->mothurOutEndLine();
135 catch(exception& e) {
136 m->errorOut(e, "GetgroupCommand", "execute");
140 //**********************************************************************************************************************