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::setParameters(){
16 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
17 CommandParameter pflow("flow", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pflow);
18 CommandParameter pbiom("biom", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pbiom);
19 CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pphylip);
20 CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pcolumn);
21 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pfasta);
22 CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname);
23 CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup);
24 CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plist);
25 CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(ptaxonomy);
26 CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pqfile);
27 CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos);
28 CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(prabund);
29 CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psabund);
30 CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pdesign);
31 CommandParameter porder("order", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(porder);
32 CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(ptree);
33 CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pshared);
34 CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pordergroup);
35 CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pcount);
36 CommandParameter prelabund("relabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(prelabund);
37 CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psff);
38 CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos);
39 CommandParameter pclear("clear", "String", "", "", "", "", "",false,false); parameters.push_back(pclear);
40 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
41 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
43 vector<string> myArray;
44 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
48 m->errorOut(e, "SetCurrentCommand", "setParameters");
52 //**********************************************************************************************************************
53 string SetCurrentCommand::getHelpString(){
55 string helpString = "";
56 helpString += "The set.current command allows you to set the current files saved by mothur.\n";
57 helpString += "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, biom, count and taxonomy.\n";
58 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";
59 helpString += "The set.current command should be in the following format: \n";
60 helpString += "set.current(fasta=yourFastaFile) or set.current(fasta=amazon.fasta, clear=name-accnos)\n";
64 m->errorOut(e, "SetCurrentCommand", "getHelpString");
70 //**********************************************************************************************************************
71 SetCurrentCommand::SetCurrentCommand(){
73 abort = true; calledHelp = true;
77 m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
81 //**********************************************************************************************************************
82 SetCurrentCommand::SetCurrentCommand(string option) {
84 abort = false; calledHelp = false;
86 //allow user to run help
87 if(option == "help") { help(); abort = true; calledHelp = true; }
88 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
91 //valid paramters for this command
92 vector<string> myArray = setParameters();
94 OptionParser parser(option);
95 map<string,string> parameters = parser.getParameters();
97 ValidParameters validParameter;
98 map<string,string>::iterator it;
99 //check to make sure all parameters are valid for command
100 for (it = parameters.begin(); it != parameters.end(); it++) {
101 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
105 //if the user changes the input directory command factory will send this info to us in the output parameter
106 string inputDir = validParameter.validFile(parameters, "inputdir", false);
107 if (inputDir == "not found"){ inputDir = ""; }
110 it = parameters.find("phylip");
111 //user has given a template file
112 if(it != parameters.end()){
113 path = m->hasPath(it->second);
114 //if the user has not given a path then, add inputdir. else leave path alone.
115 if (path == "") { parameters["phylip"] = inputDir + it->second; }
118 it = parameters.find("column");
119 //user has given a template file
120 if(it != parameters.end()){
121 path = m->hasPath(it->second);
122 //if the user has not given a path then, add inputdir. else leave path alone.
123 if (path == "") { parameters["column"] = inputDir + it->second; }
126 it = parameters.find("fasta");
127 //user has given a template file
128 if(it != parameters.end()){
129 path = m->hasPath(it->second);
130 //if the user has not given a path then, add inputdir. else leave path alone.
131 if (path == "") { parameters["fasta"] = inputDir + it->second; }
134 it = parameters.find("list");
135 //user has given a template file
136 if(it != parameters.end()){
137 path = m->hasPath(it->second);
138 //if the user has not given a path then, add inputdir. else leave path alone.
139 if (path == "") { parameters["list"] = inputDir + it->second; }
142 it = parameters.find("rabund");
143 //user has given a template file
144 if(it != parameters.end()){
145 path = m->hasPath(it->second);
146 //if the user has not given a path then, add inputdir. else leave path alone.
147 if (path == "") { parameters["rabund"] = inputDir + it->second; }
150 it = parameters.find("sabund");
151 //user has given a template file
152 if(it != parameters.end()){
153 path = m->hasPath(it->second);
154 //if the user has not given a path then, add inputdir. else leave path alone.
155 if (path == "") { parameters["sabund"] = inputDir + it->second; }
158 it = parameters.find("name");
159 //user has given a template file
160 if(it != parameters.end()){
161 path = m->hasPath(it->second);
162 //if the user has not given a path then, add inputdir. else leave path alone.
163 if (path == "") { parameters["name"] = inputDir + it->second; }
166 it = parameters.find("group");
167 //user has given a template file
168 if(it != parameters.end()){
169 path = m->hasPath(it->second);
170 //if the user has not given a path then, add inputdir. else leave path alone.
171 if (path == "") { parameters["group"] = inputDir + it->second; }
174 it = parameters.find("design");
175 //user has given a template file
176 if(it != parameters.end()){
177 path = m->hasPath(it->second);
178 //if the user has not given a path then, add inputdir. else leave path alone.
179 if (path == "") { parameters["design"] = inputDir + it->second; }
182 it = parameters.find("order");
183 //user has given a template file
184 if(it != parameters.end()){
185 path = m->hasPath(it->second);
186 //if the user has not given a path then, add inputdir. else leave path alone.
187 if (path == "") { parameters["order"] = inputDir + it->second; }
190 it = parameters.find("tree");
191 //user has given a template file
192 if(it != parameters.end()){
193 path = m->hasPath(it->second);
194 //if the user has not given a path then, add inputdir. else leave path alone.
195 if (path == "") { parameters["tree"] = inputDir + it->second; }
198 it = parameters.find("shared");
199 //user has given a template file
200 if(it != parameters.end()){
201 path = m->hasPath(it->second);
202 //if the user has not given a path then, add inputdir. else leave path alone.
203 if (path == "") { parameters["shared"] = inputDir + it->second; }
206 it = parameters.find("ordergroup");
207 //user has given a template file
208 if(it != parameters.end()){
209 path = m->hasPath(it->second);
210 //if the user has not given a path then, add inputdir. else leave path alone.
211 if (path == "") { parameters["ordergroup"] = inputDir + it->second; }
214 it = parameters.find("count");
215 //user has given a template file
216 if(it != parameters.end()){
217 path = m->hasPath(it->second);
218 //if the user has not given a path then, add inputdir. else leave path alone.
219 if (path == "") { parameters["count"] = inputDir + it->second; }
222 it = parameters.find("relabund");
223 //user has given a template file
224 if(it != parameters.end()){
225 path = m->hasPath(it->second);
226 //if the user has not given a path then, add inputdir. else leave path alone.
227 if (path == "") { parameters["relabund"] = inputDir + it->second; }
230 it = parameters.find("fasta");
231 //user has given a template file
232 if(it != parameters.end()){
233 path = m->hasPath(it->second);
234 //if the user has not given a path then, add inputdir. else leave path alone.
235 if (path == "") { parameters["fasta"] = inputDir + it->second; }
238 it = parameters.find("qfile");
239 //user has given a template file
240 if(it != parameters.end()){
241 path = m->hasPath(it->second);
242 //if the user has not given a path then, add inputdir. else leave path alone.
243 if (path == "") { parameters["qfile"] = inputDir + it->second; }
246 it = parameters.find("sff");
247 //user has given a template file
248 if(it != parameters.end()){
249 path = m->hasPath(it->second);
250 //if the user has not given a path then, add inputdir. else leave path alone.
251 if (path == "") { parameters["sff"] = inputDir + it->second; }
254 it = parameters.find("oligos");
255 //user has given a template file
256 if(it != parameters.end()){
257 path = m->hasPath(it->second);
258 //if the user has not given a path then, add inputdir. else leave path alone.
259 if (path == "") { parameters["oligos"] = inputDir + it->second; }
262 it = parameters.find("accnos");
263 //user has given a template file
264 if(it != parameters.end()){
265 path = m->hasPath(it->second);
266 //if the user has not given a path then, add inputdir. else leave path alone.
267 if (path == "") { parameters["accnos"] = inputDir + it->second; }
270 it = parameters.find("taxonomy");
271 //user has given a template file
272 if(it != parameters.end()){
273 path = m->hasPath(it->second);
274 //if the user has not given a path then, add inputdir. else leave path alone.
275 if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
278 it = parameters.find("flow");
279 //user has given a template file
280 if(it != parameters.end()){
281 path = m->hasPath(it->second);
282 //if the user has not given a path then, add inputdir. else leave path alone.
283 if (path == "") { parameters["flow"] = inputDir + it->second; }
286 it = parameters.find("biom");
287 //user has given a template file
288 if(it != parameters.end()){
289 path = m->hasPath(it->second);
290 //if the user has not given a path then, add inputdir. else leave path alone.
291 if (path == "") { parameters["biom"] = inputDir + it->second; }
295 //check for parameters
296 phylipfile = validParameter.validFile(parameters, "phylip", true);
297 if (phylipfile == "not open") { m->mothurOut("Ignoring: " + parameters["phylip"]); m->mothurOutEndLine(); phylipfile = ""; }
298 else if (phylipfile == "not found") { phylipfile = ""; }
299 if (phylipfile != "") { m->setPhylipFile(phylipfile); }
301 columnfile = validParameter.validFile(parameters, "column", true);
302 if (columnfile == "not open") { m->mothurOut("Ignoring: " + parameters["column"]); m->mothurOutEndLine(); columnfile = ""; }
303 else if (columnfile == "not found") { columnfile = ""; }
304 if (columnfile != "") { m->setColumnFile(columnfile); }
306 listfile = validParameter.validFile(parameters, "list", true);
307 if (listfile == "not open") { m->mothurOut("Ignoring: " + parameters["list"]); m->mothurOutEndLine(); listfile = ""; }
308 else if (listfile == "not found") { listfile = ""; }
309 if (listfile != "") { m->setListFile(listfile); }
311 rabundfile = validParameter.validFile(parameters, "rabund", true);
312 if (rabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["rabund"]); m->mothurOutEndLine(); rabundfile = ""; }
313 else if (rabundfile == "not found") { rabundfile = ""; }
314 if (rabundfile != "") { m->setRabundFile(rabundfile); }
316 sabundfile = validParameter.validFile(parameters, "sabund", true);
317 if (sabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["sabund"]); m->mothurOutEndLine(); sabundfile = ""; }
318 else if (sabundfile == "not found") { sabundfile = ""; }
319 if (sabundfile != "") { m->setSabundFile(sabundfile); }
321 namefile = validParameter.validFile(parameters, "name", true);
322 if (namefile == "not open") { m->mothurOut("Ignoring: " + parameters["name"]); m->mothurOutEndLine(); namefile = ""; }
323 else if (namefile == "not found") { namefile = ""; }
324 if (namefile != "") { m->setNameFile(namefile); }
326 groupfile = validParameter.validFile(parameters, "group", true);
327 if (groupfile == "not open") { m->mothurOut("Ignoring: " + parameters["group"]); m->mothurOutEndLine(); groupfile = ""; }
328 else if (groupfile == "not found") { groupfile = ""; }
329 if (groupfile != "") { m->setGroupFile(groupfile); }
331 countfile = validParameter.validFile(parameters, "count", true);
332 if (countfile == "not open") { m->mothurOut("Ignoring: " + parameters["count"]); m->mothurOutEndLine(); countfile = ""; }
333 else if (countfile == "not found") { countfile = ""; }
334 if (countfile != "") { m->setCountTableFile(countfile); }
336 designfile = validParameter.validFile(parameters, "design", true);
337 if (designfile == "not open") { m->mothurOut("Ignoring: " + parameters["design"]); m->mothurOutEndLine(); designfile = ""; }
338 else if (designfile == "not found") { designfile = ""; }
339 if (designfile != "") { m->setDesignFile(designfile); }
341 orderfile = validParameter.validFile(parameters, "order", true);
342 if (orderfile == "not open") { m->mothurOut("Ignoring: " + parameters["order"]); m->mothurOutEndLine(); orderfile = ""; }
343 else if (orderfile == "not found") { orderfile = ""; }
344 if (orderfile != "") { m->setOrderFile(orderfile); }
346 treefile = validParameter.validFile(parameters, "tree", true);
347 if (treefile == "not open") { m->mothurOut("Ignoring: " + parameters["tree"]); m->mothurOutEndLine(); treefile = ""; }
348 else if (treefile == "not found") { treefile = ""; }
349 if (treefile != "") { m->setTreeFile(treefile); }
351 sharedfile = validParameter.validFile(parameters, "shared", true);
352 if (sharedfile == "not open") { m->mothurOut("Ignoring: " + parameters["shared"]); m->mothurOutEndLine(); sharedfile = ""; }
353 else if (sharedfile == "not found") { sharedfile = ""; }
354 if (sharedfile != "") { m->setSharedFile(sharedfile); }
356 ordergroupfile = validParameter.validFile(parameters, "ordergroup", true);
357 if (ordergroupfile == "not open") { m->mothurOut("Ignoring: " + parameters["ordergroup"]); m->mothurOutEndLine(); ordergroupfile = ""; }
358 else if (ordergroupfile == "not found") { ordergroupfile = ""; }
359 if (ordergroupfile != "") { m->setOrderGroupFile(ordergroupfile); }
361 relabundfile = validParameter.validFile(parameters, "relabund", true);
362 if (relabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["relabund"]); m->mothurOutEndLine(); relabundfile = ""; }
363 else if (relabundfile == "not found") { relabundfile = ""; }
364 if (relabundfile != "") { m->setRelAbundFile(relabundfile); }
366 fastafile = validParameter.validFile(parameters, "fasta", true);
367 if (fastafile == "not open") { m->mothurOut("Ignoring: " + parameters["fasta"]); m->mothurOutEndLine(); fastafile = ""; }
368 else if (fastafile == "not found") { fastafile = ""; }
369 if (fastafile != "") { m->setFastaFile(fastafile); }
371 qualfile = validParameter.validFile(parameters, "qfile", true);
372 if (qualfile == "not open") { m->mothurOut("Ignoring: " + parameters["qfile"]); m->mothurOutEndLine(); qualfile = ""; }
373 else if (qualfile == "not found") { qualfile = ""; }
374 if (qualfile != "") { m->setQualFile(qualfile); }
376 sfffile = validParameter.validFile(parameters, "sff", true);
377 if (sfffile == "not open") { m->mothurOut("Ignoring: " + parameters["sff"]); m->mothurOutEndLine(); sfffile = ""; }
378 else if (sfffile == "not found") { sfffile = ""; }
379 if (sfffile != "") { m->setSFFFile(sfffile); }
381 oligosfile = validParameter.validFile(parameters, "oligos", true);
382 if (oligosfile == "not open") { m->mothurOut("Ignoring: " + parameters["oligos"]); m->mothurOutEndLine(); oligosfile = ""; }
383 else if (oligosfile == "not found") { oligosfile = ""; }
384 if (oligosfile != "") { m->setOligosFile(oligosfile); }
386 accnosfile = validParameter.validFile(parameters, "accnos", true);
387 if (accnosfile == "not open") { m->mothurOut("Ignoring: " + parameters["accnos"]); m->mothurOutEndLine(); accnosfile = ""; }
388 else if (accnosfile == "not found") { accnosfile = ""; }
389 if (accnosfile != "") { m->setAccnosFile(accnosfile); }
391 taxonomyfile = validParameter.validFile(parameters, "taxonomy", true);
392 if (taxonomyfile == "not open") { m->mothurOut("Ignoring: " + parameters["taxonomy"]); m->mothurOutEndLine(); taxonomyfile = ""; }
393 else if (taxonomyfile == "not found") { taxonomyfile = ""; }
394 if (taxonomyfile != "") { m->setTaxonomyFile(taxonomyfile); }
396 flowfile = validParameter.validFile(parameters, "flow", true);
397 if (flowfile == "not open") { m->mothurOut("Ignoring: " + parameters["flow"]); m->mothurOutEndLine(); flowfile = ""; }
398 else if (flowfile == "not found") { flowfile = ""; }
399 if (flowfile != "") { m->setFlowFile(flowfile); }
401 biomfile = validParameter.validFile(parameters, "biom", true);
402 if (biomfile == "not open") { m->mothurOut("Ignoring: " + parameters["biom"]); m->mothurOutEndLine(); biomfile = ""; }
403 else if (biomfile == "not found") { biomfile = ""; }
404 if (biomfile != "") { m->setBiomFile(biomfile); }
406 processors = validParameter.validFile(parameters, "processors", false);
407 if (processors == "not found") { processors = "1"; }
408 if (processors != "") { m->setProcessors(processors); }
410 clearTypes = validParameter.validFile(parameters, "clear", false);
411 if (clearTypes == "not found") { clearTypes = ""; }
412 else { m->splitAtDash(clearTypes, types); }
416 catch(exception& e) {
417 m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
421 //**********************************************************************************************************************
423 int SetCurrentCommand::execute(){
426 if (abort == true) { if (calledHelp) { return 0; } return 2; }
428 //user wants to clear a type
429 if (types.size() != 0) {
430 for (int i = 0; i < types.size(); i++) {
432 if (m->control_pressed) { break; }
434 //look for file types
435 if (types[i] == "fasta") {
437 }else if (types[i] == "qfile") {
439 }else if (types[i] == "phylip") {
440 m->setPhylipFile("");
441 }else if (types[i] == "column") {
442 m->setColumnFile("");
443 }else if (types[i] == "list") {
445 }else if (types[i] == "rabund") {
446 m->setRabundFile("");
447 }else if (types[i] == "sabund") {
448 m->setSabundFile("");
449 }else if (types[i] == "name") {
451 }else if (types[i] == "group") {
453 }else if (types[i] == "order") {
455 }else if (types[i] == "ordergroup") {
456 m->setOrderGroupFile("");
457 }else if (types[i] == "tree") {
459 }else if (types[i] == "shared") {
460 m->setSharedFile("");
461 }else if (types[i] == "relabund") {
462 m->setRelAbundFile("");
463 }else if (types[i] == "design") {
464 m->setDesignFile("");
465 }else if (types[i] == "sff") {
467 }else if (types[i] == "oligos") {
468 m->setOligosFile("");
469 }else if (types[i] == "accnos") {
470 m->setAccnosFile("");
471 }else if (types[i] == "taxonomy") {
472 m->setTaxonomyFile("");
473 }else if (types[i] == "flow") {
475 }else if (types[i] == "biom") {
477 }else if (types[i] == "count") {
478 m->setCountTableFile("");
479 }else if (types[i] == "processors") {
480 m->setProcessors("1");
481 }else if (types[i] == "all") {
482 m->clearCurrentFiles();
484 m->mothurOut("[ERROR]: mothur does not save a current file for " + types[i]); m->mothurOutEndLine();
489 m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine();
490 m->printCurrentFiles();
495 catch(exception& e) {
496 m->errorOut(e, "SetCurrentCommand", "execute");
501 //**********************************************************************************************************************