]> git.donarmstrong.com Git - mothur.git/blob - commandfactory.cpp
added sorted parameter to get.oturep, added error checking to chimera classes in...
[mothur.git] / commandfactory.cpp
1 /*
2  *  commandfactory.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 10/25/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "command.hpp"
11 #include "readdistcommand.h"
12 #include "readtreecommand.h"
13 #include "readotucommand.h"
14 #include "clustercommand.h"
15 #include "collectcommand.h"
16 #include "collectsharedcommand.h"
17 #include "getgroupcommand.h"
18 #include "getlabelcommand.h"
19 #include "getlinecommand.h"
20 #include "rarefactcommand.h"
21 #include "summarycommand.h"
22 #include "summarysharedcommand.h"
23 #include "rarefactsharedcommand.h"
24 #include "quitcommand.h"
25 #include "helpcommand.h"
26 #include "commandfactory.hpp"
27 #include "deconvolutecommand.h"
28 #include "parsimonycommand.h"
29 #include "unifracunweightedcommand.h"
30 #include "unifracweightedcommand.h"
31 #include "libshuffcommand.h"
32 #include "heatmapcommand.h"
33 #include "heatmapsimcommand.h"
34 #include "filterseqscommand.h"
35 #include "venncommand.h"
36 #include "nocommands.h"
37 #include "binsequencecommand.h"
38 #include "getoturepcommand.h"
39 #include "treegroupscommand.h"
40 #include "bootstrapsharedcommand.h"
41 //#include "consensuscommand.h"
42 #include "distancecommand.h"
43 #include "aligncommand.h"
44 #include "matrixoutputcommand.h"
45 #include "getsabundcommand.h"
46 #include "getrabundcommand.h"
47 #include "seqsummarycommand.h"
48 #include "screenseqscommand.h"
49 #include "reversecommand.h"
50 #include "trimseqscommand.h"
51 #include "mergefilecommand.h"
52 #include "chimeraseqscommand.h"
53 #include "listseqscommand.h"
54 #include "getseqscommand.h"
55 #include "removeseqscommand.h"
56 #include "systemcommand.h"
57 #include "secondarystructurecommand.h"
58 #include "getsharedotucommand.h"
59 #include "getlistcountcommand.h"
60 #include "hclustercommand.h"
61 #include "classifyseqscommand.h"
62 #include "phylotypecommand.h"
63
64 /*******************************************************/
65
66 /******************************************************/
67 CommandFactory* CommandFactory::getInstance() {
68         if( _uniqueInstance == 0) {
69                 _uniqueInstance = new CommandFactory();
70         }
71         return _uniqueInstance;
72 }
73 /***********************************************************/
74
75 /***********************************************************/
76 CommandFactory::CommandFactory(){
77         _uniqueInstance = 0;
78         string s = "";
79         command = new NoCommand(s);
80         
81         
82         //initialize list of valid commands
83         commands["read.dist"]                   = "read.dist"; 
84         commands["read.otu"]                    = "read.otu";
85         commands["read.tree"]                   = "read.tree"; 
86         commands["bin.seqs"]                    = "bin.seqs"; 
87         commands["get.oturep"]                  = "get.oturep";
88         commands["cluster"]                             = "cluster"; 
89         commands["unique.seqs"]                 = "unique.seqs"; 
90         commands["dist.seqs"]                   = "dist.seqs";
91         commands["dist.shared"]                 = "dist.shared";
92         commands["collect.single"]              = "collect.single"; 
93         commands["collect.shared"]              = "collect.shared"; 
94         commands["rarefaction.single"]  = "rarefaction.single"; 
95         commands["rarefaction.shared"]  = "rarefaction.shared"; 
96         commands["summary.single"]              = "summary.single"; 
97         commands["summary.shared"]              = "summary.shared"; 
98         commands["parsimony"]                   = "parsimony";
99         commands["unifrac.weighted"]    = "unifrac.weighted"; 
100         commands["unifrac.unweighted"]  = "unifrac.unweighted"; 
101         commands["libshuff"]                    = "libshuff";
102         commands["tree.shared"]                 = "tree.shared";
103         commands["heatmap.bin"]                 = "heatmap.bin";
104         commands["heatmap.sim"]                 = "heatmap.sim";
105         commands["venn"]                                = "venn";
106         commands["get.group"]           = "get.group";
107         commands["get.label"]           = "get.label";
108         commands["get.line"]            = "get.line";
109         commands["get.sabund"]          = "get.sabund";
110         commands["get.rabund"]          = "get.rabund";
111         commands["bootstrap.shared"]    = "bootstrap.shared";
112         //commands["consensus"]                 = "consensus";
113         commands["help"]                                = "help"; 
114         commands["filter.seqs"]                 = "filter.seqs";
115         commands["align.seqs"]                  = "align.seqs";
116         commands["summary.seqs"]                = "summary.seqs";
117         commands["screen.seqs"]                 = "screen.seqs";
118         commands["reverse.seqs"]                = "reverse.seqs";
119         commands["trim.seqs"]                   = "trim.seqs";
120         commands["chimera.seqs"]                = "chimera.seqs";
121         commands["list.seqs"]                   = "list.seqs";
122         commands["get.seqs"]                    = "get.seqs";
123         commands["remove.seqs"]                 = "get.seqs";
124         commands["system"]                              = "system";
125         commands["align.check"]                 = "align.check";
126         commands["get.sharedseqs"]              = "get.sharedseqs";
127         commands["get.otulist"]                 = "get.otulist";
128         commands["quit"]                                = "quit"; 
129         commands["hcluster"]                    = "hcluster"; 
130         commands["classify.seqs"]               = "classify.seqs"; 
131         commands["phylotype"]                   = "phylotype";
132
133 }
134 /***********************************************************/
135
136 /***********************************************************/
137 CommandFactory::~CommandFactory(){
138         delete command;
139 }
140
141 /***********************************************************/
142
143 /***********************************************************/
144 //This function calls the appropriate command fucntions based on user input.
145 Command* CommandFactory::getCommand(string commandName, string optionString){
146         try {
147                 delete command;   //delete the old command
148
149                 if(commandName == "read.dist")                                  {       command = new ReadDistCommand(optionString);                    }
150                 else if(commandName == "read.otu")                              {       command = new ReadOtuCommand(optionString);                             }
151                 else if(commandName == "read.tree")                             {       command = new ReadTreeCommand(optionString);                    }
152                 else if(commandName == "cluster")                               {       command = new ClusterCommand(optionString);                             }
153                 else if(commandName == "unique.seqs")                   {       command = new DeconvoluteCommand(optionString);                 }
154                 else if(commandName == "parsimony")                             {       command = new ParsimonyCommand(optionString);                   }
155                 else if(commandName == "help")                                  {       command = new HelpCommand(optionString);                                }
156                 else if(commandName == "quit")                                  {       command = new QuitCommand(optionString);                                }
157                 else if(commandName == "collect.single")                {       command = new CollectCommand(optionString);                             }
158                 else if(commandName == "collect.shared")                {       command = new CollectSharedCommand(optionString);               }
159                 else if(commandName == "rarefaction.single")    {       command = new RareFactCommand(optionString);                    }
160                 else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand(optionString);              }
161                 else if(commandName == "summary.single")                {       command = new SummaryCommand(optionString);                             }
162                 else if(commandName == "summary.shared")                {       command = new SummarySharedCommand(optionString);               }
163                 else if(commandName == "unifrac.weighted")              {       command = new UnifracWeightedCommand(optionString);             }
164                 else if(commandName == "unifrac.unweighted")    {       command = new UnifracUnweightedCommand(optionString);   }
165                 else if(commandName == "get.group")             {   command = new GetgroupCommand(optionString);                        }
166                 else if(commandName == "get.label")             {   command = new GetlabelCommand(optionString);                        }
167                 else if(commandName == "get.line")              {   command = new GetlineCommand(optionString);                         }
168                 else if(commandName == "get.sabund")            {   command = new GetSAbundCommand(optionString);                       }
169                 else if(commandName == "get.rabund")            {   command = new GetRAbundCommand(optionString);                       }
170                 else if(commandName == "libshuff")              {   command = new LibShuffCommand(optionString);                        }
171                 else if(commandName == "heatmap.bin")                   {   command = new HeatMapCommand(optionString);                         }
172                 else if(commandName == "heatmap.sim")                   {   command = new HeatMapSimCommand(optionString);                      }
173                 else if(commandName == "filter.seqs")                   {   command = new FilterSeqsCommand(optionString);                      }
174                 else if(commandName == "venn")                                  {   command = new VennCommand(optionString);                            }
175                 else if(commandName == "bin.seqs")                              {   command = new BinSeqCommand(optionString);                          }
176                 else if(commandName == "get.oturep")                    {   command = new GetOTURepCommand(optionString);                       }
177                 else if(commandName == "tree.shared")                   {   command = new TreeGroupCommand(optionString);                       }
178                 else if(commandName == "dist.shared")                   {   command = new MatrixOutputCommand(optionString);            }
179                 else if(commandName == "bootstrap.shared")              {   command = new BootSharedCommand(optionString);                      }
180                 //else if(commandName == "consensus")                   {   command = new ConcensusCommand(optionString);                       }
181                 else if(commandName == "dist.seqs")                             {   command = new DistanceCommand(optionString);                        }
182                 else if(commandName == "align.seqs")                    {   command = new AlignCommand(optionString);                           }
183                 else if(commandName == "summary.seqs")                  {       command = new SeqSummaryCommand(optionString);                  }
184                 else if(commandName == "screen.seqs")                   {       command = new ScreenSeqsCommand(optionString);                  }
185                 else if(commandName == "reverse.seqs")                  {       command = new ReverseSeqsCommand(optionString);                 }
186                 else if(commandName == "trim.seqs")                             {       command = new TrimSeqsCommand(optionString);                    }
187                 else if(commandName == "chimera.seqs")                  {       command = new ChimeraSeqsCommand(optionString);                 }
188                 else if(commandName == "list.seqs")                             {       command = new ListSeqsCommand(optionString);                    }
189                 else if(commandName == "get.seqs")                              {       command = new GetSeqsCommand(optionString);                             }
190                 else if(commandName == "remove.seqs")                   {       command = new RemoveSeqsCommand(optionString);                  }
191                 else if(commandName == "merge.files")                   {       command = new MergeFileCommand(optionString);                   }
192                 else if(commandName == "system")                                {       command = new SystemCommand(optionString);                              }
193                 else if(commandName == "align.check")                   {       command = new AlignCheckCommand(optionString);                  }
194                 else if(commandName == "get.sharedseqs")                {       command = new GetSharedOTUCommand(optionString);                }
195                 else if(commandName == "get.otulist")                   {       command = new GetListCountCommand(optionString);                }
196                 else if(commandName == "hcluster")                              {       command = new HClusterCommand(optionString);                    }
197                 else if(commandName == "classify.seqs")                 {       command = new ClassifySeqsCommand(optionString);                }
198                 else if(commandName == "phylotype")                             {       command = new PhylotypeCommand(optionString);                   }
199                 else                                                                                    {       command = new NoCommand(optionString);                                  }
200
201                 return command;
202         }
203         catch(exception& e) {
204                 errorOut(e, "CommandFactory", "getCommand");
205                 exit(1);
206         }
207 }
208 /***********************************************************/
209 //This function is used to interrupt a command
210 Command* CommandFactory::getCommand(){
211         try {
212                 delete command;   //delete the old command
213
214                 string s = "";
215             command = new NoCommand(s);
216         
217                 return command;
218         }
219         catch(exception& e) {
220                 errorOut(e, "CommandFactory", "getCommand");
221                 exit(1);
222         }
223 }
224 /***********************************************************************/
225 bool CommandFactory::isValidCommand(string command) {
226         try {   
227         
228                 //is the command in the map
229                 if ((commands.find(command)) != (commands.end())) {
230                         return true;
231                 }else{
232                         mothurOut(command + " is not a valid command in Mothur.  Valid commands are ");
233                         for (it = commands.begin(); it != commands.end(); it++) {
234                                 mothurOut(it->first + ", ");
235                         }
236                         mothurOutEndLine();
237                         return false;
238                 }
239                 
240         }
241         catch(exception& e) {
242                 errorOut(e, "CommandFactory", "isValidCommand");
243                 exit(1);
244         }
245 }
246
247 /***********************************************************************/
248 void CommandFactory::printCommands(ostream& out) {
249         try {   
250                 out << "Valid commands are ";
251                 for (it = commands.begin(); it != commands.end(); it++) {
252                         out << it->first << ", ";
253                 }
254                 out << endl;
255         }
256         catch(exception& e) {
257                 errorOut(e, "CommandFactory", "printCommands");
258                 exit(1);
259         }
260 }
261 /***********************************************************************/
262
263
264
265