]> git.donarmstrong.com Git - mothur.git/blob - getcurrentcommand.cpp
added set.current and get.current commands and modified existing commands to update...
[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 //**********************************************************************************************************************
14 vector<string> GetCurrentCommand::getValidParameters(){ 
15         try {
16                 string Array[] =  {"outputdir","inputdir","clear"};
17                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
18                 return myArray;
19         }
20         catch(exception& e) {
21                 m->errorOut(e, "GetCurrentCommand", "getValidParameters");
22                 exit(1);
23         }
24 }
25 //**********************************************************************************************************************
26 GetCurrentCommand::GetCurrentCommand(){ 
27         try {
28                 abort = true; calledHelp = true; 
29         }
30         catch(exception& e) {
31                 m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand");
32                 exit(1);
33         }
34 }
35 //**********************************************************************************************************************
36 vector<string> GetCurrentCommand::getRequiredParameters(){      
37         try {
38                 vector<string> myArray;
39                 return myArray;
40         }
41         catch(exception& e) {
42                 m->errorOut(e, "GetCurrentCommand", "getRequiredParameters");
43                 exit(1);
44         }
45 }
46 //**********************************************************************************************************************
47 vector<string> GetCurrentCommand::getRequiredFiles(){   
48         try {
49                 vector<string> myArray;
50                 return myArray;
51         }
52         catch(exception& e) {
53                 m->errorOut(e, "GetCurrentCommand", "getRequiredFiles");
54                 exit(1);
55         }
56 }
57 //**********************************************************************************************************************
58 GetCurrentCommand::GetCurrentCommand(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                 
65                 else {
66                         //valid paramters for this command
67                         string Array[] =  {"outputdir","inputdir","clear"};
68                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
69                         
70                         OptionParser parser(option);
71                         map<string,string> parameters = parser.getParameters();
72                         
73                         ValidParameters validParameter;
74                         //check to make sure all parameters are valid for command
75                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
76                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
77                         }
78                         
79                         clearTypes = validParameter.validFile(parameters, "clear", false);                      
80                         if (clearTypes == "not found") { clearTypes = ""; }
81                         else { m->splitAtDash(clearTypes, types);       }
82                 }
83                 
84         }
85         catch(exception& e) {
86                 m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand");
87                 exit(1);
88         }
89 }
90 //**********************************************************************************************************************
91
92 void GetCurrentCommand::help(){
93         try {
94                 m->mothurOut("The get.current command outputs the current files saved by mothur.\n");
95                 m->mothurOut("The get.current command has one parameter: clear.\n");
96                 m->mothurOut("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");
97                 m->mothurOut("The get.current command should be in the following format: \n");
98                 m->mothurOut("get.current() or get.current(clear=fasta-name-accnos)\n");
99                 
100         }
101         catch(exception& e) {
102                 m->errorOut(e, "GetCurrentCommand", "help");
103                 exit(1);
104         }
105 }
106
107 //**********************************************************************************************************************
108 GetCurrentCommand::~GetCurrentCommand(){}
109 //**********************************************************************************************************************
110
111 int GetCurrentCommand::execute(){
112         try {
113                 
114                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
115                 
116                 //user wants to clear a type
117                 if (types.size() != 0) {
118                         for (int i = 0; i < types.size(); i++) {
119                                 
120                                 if (m->control_pressed) { break; }
121                                 
122                                 //look for file types
123                                 if (types[i] == "fasta") {
124                                         m->setFastaFile("");
125                                 }else if (types[i] == "qfile") {
126                                         m->setQualFile("");
127                                 }else if (types[i] == "phylip") {
128                                         m->setPhylipFile("");
129                                 }else if (types[i] == "column") {
130                                         m->setColumnFile("");
131                                 }else if (types[i] == "list") {
132                                         m->setListFile("");
133                                 }else if (types[i] == "rabund") {
134                                         m->setRabundFile("");
135                                 }else if (types[i] == "sabund") {
136                                         m->setSabundFile("");
137                                 }else if (types[i] == "name") {
138                                         m->setNameFile("");
139                                 }else if (types[i] == "group") {
140                                         m->setGroupFile("");
141                                 }else if (types[i] == "order") {
142                                         m->setOrderFile("");
143                                 }else if (types[i] == "ordergroup") {
144                                         m->setOrderGroupFile("");
145                                 }else if (types[i] == "tree") {
146                                         m->setTreeFile("");
147                                 }else if (types[i] == "shared") {
148                                         m->setSharedFile("");
149                                 }else if (types[i] == "relabund") {
150                                         m->setRelAbundFile("");
151                                 }else if (types[i] == "design") {
152                                         m->setDesignFile("");
153                                 }else if (types[i] == "sff") {
154                                         m->setSFFFile("");
155                                 }else if (types[i] == "oligos") {
156                                         m->setOligosFile("");
157                                 }else if (types[i] == "accnos") {
158                                         m->setAccnosFile("");
159                                 }else if (types[i] == "taxonomy") {
160                                                 m->setTaxonomyFile("");
161                                 }else if (types[i] == "all") {
162                                         m->clearCurrentFiles();
163                                 }else {
164                                         m->mothurOut("[ERROR]: mothur does not save a current file for " + types[i]); m->mothurOutEndLine();
165                                 }
166                         }
167                 }
168                 
169                 m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine();
170                 m->printCurrentFiles();
171                 
172                 return 0;       
173         }
174         
175         catch(exception& e) {
176                 m->errorOut(e, "GetCurrentCommand", "execute");
177                 exit(1);
178         }
179 }
180
181 //**********************************************************************************************************************
182
183
184