]> git.donarmstrong.com Git - mothur.git/blob - getcurrentcommand.cpp
working on pam
[mothur.git] / getcurrentcommand.cpp
1 /*
2  *  getcurrentcommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 3/16/11.
6  *  Copyright 2011 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "getcurrentcommand.h"
11
12 //**********************************************************************************************************************
13 vector<string> GetCurrentCommand::setParameters(){      
14         try {
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);
18                 
19                 vector<string> myArray;
20                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
21                 return myArray;
22         }
23         catch(exception& e) {
24                 m->errorOut(e, "GetCurrentCommand", "setParameters");
25                 exit(1);
26         }
27 }
28 //**********************************************************************************************************************
29 string GetCurrentCommand::getHelpString(){      
30         try {
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";
37                 return helpString;
38         }
39         catch(exception& e) {
40                 m->errorOut(e, "GetCurrentCommand", "getHelpString");
41                 exit(1);
42         }
43 }
44 //**********************************************************************************************************************
45 GetCurrentCommand::GetCurrentCommand(){ 
46         try {
47                 abort = true; calledHelp = true;
48                 setParameters();
49         }
50         catch(exception& e) {
51                 m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand");
52                 exit(1);
53         }
54 }
55 //**********************************************************************************************************************
56 GetCurrentCommand::GetCurrentCommand(string option)  {
57         try {
58                 abort = false; calledHelp = false;   
59                 
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;}
63                 
64                 else {
65                         vector<string> myArray = setParameters();
66                         
67                         OptionParser parser(option);
68                         map<string,string> parameters = parser.getParameters();
69                         
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;  }
74                         }
75                         
76                         clearTypes = validParameter.validFile(parameters, "clear", false);                      
77                         if (clearTypes == "not found") { clearTypes = ""; }
78                         else { m->splitAtDash(clearTypes, types);       }
79                 }
80                 
81         }
82         catch(exception& e) {
83                 m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand");
84                 exit(1);
85         }
86 }
87 //**********************************************************************************************************************
88
89 int GetCurrentCommand::execute(){
90         try {
91                 
92                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
93                 
94                 //user wants to clear a type
95                 if (types.size() != 0) {
96                         for (int i = 0; i < types.size(); i++) {
97                                 
98                                 if (m->control_pressed) { break; }
99                                 
100                                 //look for file types
101                                 if (types[i] == "fasta") {
102                                         m->setFastaFile("");
103                                 }else if (types[i] == "qfile") {
104                                         m->setQualFile("");
105                                 }else if (types[i] == "phylip") {
106                                         m->setPhylipFile("");
107                                 }else if (types[i] == "column") {
108                                         m->setColumnFile("");
109                                 }else if (types[i] == "list") {
110                                         m->setListFile("");
111                                 }else if (types[i] == "rabund") {
112                                         m->setRabundFile("");
113                                 }else if (types[i] == "sabund") {
114                                         m->setSabundFile("");
115                                 }else if (types[i] == "name") {
116                                         m->setNameFile("");
117                                 }else if (types[i] == "group") {
118                                         m->setGroupFile("");
119                                 }else if (types[i] == "order") {
120                                         m->setOrderFile("");
121                                 }else if (types[i] == "ordergroup") {
122                                         m->setOrderGroupFile("");
123                                 }else if (types[i] == "tree") {
124                                         m->setTreeFile("");
125                                 }else if (types[i] == "shared") {
126                                         m->setSharedFile("");
127                                 }else if (types[i] == "relabund") {
128                                         m->setRelAbundFile("");
129                                 }else if (types[i] == "design") {
130                                         m->setDesignFile("");
131                                 }else if (types[i] == "sff") {
132                                         m->setSFFFile("");
133                                 }else if (types[i] == "oligos") {
134                                         m->setOligosFile("");
135                                 }else if (types[i] == "accnos") {
136                                         m->setAccnosFile("");
137                                 }else if (types[i] == "taxonomy") {
138                                         m->setTaxonomyFile("");
139                                 }else if (types[i] == "flow") {
140                                         m->setFlowFile("");
141                 }else if (types[i] == "biom") {
142                                         m->setBiomFile("");
143                 }else if (types[i] == "count") {
144                                         m->setCountTableFile("");
145                 }else if (types[i] == "summary") {
146                                         m->setSummaryFile("");
147                                 }else if (types[i] == "processors") {
148                                         m->setProcessors("1");
149                                 }else if (types[i] == "all") {
150                                         m->clearCurrentFiles();
151                                 }else {
152                                         m->mothurOut("[ERROR]: mothur does not save a current file for " + types[i]); m->mothurOutEndLine();
153                                 }
154                         }
155                 }
156                 
157                 if (m->hasCurrentFiles()) {
158                         m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine();
159                         m->printCurrentFiles();
160                 }
161                 
162                 return 0;       
163         }
164         
165         catch(exception& e) {
166                 m->errorOut(e, "GetCurrentCommand", "execute");
167                 exit(1);
168         }
169 }
170
171 //**********************************************************************************************************************
172
173
174