2 * setcurrentcommand.cpp
5 * Created by westcott on 3/16/11.
6 * Copyright 2011 Schloss Lab. All rights reserved.
10 #include "setcurrentcommand.h"
12 //**********************************************************************************************************************
13 vector<string> SetCurrentCommand::getValidParameters(){
15 string Array[] = {"outputdir","inputdir","clear", "phylip", "column", "list","rabund","sabund","name","group",
16 "design","order","tree","shared","ordergroup","relabund","fasta","qfile","sff","oligos","accnos","taxonomy"};
17 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
21 m->errorOut(e, "SetCurrentCommand", "getValidParameters");
25 //**********************************************************************************************************************
26 SetCurrentCommand::SetCurrentCommand(){
28 abort = true; calledHelp = true;
31 m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
35 //**********************************************************************************************************************
36 vector<string> SetCurrentCommand::getRequiredParameters(){
38 vector<string> myArray;
42 m->errorOut(e, "SetCurrentCommand", "getRequiredParameters");
46 //**********************************************************************************************************************
47 vector<string> SetCurrentCommand::getRequiredFiles(){
49 vector<string> myArray;
53 m->errorOut(e, "SetCurrentCommand", "getRequiredFiles");
57 //**********************************************************************************************************************
58 SetCurrentCommand::SetCurrentCommand(string option) {
60 abort = false; calledHelp = false;
62 //allow user to run help
63 if(option == "help") { help(); abort = true; calledHelp = true; }
66 //valid paramters for this command
67 string Array[] = {"outputdir","inputdir","clear", "phylip", "column", "list","rabund","sabund","name","group",
68 "design","order","tree","shared","ordergroup","relabund","fasta","qfile","sff","oligos","accnos","taxonomy"};
69 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
71 OptionParser parser(option);
72 map<string,string> parameters = parser.getParameters();
74 ValidParameters validParameter;
75 map<string,string>::iterator it;
76 //check to make sure all parameters are valid for command
77 for (it = parameters.begin(); it != parameters.end(); it++) {
78 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
82 //if the user changes the input directory command factory will send this info to us in the output parameter
83 string inputDir = validParameter.validFile(parameters, "inputdir", false);
84 if (inputDir == "not found"){ inputDir = ""; }
87 it = parameters.find("phylip");
88 //user has given a template file
89 if(it != parameters.end()){
90 path = m->hasPath(it->second);
91 //if the user has not given a path then, add inputdir. else leave path alone.
92 if (path == "") { parameters["phylip"] = inputDir + it->second; }
95 it = parameters.find("column");
96 //user has given a template file
97 if(it != parameters.end()){
98 path = m->hasPath(it->second);
99 //if the user has not given a path then, add inputdir. else leave path alone.
100 if (path == "") { parameters["column"] = inputDir + it->second; }
103 it = parameters.find("fasta");
104 //user has given a template file
105 if(it != parameters.end()){
106 path = m->hasPath(it->second);
107 //if the user has not given a path then, add inputdir. else leave path alone.
108 if (path == "") { parameters["fasta"] = inputDir + it->second; }
111 it = parameters.find("list");
112 //user has given a template file
113 if(it != parameters.end()){
114 path = m->hasPath(it->second);
115 //if the user has not given a path then, add inputdir. else leave path alone.
116 if (path == "") { parameters["list"] = inputDir + it->second; }
119 it = parameters.find("rabund");
120 //user has given a template file
121 if(it != parameters.end()){
122 path = m->hasPath(it->second);
123 //if the user has not given a path then, add inputdir. else leave path alone.
124 if (path == "") { parameters["rabund"] = inputDir + it->second; }
127 it = parameters.find("sabund");
128 //user has given a template file
129 if(it != parameters.end()){
130 path = m->hasPath(it->second);
131 //if the user has not given a path then, add inputdir. else leave path alone.
132 if (path == "") { parameters["sabund"] = inputDir + it->second; }
135 it = parameters.find("name");
136 //user has given a template file
137 if(it != parameters.end()){
138 path = m->hasPath(it->second);
139 //if the user has not given a path then, add inputdir. else leave path alone.
140 if (path == "") { parameters["name"] = inputDir + it->second; }
143 it = parameters.find("group");
144 //user has given a template file
145 if(it != parameters.end()){
146 path = m->hasPath(it->second);
147 //if the user has not given a path then, add inputdir. else leave path alone.
148 if (path == "") { parameters["group"] = inputDir + it->second; }
151 it = parameters.find("design");
152 //user has given a template file
153 if(it != parameters.end()){
154 path = m->hasPath(it->second);
155 //if the user has not given a path then, add inputdir. else leave path alone.
156 if (path == "") { parameters["design"] = inputDir + it->second; }
159 it = parameters.find("order");
160 //user has given a template file
161 if(it != parameters.end()){
162 path = m->hasPath(it->second);
163 //if the user has not given a path then, add inputdir. else leave path alone.
164 if (path == "") { parameters["order"] = inputDir + it->second; }
167 it = parameters.find("tree");
168 //user has given a template file
169 if(it != parameters.end()){
170 path = m->hasPath(it->second);
171 //if the user has not given a path then, add inputdir. else leave path alone.
172 if (path == "") { parameters["tree"] = inputDir + it->second; }
175 it = parameters.find("shared");
176 //user has given a template file
177 if(it != parameters.end()){
178 path = m->hasPath(it->second);
179 //if the user has not given a path then, add inputdir. else leave path alone.
180 if (path == "") { parameters["shared"] = inputDir + it->second; }
183 it = parameters.find("ordergroup");
184 //user has given a template file
185 if(it != parameters.end()){
186 path = m->hasPath(it->second);
187 //if the user has not given a path then, add inputdir. else leave path alone.
188 if (path == "") { parameters["ordergroup"] = inputDir + it->second; }
191 it = parameters.find("relabund");
192 //user has given a template file
193 if(it != parameters.end()){
194 path = m->hasPath(it->second);
195 //if the user has not given a path then, add inputdir. else leave path alone.
196 if (path == "") { parameters["relabund"] = inputDir + it->second; }
199 it = parameters.find("fasta");
200 //user has given a template file
201 if(it != parameters.end()){
202 path = m->hasPath(it->second);
203 //if the user has not given a path then, add inputdir. else leave path alone.
204 if (path == "") { parameters["fasta"] = inputDir + it->second; }
207 it = parameters.find("qfile");
208 //user has given a template file
209 if(it != parameters.end()){
210 path = m->hasPath(it->second);
211 //if the user has not given a path then, add inputdir. else leave path alone.
212 if (path == "") { parameters["qfile"] = inputDir + it->second; }
215 it = parameters.find("sff");
216 //user has given a template file
217 if(it != parameters.end()){
218 path = m->hasPath(it->second);
219 //if the user has not given a path then, add inputdir. else leave path alone.
220 if (path == "") { parameters["sff"] = inputDir + it->second; }
223 it = parameters.find("oligos");
224 //user has given a template file
225 if(it != parameters.end()){
226 path = m->hasPath(it->second);
227 //if the user has not given a path then, add inputdir. else leave path alone.
228 if (path == "") { parameters["oligos"] = inputDir + it->second; }
231 it = parameters.find("accnos");
232 //user has given a template file
233 if(it != parameters.end()){
234 path = m->hasPath(it->second);
235 //if the user has not given a path then, add inputdir. else leave path alone.
236 if (path == "") { parameters["accnos"] = inputDir + it->second; }
239 it = parameters.find("taxonomy");
240 //user has given a template file
241 if(it != parameters.end()){
242 path = m->hasPath(it->second);
243 //if the user has not given a path then, add inputdir. else leave path alone.
244 if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
248 //check for parameters
249 phylipfile = validParameter.validFile(parameters, "phylip", true);
250 if (phylipfile == "not open") { m->mothurOut("Ignoring: " + parameters["phylip"]); m->mothurOutEndLine(); phylipfile = ""; }
251 else if (phylipfile == "not found") { phylipfile = ""; }
252 if (phylipfile != "") { m->setPhylipFile(phylipfile); }
254 columnfile = validParameter.validFile(parameters, "column", true);
255 if (columnfile == "not open") { m->mothurOut("Ignoring: " + parameters["column"]); m->mothurOutEndLine(); columnfile = ""; }
256 else if (columnfile == "not found") { columnfile = ""; }
257 if (columnfile != "") { m->setColumnFile(columnfile); }
259 listfile = validParameter.validFile(parameters, "list", true);
260 if (listfile == "not open") { m->mothurOut("Ignoring: " + parameters["list"]); m->mothurOutEndLine(); listfile = ""; }
261 else if (listfile == "not found") { listfile = ""; }
262 if (listfile != "") { m->setListFile(listfile); }
264 rabundfile = validParameter.validFile(parameters, "rabund", true);
265 if (rabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["rabund"]); m->mothurOutEndLine(); rabundfile = ""; }
266 else if (rabundfile == "not found") { rabundfile = ""; }
267 if (rabundfile != "") { m->setRabundFile(rabundfile); }
269 sabundfile = validParameter.validFile(parameters, "sabund", true);
270 if (sabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["sabund"]); m->mothurOutEndLine(); sabundfile = ""; }
271 else if (sabundfile == "not found") { sabundfile = ""; }
272 if (sabundfile != "") { m->setSabundFile(sabundfile); }
274 namefile = validParameter.validFile(parameters, "name", true);
275 if (namefile == "not open") { m->mothurOut("Ignoring: " + parameters["name"]); m->mothurOutEndLine(); namefile = ""; }
276 else if (namefile == "not found") { namefile = ""; }
277 if (namefile != "") { m->setNameFile(namefile); }
279 groupfile = validParameter.validFile(parameters, "group", true);
280 if (groupfile == "not open") { m->mothurOut("Ignoring: " + parameters["group"]); m->mothurOutEndLine(); groupfile = ""; }
281 else if (groupfile == "not found") { groupfile = ""; }
282 if (groupfile != "") { m->setGroupFile(groupfile); }
284 designfile = validParameter.validFile(parameters, "design", true);
285 if (designfile == "not open") { m->mothurOut("Ignoring: " + parameters["design"]); m->mothurOutEndLine(); designfile = ""; }
286 else if (designfile == "not found") { designfile = ""; }
287 if (designfile != "") { m->setDesignFile(designfile); }
289 orderfile = validParameter.validFile(parameters, "order", true);
290 if (orderfile == "not open") { m->mothurOut("Ignoring: " + parameters["order"]); m->mothurOutEndLine(); orderfile = ""; }
291 else if (orderfile == "not found") { orderfile = ""; }
292 if (orderfile != "") { m->setOrderFile(orderfile); }
294 treefile = validParameter.validFile(parameters, "tree", true);
295 if (treefile == "not open") { m->mothurOut("Ignoring: " + parameters["tree"]); m->mothurOutEndLine(); treefile = ""; }
296 else if (treefile == "not found") { treefile = ""; }
297 if (treefile != "") { m->setTreeFile(treefile); }
299 sharedfile = validParameter.validFile(parameters, "shared", true);
300 if (sharedfile == "not open") { m->mothurOut("Ignoring: " + parameters["shared"]); m->mothurOutEndLine(); sharedfile = ""; }
301 else if (sharedfile == "not found") { sharedfile = ""; }
302 if (sharedfile != "") { m->setSharedFile(sharedfile); }
304 ordergroupfile = validParameter.validFile(parameters, "ordergroup", true);
305 if (ordergroupfile == "not open") { m->mothurOut("Ignoring: " + parameters["ordergroup"]); m->mothurOutEndLine(); ordergroupfile = ""; }
306 else if (ordergroupfile == "not found") { ordergroupfile = ""; }
307 if (ordergroupfile != "") { m->setOrderGroupFile(ordergroupfile); }
309 relabundfile = validParameter.validFile(parameters, "relabund", true);
310 if (relabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["relabund"]); m->mothurOutEndLine(); relabundfile = ""; }
311 else if (relabundfile == "not found") { relabundfile = ""; }
312 if (relabundfile != "") { m->setRelAbundFile(relabundfile); }
314 fastafile = validParameter.validFile(parameters, "fasta", true);
315 if (fastafile == "not open") { m->mothurOut("Ignoring: " + parameters["fasta"]); m->mothurOutEndLine(); fastafile = ""; }
316 else if (fastafile == "not found") { fastafile = ""; }
317 if (fastafile != "") { m->setFastaFile(fastafile); }
319 qualfile = validParameter.validFile(parameters, "qfile", true);
320 if (qualfile == "not open") { m->mothurOut("Ignoring: " + parameters["qfile"]); m->mothurOutEndLine(); qualfile = ""; }
321 else if (qualfile == "not found") { qualfile = ""; }
322 if (qualfile != "") { m->setQualFile(qualfile); }
324 sfffile = validParameter.validFile(parameters, "sff", true);
325 if (sfffile == "not open") { m->mothurOut("Ignoring: " + parameters["sff"]); m->mothurOutEndLine(); sfffile = ""; }
326 else if (sfffile == "not found") { sfffile = ""; }
327 if (sfffile != "") { m->setSFFFile(sfffile); }
329 oligosfile = validParameter.validFile(parameters, "oligos", true);
330 if (oligosfile == "not open") { m->mothurOut("Ignoring: " + parameters["oligos"]); m->mothurOutEndLine(); oligosfile = ""; }
331 else if (oligosfile == "not found") { oligosfile = ""; }
332 if (oligosfile != "") { m->setOligosFile(oligosfile); }
334 accnosfile = validParameter.validFile(parameters, "accnos", true);
335 if (accnosfile == "not open") { m->mothurOut("Ignoring: " + parameters["accnos"]); m->mothurOutEndLine(); accnosfile = ""; }
336 else if (accnosfile == "not found") { accnosfile = ""; }
337 if (accnosfile != "") { m->setAccnosFile(accnosfile); }
339 taxonomyfile = validParameter.validFile(parameters, "taxonomy", true);
340 if (taxonomyfile == "not open") { m->mothurOut("Ignoring: " + parameters["taxonomy"]); m->mothurOutEndLine(); taxonomyfile = ""; }
341 else if (taxonomyfile == "not found") { taxonomyfile = ""; }
342 if (taxonomyfile != "") { m->setTaxonomyFile(taxonomyfile); }
344 clearTypes = validParameter.validFile(parameters, "clear", false);
345 if (clearTypes == "not found") { clearTypes = ""; }
346 else { m->splitAtDash(clearTypes, types); }
350 catch(exception& e) {
351 m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
355 //**********************************************************************************************************************
357 void SetCurrentCommand::help(){
359 m->mothurOut("The set.current command allows you to set the current files saved by mothur.\n");
360 m->mothurOut("The set.current command parameters are: clear, phylip, column, list, rabund, sabund, name, group, design, order, tree, shared, ordergroup, relabund, fasta, qfile, sff, oligos, accnos, taxonomy.\n");
361 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");
362 m->mothurOut("The set.current command should be in the following format: \n");
363 m->mothurOut("set.current(fasta=yourFastaFile) or set.current(fasta=amazon.fasta, clear=name-accnos)\n");
366 catch(exception& e) {
367 m->errorOut(e, "SetCurrentCommand", "help");
372 //**********************************************************************************************************************
373 SetCurrentCommand::~SetCurrentCommand(){}
374 //**********************************************************************************************************************
376 int SetCurrentCommand::execute(){
379 if (abort == true) { if (calledHelp) { return 0; } return 2; }
381 //user wants to clear a type
382 if (types.size() != 0) {
383 for (int i = 0; i < types.size(); i++) {
385 if (m->control_pressed) { break; }
387 //look for file types
388 if (types[i] == "fasta") {
390 }else if (types[i] == "qfile") {
392 }else if (types[i] == "phylip") {
393 m->setPhylipFile("");
394 }else if (types[i] == "column") {
395 m->setColumnFile("");
396 }else if (types[i] == "list") {
398 }else if (types[i] == "rabund") {
399 m->setRabundFile("");
400 }else if (types[i] == "sabund") {
401 m->setSabundFile("");
402 }else if (types[i] == "name") {
404 }else if (types[i] == "group") {
406 }else if (types[i] == "order") {
408 }else if (types[i] == "ordergroup") {
409 m->setOrderGroupFile("");
410 }else if (types[i] == "tree") {
412 }else if (types[i] == "shared") {
413 m->setSharedFile("");
414 }else if (types[i] == "relabund") {
415 m->setRelAbundFile("");
416 }else if (types[i] == "design") {
417 m->setDesignFile("");
418 }else if (types[i] == "sff") {
420 }else if (types[i] == "oligos") {
421 m->setOligosFile("");
422 }else if (types[i] == "accnos") {
423 m->setAccnosFile("");
424 }else if (types[i] == "taxonomy") {
425 m->setTaxonomyFile("");
426 }else if (types[i] == "all") {
427 m->clearCurrentFiles();
429 m->mothurOut("[ERROR]: mothur does not save a current file for " + types[i]); m->mothurOutEndLine();
434 m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine();
435 m->printCurrentFiles();
440 catch(exception& e) {
441 m->errorOut(e, "SetCurrentCommand", "execute");
446 //**********************************************************************************************************************