]> git.donarmstrong.com Git - mothur.git/blob - setdircommand.cpp
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / setdircommand.cpp
1 /*
2  *  setoutdircommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 1/21/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "setdircommand.h"
11
12 //**********************************************************************************************************************
13 vector<string> SetDirectoryCommand::setParameters(){    
14         try {
15                 CommandParameter ptempdefault("tempdefault", "String", "", "", "", "", "","",false,false); parameters.push_back(ptempdefault);
16         CommandParameter pdebug("debug", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pdebug);
17                 CommandParameter pinput("input", "String", "", "", "", "", "","",false,false,true); parameters.push_back(pinput);
18                 CommandParameter poutput("output", "String", "", "", "", "", "","",false,false,true); parameters.push_back(poutput);
19                 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
20                 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
21                 
22                 vector<string> myArray;
23                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
24                 return myArray;
25         }
26         catch(exception& e) {
27                 m->errorOut(e, "SetDirectoryCommand", "setParameters");
28                 exit(1);
29         }
30 }
31 //**********************************************************************************************************************
32 string SetDirectoryCommand::getHelpString(){    
33         try {
34                 string helpString = "";
35                 helpString += "The set.dir command can be used to direct the output files generated by mothur to a specific place, the directory must exist.\n";
36                 helpString += "The set.dir command can also be used to specify the directory where your input files are located, the directory must exist.\n";
37                 helpString += "The set.dir command can also be used to override or set the default location mothur will look for files if it is unable to find them, the directory must exist.\n";
38         helpString += "The set.dir command can also be used to run mothur in debug mode.\n";
39                 helpString += "The set.dir command parameters are input, output, tempdefault and debug and one is required.\n";
40         helpString += "To run mothur in debug mode set debug=true. Default debug=false.\n";
41                 helpString += "To return the output to the same directory as the input files you may enter: output=clear.\n";
42                 helpString += "To return the input to the current working directory you may enter: input=clear.\n";
43                 helpString += "To set the output to the directory where mothur.exe is located you may enter: output=default.\n";
44                 helpString += "To set the input to the directory where mothur.exe is located you may enter: input=default.\n";
45                 helpString += "To return the tempdefault to the default you provided at compile time you may enter: tempdefault=clear.\n";
46                 helpString += "To set the tempdefault to the directory where mothur.exe is located you may enter: tempdefault=default.\n";
47                 helpString += "The set.dir command should be in the following format: set.dir(output=yourOutputDirectory, input=yourInputDirectory, tempdefault=yourTempDefault).\n";
48                 helpString += "Example set.outdir(output=/Users/lab/desktop/outputs, input=/Users/lab/desktop/inputs).\n";
49                 helpString += "Note: No spaces between parameter labels (i.e. output), '=' and parameters (i.e.yourOutputDirectory).\n";
50                 return helpString;
51         }
52         catch(exception& e) {
53                 m->errorOut(e, "SetDirectoryCommand", "getHelpString");
54                 exit(1);
55         }
56 }
57 //**********************************************************************************************************************
58
59 SetDirectoryCommand::SetDirectoryCommand(string option)  {
60         try {
61                 abort = false; calledHelp = false;   
62                 
63                 //allow user to run help
64                 if(option == "help") { help(); abort = true; calledHelp = true; }
65                 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
66                 
67                 else {
68                         vector<string> myArray = setParameters();
69                         
70                         OptionParser parser(option);
71                         map<string, string> parameters = parser.getParameters();
72                         
73                         ValidParameters validParameter;
74                         //check to make sure all parameters are valid for command
75                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
76                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
77                         }
78                 
79                         output = validParameter.validFile(parameters, "output", false);                 
80                         if (output == "not found") {  output = "";  } 
81                         
82                         input = validParameter.validFile(parameters, "input", false);                   
83                         if (input == "not found") {  input = "";  }
84                         
85                         tempdefault = validParameter.validFile(parameters, "tempdefault", false);                       
86                         if (tempdefault == "not found") {  tempdefault = "";  }
87             
88             bool debug = false;
89             bool nodebug = false;
90             debugOnly = false;
91             string temp = validParameter.validFile(parameters, "debug", false);                 
92                         if (temp == "not found") {  debug = false;  nodebug=true; }
93             else {  debug = m->isTrue(temp); }
94             m->debug = debug;
95             
96             if (debug) { m->mothurOut("Setting [DEBUG] flag.\n"); }
97                                 
98                         if ((input == "") && (output == "") && (tempdefault == "") && nodebug) {        
99                                 m->mothurOut("You must provide either an input, output, tempdefault or debug for the set.outdir command."); m->mothurOutEndLine(); abort = true;
100                         }else if((input == "") && (output == "") && (tempdefault == "")) { debugOnly = true; }
101                 }
102         }
103         catch(exception& e) {
104                 m->errorOut(e, "SetDirectoryCommand", "SetDirectoryCommand");
105                 exit(1);
106         }
107 }
108 //**********************************************************************************************************************
109
110 int SetDirectoryCommand::execute(){
111         try {
112                 
113                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
114                 
115         if (debugOnly) { return 0; }
116         
117                 commandFactory = CommandFactory::getInstance();
118                 
119                 m->mothurOut("Mothur's directories:"); m->mothurOutEndLine();
120                 
121                 //redirect output
122                 if ((output == "clear") || (output == "")) {  output = "";  commandFactory->setOutputDirectory(output);  }
123                 else if (output == "default") { 
124                         string exepath = m->argv;
125                         output = exepath.substr(0, (exepath.find_last_of('m')));
126                         
127                         m->mothurOut("outputDir=" + output); m->mothurOutEndLine();  
128                         commandFactory->setOutputDirectory(output);
129                 }else {
130             if (m->dirCheck(output)) {
131                 m->mothurOut("outputDir=" + output); m->mothurOutEndLine();  
132                                 commandFactory->setOutputDirectory(output);
133             }
134                 }
135                 
136                 //redirect input
137                 if ((input == "clear") || (input == "")) {  input = "";  commandFactory->setInputDirectory(input);  }
138                 else if (input == "default") { 
139                         string exepath = m->argv;
140                         input = exepath.substr(0, (exepath.find_last_of('m')));
141                         
142                         m->mothurOut("inputDir=" + input); m->mothurOutEndLine();  
143                         commandFactory->setInputDirectory(input);
144                 }else {
145             if (m->dirCheck(input)) {
146                 m->mothurOut("inputDir=" + input); m->mothurOutEndLine();  
147                                 commandFactory->setInputDirectory(input); 
148             }
149         }
150                 
151                 //set default
152                 if (tempdefault == "clear") {  
153                         #ifdef MOTHUR_FILES
154                                 string temp = MOTHUR_FILES; 
155                                 m->mothurOut("tempDefault=" + temp); m->mothurOutEndLine();  
156                                 m->setDefaultPath(temp);
157                         #else
158                                 string temp = ""; 
159                                 m->mothurOut("No default directory defined at compile time."); m->mothurOutEndLine();  
160                                 m->setDefaultPath(temp);
161                         #endif
162                 }else if (tempdefault == "") {  //do nothing
163                 }else if (tempdefault == "default") { 
164                         string exepath = m->argv;
165                         tempdefault = exepath.substr(0, (exepath.find_last_of('m')));
166                         
167                         m->mothurOut("tempDefault=" + tempdefault); m->mothurOutEndLine();  
168                         m->setDefaultPath(tempdefault);
169                 }else {
170             if (m->dirCheck(tempdefault)) {
171                 m->mothurOut("tempDefault=" + tempdefault); m->mothurOutEndLine();  
172                                 m->setDefaultPath(tempdefault); 
173             }
174         }
175
176                 return 0;
177         }
178         catch(exception& e) {
179                 m->errorOut(e, "SetDirectoryCommand", "execute");
180                 exit(1);
181         }
182 }
183 //**********************************************************************************************************************/