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,true); 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 psummary("summary", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psummary);
22 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pfasta);
23 CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pname);
24 CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pgroup);
25 CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(plist);
26 CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptaxonomy);
27 CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pqfile);
28 CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos);
29 CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prabund);
30 CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psabund);
31 CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pdesign);
32 CommandParameter porder("order", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(porder);
33 CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptree);
34 CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pshared);
35 CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pordergroup);
36 CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcount);
37 CommandParameter prelabund("relabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prelabund);
38 CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psff);
39 CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(poligos);
40 CommandParameter pclear("clear", "String", "", "", "", "", "","",false,false); parameters.push_back(pclear);
41 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
42 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
44 vector<string> myArray;
45 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
49 m->errorOut(e, "SetCurrentCommand", "setParameters");
53 //**********************************************************************************************************************
54 string SetCurrentCommand::getHelpString(){
56 string helpString = "";
57 helpString += "The set.current command allows you to set the current files saved by mothur.\n";
58 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, summary and taxonomy.\n";
59 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";
60 helpString += "The set.current command should be in the following format: \n";
61 helpString += "set.current(fasta=yourFastaFile) or set.current(fasta=amazon.fasta, clear=name-accnos)\n";
65 m->errorOut(e, "SetCurrentCommand", "getHelpString");
71 //**********************************************************************************************************************
72 SetCurrentCommand::SetCurrentCommand(){
74 abort = true; calledHelp = true;
78 m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
82 //**********************************************************************************************************************
83 SetCurrentCommand::SetCurrentCommand(string option) {
85 abort = false; calledHelp = false;
87 //allow user to run help
88 if(option == "help") { help(); abort = true; calledHelp = true; }
89 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
92 //valid paramters for this command
93 vector<string> myArray = setParameters();
95 OptionParser parser(option);
96 map<string,string> parameters = parser.getParameters();
98 ValidParameters validParameter;
99 map<string,string>::iterator it;
100 //check to make sure all parameters are valid for command
101 for (it = parameters.begin(); it != parameters.end(); it++) {
102 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
106 //if the user changes the input directory command factory will send this info to us in the output parameter
107 string inputDir = validParameter.validFile(parameters, "inputdir", false);
108 if (inputDir == "not found"){ inputDir = ""; }
111 it = parameters.find("phylip");
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["phylip"] = inputDir + it->second; }
119 it = parameters.find("column");
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["column"] = inputDir + it->second; }
127 it = parameters.find("fasta");
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["fasta"] = inputDir + it->second; }
135 it = parameters.find("list");
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["list"] = inputDir + it->second; }
143 it = parameters.find("rabund");
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["rabund"] = inputDir + it->second; }
151 it = parameters.find("sabund");
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["sabund"] = inputDir + it->second; }
159 it = parameters.find("name");
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["name"] = inputDir + it->second; }
167 it = parameters.find("group");
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["group"] = inputDir + it->second; }
175 it = parameters.find("design");
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["design"] = inputDir + it->second; }
183 it = parameters.find("order");
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["order"] = inputDir + it->second; }
191 it = parameters.find("tree");
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["tree"] = inputDir + it->second; }
199 it = parameters.find("shared");
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["shared"] = inputDir + it->second; }
207 it = parameters.find("ordergroup");
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["ordergroup"] = inputDir + it->second; }
215 it = parameters.find("count");
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["count"] = inputDir + it->second; }
223 it = parameters.find("relabund");
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["relabund"] = inputDir + it->second; }
231 it = parameters.find("fasta");
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["fasta"] = inputDir + it->second; }
239 it = parameters.find("qfile");
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["qfile"] = inputDir + it->second; }
247 it = parameters.find("sff");
248 //user has given a template file
249 if(it != parameters.end()){
250 path = m->hasPath(it->second);
251 //if the user has not given a path then, add inputdir. else leave path alone.
252 if (path == "") { parameters["sff"] = inputDir + it->second; }
255 it = parameters.find("oligos");
256 //user has given a template file
257 if(it != parameters.end()){
258 path = m->hasPath(it->second);
259 //if the user has not given a path then, add inputdir. else leave path alone.
260 if (path == "") { parameters["oligos"] = inputDir + it->second; }
263 it = parameters.find("accnos");
264 //user has given a template file
265 if(it != parameters.end()){
266 path = m->hasPath(it->second);
267 //if the user has not given a path then, add inputdir. else leave path alone.
268 if (path == "") { parameters["accnos"] = inputDir + it->second; }
271 it = parameters.find("taxonomy");
272 //user has given a template file
273 if(it != parameters.end()){
274 path = m->hasPath(it->second);
275 //if the user has not given a path then, add inputdir. else leave path alone.
276 if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
279 it = parameters.find("flow");
280 //user has given a template file
281 if(it != parameters.end()){
282 path = m->hasPath(it->second);
283 //if the user has not given a path then, add inputdir. else leave path alone.
284 if (path == "") { parameters["flow"] = inputDir + it->second; }
287 it = parameters.find("biom");
288 //user has given a template file
289 if(it != parameters.end()){
290 path = m->hasPath(it->second);
291 //if the user has not given a path then, add inputdir. else leave path alone.
292 if (path == "") { parameters["biom"] = inputDir + it->second; }
295 it = parameters.find("summary");
296 //user has given a template file
297 if(it != parameters.end()){
298 path = m->hasPath(it->second);
299 //if the user has not given a path then, add inputdir. else leave path alone.
300 if (path == "") { parameters["summary"] = inputDir + it->second; }
304 //check for parameters
305 phylipfile = validParameter.validFile(parameters, "phylip", true);
306 if (phylipfile == "not open") { m->mothurOut("Ignoring: " + parameters["phylip"]); m->mothurOutEndLine(); phylipfile = ""; }
307 else if (phylipfile == "not found") { phylipfile = ""; }
308 if (phylipfile != "") { m->setPhylipFile(phylipfile); }
310 columnfile = validParameter.validFile(parameters, "column", true);
311 if (columnfile == "not open") { m->mothurOut("Ignoring: " + parameters["column"]); m->mothurOutEndLine(); columnfile = ""; }
312 else if (columnfile == "not found") { columnfile = ""; }
313 if (columnfile != "") { m->setColumnFile(columnfile); }
315 listfile = validParameter.validFile(parameters, "list", true);
316 if (listfile == "not open") { m->mothurOut("Ignoring: " + parameters["list"]); m->mothurOutEndLine(); listfile = ""; }
317 else if (listfile == "not found") { listfile = ""; }
318 if (listfile != "") { m->setListFile(listfile); }
320 rabundfile = validParameter.validFile(parameters, "rabund", true);
321 if (rabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["rabund"]); m->mothurOutEndLine(); rabundfile = ""; }
322 else if (rabundfile == "not found") { rabundfile = ""; }
323 if (rabundfile != "") { m->setRabundFile(rabundfile); }
325 sabundfile = validParameter.validFile(parameters, "sabund", true);
326 if (sabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["sabund"]); m->mothurOutEndLine(); sabundfile = ""; }
327 else if (sabundfile == "not found") { sabundfile = ""; }
328 if (sabundfile != "") { m->setSabundFile(sabundfile); }
330 namefile = validParameter.validFile(parameters, "name", true);
331 if (namefile == "not open") { m->mothurOut("Ignoring: " + parameters["name"]); m->mothurOutEndLine(); namefile = ""; }
332 else if (namefile == "not found") { namefile = ""; }
333 if (namefile != "") { m->setNameFile(namefile); }
335 groupfile = validParameter.validFile(parameters, "group", true);
336 if (groupfile == "not open") { m->mothurOut("Ignoring: " + parameters["group"]); m->mothurOutEndLine(); groupfile = ""; }
337 else if (groupfile == "not found") { groupfile = ""; }
338 if (groupfile != "") { m->setGroupFile(groupfile); }
340 countfile = validParameter.validFile(parameters, "count", true);
341 if (countfile == "not open") { m->mothurOut("Ignoring: " + parameters["count"]); m->mothurOutEndLine(); countfile = ""; }
342 else if (countfile == "not found") { countfile = ""; }
343 if (countfile != "") { m->setCountTableFile(countfile); }
345 designfile = validParameter.validFile(parameters, "design", true);
346 if (designfile == "not open") { m->mothurOut("Ignoring: " + parameters["design"]); m->mothurOutEndLine(); designfile = ""; }
347 else if (designfile == "not found") { designfile = ""; }
348 if (designfile != "") { m->setDesignFile(designfile); }
350 orderfile = validParameter.validFile(parameters, "order", true);
351 if (orderfile == "not open") { m->mothurOut("Ignoring: " + parameters["order"]); m->mothurOutEndLine(); orderfile = ""; }
352 else if (orderfile == "not found") { orderfile = ""; }
353 if (orderfile != "") { m->setOrderFile(orderfile); }
355 treefile = validParameter.validFile(parameters, "tree", true);
356 if (treefile == "not open") { m->mothurOut("Ignoring: " + parameters["tree"]); m->mothurOutEndLine(); treefile = ""; }
357 else if (treefile == "not found") { treefile = ""; }
358 if (treefile != "") { m->setTreeFile(treefile); }
360 sharedfile = validParameter.validFile(parameters, "shared", true);
361 if (sharedfile == "not open") { m->mothurOut("Ignoring: " + parameters["shared"]); m->mothurOutEndLine(); sharedfile = ""; }
362 else if (sharedfile == "not found") { sharedfile = ""; }
363 if (sharedfile != "") { m->setSharedFile(sharedfile); }
365 ordergroupfile = validParameter.validFile(parameters, "ordergroup", true);
366 if (ordergroupfile == "not open") { m->mothurOut("Ignoring: " + parameters["ordergroup"]); m->mothurOutEndLine(); ordergroupfile = ""; }
367 else if (ordergroupfile == "not found") { ordergroupfile = ""; }
368 if (ordergroupfile != "") { m->setOrderGroupFile(ordergroupfile); }
370 relabundfile = validParameter.validFile(parameters, "relabund", true);
371 if (relabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["relabund"]); m->mothurOutEndLine(); relabundfile = ""; }
372 else if (relabundfile == "not found") { relabundfile = ""; }
373 if (relabundfile != "") { m->setRelAbundFile(relabundfile); }
375 fastafile = validParameter.validFile(parameters, "fasta", true);
376 if (fastafile == "not open") { m->mothurOut("Ignoring: " + parameters["fasta"]); m->mothurOutEndLine(); fastafile = ""; }
377 else if (fastafile == "not found") { fastafile = ""; }
378 if (fastafile != "") { m->setFastaFile(fastafile); }
380 qualfile = validParameter.validFile(parameters, "qfile", true);
381 if (qualfile == "not open") { m->mothurOut("Ignoring: " + parameters["qfile"]); m->mothurOutEndLine(); qualfile = ""; }
382 else if (qualfile == "not found") { qualfile = ""; }
383 if (qualfile != "") { m->setQualFile(qualfile); }
385 sfffile = validParameter.validFile(parameters, "sff", true);
386 if (sfffile == "not open") { m->mothurOut("Ignoring: " + parameters["sff"]); m->mothurOutEndLine(); sfffile = ""; }
387 else if (sfffile == "not found") { sfffile = ""; }
388 if (sfffile != "") { m->setSFFFile(sfffile); }
390 oligosfile = validParameter.validFile(parameters, "oligos", true);
391 if (oligosfile == "not open") { m->mothurOut("Ignoring: " + parameters["oligos"]); m->mothurOutEndLine(); oligosfile = ""; }
392 else if (oligosfile == "not found") { oligosfile = ""; }
393 if (oligosfile != "") { m->setOligosFile(oligosfile); }
395 accnosfile = validParameter.validFile(parameters, "accnos", true);
396 if (accnosfile == "not open") { m->mothurOut("Ignoring: " + parameters["accnos"]); m->mothurOutEndLine(); accnosfile = ""; }
397 else if (accnosfile == "not found") { accnosfile = ""; }
398 if (accnosfile != "") { m->setAccnosFile(accnosfile); }
400 taxonomyfile = validParameter.validFile(parameters, "taxonomy", true);
401 if (taxonomyfile == "not open") { m->mothurOut("Ignoring: " + parameters["taxonomy"]); m->mothurOutEndLine(); taxonomyfile = ""; }
402 else if (taxonomyfile == "not found") { taxonomyfile = ""; }
403 if (taxonomyfile != "") { m->setTaxonomyFile(taxonomyfile); }
405 flowfile = validParameter.validFile(parameters, "flow", true);
406 if (flowfile == "not open") { m->mothurOut("Ignoring: " + parameters["flow"]); m->mothurOutEndLine(); flowfile = ""; }
407 else if (flowfile == "not found") { flowfile = ""; }
408 if (flowfile != "") { m->setFlowFile(flowfile); }
410 biomfile = validParameter.validFile(parameters, "biom", true);
411 if (biomfile == "not open") { m->mothurOut("Ignoring: " + parameters["biom"]); m->mothurOutEndLine(); biomfile = ""; }
412 else if (biomfile == "not found") { biomfile = ""; }
413 if (biomfile != "") { m->setBiomFile(biomfile); }
415 summaryfile = validParameter.validFile(parameters, "summary", true);
416 if (summaryfile == "not open") { m->mothurOut("Ignoring: " + parameters["summary"]); m->mothurOutEndLine(); summaryfile = ""; }
417 else if (summaryfile == "not found") { summaryfile = ""; }
418 if (summaryfile != "") { m->setSummaryFile(summaryfile); }
421 processors = validParameter.validFile(parameters, "processors", false);
422 if (processors == "not found") { processors = "1"; }
423 if (processors != "") { m->setProcessors(processors); }
425 clearTypes = validParameter.validFile(parameters, "clear", false);
426 if (clearTypes == "not found") { clearTypes = ""; }
427 else { m->splitAtDash(clearTypes, types); }
431 catch(exception& e) {
432 m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
436 //**********************************************************************************************************************
438 int SetCurrentCommand::execute(){
441 if (abort == true) { if (calledHelp) { return 0; } return 2; }
443 //user wants to clear a type
444 if (types.size() != 0) {
445 for (int i = 0; i < types.size(); i++) {
447 if (m->control_pressed) { break; }
449 //look for file types
450 if (types[i] == "fasta") {
452 }else if (types[i] == "qfile") {
454 }else if (types[i] == "phylip") {
455 m->setPhylipFile("");
456 }else if (types[i] == "column") {
457 m->setColumnFile("");
458 }else if (types[i] == "list") {
460 }else if (types[i] == "rabund") {
461 m->setRabundFile("");
462 }else if (types[i] == "sabund") {
463 m->setSabundFile("");
464 }else if (types[i] == "name") {
466 }else if (types[i] == "group") {
468 }else if (types[i] == "order") {
470 }else if (types[i] == "ordergroup") {
471 m->setOrderGroupFile("");
472 }else if (types[i] == "tree") {
474 }else if (types[i] == "shared") {
475 m->setSharedFile("");
476 }else if (types[i] == "relabund") {
477 m->setRelAbundFile("");
478 }else if (types[i] == "design") {
479 m->setDesignFile("");
480 }else if (types[i] == "sff") {
482 }else if (types[i] == "oligos") {
483 m->setOligosFile("");
484 }else if (types[i] == "accnos") {
485 m->setAccnosFile("");
486 }else if (types[i] == "taxonomy") {
487 m->setTaxonomyFile("");
488 }else if (types[i] == "flow") {
490 }else if (types[i] == "biom") {
492 }else if (types[i] == "count") {
493 m->setCountTableFile("");
494 }else if (types[i] == "summary") {
495 m->setSummaryFile("");
496 }else if (types[i] == "processors") {
497 m->setProcessors("1");
498 }else if (types[i] == "all") {
499 m->clearCurrentFiles();
501 m->mothurOut("[ERROR]: mothur does not save a current file for " + types[i]); m->mothurOutEndLine();
506 m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine();
507 m->printCurrentFiles();
512 catch(exception& e) {
513 m->errorOut(e, "SetCurrentCommand", "execute");
518 //**********************************************************************************************************************