]> git.donarmstrong.com Git - mothur.git/blob - commandfactory.cpp
added count.seqs command and made some modifcations to the uchime code to allow it...
[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 "rarefactcommand.h"
20 #include "summarycommand.h"
21 #include "summarysharedcommand.h"
22 #include "rarefactsharedcommand.h"
23 #include "quitcommand.h"
24 #include "helpcommand.h"
25 #include "commandfactory.hpp"
26 #include "deconvolutecommand.h"
27 #include "parsimonycommand.h"
28 #include "unifracunweightedcommand.h"
29 #include "unifracweightedcommand.h"
30 #include "libshuffcommand.h"
31 #include "heatmapcommand.h"
32 #include "heatmapsimcommand.h"
33 #include "filterseqscommand.h"
34 #include "venncommand.h"
35 #include "nocommands.h"
36 #include "binsequencecommand.h"
37 #include "getoturepcommand.h"
38 #include "treegroupscommand.h"
39 #include "bootstrapsharedcommand.h"
40 //#include "consensuscommand.h"
41 #include "distancecommand.h"
42 #include "aligncommand.h"
43 #include "matrixoutputcommand.h"
44 #include "getsabundcommand.h"
45 #include "getrabundcommand.h"
46 #include "seqsummarycommand.h"
47 #include "screenseqscommand.h"
48 #include "reversecommand.h"
49 #include "trimseqscommand.h"
50 #include "mergefilecommand.h"
51 #include "listseqscommand.h"
52 #include "getseqscommand.h"
53 #include "removeseqscommand.h"
54 #include "systemcommand.h"
55 #include "secondarystructurecommand.h"
56 #include "getsharedotucommand.h"
57 #include "getlistcountcommand.h"
58 #include "hclustercommand.h"
59 #include "classifyseqscommand.h"
60 #include "phylotypecommand.h"
61 #include "mgclustercommand.h"
62 #include "preclustercommand.h"
63 #include "pcoacommand.h"
64 #include "otuhierarchycommand.h"
65 #include "setdircommand.h"
66 #include "parselistscommand.h"
67 #include "chimeraccodecommand.h"
68 #include "chimeracheckcommand.h"
69 #include "chimeraslayercommand.h"
70 #include "chimerapintailcommand.h"
71 #include "chimerabellerophoncommand.h"
72 #include "chimerauchimecommand.h"
73 #include "setlogfilecommand.h"
74 #include "phylodiversitycommand.h"
75 #include "makegroupcommand.h"
76 #include "chopseqscommand.h"
77 #include "clearcutcommand.h"
78 #include "catchallcommand.h"
79 #include "splitabundcommand.h"
80 #include "clustersplitcommand.h"
81 #include "classifyotucommand.h"
82 #include "degapseqscommand.h"
83 #include "getrelabundcommand.h"
84 #include "sensspeccommand.h"
85 #include "sffinfocommand.h"
86 #include "seqerrorcommand.h"
87 #include "normalizesharedcommand.h"
88 #include "metastatscommand.h"
89 #include "splitgroupscommand.h"
90 #include "clusterfragmentscommand.h"
91 #include "getlineagecommand.h"
92 #include "removelineagecommand.h"
93 #include "parsefastaqcommand.h"
94 #include "pipelinepdscommand.h"
95 #include "deuniqueseqscommand.h"
96 #include "pairwiseseqscommand.h"
97 #include "clusterdoturcommand.h"
98 #include "subsamplecommand.h"
99 #include "removegroupscommand.h"
100 #include "getgroupscommand.h"
101 #include "getotuscommand.h"
102 #include "removeotuscommand.h"
103 #include "indicatorcommand.h"
104 #include "consensusseqscommand.h"
105 #include "trimflowscommand.h"
106 #include "corraxescommand.h"
107 #include "shhhercommand.h"
108 #include "pcacommand.h"
109 #include "nmdscommand.h"
110 #include "removerarecommand.h"
111 #include "mergegroupscommand.h"
112 #include "amovacommand.h"
113 #include "homovacommand.h"
114 #include "mantelcommand.h"
115 #include "makefastqcommand.h"
116 #include "anosimcommand.h"
117 #include "getcurrentcommand.h"
118 #include "setcurrentcommand.h"
119 #include "sharedcommand.h"
120 #include "getcommandinfocommand.h"
121 #include "deuniquetreecommand.h"
122 #include "countseqscommand.h"
123
124 /*******************************************************/
125
126 /******************************************************/
127 CommandFactory* CommandFactory::getInstance() {
128         if( _uniqueInstance == 0) {
129                 _uniqueInstance = new CommandFactory();
130         }
131         return _uniqueInstance;
132 }
133 /***********************************************************/
134
135 /***********************************************************/
136 //note: This class is resposible for knowing which commands are mpiEnabled,
137 //If a command is not enabled only process 0 will execute the command. 
138 //This avoids redundant outputs on pieces of code we have not paralellized. 
139 //If you add mpi code to a existing command you need to modify the list below or the code will hang on MPI blocking commands like FIle_open. 
140 //example:  commands["dist.seqs"] = "MPIEnabled";
141
142 CommandFactory::CommandFactory(){
143         string s = "";
144         m = MothurOut::getInstance();
145         
146         command = new NoCommand(s);
147         shellcommand = new NoCommand(s);
148         pipecommand = new NoCommand(s);
149         
150         outputDir = ""; inputDir = "";
151         logFileName = "";
152         append = false;
153         
154         //initialize list of valid commands
155         commands["read.dist"]                   = "read.dist"; 
156         commands["read.otu"]                    = "read.otu";
157         commands["read.tree"]                   = "read.tree"; 
158         commands["make.shared"]                 = "make.shared"; 
159         commands["bin.seqs"]                    = "bin.seqs"; 
160         commands["get.oturep"]                  = "get.oturep";
161         commands["cluster"]                             = "cluster"; 
162         commands["unique.seqs"]                 = "unique.seqs"; 
163         commands["dist.shared"]                 = "dist.shared";
164         commands["collect.single"]              = "collect.single"; 
165         commands["collect.shared"]              = "collect.shared"; 
166         commands["rarefaction.single"]  = "rarefaction.single"; 
167         commands["rarefaction.shared"]  = "rarefaction.shared"; 
168         commands["summary.single"]              = "summary.single"; 
169         commands["summary.shared"]              = "summary.shared"; 
170         commands["parsimony"]                   = "parsimony";
171         commands["unifrac.weighted"]    = "unifrac.weighted"; 
172         commands["unifrac.unweighted"]  = "unifrac.unweighted"; 
173         commands["libshuff"]                    = "libshuff";
174         commands["tree.shared"]                 = "tree.shared";
175         commands["heatmap.bin"]                 = "heatmap.bin";
176         commands["heatmap.sim"]                 = "heatmap.sim";
177         commands["venn"]                                = "venn";
178         commands["get.group"]           = "get.group";
179         commands["get.label"]           = "get.label";
180         commands["get.sabund"]          = "get.sabund";
181         commands["get.rabund"]          = "get.rabund";
182         commands["bootstrap.shared"]    = "bootstrap.shared";
183         //commands["consensus"]                 = "consensus";
184         commands["help"]                                = "help";
185         commands["reverse.seqs"]                = "reverse.seqs";
186         commands["trim.seqs"]                   = "trim.seqs";
187         commands["trim.flows"]                  = "trim.flows";
188         commands["list.seqs"]                   = "list.seqs";
189         commands["get.seqs"]                    = "get.seqs";
190         commands["remove.seqs"]                 = "remove.seqs";
191         commands["system"]                              = "system";
192         commands["align.check"]                 = "align.check";
193         commands["get.sharedseqs"]              = "get.sharedseqs";
194         commands["get.otulist"]                 = "get.otulist";
195         commands["hcluster"]                    = "hcluster"; 
196         commands["phylotype"]                   = "phylotype";
197         commands["mgcluster"]                   = "mgcluster";
198         commands["pre.cluster"]                 = "pre.cluster";
199         commands["pcoa"]                                = "pcoa";
200         commands["otu.hierarchy"]               = "otu.hierarchy";
201         commands["set.dir"]                             = "set.dir";
202         commands["merge.files"]                 = "merge.files";
203         commands["parse.list"]                  = "parse.list";
204         commands["set.logfile"]                 = "set.logfile";
205         commands["phylo.diversity"]             = "phylo.diversity";
206         commands["make.group"]                  = "make.group";
207         commands["chop.seqs"]                   = "chop.seqs";
208         commands["clearcut"]                    = "clearcut";
209         commands["catchall"]                    = "catchall";
210         commands["split.abund"]                 = "split.abund";
211         commands["classify.otu"]                = "classify.otu";
212         commands["degap.seqs"]                  = "degap.seqs";
213         commands["get.relabund"]                = "get.relabund";
214         commands["sffinfo"]                             = "sffinfo";
215         commands["normalize.shared"]    = "normalize.shared";
216         commands["metastats"]                   = "metastats";
217         commands["split.groups"]                = "split.groups";
218         commands["cluster.fragments"]   = "cluster.fragments";
219         commands["get.lineage"]                 = "get.lineage";
220         commands["remove.lineage"]              = "remove.lineage";
221         commands["fastq.info"]                  = "fastq.info";
222         commands["deunique.seqs"]               = "deunique.seqs";
223         commands["cluster.classic"]             = "cluster.classic";
224         commands["sub.sample"]                  = "sub.sample";
225         commands["remove.groups"]               = "remove.groups";
226         commands["get.groups"]                  = "get.groups";
227         commands["get.otus"]                    = "get.otus";
228         commands["remove.otus"]                 = "remove.otus";
229         commands["indicator"]                   = "indicator";
230         commands["consensus.seqs"]              = "consensus.seqs";
231         commands["corr.axes"]                   = "corr.axes";
232         commands["pca"]                                 = "pca";
233         commands["nmds"]                                = "nmds";
234         commands["remove.rare"]                 = "remove.rare";
235         commands["amova"]                               = "amova";
236         commands["homova"]                              = "homova";
237         commands["mantel"]                              = "mantel";
238         commands["anosim"]                              = "anosim";
239         commands["make.fastq"]                  = "make.fastq";
240         commands["merge.groups"]                = "merge.groups";
241         commands["get.current"]                 = "get.current";
242         commands["set.current"]                 = "set.current";
243         commands["get.commandinfo"]             = "get.commandinfo";
244         commands["deunique.tree"]               = "deunique.tree";
245         commands["count.seqs"]                  = "count.seqs";
246         commands["pairwise.seqs"]               = "MPIEnabled";
247         commands["pipeline.pds"]                = "MPIEnabled";
248         commands["classify.seqs"]               = "MPIEnabled"; 
249         commands["dist.seqs"]                   = "MPIEnabled";
250         commands["filter.seqs"]                 = "MPIEnabled";
251         commands["align.seqs"]                  = "MPIEnabled";
252         commands["chimera.ccode"]               = "MPIEnabled";
253         commands["chimera.check"]               = "MPIEnabled";
254         commands["chimera.slayer"]              = "MPIEnabled";
255         commands["chimera.uchime"]              = "MPIEnabled";
256         commands["chimera.pintail"]             = "MPIEnabled";
257         commands["chimera.bellerophon"] = "MPIEnabled";
258         commands["screen.seqs"]                 = "MPIEnabled";
259         commands["summary.seqs"]                = "MPIEnabled";
260         commands["cluster.split"]               = "MPIEnabled";
261         commands["shhh.seqs"]                   = "MPIEnabled";
262         commands["sens.spec"]                   = "sens.spec";
263         commands["seq.error"]                   = "seq.error";
264         commands["quit"]                                = "MPIEnabled"; 
265
266 }
267 /***********************************************************/
268
269 /***********************************************************/
270 bool CommandFactory::MPIEnabled(string commandName) {
271         bool mpi = false;
272         it = commands.find(commandName);
273         if (it != commands.end()) { 
274                 if (it->second == "MPIEnabled") { return true; }
275         }
276         return mpi;
277 }
278 /***********************************************************/
279
280 /***********************************************************/
281 CommandFactory::~CommandFactory(){
282         _uniqueInstance = 0;
283         delete command;
284         delete shellcommand;
285         delete pipecommand;
286 }
287
288 /***********************************************************/
289
290 /***********************************************************/
291 //This function calls the appropriate command fucntions based on user input.
292 Command* CommandFactory::getCommand(string commandName, string optionString){
293         try {
294                 delete command;   //delete the old command
295                 
296                 //user has opted to redirect output from dir where input files are located to some other place
297                 if (outputDir != "") { 
298                         if (optionString != "") { optionString += ", outputdir=" + outputDir; }
299                         else { optionString += "outputdir=" + outputDir; }
300                 }
301                 
302                 //user has opted to redirect input from dir where mothur.exe is located to some other place
303                 if (inputDir != "") { 
304                         if (optionString != "") { optionString += ", inputdir=" + inputDir; }
305                         else { optionString += "inputdir=" + inputDir; }
306                 }
307                 
308                 if(commandName == "read.dist")                                  {       command = new ReadDistCommand(optionString);                            }
309                 else if(commandName == "read.otu")                              {       command = new ReadOtuCommand(optionString);                                     }
310                 else if(commandName == "read.tree")                             {       command = new ReadTreeCommand(optionString);                            }
311                 else if(commandName == "cluster")                               {       command = new ClusterCommand(optionString);                                     }
312                 else if(commandName == "unique.seqs")                   {       command = new DeconvoluteCommand(optionString);                         }
313                 else if(commandName == "parsimony")                             {       command = new ParsimonyCommand(optionString);                           }
314                 else if(commandName == "help")                                  {       command = new HelpCommand(optionString);                                        }
315                 else if(commandName == "quit")                                  {       command = new QuitCommand(optionString);                                        }
316                 else if(commandName == "collect.single")                {       command = new CollectCommand(optionString);                                     }
317                 else if(commandName == "collect.shared")                {       command = new CollectSharedCommand(optionString);                       }
318                 else if(commandName == "rarefaction.single")    {       command = new RareFactCommand(optionString);                            }
319                 else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand(optionString);                      }
320                 else if(commandName == "summary.single")                {       command = new SummaryCommand(optionString);                                     }
321                 else if(commandName == "summary.shared")                {       command = new SummarySharedCommand(optionString);                       }
322                 else if(commandName == "unifrac.weighted")              {       command = new UnifracWeightedCommand(optionString);                     }
323                 else if(commandName == "unifrac.unweighted")    {       command = new UnifracUnweightedCommand(optionString);           }
324                 else if(commandName == "get.group")             {   command = new GetgroupCommand(optionString);                                }
325                 else if(commandName == "get.label")             {   command = new GetlabelCommand(optionString);                                }
326                 else if(commandName == "get.sabund")            {   command = new GetSAbundCommand(optionString);                               }
327                 else if(commandName == "get.rabund")            {   command = new GetRAbundCommand(optionString);                               }
328                 else if(commandName == "libshuff")              {   command = new LibShuffCommand(optionString);                                }
329                 else if(commandName == "heatmap.bin")                   {   command = new HeatMapCommand(optionString);                                 }
330                 else if(commandName == "heatmap.sim")                   {   command = new HeatMapSimCommand(optionString);                              }
331                 else if(commandName == "filter.seqs")                   {   command = new FilterSeqsCommand(optionString);                              }
332                 else if(commandName == "venn")                                  {   command = new VennCommand(optionString);                                    }
333                 else if(commandName == "bin.seqs")                              {   command = new BinSeqCommand(optionString);                                  }
334                 else if(commandName == "get.oturep")                    {   command = new GetOTURepCommand(optionString);                               }
335                 else if(commandName == "tree.shared")                   {   command = new TreeGroupCommand(optionString);                               }
336                 else if(commandName == "dist.shared")                   {   command = new MatrixOutputCommand(optionString);                    }
337                 else if(commandName == "bootstrap.shared")              {   command = new BootSharedCommand(optionString);                              }
338                 else if(commandName == "consensus")                             {   command = new ConcensusCommand(optionString);                               }
339                 else if(commandName == "dist.seqs")                             {   command = new DistanceCommand(optionString);                                }
340                 else if(commandName == "align.seqs")                    {   command = new AlignCommand(optionString);                                   }
341                 else if(commandName == "summary.seqs")                  {       command = new SeqSummaryCommand(optionString);                          }
342                 else if(commandName == "screen.seqs")                   {       command = new ScreenSeqsCommand(optionString);                          }
343                 else if(commandName == "reverse.seqs")                  {       command = new ReverseSeqsCommand(optionString);                         }
344                 else if(commandName == "trim.seqs")                             {       command = new TrimSeqsCommand(optionString);                            }
345                 else if(commandName == "trim.flows")                    {       command = new TrimFlowsCommand(optionString);                           }
346                 else if(commandName == "shhh.seqs")                             {       command = new ShhherCommand(optionString);                                      }
347                 else if(commandName == "list.seqs")                             {       command = new ListSeqsCommand(optionString);                            }
348                 else if(commandName == "get.seqs")                              {       command = new GetSeqsCommand(optionString);                                     }
349                 else if(commandName == "remove.seqs")                   {       command = new RemoveSeqsCommand(optionString);                          }
350                 else if(commandName == "merge.files")                   {       command = new MergeFileCommand(optionString);                           }
351                 else if(commandName == "system")                                {       command = new SystemCommand(optionString);                                      }
352                 else if(commandName == "align.check")                   {       command = new AlignCheckCommand(optionString);                          }
353                 else if(commandName == "get.sharedseqs")                {       command = new GetSharedOTUCommand(optionString);                        }
354                 else if(commandName == "get.otulist")                   {       command = new GetListCountCommand(optionString);                        }
355                 else if(commandName == "hcluster")                              {       command = new HClusterCommand(optionString);                            }
356                 else if(commandName == "classify.seqs")                 {       command = new ClassifySeqsCommand(optionString);                        }
357                 else if(commandName == "chimera.ccode")                 {       command = new ChimeraCcodeCommand(optionString);                        }
358                 else if(commandName == "chimera.check")                 {       command = new ChimeraCheckCommand(optionString);                        }
359                 else if(commandName == "chimera.slayer")                {       command = new ChimeraSlayerCommand(optionString);                       }
360                 else if(commandName == "chimera.uchime")                {       command = new ChimeraUchimeCommand(optionString);                       }
361                 else if(commandName == "chimera.pintail")               {       command = new ChimeraPintailCommand(optionString);                      }
362                 else if(commandName == "chimera.bellerophon")   {       command = new ChimeraBellerophonCommand(optionString);          }
363                 else if(commandName == "phylotype")                             {       command = new PhylotypeCommand(optionString);                           }
364                 else if(commandName == "mgcluster")                             {       command = new MGClusterCommand(optionString);                           }
365                 else if(commandName == "pre.cluster")                   {       command = new PreClusterCommand(optionString);                          }
366                 else if(commandName == "pcoa")                                  {       command = new PCOACommand(optionString);                                        }
367                 else if(commandName == "pca")                                   {       command = new PCACommand(optionString);                                         }
368                 else if(commandName == "nmds")                                  {       command = new NMDSCommand(optionString);                                        }
369                 else if(commandName == "otu.hierarchy")                 {       command = new OtuHierarchyCommand(optionString);                        }
370                 else if(commandName == "set.dir")                               {       command = new SetDirectoryCommand(optionString);                        }
371                 else if(commandName == "set.logfile")                   {       command = new SetLogFileCommand(optionString);                          }
372                 else if(commandName == "parse.list")                    {       command = new ParseListCommand(optionString);                           }
373                 else if(commandName == "phylo.diversity")               {       command = new PhyloDiversityCommand(optionString);                      }
374                 else if(commandName == "make.group")                    {       command = new MakeGroupCommand(optionString);                           }
375                 else if(commandName == "chop.seqs")                             {       command = new ChopSeqsCommand(optionString);                            }
376                 else if(commandName == "clearcut")                              {       command = new ClearcutCommand(optionString);                            }
377                 else if(commandName == "catchall")                              {       command = new CatchAllCommand(optionString);                            }
378                 else if(commandName == "split.abund")                   {       command = new SplitAbundCommand(optionString);                          }
379                 else if(commandName == "cluster.split")                 {       command = new ClusterSplitCommand(optionString);                        }
380                 else if(commandName == "classify.otu")                  {       command = new ClassifyOtuCommand(optionString);                         }
381                 else if(commandName == "degap.seqs")                    {       command = new DegapSeqsCommand(optionString);                           }
382                 else if(commandName == "get.relabund")                  {       command = new GetRelAbundCommand(optionString);                         }
383                 else if(commandName == "sens.spec")                             {       command = new SensSpecCommand(optionString);                            }
384                 else if(commandName == "seq.error")                             {       command = new SeqErrorCommand(optionString);                            }
385                 else if(commandName == "sffinfo")                               {       command = new SffInfoCommand(optionString);                                     }
386                 else if(commandName == "normalize.shared")              {       command = new NormalizeSharedCommand(optionString);                     }
387                 else if(commandName == "metastats")                             {       command = new MetaStatsCommand(optionString);                           }
388                 else if(commandName == "split.groups")                  {       command = new SplitGroupCommand(optionString);                          }
389                 else if(commandName == "cluster.fragments")             {       command = new ClusterFragmentsCommand(optionString);            }
390                 else if(commandName == "get.lineage")                   {       command = new GetLineageCommand(optionString);                          }
391                 else if(commandName == "remove.lineage")                {       command = new RemoveLineageCommand(optionString);                       }
392                 else if(commandName == "get.groups")                    {       command = new GetGroupsCommand(optionString);                           }
393                 else if(commandName == "remove.groups")                 {       command = new RemoveGroupsCommand(optionString);                        }
394                 else if(commandName == "get.otus")                              {       command = new GetOtusCommand(optionString);                                     }
395                 else if(commandName == "remove.otus")                   {       command = new RemoveOtusCommand(optionString);                          }
396                 else if(commandName == "fastq.info")                    {       command = new ParseFastaQCommand(optionString);                         }
397                 else if(commandName == "pipeline.pds")                  {       command = new PipelineCommand(optionString);                            }
398                 else if(commandName == "deunique.seqs")                 {       command = new DeUniqueSeqsCommand(optionString);                        }
399                 else if(commandName == "pairwise.seqs")                 {       command = new PairwiseSeqsCommand(optionString);                        }
400                 else if(commandName == "cluster.classic")               {       command = new ClusterDoturCommand(optionString);                        }
401                 else if(commandName == "sub.sample")                    {       command = new SubSampleCommand(optionString);                           }
402                 else if(commandName == "indicator")                             {       command = new IndicatorCommand(optionString);                           }
403                 else if(commandName == "consensus.seqs")                {       command = new ConsensusSeqsCommand(optionString);                       }
404                 else if(commandName == "corr.axes")                             {       command = new CorrAxesCommand(optionString);                            }
405                 else if(commandName == "remove.rare")                   {       command = new RemoveRareCommand(optionString);                          }
406                 else if(commandName == "merge.groups")                  {       command = new MergeGroupsCommand(optionString);                         }
407                 else if(commandName == "amova")                                 {       command = new AmovaCommand(optionString);                                       }
408                 else if(commandName == "homova")                                {       command = new HomovaCommand(optionString);                                      }
409                 else if(commandName == "mantel")                                {       command = new MantelCommand(optionString);                                      }
410                 else if(commandName == "make.fastq")                    {       command = new MakeFastQCommand(optionString);                           }
411                 else if(commandName == "get.current")                   {       command = new GetCurrentCommand(optionString);                          }
412                 else if(commandName == "set.current")                   {       command = new SetCurrentCommand(optionString);                          }
413                 else if(commandName == "anosim")                                {       command = new AnosimCommand(optionString);                                      }
414                 else if(commandName == "make.shared")                   {       command = new SharedCommand(optionString);                                      }
415                 else if(commandName == "get.commandinfo")               {       command = new GetCommandInfoCommand(optionString);                      }
416                 else if(commandName == "deunique.tree")                 {       command = new DeuniqueTreeCommand(optionString);                        }
417                 else if(commandName == "count.seqs")                    {       command = new CountSeqsCommand(optionString);                           }
418                 else                                                                                    {       command = new NoCommand(optionString);                                          }
419
420                 return command;
421         }
422         catch(exception& e) {
423                 m->errorOut(e, "CommandFactory", "getCommand");
424                 exit(1);
425         }
426 }
427 /***********************************************************/
428
429 /***********************************************************/
430 //This function calls the appropriate command fucntions based on user input.
431 Command* CommandFactory::getCommand(string commandName, string optionString, string mode){
432         try {
433                 delete pipecommand;   //delete the old command
434                 
435                 //user has opted to redirect output from dir where input files are located to some other place
436                 if (outputDir != "") { 
437                         if (optionString != "") { optionString += ", outputdir=" + outputDir; }
438                         else { optionString += "outputdir=" + outputDir; }
439                 }
440                 
441                 //user has opted to redirect input from dir where mothur.exe is located to some other place
442                 if (inputDir != "") { 
443                         if (optionString != "") { optionString += ", inputdir=" + inputDir; }
444                         else { optionString += "inputdir=" + inputDir; }
445                 }
446                 
447                 if(commandName == "read.dist")                                  {       pipecommand = new ReadDistCommand(optionString);                                }
448                 else if(commandName == "read.otu")                              {       pipecommand = new ReadOtuCommand(optionString);                                 }
449                 else if(commandName == "read.tree")                             {       pipecommand = new ReadTreeCommand(optionString);                                }
450                 else if(commandName == "cluster")                               {       pipecommand = new ClusterCommand(optionString);                                 }
451                 else if(commandName == "unique.seqs")                   {       pipecommand = new DeconvoluteCommand(optionString);                             }
452                 else if(commandName == "parsimony")                             {       pipecommand = new ParsimonyCommand(optionString);                               }
453                 else if(commandName == "help")                                  {       pipecommand = new HelpCommand(optionString);                                    }
454                 else if(commandName == "quit")                                  {       pipecommand = new QuitCommand(optionString);                                    }
455                 else if(commandName == "collect.single")                {       pipecommand = new CollectCommand(optionString);                                 }
456                 else if(commandName == "collect.shared")                {       pipecommand = new CollectSharedCommand(optionString);                   }
457                 else if(commandName == "rarefaction.single")    {       pipecommand = new RareFactCommand(optionString);                                }
458                 else if(commandName == "rarefaction.shared")    {       pipecommand = new RareFactSharedCommand(optionString);                  }
459                 else if(commandName == "summary.single")                {       pipecommand = new SummaryCommand(optionString);                                 }
460                 else if(commandName == "summary.shared")                {       pipecommand = new SummarySharedCommand(optionString);                   }
461                 else if(commandName == "unifrac.weighted")              {       pipecommand = new UnifracWeightedCommand(optionString);                 }
462                 else if(commandName == "unifrac.unweighted")    {       pipecommand = new UnifracUnweightedCommand(optionString);               }
463                 else if(commandName == "get.group")             {   pipecommand = new GetgroupCommand(optionString);                            }
464                 else if(commandName == "get.label")             {   pipecommand = new GetlabelCommand(optionString);                            }
465                 else if(commandName == "get.sabund")            {   pipecommand = new GetSAbundCommand(optionString);                           }
466                 else if(commandName == "get.rabund")            {   pipecommand = new GetRAbundCommand(optionString);                           }
467                 else if(commandName == "libshuff")              {   pipecommand = new LibShuffCommand(optionString);                            }
468                 else if(commandName == "heatmap.bin")                   {   pipecommand = new HeatMapCommand(optionString);                                     }
469                 else if(commandName == "heatmap.sim")                   {   pipecommand = new HeatMapSimCommand(optionString);                          }
470                 else if(commandName == "filter.seqs")                   {   pipecommand = new FilterSeqsCommand(optionString);                          }
471                 else if(commandName == "venn")                                  {   pipecommand = new VennCommand(optionString);                                        }
472                 else if(commandName == "bin.seqs")                              {   pipecommand = new BinSeqCommand(optionString);                                      }
473                 else if(commandName == "get.oturep")                    {   pipecommand = new GetOTURepCommand(optionString);                           }
474                 else if(commandName == "tree.shared")                   {   pipecommand = new TreeGroupCommand(optionString);                           }
475                 else if(commandName == "dist.shared")                   {   pipecommand = new MatrixOutputCommand(optionString);                        }
476                 else if(commandName == "bootstrap.shared")              {   pipecommand = new BootSharedCommand(optionString);                          }
477                 else if(commandName == "consensus")                             {   pipecommand = new ConcensusCommand(optionString);                           }
478                 else if(commandName == "dist.seqs")                             {   pipecommand = new DistanceCommand(optionString);                            }
479                 else if(commandName == "align.seqs")                    {   pipecommand = new AlignCommand(optionString);                                       }
480                 else if(commandName == "summary.seqs")                  {       pipecommand = new SeqSummaryCommand(optionString);                              }
481                 else if(commandName == "screen.seqs")                   {       pipecommand = new ScreenSeqsCommand(optionString);                              }
482                 else if(commandName == "reverse.seqs")                  {       pipecommand = new ReverseSeqsCommand(optionString);                             }
483                 else if(commandName == "trim.seqs")                             {       pipecommand = new TrimSeqsCommand(optionString);                                }
484                 else if(commandName == "trim.flows")                    {       pipecommand = new TrimFlowsCommand(optionString);                               }
485                 else if(commandName == "shhh.seqs")                             {       pipecommand = new ShhherCommand(optionString);                                  }
486                 else if(commandName == "list.seqs")                             {       pipecommand = new ListSeqsCommand(optionString);                                }
487                 else if(commandName == "get.seqs")                              {       pipecommand = new GetSeqsCommand(optionString);                                 }
488                 else if(commandName == "remove.seqs")                   {       pipecommand = new RemoveSeqsCommand(optionString);                              }
489                 else if(commandName == "merge.files")                   {       pipecommand = new MergeFileCommand(optionString);                               }
490                 else if(commandName == "system")                                {       pipecommand = new SystemCommand(optionString);                                  }
491                 else if(commandName == "align.check")                   {       pipecommand = new AlignCheckCommand(optionString);                              }
492                 else if(commandName == "get.sharedseqs")                {       pipecommand = new GetSharedOTUCommand(optionString);                    }
493                 else if(commandName == "get.otulist")                   {       pipecommand = new GetListCountCommand(optionString);                    }
494                 else if(commandName == "hcluster")                              {       pipecommand = new HClusterCommand(optionString);                                }
495                 else if(commandName == "classify.seqs")                 {       pipecommand = new ClassifySeqsCommand(optionString);                    }
496                 else if(commandName == "chimera.ccode")                 {       pipecommand = new ChimeraCcodeCommand(optionString);                    }
497                 else if(commandName == "chimera.check")                 {       pipecommand = new ChimeraCheckCommand(optionString);                    }
498                 else if(commandName == "chimera.uchime")                {       pipecommand = new ChimeraUchimeCommand(optionString);                   }
499                 else if(commandName == "chimera.slayer")                {       pipecommand = new ChimeraSlayerCommand(optionString);                   }
500                 else if(commandName == "chimera.pintail")               {       pipecommand = new ChimeraPintailCommand(optionString);                  }
501                 else if(commandName == "chimera.bellerophon")   {       pipecommand = new ChimeraBellerophonCommand(optionString);              }
502                 else if(commandName == "phylotype")                             {       pipecommand = new PhylotypeCommand(optionString);                               }
503                 else if(commandName == "mgcluster")                             {       pipecommand = new MGClusterCommand(optionString);                               }
504                 else if(commandName == "pre.cluster")                   {       pipecommand = new PreClusterCommand(optionString);                              }
505                 else if(commandName == "pcoa")                                  {       pipecommand = new PCOACommand(optionString);                                    }
506                 else if(commandName == "pca")                                   {       pipecommand = new PCACommand(optionString);                                             }
507                 else if(commandName == "nmds")                                  {       pipecommand = new NMDSCommand(optionString);                                    }
508                 else if(commandName == "otu.hierarchy")                 {       pipecommand = new OtuHierarchyCommand(optionString);                    }
509                 else if(commandName == "set.dir")                               {       pipecommand = new SetDirectoryCommand(optionString);                    }
510                 else if(commandName == "set.logfile")                   {       pipecommand = new SetLogFileCommand(optionString);                              }
511                 else if(commandName == "parse.list")                    {       pipecommand = new ParseListCommand(optionString);                               }
512                 else if(commandName == "phylo.diversity")               {       pipecommand = new PhyloDiversityCommand(optionString);                  }
513                 else if(commandName == "make.group")                    {       pipecommand = new MakeGroupCommand(optionString);                               }
514                 else if(commandName == "chop.seqs")                             {       pipecommand = new ChopSeqsCommand(optionString);                                }
515                 else if(commandName == "clearcut")                              {       pipecommand = new ClearcutCommand(optionString);                                }
516                 else if(commandName == "catchall")                              {       pipecommand = new CatchAllCommand(optionString);                                }
517                 else if(commandName == "split.abund")                   {       pipecommand = new SplitAbundCommand(optionString);                              }
518                 else if(commandName == "cluster.split")                 {       pipecommand = new ClusterSplitCommand(optionString);                    }
519                 else if(commandName == "classify.otu")                  {       pipecommand = new ClassifyOtuCommand(optionString);                             }
520                 else if(commandName == "degap.seqs")                    {       pipecommand = new DegapSeqsCommand(optionString);                               }
521                 else if(commandName == "get.relabund")                  {       pipecommand = new GetRelAbundCommand(optionString);                             }
522                 else if(commandName == "sens.spec")                             {       pipecommand = new SensSpecCommand(optionString);                                }
523                 else if(commandName == "seq.error")                             {       pipecommand = new SeqErrorCommand(optionString);                                }
524                 else if(commandName == "sffinfo")                               {       pipecommand = new SffInfoCommand(optionString);                                 }
525                 else if(commandName == "normalize.shared")              {       pipecommand = new NormalizeSharedCommand(optionString);                 }
526                 else if(commandName == "metastats")                             {       pipecommand = new MetaStatsCommand(optionString);                               }
527                 else if(commandName == "split.groups")                  {       pipecommand = new SplitGroupCommand(optionString);                              }
528                 else if(commandName == "cluster.fragments")             {       pipecommand = new ClusterFragmentsCommand(optionString);                }
529                 else if(commandName == "get.lineage")                   {       pipecommand = new GetLineageCommand(optionString);                              }
530                 else if(commandName == "get.groups")                    {       pipecommand = new GetGroupsCommand(optionString);                               }
531                 else if(commandName == "remove.lineage")                {       pipecommand = new RemoveLineageCommand(optionString);                   }
532                 else if(commandName == "remove.groups")                 {       pipecommand = new RemoveGroupsCommand(optionString);                    }
533                 else if(commandName == "get.otus")                              {       pipecommand = new GetOtusCommand(optionString);                                 }
534                 else if(commandName == "remove.otus")                   {       pipecommand = new RemoveOtusCommand(optionString);                              }
535                 else if(commandName == "fastq.info")                    {       pipecommand = new ParseFastaQCommand(optionString);                             }
536                 else if(commandName == "deunique.seqs")                 {       pipecommand = new DeUniqueSeqsCommand(optionString);                    }
537                 else if(commandName == "pairwise.seqs")                 {       pipecommand = new PairwiseSeqsCommand(optionString);                    }
538                 else if(commandName == "cluster.classic")               {       pipecommand = new ClusterDoturCommand(optionString);                    }
539                 else if(commandName == "sub.sample")                    {       pipecommand = new SubSampleCommand(optionString);                               }
540                 else if(commandName == "indicator")                             {       pipecommand = new IndicatorCommand(optionString);                               }
541                 else if(commandName == "consensus.seqs")                {       pipecommand = new ConsensusSeqsCommand(optionString);                   }
542                 else if(commandName == "corr.axes")                             {       pipecommand = new CorrAxesCommand(optionString);                                }
543                 else if(commandName == "remove.rare")                   {       pipecommand = new RemoveRareCommand(optionString);                              }
544                 else if(commandName == "merge.groups")                  {       pipecommand = new MergeGroupsCommand(optionString);                             }
545                 else if(commandName == "amova")                                 {       pipecommand = new AmovaCommand(optionString);                                   }
546                 else if(commandName == "homova")                                {       pipecommand = new HomovaCommand(optionString);                                  }
547                 else if(commandName == "mantel")                                {       pipecommand = new MantelCommand(optionString);                                  }
548                 else if(commandName == "anosim")                                {       pipecommand = new AnosimCommand(optionString);                                  }
549                 else if(commandName == "make.fastq")                    {       pipecommand = new MakeFastQCommand(optionString);                               }
550                 else if(commandName == "get.current")                   {       pipecommand = new GetCurrentCommand(optionString);                              }
551                 else if(commandName == "set.current")                   {       pipecommand = new SetCurrentCommand(optionString);                              }
552                 else if(commandName == "make.shared")                   {       pipecommand = new SharedCommand(optionString);                                  }
553                 else if(commandName == "get.commandinfo")               {       pipecommand = new GetCommandInfoCommand(optionString);                  }
554                 else if(commandName == "deunique.tree")                 {       pipecommand = new DeuniqueTreeCommand(optionString);                    }
555                 else if(commandName == "count.seqs")                    {       pipecommand = new CountSeqsCommand(optionString);                               }
556                 else                                                                                    {       pipecommand = new NoCommand(optionString);                                              }
557
558                 return pipecommand;
559         }
560         catch(exception& e) {
561                 m->errorOut(e, "CommandFactory", "getCommand");
562                 exit(1);
563         }
564 }
565 /***********************************************************/
566
567 /***********************************************************/
568 //This function calls the appropriate command fucntions based on user input, this is used by the pipeline command to check a users piepline for errors before running
569 Command* CommandFactory::getCommand(string commandName){
570         try {
571                 delete shellcommand;   //delete the old command
572                 
573                 if(commandName == "read.dist")                                  {       shellcommand = new ReadDistCommand();                           }
574                 else if(commandName == "read.otu")                              {       shellcommand = new ReadOtuCommand();                            }
575                 else if(commandName == "read.tree")                             {       shellcommand = new ReadTreeCommand();                           }
576                 else if(commandName == "cluster")                               {       shellcommand = new ClusterCommand();                            }
577                 else if(commandName == "unique.seqs")                   {       shellcommand = new DeconvoluteCommand();                        }
578                 else if(commandName == "parsimony")                             {       shellcommand = new ParsimonyCommand();                          }
579                 else if(commandName == "help")                                  {       shellcommand = new HelpCommand();                                       }
580                 else if(commandName == "quit")                                  {       shellcommand = new QuitCommand();                                       }
581                 else if(commandName == "collect.single")                {       shellcommand = new CollectCommand();                            }
582                 else if(commandName == "collect.shared")                {       shellcommand = new CollectSharedCommand();                      }
583                 else if(commandName == "rarefaction.single")    {       shellcommand = new RareFactCommand();                           }
584                 else if(commandName == "rarefaction.shared")    {       shellcommand = new RareFactSharedCommand();                     }
585                 else if(commandName == "summary.single")                {       shellcommand = new SummaryCommand();                            }
586                 else if(commandName == "summary.shared")                {       shellcommand = new SummarySharedCommand();                      }
587                 else if(commandName == "unifrac.weighted")              {       shellcommand = new UnifracWeightedCommand();            }
588                 else if(commandName == "unifrac.unweighted")    {       shellcommand = new UnifracUnweightedCommand();          }
589                 else if(commandName == "get.group")             {   shellcommand = new GetgroupCommand();                               }
590                 else if(commandName == "get.label")             {   shellcommand = new GetlabelCommand();                               }
591                 else if(commandName == "get.sabund")            {   shellcommand = new GetSAbundCommand();                              }
592                 else if(commandName == "get.rabund")            {   shellcommand = new GetRAbundCommand();                              }
593                 else if(commandName == "libshuff")              {   shellcommand = new LibShuffCommand();                               }
594                 else if(commandName == "heatmap.bin")                   {   shellcommand = new HeatMapCommand();                                }
595                 else if(commandName == "heatmap.sim")                   {   shellcommand = new HeatMapSimCommand();                             }
596                 else if(commandName == "filter.seqs")                   {   shellcommand = new FilterSeqsCommand();                             }
597                 else if(commandName == "venn")                                  {   shellcommand = new VennCommand();                                   }
598                 else if(commandName == "bin.seqs")                              {   shellcommand = new BinSeqCommand();                                 }
599                 else if(commandName == "get.oturep")                    {   shellcommand = new GetOTURepCommand();                              }
600                 else if(commandName == "tree.shared")                   {   shellcommand = new TreeGroupCommand();                              }
601                 else if(commandName == "dist.shared")                   {   shellcommand = new MatrixOutputCommand();                   }
602                 else if(commandName == "bootstrap.shared")              {   shellcommand = new BootSharedCommand();                             }
603                 else if(commandName == "consensus")                             {   shellcommand = new ConcensusCommand();                              }
604                 else if(commandName == "dist.seqs")                             {   shellcommand = new DistanceCommand();                               }
605                 else if(commandName == "align.seqs")                    {   shellcommand = new AlignCommand();                                  }
606                 else if(commandName == "summary.seqs")                  {       shellcommand = new SeqSummaryCommand();                         }
607                 else if(commandName == "screen.seqs")                   {       shellcommand = new ScreenSeqsCommand();                         }
608                 else if(commandName == "reverse.seqs")                  {       shellcommand = new ReverseSeqsCommand();                        }
609                 else if(commandName == "trim.seqs")                             {       shellcommand = new TrimSeqsCommand();                           }
610                 else if(commandName == "trim.flows")                    {       shellcommand = new TrimFlowsCommand();                          }
611                 else if(commandName == "shhh.seqs")                             {       shellcommand = new ShhherCommand();                                     }
612                 else if(commandName == "list.seqs")                             {       shellcommand = new ListSeqsCommand();                           }
613                 else if(commandName == "get.seqs")                              {       shellcommand = new GetSeqsCommand();                            }
614                 else if(commandName == "remove.seqs")                   {       shellcommand = new RemoveSeqsCommand();                         }
615                 else if(commandName == "merge.files")                   {       shellcommand = new MergeFileCommand();                          }
616                 else if(commandName == "system")                                {       shellcommand = new SystemCommand();                                     }
617                 else if(commandName == "align.check")                   {       shellcommand = new AlignCheckCommand();                         }
618                 else if(commandName == "get.sharedseqs")                {       shellcommand = new GetSharedOTUCommand();                       }
619                 else if(commandName == "get.otulist")                   {       shellcommand = new GetListCountCommand();                       }
620                 else if(commandName == "hcluster")                              {       shellcommand = new HClusterCommand();                           }
621                 else if(commandName == "classify.seqs")                 {       shellcommand = new ClassifySeqsCommand();                       }
622                 else if(commandName == "chimera.ccode")                 {       shellcommand = new ChimeraCcodeCommand();                       }
623                 else if(commandName == "chimera.check")                 {       shellcommand = new ChimeraCheckCommand();                       }
624                 else if(commandName == "chimera.slayer")                {       shellcommand = new ChimeraSlayerCommand();                      }
625                 else if(commandName == "chimera.uchime")                {       shellcommand = new ChimeraUchimeCommand();                      }
626                 else if(commandName == "chimera.pintail")               {       shellcommand = new ChimeraPintailCommand();                     }
627                 else if(commandName == "chimera.bellerophon")   {       shellcommand = new ChimeraBellerophonCommand();         }
628                 else if(commandName == "phylotype")                             {       shellcommand = new PhylotypeCommand();                          }
629                 else if(commandName == "mgcluster")                             {       shellcommand = new MGClusterCommand();                          }
630                 else if(commandName == "pre.cluster")                   {       shellcommand = new PreClusterCommand();                         }
631                 else if(commandName == "pcoa")                                  {       shellcommand = new PCOACommand();                                       }
632                 else if(commandName == "pca")                                   {       shellcommand = new PCACommand();                                        }
633                 else if(commandName == "nmds")                                  {       shellcommand = new NMDSCommand();                                       }
634                 else if(commandName == "otu.hierarchy")                 {       shellcommand = new OtuHierarchyCommand();                       }
635                 else if(commandName == "set.dir")                               {       shellcommand = new SetDirectoryCommand();                       }
636                 else if(commandName == "set.logfile")                   {       shellcommand = new SetLogFileCommand();                         }
637                 else if(commandName == "parse.list")                    {       shellcommand = new ParseListCommand();                          }
638                 else if(commandName == "phylo.diversity")               {       shellcommand = new PhyloDiversityCommand();                     }
639                 else if(commandName == "make.group")                    {       shellcommand = new MakeGroupCommand();                          }
640                 else if(commandName == "chop.seqs")                             {       shellcommand = new ChopSeqsCommand();                           }
641                 else if(commandName == "clearcut")                              {       shellcommand = new ClearcutCommand();                           }
642                 else if(commandName == "catchall")                              {       shellcommand = new CatchAllCommand();                           }
643                 else if(commandName == "split.abund")                   {       shellcommand = new SplitAbundCommand();                         }
644                 else if(commandName == "cluster.split")                 {       shellcommand = new ClusterSplitCommand();                       }
645                 else if(commandName == "classify.otu")                  {       shellcommand = new ClassifyOtuCommand();                        }
646                 else if(commandName == "degap.seqs")                    {       shellcommand = new DegapSeqsCommand();                          }
647                 else if(commandName == "get.relabund")                  {       shellcommand = new GetRelAbundCommand();                        }
648                 else if(commandName == "sens.spec")                             {       shellcommand = new SensSpecCommand();                           }
649                 else if(commandName == "seq.error")                             {       shellcommand = new SeqErrorCommand();                           }
650                 else if(commandName == "sffinfo")                               {       shellcommand = new SffInfoCommand();                            }
651                 else if(commandName == "normalize.shared")              {       shellcommand = new NormalizeSharedCommand();            }
652                 else if(commandName == "metastats")                             {       shellcommand = new MetaStatsCommand();                          }
653                 else if(commandName == "split.groups")                  {       shellcommand = new SplitGroupCommand();                         }
654                 else if(commandName == "cluster.fragments")             {       shellcommand = new ClusterFragmentsCommand();           }
655                 else if(commandName == "get.lineage")                   {       shellcommand = new GetLineageCommand();                         }
656                 else if(commandName == "remove.lineage")                {       shellcommand = new RemoveLineageCommand();                      }
657                 else if(commandName == "get.groups")                    {       shellcommand = new GetGroupsCommand();                          }
658                 else if(commandName == "remove.groups")                 {       shellcommand = new RemoveGroupsCommand();                       }
659                 else if(commandName == "get.otus")                              {       shellcommand = new GetOtusCommand();                            }
660                 else if(commandName == "remove.otus")                   {       shellcommand = new RemoveOtusCommand();                         }
661                 else if(commandName == "fastq.info")                    {       shellcommand = new ParseFastaQCommand();                        }
662                 else if(commandName == "deunique.seqs")                 {       shellcommand = new DeUniqueSeqsCommand();                       }
663                 else if(commandName == "pairwise.seqs")                 {       shellcommand = new PairwiseSeqsCommand();                       }
664                 else if(commandName == "cluster.classic")               {       shellcommand = new ClusterDoturCommand();                       }
665                 else if(commandName == "sub.sample")                    {       shellcommand = new SubSampleCommand();                          }
666                 else if(commandName == "indicator")                             {       shellcommand = new IndicatorCommand();                          }
667                 else if(commandName == "consensus.seqs")                {       shellcommand = new ConsensusSeqsCommand();                      }
668                 else if(commandName == "corr.axes")                             {       shellcommand = new CorrAxesCommand();                           }
669                 else if(commandName == "remove.rare")                   {       shellcommand = new RemoveRareCommand();                         }
670                 else if(commandName == "merge.groups")                  {       shellcommand = new MergeGroupsCommand();                        }
671                 else if(commandName == "amova")                                 {       shellcommand = new AmovaCommand();                                      }
672                 else if(commandName == "homova")                                {       shellcommand = new HomovaCommand();                                     }
673                 else if(commandName == "mantel")                                {       shellcommand = new MantelCommand();                                     }
674                 else if(commandName == "anosim")                                {       shellcommand = new AnosimCommand();                                     }
675                 else if(commandName == "make.fastq")                    {       shellcommand = new MakeFastQCommand();                          }
676                 else if(commandName == "get.current")                   {       shellcommand = new GetCurrentCommand();                         }
677                 else if(commandName == "set.current")                   {       shellcommand = new SetCurrentCommand();                         }
678                 else if(commandName == "make.shared")                   {       shellcommand = new SharedCommand();                                     }
679                 else if(commandName == "get.commandinfo")               {       shellcommand = new GetCommandInfoCommand();                     }
680                 else if(commandName == "deunique.tree")                 {       shellcommand = new DeuniqueTreeCommand();                       }
681                 else if(commandName == "count.seqs")                    {       shellcommand = new CountSeqsCommand();                          }
682                 else                                                                                    {       shellcommand = new NoCommand();                                         }
683
684                 return shellcommand;
685         }
686         catch(exception& e) {
687                 m->errorOut(e, "CommandFactory", "getCommand");
688                 exit(1);
689         }
690 }
691 /***********************************************************
692 //This function is used to interrupt a command
693 Command* CommandFactory::getCommand(){
694         try {
695                 delete command;   //delete the old command
696
697                 string s = "";
698             command = new NoCommand(s);
699         
700                 return command;
701         }
702         catch(exception& e) {
703                 m->errorOut(e, "CommandFactory", "getCommand");
704                 exit(1);
705         }
706 }
707 /***********************************************************************/
708 bool CommandFactory::isValidCommand(string command) {
709         try {   
710         
711                 //is the command in the map
712                 if ((commands.find(command)) != (commands.end())) {
713                         return true;
714                 }else{
715                         m->mothurOut(command + " is not a valid command in Mothur.  Valid commands are ");
716                         for (it = commands.begin(); it != commands.end(); it++) {
717                                 m->mothurOut(it->first + ", ");
718                         }
719                         m->mothurOutEndLine();
720                         return false;
721                 }
722                 
723         }
724         catch(exception& e) {
725                 m->errorOut(e, "CommandFactory", "isValidCommand");
726                 exit(1);
727         }
728 }
729 /***********************************************************************/
730 bool CommandFactory::isValidCommand(string command, string noError) {
731         try {   
732         
733                 //is the command in the map
734                 if ((commands.find(command)) != (commands.end())) {
735                         return true;
736                 }else{
737                         return false;
738                 }
739                 
740         }
741         catch(exception& e) {
742                 m->errorOut(e, "CommandFactory", "isValidCommand");
743                 exit(1);
744         }
745 }
746 /***********************************************************************/
747 void CommandFactory::printCommands(ostream& out) {
748         try {   
749                 out << "Valid commands are: ";
750                 for (it = commands.begin(); it != commands.end(); it++) {
751                         out << it->first << ",";
752                 }
753                 out << endl;
754         }
755         catch(exception& e) {
756                 m->errorOut(e, "CommandFactory", "printCommands");
757                 exit(1);
758         }
759 }
760 /***********************************************************************/
761
762
763
764