2 * getcurrentcommand.cpp
5 * Created by westcott on 3/16/11.
6 * Copyright 2011 Schloss Lab. All rights reserved.
10 #include "getcurrentcommand.h"
12 //**********************************************************************************************************************
13 vector<string> GetCurrentCommand::setParameters(){
15 CommandParameter pclear("clear", "String", "", "", "", "", "","",false,false); parameters.push_back(pclear);
16 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
17 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
19 vector<string> myArray;
20 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
24 m->errorOut(e, "GetCurrentCommand", "setParameters");
28 //**********************************************************************************************************************
29 string GetCurrentCommand::getHelpString(){
31 string helpString = "";
32 helpString += "The get.current command outputs the current files saved by mothur.\n";
33 helpString += "The get.current command has one parameter: clear.\n";
34 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";
35 helpString += "The get.current command should be in the following format: \n";
36 helpString += "get.current() or get.current(clear=fasta-name-accnos)\n";
40 m->errorOut(e, "GetCurrentCommand", "getHelpString");
44 //**********************************************************************************************************************
45 GetCurrentCommand::GetCurrentCommand(){
47 abort = true; calledHelp = true;
51 m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand");
55 //**********************************************************************************************************************
56 GetCurrentCommand::GetCurrentCommand(string option) {
58 abort = false; calledHelp = false;
60 //allow user to run help
61 if(option == "help") { help(); abort = true; calledHelp = true; }
62 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
65 vector<string> myArray = setParameters();
67 OptionParser parser(option);
68 map<string,string> parameters = parser.getParameters();
70 ValidParameters validParameter;
71 //check to make sure all parameters are valid for command
72 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
73 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
76 clearTypes = validParameter.validFile(parameters, "clear", false);
77 if (clearTypes == "not found") { clearTypes = ""; }
78 else { m->splitAtDash(clearTypes, types); }
83 m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand");
87 //**********************************************************************************************************************
89 int GetCurrentCommand::execute(){
92 if (abort == true) { if (calledHelp) { return 0; } return 2; }
94 cFactory = CommandFactory::getInstance();
96 //user wants to clear a type
97 if (types.size() != 0) {
98 for (int i = 0; i < types.size(); i++) {
100 if (m->control_pressed) { break; }
102 //look for file types
103 if (types[i] == "fasta") {
105 }else if (types[i] == "qfile") {
107 }else if (types[i] == "phylip") {
108 m->setPhylipFile("");
109 }else if (types[i] == "column") {
110 m->setColumnFile("");
111 }else if (types[i] == "list") {
113 }else if (types[i] == "rabund") {
114 m->setRabundFile("");
115 }else if (types[i] == "sabund") {
116 m->setSabundFile("");
117 }else if (types[i] == "name") {
119 }else if (types[i] == "group") {
121 }else if (types[i] == "order") {
123 }else if (types[i] == "ordergroup") {
124 m->setOrderGroupFile("");
125 }else if (types[i] == "tree") {
127 }else if (types[i] == "shared") {
128 m->setSharedFile("");
129 }else if (types[i] == "relabund") {
130 m->setRelAbundFile("");
131 }else if (types[i] == "design") {
132 m->setDesignFile("");
133 }else if (types[i] == "sff") {
135 }else if (types[i] == "oligos") {
136 m->setOligosFile("");
137 }else if (types[i] == "accnos") {
138 m->setAccnosFile("");
139 }else if (types[i] == "taxonomy") {
140 m->setTaxonomyFile("");
141 }else if (types[i] == "flow") {
143 }else if (types[i] == "biom") {
145 }else if (types[i] == "count") {
146 m->setCountTableFile("");
147 }else if (types[i] == "summary") {
148 m->setSummaryFile("");
149 }else if (types[i] == "processors") {
150 m->setProcessors("1");
151 }else if (types[i] == "all") {
152 m->clearCurrentFiles();
154 m->mothurOut("[ERROR]: mothur does not save a current file for " + types[i]); m->mothurOutEndLine();
159 if (m->hasCurrentFiles()) {
160 m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine();
161 m->printCurrentFiles();
164 string inputDir = cFactory->getInputDir();
165 if (inputDir != "") {
166 m->mothurOutEndLine(); m->mothurOut("Current input directory saved by mothur: " + inputDir); m->mothurOutEndLine();
169 string outputDir = cFactory->getOutputDir();
170 if (outputDir != "") {
171 m->mothurOutEndLine(); m->mothurOut("Current output directory saved by mothur: " + outputDir); m->mothurOutEndLine();
173 string defaultPath = m->getDefaultPath();
174 if (defaultPath != "") {
175 m->mothurOutEndLine(); m->mothurOut("Current default directory saved by mothur: " + defaultPath); m->mothurOutEndLine();
180 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
184 temp = m->getFullPathName(temp);
185 m->mothurOutEndLine(); m->mothurOut("Current working directory: " + temp); m->mothurOutEndLine();
190 catch(exception& e) {
191 m->errorOut(e, "GetCurrentCommand", "execute");
196 //**********************************************************************************************************************