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