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