]> git.donarmstrong.com Git - mothur.git/blob - getcurrentcommand.cpp
fixes while testing 1.33.0
[mothur.git] / getcurrentcommand.cpp
1 /*
2  *  getcurrentcommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 3/16/11.
6  *  Copyright 2011 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "getcurrentcommand.h"
11
12 //**********************************************************************************************************************
13 vector<string> GetCurrentCommand::setParameters(){      
14         try {
15                 CommandParameter pclear("clear", "String", "", "", "", "", "","",false,false); parameters.push_back(pclear);
16                 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
17                 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
18                 
19                 vector<string> myArray;
20                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
21                 return myArray;
22         }
23         catch(exception& e) {
24                 m->errorOut(e, "GetCurrentCommand", "setParameters");
25                 exit(1);
26         }
27 }
28 //**********************************************************************************************************************
29 string GetCurrentCommand::getHelpString(){      
30         try {
31                 string helpString = "";
32                 helpString += "The get.current command outputs the current files saved by mothur.\n";
33                 helpString += "The get.current command has one parameter: clear.\n";
34                 helpString += "The clear paramter is used to indicate which file types you would like to clear values for, multiple types can be separated by dashes.\n";
35                 helpString += "The get.current command should be in the following format: \n";
36                 helpString += "get.current() or get.current(clear=fasta-name-accnos)\n";
37                 return helpString;
38         }
39         catch(exception& e) {
40                 m->errorOut(e, "GetCurrentCommand", "getHelpString");
41                 exit(1);
42         }
43 }
44 //**********************************************************************************************************************
45 GetCurrentCommand::GetCurrentCommand(){ 
46         try {
47                 abort = true; calledHelp = true;
48                 setParameters();
49         }
50         catch(exception& e) {
51                 m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand");
52                 exit(1);
53         }
54 }
55 //**********************************************************************************************************************
56 GetCurrentCommand::GetCurrentCommand(string option)  {
57         try {
58                 abort = false; calledHelp = false;   
59                 
60                 //allow user to run help
61                 if(option == "help") { help(); abort = true; calledHelp = true; }
62                 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
63                 
64                 else {
65                         vector<string> myArray = setParameters();
66                         
67                         OptionParser parser(option);
68                         map<string,string> parameters = parser.getParameters();
69                         
70                         ValidParameters validParameter;
71                         //check to make sure all parameters are valid for command
72                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
73                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
74                         }
75                         
76                         clearTypes = validParameter.validFile(parameters, "clear", false);                      
77                         if (clearTypes == "not found") { clearTypes = ""; }
78                         else { m->splitAtDash(clearTypes, types);       }
79                 }
80                 
81         }
82         catch(exception& e) {
83                 m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand");
84                 exit(1);
85         }
86 }
87 //**********************************************************************************************************************
88
89 int GetCurrentCommand::execute(){
90         try {
91                 
92                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
93         
94                 cFactory = CommandFactory::getInstance();
95         
96                 //user wants to clear a type
97                 if (types.size() != 0) {
98                         for (int i = 0; i < types.size(); i++) {
99                                 
100                                 if (m->control_pressed) { break; }
101                                 
102                                 //look for file types
103                                 if (types[i] == "fasta") {
104                                         m->setFastaFile("");
105                                 }else if (types[i] == "qfile") {
106                                         m->setQualFile("");
107                                 }else if (types[i] == "phylip") {
108                                         m->setPhylipFile("");
109                                 }else if (types[i] == "column") {
110                                         m->setColumnFile("");
111                                 }else if (types[i] == "list") {
112                                         m->setListFile("");
113                                 }else if (types[i] == "rabund") {
114                                         m->setRabundFile("");
115                                 }else if (types[i] == "sabund") {
116                                         m->setSabundFile("");
117                                 }else if (types[i] == "name") {
118                                         m->setNameFile("");
119                                 }else if (types[i] == "group") {
120                                         m->setGroupFile("");
121                                 }else if (types[i] == "order") {
122                                         m->setOrderFile("");
123                                 }else if (types[i] == "ordergroup") {
124                                         m->setOrderGroupFile("");
125                                 }else if (types[i] == "tree") {
126                                         m->setTreeFile("");
127                                 }else if (types[i] == "shared") {
128                                         m->setSharedFile("");
129                                 }else if (types[i] == "relabund") {
130                                         m->setRelAbundFile("");
131                                 }else if (types[i] == "design") {
132                                         m->setDesignFile("");
133                                 }else if (types[i] == "sff") {
134                                         m->setSFFFile("");
135                                 }else if (types[i] == "oligos") {
136                                         m->setOligosFile("");
137                                 }else if (types[i] == "accnos") {
138                                         m->setAccnosFile("");
139                                 }else if (types[i] == "taxonomy") {
140                                         m->setTaxonomyFile("");
141                                 }else if (types[i] == "flow") {
142                                         m->setFlowFile("");
143                 }else if (types[i] == "biom") {
144                                         m->setBiomFile("");
145                 }else if (types[i] == "count") {
146                                         m->setCountTableFile("");
147                 }else if (types[i] == "summary") {
148                                         m->setSummaryFile("");
149                                 }else if (types[i] == "processors") {
150                                         m->setProcessors("1");
151                                 }else if (types[i] == "all") {
152                                         m->clearCurrentFiles();
153                                 }else {
154                                         m->mothurOut("[ERROR]: mothur does not save a current file for " + types[i]); m->mothurOutEndLine();
155                                 }
156                         }
157                 }
158                 
159                 if (m->hasCurrentFiles()) {
160                         m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine();
161                         m->printCurrentFiles();
162                 }
163         
164         string inputDir = cFactory->getInputDir();
165         if (inputDir != "") {
166             m->mothurOutEndLine(); m->mothurOut("Current input directory saved by mothur: " + inputDir); m->mothurOutEndLine();
167         }
168         
169         string outputDir = cFactory->getOutputDir();
170         if (outputDir != "") {
171             m->mothurOutEndLine(); m->mothurOut("Current output directory saved by mothur: " + outputDir); m->mothurOutEndLine();
172         }
173         string defaultPath = m->getDefaultPath();
174         if (defaultPath != "") {
175             m->mothurOutEndLine(); m->mothurOut("Current default directory saved by mothur: " + defaultPath); m->mothurOutEndLine();
176         }
177         
178         
179         string temp = "./";
180 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
181 #else
182             temp = ".\\";
183 #endif
184         temp = m->getFullPathName(temp);
185         m->mothurOutEndLine(); m->mothurOut("Current working directory: " + temp); m->mothurOutEndLine();
186                 
187                 return 0;
188         }
189         
190         catch(exception& e) {
191                 m->errorOut(e, "GetCurrentCommand", "execute");
192                 exit(1);
193         }
194 }
195
196 //**********************************************************************************************************************
197
198
199