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 prelabund("relabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(prelabund);
36 CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psff);
37 CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos);
38 CommandParameter pclear("clear", "String", "", "", "", "", "",false,false); parameters.push_back(pclear);
39 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
40 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
42 vector<string> myArray;
43 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
47 m->errorOut(e, "SetCurrentCommand", "setParameters");
51 //**********************************************************************************************************************
52 string SetCurrentCommand::getHelpString(){
54 string helpString = "";
55 helpString += "The set.current command allows you to set the current files saved by mothur.\n";
56 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 and taxonomy.\n";
57 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";
58 helpString += "The set.current command should be in the following format: \n";
59 helpString += "set.current(fasta=yourFastaFile) or set.current(fasta=amazon.fasta, clear=name-accnos)\n";
63 m->errorOut(e, "SetCurrentCommand", "getHelpString");
69 //**********************************************************************************************************************
70 SetCurrentCommand::SetCurrentCommand(){
72 abort = true; calledHelp = true;
76 m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
80 //**********************************************************************************************************************
81 SetCurrentCommand::SetCurrentCommand(string option) {
83 abort = false; calledHelp = false;
85 //allow user to run help
86 if(option == "help") { help(); abort = true; calledHelp = true; }
87 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
90 //valid paramters for this command
91 vector<string> myArray = setParameters();
93 OptionParser parser(option);
94 map<string,string> parameters = parser.getParameters();
96 ValidParameters validParameter;
97 map<string,string>::iterator it;
98 //check to make sure all parameters are valid for command
99 for (it = parameters.begin(); it != parameters.end(); it++) {
100 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
104 //if the user changes the input directory command factory will send this info to us in the output parameter
105 string inputDir = validParameter.validFile(parameters, "inputdir", false);
106 if (inputDir == "not found"){ inputDir = ""; }
109 it = parameters.find("phylip");
110 //user has given a template file
111 if(it != parameters.end()){
112 path = m->hasPath(it->second);
113 //if the user has not given a path then, add inputdir. else leave path alone.
114 if (path == "") { parameters["phylip"] = inputDir + it->second; }
117 it = parameters.find("column");
118 //user has given a template file
119 if(it != parameters.end()){
120 path = m->hasPath(it->second);
121 //if the user has not given a path then, add inputdir. else leave path alone.
122 if (path == "") { parameters["column"] = inputDir + it->second; }
125 it = parameters.find("fasta");
126 //user has given a template file
127 if(it != parameters.end()){
128 path = m->hasPath(it->second);
129 //if the user has not given a path then, add inputdir. else leave path alone.
130 if (path == "") { parameters["fasta"] = inputDir + it->second; }
133 it = parameters.find("list");
134 //user has given a template file
135 if(it != parameters.end()){
136 path = m->hasPath(it->second);
137 //if the user has not given a path then, add inputdir. else leave path alone.
138 if (path == "") { parameters["list"] = inputDir + it->second; }
141 it = parameters.find("rabund");
142 //user has given a template file
143 if(it != parameters.end()){
144 path = m->hasPath(it->second);
145 //if the user has not given a path then, add inputdir. else leave path alone.
146 if (path == "") { parameters["rabund"] = inputDir + it->second; }
149 it = parameters.find("sabund");
150 //user has given a template file
151 if(it != parameters.end()){
152 path = m->hasPath(it->second);
153 //if the user has not given a path then, add inputdir. else leave path alone.
154 if (path == "") { parameters["sabund"] = inputDir + it->second; }
157 it = parameters.find("name");
158 //user has given a template file
159 if(it != parameters.end()){
160 path = m->hasPath(it->second);
161 //if the user has not given a path then, add inputdir. else leave path alone.
162 if (path == "") { parameters["name"] = inputDir + it->second; }
165 it = parameters.find("group");
166 //user has given a template file
167 if(it != parameters.end()){
168 path = m->hasPath(it->second);
169 //if the user has not given a path then, add inputdir. else leave path alone.
170 if (path == "") { parameters["group"] = inputDir + it->second; }
173 it = parameters.find("design");
174 //user has given a template file
175 if(it != parameters.end()){
176 path = m->hasPath(it->second);
177 //if the user has not given a path then, add inputdir. else leave path alone.
178 if (path == "") { parameters["design"] = inputDir + it->second; }
181 it = parameters.find("order");
182 //user has given a template file
183 if(it != parameters.end()){
184 path = m->hasPath(it->second);
185 //if the user has not given a path then, add inputdir. else leave path alone.
186 if (path == "") { parameters["order"] = inputDir + it->second; }
189 it = parameters.find("tree");
190 //user has given a template file
191 if(it != parameters.end()){
192 path = m->hasPath(it->second);
193 //if the user has not given a path then, add inputdir. else leave path alone.
194 if (path == "") { parameters["tree"] = inputDir + it->second; }
197 it = parameters.find("shared");
198 //user has given a template file
199 if(it != parameters.end()){
200 path = m->hasPath(it->second);
201 //if the user has not given a path then, add inputdir. else leave path alone.
202 if (path == "") { parameters["shared"] = inputDir + it->second; }
205 it = parameters.find("ordergroup");
206 //user has given a template file
207 if(it != parameters.end()){
208 path = m->hasPath(it->second);
209 //if the user has not given a path then, add inputdir. else leave path alone.
210 if (path == "") { parameters["ordergroup"] = inputDir + it->second; }
213 it = parameters.find("relabund");
214 //user has given a template file
215 if(it != parameters.end()){
216 path = m->hasPath(it->second);
217 //if the user has not given a path then, add inputdir. else leave path alone.
218 if (path == "") { parameters["relabund"] = inputDir + it->second; }
221 it = parameters.find("fasta");
222 //user has given a template file
223 if(it != parameters.end()){
224 path = m->hasPath(it->second);
225 //if the user has not given a path then, add inputdir. else leave path alone.
226 if (path == "") { parameters["fasta"] = inputDir + it->second; }
229 it = parameters.find("qfile");
230 //user has given a template file
231 if(it != parameters.end()){
232 path = m->hasPath(it->second);
233 //if the user has not given a path then, add inputdir. else leave path alone.
234 if (path == "") { parameters["qfile"] = inputDir + it->second; }
237 it = parameters.find("sff");
238 //user has given a template file
239 if(it != parameters.end()){
240 path = m->hasPath(it->second);
241 //if the user has not given a path then, add inputdir. else leave path alone.
242 if (path == "") { parameters["sff"] = inputDir + it->second; }
245 it = parameters.find("oligos");
246 //user has given a template file
247 if(it != parameters.end()){
248 path = m->hasPath(it->second);
249 //if the user has not given a path then, add inputdir. else leave path alone.
250 if (path == "") { parameters["oligos"] = inputDir + it->second; }
253 it = parameters.find("accnos");
254 //user has given a template file
255 if(it != parameters.end()){
256 path = m->hasPath(it->second);
257 //if the user has not given a path then, add inputdir. else leave path alone.
258 if (path == "") { parameters["accnos"] = inputDir + it->second; }
261 it = parameters.find("taxonomy");
262 //user has given a template file
263 if(it != parameters.end()){
264 path = m->hasPath(it->second);
265 //if the user has not given a path then, add inputdir. else leave path alone.
266 if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
269 it = parameters.find("flow");
270 //user has given a template file
271 if(it != parameters.end()){
272 path = m->hasPath(it->second);
273 //if the user has not given a path then, add inputdir. else leave path alone.
274 if (path == "") { parameters["flow"] = inputDir + it->second; }
277 it = parameters.find("biom");
278 //user has given a template file
279 if(it != parameters.end()){
280 path = m->hasPath(it->second);
281 //if the user has not given a path then, add inputdir. else leave path alone.
282 if (path == "") { parameters["biom"] = inputDir + it->second; }
286 //check for parameters
287 phylipfile = validParameter.validFile(parameters, "phylip", true);
288 if (phylipfile == "not open") { m->mothurOut("Ignoring: " + parameters["phylip"]); m->mothurOutEndLine(); phylipfile = ""; }
289 else if (phylipfile == "not found") { phylipfile = ""; }
290 if (phylipfile != "") { m->setPhylipFile(phylipfile); }
292 columnfile = validParameter.validFile(parameters, "column", true);
293 if (columnfile == "not open") { m->mothurOut("Ignoring: " + parameters["column"]); m->mothurOutEndLine(); columnfile = ""; }
294 else if (columnfile == "not found") { columnfile = ""; }
295 if (columnfile != "") { m->setColumnFile(columnfile); }
297 listfile = validParameter.validFile(parameters, "list", true);
298 if (listfile == "not open") { m->mothurOut("Ignoring: " + parameters["list"]); m->mothurOutEndLine(); listfile = ""; }
299 else if (listfile == "not found") { listfile = ""; }
300 if (listfile != "") { m->setListFile(listfile); }
302 rabundfile = validParameter.validFile(parameters, "rabund", true);
303 if (rabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["rabund"]); m->mothurOutEndLine(); rabundfile = ""; }
304 else if (rabundfile == "not found") { rabundfile = ""; }
305 if (rabundfile != "") { m->setRabundFile(rabundfile); }
307 sabundfile = validParameter.validFile(parameters, "sabund", true);
308 if (sabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["sabund"]); m->mothurOutEndLine(); sabundfile = ""; }
309 else if (sabundfile == "not found") { sabundfile = ""; }
310 if (sabundfile != "") { m->setSabundFile(sabundfile); }
312 namefile = validParameter.validFile(parameters, "name", true);
313 if (namefile == "not open") { m->mothurOut("Ignoring: " + parameters["name"]); m->mothurOutEndLine(); namefile = ""; }
314 else if (namefile == "not found") { namefile = ""; }
315 if (namefile != "") { m->setNameFile(namefile); }
317 groupfile = validParameter.validFile(parameters, "group", true);
318 if (groupfile == "not open") { m->mothurOut("Ignoring: " + parameters["group"]); m->mothurOutEndLine(); groupfile = ""; }
319 else if (groupfile == "not found") { groupfile = ""; }
320 if (groupfile != "") { m->setGroupFile(groupfile); }
322 designfile = validParameter.validFile(parameters, "design", true);
323 if (designfile == "not open") { m->mothurOut("Ignoring: " + parameters["design"]); m->mothurOutEndLine(); designfile = ""; }
324 else if (designfile == "not found") { designfile = ""; }
325 if (designfile != "") { m->setDesignFile(designfile); }
327 orderfile = validParameter.validFile(parameters, "order", true);
328 if (orderfile == "not open") { m->mothurOut("Ignoring: " + parameters["order"]); m->mothurOutEndLine(); orderfile = ""; }
329 else if (orderfile == "not found") { orderfile = ""; }
330 if (orderfile != "") { m->setOrderFile(orderfile); }
332 treefile = validParameter.validFile(parameters, "tree", true);
333 if (treefile == "not open") { m->mothurOut("Ignoring: " + parameters["tree"]); m->mothurOutEndLine(); treefile = ""; }
334 else if (treefile == "not found") { treefile = ""; }
335 if (treefile != "") { m->setTreeFile(treefile); }
337 sharedfile = validParameter.validFile(parameters, "shared", true);
338 if (sharedfile == "not open") { m->mothurOut("Ignoring: " + parameters["shared"]); m->mothurOutEndLine(); sharedfile = ""; }
339 else if (sharedfile == "not found") { sharedfile = ""; }
340 if (sharedfile != "") { m->setSharedFile(sharedfile); }
342 ordergroupfile = validParameter.validFile(parameters, "ordergroup", true);
343 if (ordergroupfile == "not open") { m->mothurOut("Ignoring: " + parameters["ordergroup"]); m->mothurOutEndLine(); ordergroupfile = ""; }
344 else if (ordergroupfile == "not found") { ordergroupfile = ""; }
345 if (ordergroupfile != "") { m->setOrderGroupFile(ordergroupfile); }
347 relabundfile = validParameter.validFile(parameters, "relabund", true);
348 if (relabundfile == "not open") { m->mothurOut("Ignoring: " + parameters["relabund"]); m->mothurOutEndLine(); relabundfile = ""; }
349 else if (relabundfile == "not found") { relabundfile = ""; }
350 if (relabundfile != "") { m->setRelAbundFile(relabundfile); }
352 fastafile = validParameter.validFile(parameters, "fasta", true);
353 if (fastafile == "not open") { m->mothurOut("Ignoring: " + parameters["fasta"]); m->mothurOutEndLine(); fastafile = ""; }
354 else if (fastafile == "not found") { fastafile = ""; }
355 if (fastafile != "") { m->setFastaFile(fastafile); }
357 qualfile = validParameter.validFile(parameters, "qfile", true);
358 if (qualfile == "not open") { m->mothurOut("Ignoring: " + parameters["qfile"]); m->mothurOutEndLine(); qualfile = ""; }
359 else if (qualfile == "not found") { qualfile = ""; }
360 if (qualfile != "") { m->setQualFile(qualfile); }
362 sfffile = validParameter.validFile(parameters, "sff", true);
363 if (sfffile == "not open") { m->mothurOut("Ignoring: " + parameters["sff"]); m->mothurOutEndLine(); sfffile = ""; }
364 else if (sfffile == "not found") { sfffile = ""; }
365 if (sfffile != "") { m->setSFFFile(sfffile); }
367 oligosfile = validParameter.validFile(parameters, "oligos", true);
368 if (oligosfile == "not open") { m->mothurOut("Ignoring: " + parameters["oligos"]); m->mothurOutEndLine(); oligosfile = ""; }
369 else if (oligosfile == "not found") { oligosfile = ""; }
370 if (oligosfile != "") { m->setOligosFile(oligosfile); }
372 accnosfile = validParameter.validFile(parameters, "accnos", true);
373 if (accnosfile == "not open") { m->mothurOut("Ignoring: " + parameters["accnos"]); m->mothurOutEndLine(); accnosfile = ""; }
374 else if (accnosfile == "not found") { accnosfile = ""; }
375 if (accnosfile != "") { m->setAccnosFile(accnosfile); }
377 taxonomyfile = validParameter.validFile(parameters, "taxonomy", true);
378 if (taxonomyfile == "not open") { m->mothurOut("Ignoring: " + parameters["taxonomy"]); m->mothurOutEndLine(); taxonomyfile = ""; }
379 else if (taxonomyfile == "not found") { taxonomyfile = ""; }
380 if (taxonomyfile != "") { m->setTaxonomyFile(taxonomyfile); }
382 flowfile = validParameter.validFile(parameters, "flow", true);
383 if (flowfile == "not open") { m->mothurOut("Ignoring: " + parameters["flow"]); m->mothurOutEndLine(); flowfile = ""; }
384 else if (flowfile == "not found") { flowfile = ""; }
385 if (flowfile != "") { m->setFlowFile(flowfile); }
387 biomfile = validParameter.validFile(parameters, "biom", true);
388 if (biomfile == "not open") { m->mothurOut("Ignoring: " + parameters["biom"]); m->mothurOutEndLine(); biomfile = ""; }
389 else if (biomfile == "not found") { biomfile = ""; }
390 if (biomfile != "") { m->setBiomFile(biomfile); }
392 processors = validParameter.validFile(parameters, "processors", false);
393 if (processors == "not found") { processors = "1"; }
394 if (processors != "") { m->setProcessors(processors); }
396 clearTypes = validParameter.validFile(parameters, "clear", false);
397 if (clearTypes == "not found") { clearTypes = ""; }
398 else { m->splitAtDash(clearTypes, types); }
402 catch(exception& e) {
403 m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
407 //**********************************************************************************************************************
409 int SetCurrentCommand::execute(){
412 if (abort == true) { if (calledHelp) { return 0; } return 2; }
414 //user wants to clear a type
415 if (types.size() != 0) {
416 for (int i = 0; i < types.size(); i++) {
418 if (m->control_pressed) { break; }
420 //look for file types
421 if (types[i] == "fasta") {
423 }else if (types[i] == "qfile") {
425 }else if (types[i] == "phylip") {
426 m->setPhylipFile("");
427 }else if (types[i] == "column") {
428 m->setColumnFile("");
429 }else if (types[i] == "list") {
431 }else if (types[i] == "rabund") {
432 m->setRabundFile("");
433 }else if (types[i] == "sabund") {
434 m->setSabundFile("");
435 }else if (types[i] == "name") {
437 }else if (types[i] == "group") {
439 }else if (types[i] == "order") {
441 }else if (types[i] == "ordergroup") {
442 m->setOrderGroupFile("");
443 }else if (types[i] == "tree") {
445 }else if (types[i] == "shared") {
446 m->setSharedFile("");
447 }else if (types[i] == "relabund") {
448 m->setRelAbundFile("");
449 }else if (types[i] == "design") {
450 m->setDesignFile("");
451 }else if (types[i] == "sff") {
453 }else if (types[i] == "oligos") {
454 m->setOligosFile("");
455 }else if (types[i] == "accnos") {
456 m->setAccnosFile("");
457 }else if (types[i] == "taxonomy") {
458 m->setTaxonomyFile("");
459 }else if (types[i] == "flow") {
461 }else if (types[i] == "biom") {
463 }else if (types[i] == "processors") {
464 m->setProcessors("1");
465 }else if (types[i] == "all") {
466 m->clearCurrentFiles();
468 m->mothurOut("[ERROR]: mothur does not save a current file for " + types[i]); m->mothurOutEndLine();
473 m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine();
474 m->printCurrentFiles();
479 catch(exception& e) {
480 m->errorOut(e, "SetCurrentCommand", "execute");
485 //**********************************************************************************************************************