]> git.donarmstrong.com Git - mothur.git/blob - getcurrentcommand.cpp
fixed bug with tree reading
[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                 
63                 else {
64                         vector<string> myArray = setParameters();
65                         
66                         OptionParser parser(option);
67                         map<string,string> parameters = parser.getParameters();
68                         
69                         ValidParameters validParameter;
70                         //check to make sure all parameters are valid for command
71                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
72                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
73                         }
74                         
75                         clearTypes = validParameter.validFile(parameters, "clear", false);                      
76                         if (clearTypes == "not found") { clearTypes = ""; }
77                         else { m->splitAtDash(clearTypes, types);       }
78                 }
79                 
80         }
81         catch(exception& e) {
82                 m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand");
83                 exit(1);
84         }
85 }
86 //**********************************************************************************************************************
87
88 int GetCurrentCommand::execute(){
89         try {
90                 
91                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
92                 
93                 //user wants to clear a type
94                 if (types.size() != 0) {
95                         for (int i = 0; i < types.size(); i++) {
96                                 
97                                 if (m->control_pressed) { break; }
98                                 
99                                 //look for file types
100                                 if (types[i] == "fasta") {
101                                         m->setFastaFile("");
102                                 }else if (types[i] == "qfile") {
103                                         m->setQualFile("");
104                                 }else if (types[i] == "phylip") {
105                                         m->setPhylipFile("");
106                                 }else if (types[i] == "column") {
107                                         m->setColumnFile("");
108                                 }else if (types[i] == "list") {
109                                         m->setListFile("");
110                                 }else if (types[i] == "rabund") {
111                                         m->setRabundFile("");
112                                 }else if (types[i] == "sabund") {
113                                         m->setSabundFile("");
114                                 }else if (types[i] == "name") {
115                                         m->setNameFile("");
116                                 }else if (types[i] == "group") {
117                                         m->setGroupFile("");
118                                 }else if (types[i] == "order") {
119                                         m->setOrderFile("");
120                                 }else if (types[i] == "ordergroup") {
121                                         m->setOrderGroupFile("");
122                                 }else if (types[i] == "tree") {
123                                         m->setTreeFile("");
124                                 }else if (types[i] == "shared") {
125                                         m->setSharedFile("");
126                                 }else if (types[i] == "relabund") {
127                                         m->setRelAbundFile("");
128                                 }else if (types[i] == "design") {
129                                         m->setDesignFile("");
130                                 }else if (types[i] == "sff") {
131                                         m->setSFFFile("");
132                                 }else if (types[i] == "oligos") {
133                                         m->setOligosFile("");
134                                 }else if (types[i] == "accnos") {
135                                         m->setAccnosFile("");
136                                 }else if (types[i] == "taxonomy") {
137                                         m->setTaxonomyFile("");
138                                 }else if (types[i] == "all") {
139                                         m->clearCurrentFiles();
140                                 }else {
141                                         m->mothurOut("[ERROR]: mothur does not save a current file for " + types[i]); m->mothurOutEndLine();
142                                 }
143                         }
144                 }
145                 
146                 m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine();
147                 m->printCurrentFiles();
148                 
149                 return 0;       
150         }
151         
152         catch(exception& e) {
153                 m->errorOut(e, "GetCurrentCommand", "execute");
154                 exit(1);
155         }
156 }
157
158 //**********************************************************************************************************************
159
160
161