]> git.donarmstrong.com Git - mothur.git/blob - getgroupcommand.cpp
changes while testing
[mothur.git] / getgroupcommand.cpp
1 /*
2  *  getgroupcommand.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 2/2/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "getgroupcommand.h"
11 #include "inputdata.h"
12
13 //**********************************************************************************************************************
14 vector<string> GetgroupCommand::setParameters(){        
15         try {
16                 CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none","",false,true, 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);
19                 
20                 vector<string> myArray;
21                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
22                 return myArray;
23         }
24         catch(exception& e) {
25                 m->errorOut(e, "GetgroupCommand", "setParameters");
26                 exit(1);
27         }
28 }
29 //**********************************************************************************************************************
30 string GetgroupCommand::getHelpString(){        
31         try {
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";
38                 return helpString;
39         }
40         catch(exception& e) {
41                 m->errorOut(e, "GetgroupCommand", "getHelpString");
42                 exit(1);
43         }
44 }
45
46 //**********************************************************************************************************************
47 GetgroupCommand::GetgroupCommand(){     
48         try {
49                 abort = true; calledHelp = true; 
50                 setParameters();
51         }
52         catch(exception& e) {
53                 m->errorOut(e, "GetgroupCommand", "GetgroupCommand");
54                 exit(1);
55         }
56 }
57 //**********************************************************************************************************************
58 GetgroupCommand::GetgroupCommand(string option)  {
59         try {
60                 abort = false; calledHelp = false;   
61                 
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;}
65                 
66                 else {
67                         vector<string> myArray = setParameters();
68                         
69                         OptionParser parser(option);
70                         map<string,string> parameters = parser.getParameters();
71                         map<string,string>::iterator it;
72                         
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;  }
77                         }
78                         
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 = "";          }
82                         else {
83                                 string path;
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;           }
90                                 }
91                         }
92                         
93                         //get shared file
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); }
102                         
103                         
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);             }
106                 }
107         }
108         catch(exception& e) {
109                 m->errorOut(e, "GetgroupCommand", "GetgroupCommand");
110                 exit(1);
111         }
112 }
113 //**********************************************************************************************************************
114
115 int GetgroupCommand::execute(){
116         try {
117         
118                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
119                                         
120                 InputData input(sharedfile, "sharedfile");
121                 vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
122                 
123                 for (int i = 0; i < lookup.size(); i++) {
124                         m->mothurOut(lookup[i]->getGroup()); m->mothurOutEndLine();
125                         delete lookup[i];
126                 }
127                         
128                 m->mothurOutEndLine();
129                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
130                 m->mothurOutEndLine();
131                 
132                 return 0;       
133         }
134
135         catch(exception& e) {
136                 m->errorOut(e, "GetgroupCommand", "execute");
137                 exit(1);
138         }
139 }
140 //**********************************************************************************************************************
141
142