]> git.donarmstrong.com Git - mothur.git/blob - commandfactory.cpp
fixes while testing 1.33.0
[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 "classifyrfsharedcommand.h"
139 #include "filtersharedcommand.h"
140 #include "primerdesigncommand.h"
141 #include "getdistscommand.h"
142 #include "removedistscommand.h"
143 #include "mergetaxsummarycommand.h"
144 #include "getmetacommunitycommand.h"
145 #include "sparcccommand.h"
146 #include "makelookupcommand.h"
147 #include "renameseqscommand.h"
148 #include "makelefsecommand.h"
149 #include "lefsecommand.h"
150 #include "kruskalwalliscommand.h"
151 #include "sracommand.h"
152 #include "mergesfffilecommand.h"
153
154 /*******************************************************/
155
156 /******************************************************/
157 CommandFactory* CommandFactory::getInstance() {
158         if( _uniqueInstance == 0) {
159                 _uniqueInstance = new CommandFactory();
160         }
161         return _uniqueInstance;
162 }
163 /***********************************************************/
164
165 /***********************************************************/
166 //note: This class is resposible for knowing which commands are mpiEnabled,
167 //If a command is not enabled only process 0 will execute the command. 
168 //This avoids redundant outputs on pieces of code we have not paralellized. 
169 //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. 
170 //example:  commands["dist.seqs"] = "MPIEnabled";
171
172 CommandFactory::CommandFactory(){
173         string s = "";
174         m = MothurOut::getInstance();
175         
176         command = new NoCommand(s);
177         shellcommand = new NoCommand(s);
178         pipecommand = new NoCommand(s);
179         
180         outputDir = ""; inputDir = "";
181         logFileName = "";
182         append = false;
183         
184         //initialize list of valid commands
185         commands["make.shared"]                 = "make.shared"; 
186         commands["bin.seqs"]                    = "bin.seqs"; 
187         commands["get.oturep"]                  = "get.oturep";
188         commands["cluster"]                             = "cluster"; 
189         commands["unique.seqs"]                 = "unique.seqs"; 
190         commands["dist.shared"]                 = "dist.shared";
191         commands["collect.single"]              = "collect.single"; 
192         commands["collect.shared"]              = "collect.shared"; 
193         commands["rarefaction.single"]  = "rarefaction.single"; 
194         commands["rarefaction.shared"]  = "rarefaction.shared"; 
195         commands["summary.single"]              = "summary.single"; 
196         commands["summary.shared"]              = "summary.shared"; 
197         commands["parsimony"]                   = "parsimony";
198         commands["unifrac.weighted"]    = "unifrac.weighted"; 
199         commands["unifrac.unweighted"]  = "unifrac.unweighted"; 
200         commands["libshuff"]                    = "libshuff";
201         commands["tree.shared"]                 = "tree.shared";
202         commands["heatmap.bin"]                 = "heatmap.bin";
203         commands["heatmap.sim"]                 = "heatmap.sim";
204         commands["venn"]                                = "venn";
205         commands["get.group"]           = "get.group";
206         commands["get.label"]           = "get.label";
207         commands["get.sabund"]          = "get.sabund";
208         commands["get.rabund"]          = "get.rabund";
209         commands["help"]                                = "help";
210         commands["reverse.seqs"]                = "reverse.seqs";
211         commands["trim.seqs"]                   = "trim.seqs";
212         commands["trim.flows"]                  = "trim.flows";
213         commands["list.seqs"]                   = "list.seqs";
214         commands["get.seqs"]                    = "get.seqs";
215         commands["remove.seqs"]                 = "remove.seqs";
216         commands["system"]                              = "system";
217         commands["align.check"]                 = "align.check";
218         commands["get.sharedseqs"]              = "get.sharedseqs";
219         commands["get.otulist"]                 = "get.otulist";
220         commands["hcluster"]                    = "hcluster"; 
221         commands["phylotype"]                   = "phylotype";
222         commands["mgcluster"]                   = "mgcluster";
223         commands["pre.cluster"]                 = "pre.cluster";
224         commands["pcoa"]                                = "pcoa";
225         commands["otu.hierarchy"]               = "otu.hierarchy";
226         commands["set.dir"]                             = "MPIEnabled";
227         commands["merge.files"]                 = "merge.files";
228         commands["parse.list"]                  = "parse.list";
229         commands["set.logfile"]                 = "set.logfile";
230         commands["phylo.diversity"]             = "phylo.diversity";
231         commands["make.group"]                  = "make.group";
232         commands["chop.seqs"]                   = "chop.seqs";
233         commands["clearcut"]                    = "clearcut";
234         commands["catchall"]                    = "catchall";
235         commands["split.abund"]                 = "split.abund";
236         commands["classify.otu"]                = "classify.otu";
237         commands["degap.seqs"]                  = "degap.seqs";
238         commands["get.relabund"]                = "get.relabund";
239         commands["sffinfo"]                             = "sffinfo";
240         commands["normalize.shared"]    = "normalize.shared";
241         commands["metastats"]                   = "metastats";
242         commands["split.groups"]                = "split.groups";
243         commands["cluster.fragments"]   = "cluster.fragments";
244         commands["get.lineage"]                 = "get.lineage";
245         commands["remove.lineage"]              = "remove.lineage";
246         commands["fastq.info"]                  = "fastq.info";
247         commands["deunique.seqs"]               = "deunique.seqs";
248         commands["cluster.classic"]             = "cluster.classic";
249         commands["sub.sample"]                  = "sub.sample";
250         commands["remove.groups"]               = "remove.groups";
251         commands["get.groups"]                  = "get.groups";
252         commands["get.otus"]                    = "get.otus";
253         commands["remove.otus"]                 = "remove.otus";
254         commands["indicator"]                   = "indicator";
255         commands["consensus.seqs"]              = "consensus.seqs";
256         commands["corr.axes"]                   = "corr.axes";
257         commands["pca"]                                 = "pca";
258         commands["nmds"]                                = "nmds";
259         commands["remove.rare"]                 = "remove.rare";
260         commands["amova"]                               = "amova";
261         commands["homova"]                              = "homova";
262         commands["mantel"]                              = "mantel";
263         commands["anosim"]                              = "anosim";
264         commands["make.fastq"]                  = "make.fastq";
265         commands["merge.groups"]                = "merge.groups";
266         commands["get.current"]                 = "MPIEnabled";
267         commands["set.current"]                 = "MPIEnabled";
268         commands["get.commandinfo"]             = "get.commandinfo";
269         commands["deunique.tree"]               = "deunique.tree";
270         commands["count.seqs"]                  = "count.seqs";
271         commands["count.groups"]                = "count.groups";
272         commands["clear.memory"]                = "clear.memory";
273         commands["pairwise.seqs"]               = "MPIEnabled";
274         commands["pipeline.pds"]                = "MPIEnabled";
275         commands["classify.seqs"]               = "MPIEnabled"; 
276         commands["dist.seqs"]                   = "MPIEnabled";
277         commands["filter.seqs"]                 = "MPIEnabled";
278         commands["align.seqs"]                  = "MPIEnabled";
279         commands["chimera.ccode"]               = "MPIEnabled";
280         commands["chimera.check"]               = "MPIEnabled";
281         commands["chimera.slayer"]              = "MPIEnabled";
282         commands["chimera.uchime"]              = "chimera.uchime";
283         commands["chimera.perseus"]             = "chimera.perseus";
284         commands["chimera.pintail"]             = "MPIEnabled";
285         commands["chimera.bellerophon"] = "MPIEnabled";
286         commands["screen.seqs"]                 = "MPIEnabled";
287         commands["summary.seqs"]                = "MPIEnabled";
288         commands["cluster.split"]               = "MPIEnabled";
289         commands["shhh.flows"]                  = "MPIEnabled";
290         commands["sens.spec"]                   = "sens.spec";
291         commands["seq.error"]                   = "seq.error";
292         commands["summary.tax"]                 = "summary.tax";
293         commands["summary.qual"]                = "summary.qual";
294         commands["shhh.seqs"]                   = "shhh.seqs";
295         commands["otu.association"]             = "otu.association";
296     commands["sort.seqs"]           = "sort.seqs";
297     commands["classify.tree"]       = "classify.tree";
298     commands["cooccurrence"]        = "cooccurrence";
299     commands["pcr.seqs"]            = "pcr.seqs";
300     commands["create.database"]     = "create.database";
301     commands["make.biom"]           = "make.biom";
302     commands["get.coremicrobiome"]  = "get.coremicrobiome";
303     commands["list.otulabels"]      = "list.otulabels";
304     commands["get.otulabels"]       = "get.otulabels";
305     commands["remove.otulabels"]    = "remove.otulabels";
306     commands["make.contigs"]        = "make.contigs";
307     commands["load.logfile"]        = "load.logfile";
308     commands["make.table"]          = "make.table";
309     commands["sff.multiple"]        = "sff.multiple";
310         commands["quit"]                                = "MPIEnabled"; 
311     commands["classify.rf"]         = "classify.rf"; 
312     commands["filter.shared"]           = "filter.shared"; 
313     commands["primer.design"]           = "primer.design";
314     commands["get.dists"]           = "get.dists";
315     commands["remove.dists"]        = "remove.dists";
316     commands["merge.taxsummary"]    = "merge.taxsummary";
317     commands["get.communitytype"]   = "get.communitytype";
318     commands["sparcc"]              = "sparcc";
319     commands["make.lookup"]         = "make.lookup";
320     commands["rename.seqs"]         = "rename.seqs";
321     commands["make.lefse"]          = "make.lefse";
322     commands["lefse"]               = "lefse";
323     commands["kruskal.wallis"]      = "kruskal.wallis";
324     commands["sra"]                 = "sra";
325     commands["merge.sfffiles"]      = "merge.sfffiles";
326     
327
328 }
329 /***********************************************************/
330
331 /***********************************************************/
332 bool CommandFactory::MPIEnabled(string commandName) {
333         bool mpi = false;
334         it = commands.find(commandName);
335         if (it != commands.end()) { 
336                 if (it->second == "MPIEnabled") { return true; }
337         }
338         return mpi;
339 }
340 /***********************************************************/
341
342 /***********************************************************/
343 CommandFactory::~CommandFactory(){
344         _uniqueInstance = 0;
345         delete command;
346         delete shellcommand;
347         delete pipecommand;
348 }
349 /***********************************************************/
350
351 /***********************************************************/
352 int CommandFactory::checkForRedirects(string optionString) {
353     try {
354         
355         int pos = optionString.find("outputdir");
356         if (pos != string::npos) { //user has set outputdir in command option string
357             string outputOption = "";
358             bool foundEquals = false;
359             for(int i=pos;i<optionString.length();i++){
360                 if(optionString[i] == ',')       { break;               }               
361                 else if(optionString[i] == '=')  { foundEquals = true;  }
362                 if (foundEquals)       {   outputOption += optionString[i]; }
363             }
364             if(m->dirCheck(outputOption)){ 
365                 setOutputDirectory(outputOption); 
366                 m->mothurOut("Setting output directory to: " + outputOption); m->mothurOutEndLine();
367             }
368         }
369         
370         pos = optionString.find("inputdir");
371         if (pos != string::npos) { //user has set inputdir in command option string
372             string intputOption = "";
373             bool foundEquals = false;
374             for(int i=pos;i<optionString.length();i++){
375                 if(optionString[i] == ',')       { break;               }               
376                 else if(optionString[i] == '=')  { foundEquals = true;  }
377                 if (foundEquals)       {   intputOption += optionString[i]; }
378             }
379             if(m->dirCheck(intputOption)){ 
380                 setInputDirectory(intputOption); 
381                 m->mothurOut("Setting input directory to: " + intputOption); m->mothurOutEndLine();
382             }
383         }
384         
385         return 0;
386         }
387         catch(exception& e) {
388                 m->errorOut(e, "CommandFactory", "getCommand");
389                 exit(1);
390         }
391 }
392 /***********************************************************/
393
394 /***********************************************************/
395 //This function calls the appropriate command fucntions based on user input.
396 Command* CommandFactory::getCommand(string commandName, string optionString){
397         try {
398         
399                 delete command;   //delete the old command
400         
401         checkForRedirects(optionString);
402                         
403                 //user has opted to redirect output from dir where input files are located to some other place
404                 if (outputDir != "") { 
405                         if (optionString != "") { optionString += ", outputdir=" + outputDir; }
406                         else { optionString += "outputdir=" + outputDir; }
407                 }
408                 
409                 //user has opted to redirect input from dir where mothur.exe is located to some other place
410                 if (inputDir != "") { 
411                         if (optionString != "") { optionString += ", inputdir=" + inputDir; }
412                         else { optionString += "inputdir=" + inputDir; }
413                 }
414                 
415                 if(commandName == "cluster")                    {       command = new ClusterCommand(optionString);                                     }
416                 else if(commandName == "unique.seqs")                   {       command = new DeconvoluteCommand(optionString);                         }
417                 else if(commandName == "parsimony")                             {       command = new ParsimonyCommand(optionString);                           }
418                 else if(commandName == "help")                                  {       command = new HelpCommand(optionString);                                        }
419                 else if(commandName == "quit")                                  {       command = new QuitCommand(optionString);                                        }
420                 else if(commandName == "collect.single")                {       command = new CollectCommand(optionString);                                     }
421                 else if(commandName == "collect.shared")                {       command = new CollectSharedCommand(optionString);                       }
422                 else if(commandName == "rarefaction.single")    {       command = new RareFactCommand(optionString);                            }
423                 else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand(optionString);                      }
424                 else if(commandName == "summary.single")                {       command = new SummaryCommand(optionString);                                     }
425                 else if(commandName == "summary.shared")                {       command = new SummarySharedCommand(optionString);                       }
426                 else if(commandName == "unifrac.weighted")              {       command = new UnifracWeightedCommand(optionString);                     }
427                 else if(commandName == "unifrac.unweighted")    {       command = new UnifracUnweightedCommand(optionString);           }
428                 else if(commandName == "get.group")             {   command = new GetgroupCommand(optionString);                                }
429                 else if(commandName == "get.label")             {   command = new GetlabelCommand(optionString);                                }
430                 else if(commandName == "get.sabund")            {   command = new GetSAbundCommand(optionString);                               }
431                 else if(commandName == "get.rabund")            {   command = new GetRAbundCommand(optionString);                               }
432                 else if(commandName == "libshuff")              {   command = new LibShuffCommand(optionString);                                }
433                 else if(commandName == "heatmap.bin")                   {   command = new HeatMapCommand(optionString);                                 }
434                 else if(commandName == "heatmap.sim")                   {   command = new HeatMapSimCommand(optionString);                              }
435                 else if(commandName == "filter.seqs")                   {   command = new FilterSeqsCommand(optionString);                              }
436                 else if(commandName == "venn")                                  {   command = new VennCommand(optionString);                                    }
437                 else if(commandName == "bin.seqs")                              {   command = new BinSeqCommand(optionString);                                  }
438                 else if(commandName == "get.oturep")                    {   command = new GetOTURepCommand(optionString);                               }
439                 else if(commandName == "tree.shared")                   {   command = new TreeGroupCommand(optionString);                               }
440                 else if(commandName == "dist.shared")                   {   command = new MatrixOutputCommand(optionString);                    }
441                 else if(commandName == "dist.seqs")                             {   command = new DistanceCommand(optionString);                                }
442                 else if(commandName == "align.seqs")                    {   command = new AlignCommand(optionString);                                   }
443                 else if(commandName == "summary.seqs")                  {       command = new SeqSummaryCommand(optionString);                          }
444                 else if(commandName == "screen.seqs")                   {       command = new ScreenSeqsCommand(optionString);                          }
445                 else if(commandName == "reverse.seqs")                  {       command = new ReverseSeqsCommand(optionString);                         }
446                 else if(commandName == "trim.seqs")                             {       command = new TrimSeqsCommand(optionString);                            }
447                 else if(commandName == "trim.flows")                    {       command = new TrimFlowsCommand(optionString);                           }
448                 else if(commandName == "shhh.flows")                    {       command = new ShhherCommand(optionString);                                      }
449                 else if(commandName == "list.seqs")                             {       command = new ListSeqsCommand(optionString);                            }
450                 else if(commandName == "get.seqs")                              {       command = new GetSeqsCommand(optionString);                                     }
451                 else if(commandName == "remove.seqs")                   {       command = new RemoveSeqsCommand(optionString);                          }
452                 else if(commandName == "merge.files")                   {       command = new MergeFileCommand(optionString);                           }
453                 else if(commandName == "system")                                {       command = new SystemCommand(optionString);                                      }
454                 else if(commandName == "align.check")                   {       command = new AlignCheckCommand(optionString);                          }
455                 else if(commandName == "get.sharedseqs")                {       command = new GetSharedOTUCommand(optionString);                        }
456                 else if(commandName == "get.otulist")                   {       command = new GetListCountCommand(optionString);                        }
457                 else if(commandName == "hcluster")                              {       command = new HClusterCommand(optionString);                            }
458                 else if(commandName == "classify.seqs")                 {       command = new ClassifySeqsCommand(optionString);                        }
459                 else if(commandName == "chimera.ccode")                 {       command = new ChimeraCcodeCommand(optionString);                        }
460                 else if(commandName == "chimera.check")                 {       command = new ChimeraCheckCommand(optionString);                        }
461                 else if(commandName == "chimera.slayer")                {       command = new ChimeraSlayerCommand(optionString);                       }
462                 else if(commandName == "chimera.uchime")                {       command = new ChimeraUchimeCommand(optionString);                       }
463                 else if(commandName == "chimera.pintail")               {       command = new ChimeraPintailCommand(optionString);                      }
464                 else if(commandName == "chimera.bellerophon")   {       command = new ChimeraBellerophonCommand(optionString);          }
465                 else if(commandName == "phylotype")                             {       command = new PhylotypeCommand(optionString);                           }
466                 else if(commandName == "mgcluster")                             {       command = new MGClusterCommand(optionString);                           }
467                 else if(commandName == "pre.cluster")                   {       command = new PreClusterCommand(optionString);                          }
468                 else if(commandName == "pcoa")                                  {       command = new PCOACommand(optionString);                                        }
469                 else if(commandName == "pca")                                   {       command = new PCACommand(optionString);                                         }
470                 else if(commandName == "nmds")                                  {       command = new NMDSCommand(optionString);                                        }
471                 else if(commandName == "otu.hierarchy")                 {       command = new OtuHierarchyCommand(optionString);                        }
472                 else if(commandName == "set.dir")                               {       command = new SetDirectoryCommand(optionString);                        }
473                 else if(commandName == "set.logfile")                   {       command = new SetLogFileCommand(optionString);                          }
474                 else if(commandName == "parse.list")                    {       command = new ParseListCommand(optionString);                           }
475                 else if(commandName == "phylo.diversity")               {       command = new PhyloDiversityCommand(optionString);                      }
476                 else if(commandName == "make.group")                    {       command = new MakeGroupCommand(optionString);                           }
477                 else if(commandName == "chop.seqs")                             {       command = new ChopSeqsCommand(optionString);                            }
478                 else if(commandName == "clearcut")                              {       command = new ClearcutCommand(optionString);                            }
479                 else if(commandName == "catchall")                              {       command = new CatchAllCommand(optionString);                            }
480                 else if(commandName == "split.abund")                   {       command = new SplitAbundCommand(optionString);                          }
481                 else if(commandName == "cluster.split")                 {       command = new ClusterSplitCommand(optionString);                        }
482                 else if(commandName == "classify.otu")                  {       command = new ClassifyOtuCommand(optionString);                         }
483                 else if(commandName == "degap.seqs")                    {       command = new DegapSeqsCommand(optionString);                           }
484                 else if(commandName == "get.relabund")                  {       command = new GetRelAbundCommand(optionString);                         }
485                 else if(commandName == "sens.spec")                             {       command = new SensSpecCommand(optionString);                            }
486                 else if(commandName == "seq.error")                             {       command = new SeqErrorCommand(optionString);                            }
487                 else if(commandName == "sffinfo")                               {       command = new SffInfoCommand(optionString);                                     }
488                 else if(commandName == "normalize.shared")              {       command = new NormalizeSharedCommand(optionString);                     }
489                 else if(commandName == "metastats")                             {       command = new MetaStatsCommand(optionString);                           }
490                 else if(commandName == "split.groups")                  {       command = new SplitGroupCommand(optionString);                          }
491                 else if(commandName == "cluster.fragments")             {       command = new ClusterFragmentsCommand(optionString);            }
492                 else if(commandName == "get.lineage")                   {       command = new GetLineageCommand(optionString);                          }
493                 else if(commandName == "remove.lineage")                {       command = new RemoveLineageCommand(optionString);                       }
494                 else if(commandName == "get.groups")                    {       command = new GetGroupsCommand(optionString);                           }
495                 else if(commandName == "remove.groups")                 {       command = new RemoveGroupsCommand(optionString);                        }
496                 else if(commandName == "get.otus")                              {       command = new GetOtusCommand(optionString);                                     }
497                 else if(commandName == "remove.otus")                   {       command = new RemoveOtusCommand(optionString);                          }
498                 else if(commandName == "fastq.info")                    {       command = new ParseFastaQCommand(optionString);                         }
499                 else if(commandName == "pipeline.pds")                  {       command = new PipelineCommand(optionString);                            }
500                 else if(commandName == "deunique.seqs")                 {       command = new DeUniqueSeqsCommand(optionString);                        }
501                 else if(commandName == "pairwise.seqs")                 {       command = new PairwiseSeqsCommand(optionString);                        }
502                 else if(commandName == "cluster.classic")               {       command = new ClusterDoturCommand(optionString);                        }
503                 else if(commandName == "sub.sample")                    {       command = new SubSampleCommand(optionString);                           }
504                 else if(commandName == "indicator")                             {       command = new IndicatorCommand(optionString);                           }
505                 else if(commandName == "consensus.seqs")                {       command = new ConsensusSeqsCommand(optionString);                       }
506                 else if(commandName == "corr.axes")                             {       command = new CorrAxesCommand(optionString);                            }
507                 else if(commandName == "remove.rare")                   {       command = new RemoveRareCommand(optionString);                          }
508                 else if(commandName == "merge.groups")                  {       command = new MergeGroupsCommand(optionString);                         }
509                 else if(commandName == "amova")                                 {       command = new AmovaCommand(optionString);                                       }
510                 else if(commandName == "homova")                                {       command = new HomovaCommand(optionString);                                      }
511                 else if(commandName == "mantel")                                {       command = new MantelCommand(optionString);                                      }
512                 else if(commandName == "make.fastq")                    {       command = new MakeFastQCommand(optionString);                           }
513                 else if(commandName == "get.current")                   {       command = new GetCurrentCommand(optionString);                          }
514                 else if(commandName == "set.current")                   {       command = new SetCurrentCommand(optionString);                          }
515                 else if(commandName == "anosim")                                {       command = new AnosimCommand(optionString);                                      }
516                 else if(commandName == "make.shared")                   {       command = new SharedCommand(optionString);                                      }
517                 else if(commandName == "get.commandinfo")               {       command = new GetCommandInfoCommand(optionString);                      }
518                 else if(commandName == "deunique.tree")                 {       command = new DeuniqueTreeCommand(optionString);                        }
519                 else if((commandName == "count.seqs") || (commandName == "make.table"))                 {       command = new CountSeqsCommand(optionString);                           }
520                 else if(commandName == "count.groups")                  {       command = new CountGroupsCommand(optionString);                         }
521                 else if(commandName == "clear.memory")                  {       command = new ClearMemoryCommand(optionString);                         }
522                 else if(commandName == "summary.tax")                   {       command = new SummaryTaxCommand(optionString);                          }
523                 else if(commandName == "summary.qual")                  {       command = new SummaryQualCommand(optionString);                         }
524                 else if(commandName == "chimera.perseus")               {       command = new ChimeraPerseusCommand(optionString);                      }
525                 else if(commandName == "shhh.seqs")                             {       command = new ShhhSeqsCommand(optionString);                            }
526                 else if(commandName == "otu.association")               {       command = new OTUAssociationCommand(optionString);                      }
527         else if(commandName == "sort.seqs")             {       command = new SortSeqsCommand(optionString);                }
528         else if(commandName == "classify.tree")         {       command = new ClassifyTreeCommand(optionString);            }
529         else if(commandName == "cooccurrence")          {       command = new CooccurrenceCommand(optionString);            }
530         else if(commandName == "pcr.seqs")              {       command = new PcrSeqsCommand(optionString);                 }
531         else if(commandName == "create.database")       {       command = new CreateDatabaseCommand(optionString);          }
532         else if(commandName == "make.biom")             {       command = new MakeBiomCommand(optionString);                }
533         else if(commandName == "get.coremicrobiome")    {       command = new GetCoreMicroBiomeCommand(optionString);       }
534         else if(commandName == "list.otulabels")        {       command = new ListOtuLabelsCommand(optionString);           }
535         else if(commandName == "get.otulabels")         {       command = new GetOtuLabelsCommand(optionString);            }
536         else if(commandName == "remove.otulabels")      {       command = new RemoveOtuLabelsCommand(optionString);         }
537         else if(commandName == "make.contigs")          {       command = new MakeContigsCommand(optionString);             }
538         else if(commandName == "load.logfile")          {       command = new LoadLogfileCommand(optionString);             }
539         else if(commandName == "sff.multiple")          {       command = new SffMultipleCommand(optionString);             }
540         else if(commandName == "classify.rf")           {       command = new ClassifyRFSharedCommand(optionString);        }
541         else if(commandName == "filter.shared")         {       command = new FilterSharedCommand(optionString);            }
542         else if(commandName == "primer.design")         {       command = new PrimerDesignCommand(optionString);            }
543         else if(commandName == "get.dists")             {       command = new GetDistsCommand(optionString);                }
544         else if(commandName == "remove.dists")          {       command = new RemoveDistsCommand(optionString);             }
545         else if(commandName == "merge.taxsummary")      {       command = new MergeTaxSummaryCommand(optionString);         }
546         else if(commandName == "get.communitytype")     {       command = new GetMetaCommunityCommand(optionString);        }
547         else if(commandName == "sparcc")                {       command = new SparccCommand(optionString);                  }
548         else if(commandName == "make.lookup")                   {       command = new MakeLookupCommand(optionString);                          }
549         else if(commandName == "rename.seqs")                   {       command = new RenameSeqsCommand(optionString);                          }
550         else if(commandName == "make.lefse")                    {       command = new MakeLefseCommand(optionString);                           }
551         else if(commandName == "lefse")                 {       command = new LefseCommand(optionString);                   }
552         else if(commandName == "kruskal.wallis")        {       command = new KruskalWallisCommand(optionString);           }
553         else if(commandName == "sra")                   {       command = new SRACommand(optionString);                     }
554         else if(commandName == "merge.sfffiles")        {       command = new MergeSfffilesCommand(optionString);           }
555                 else                                                                                    {       command = new NoCommand(optionString);                                          }
556
557                 return command;
558         }
559         catch(exception& e) {
560                 m->errorOut(e, "CommandFactory", "getCommand");
561                 exit(1);
562         }
563 }
564 /***********************************************************/
565
566 /***********************************************************/
567 //This function calls the appropriate command fucntions based on user input.
568 Command* CommandFactory::getCommand(string commandName, string optionString, string mode){
569         try {
570                 delete pipecommand;   //delete the old command
571                 
572         checkForRedirects(optionString);
573         
574                 //user has opted to redirect output from dir where input files are located to some other place
575                 if (outputDir != "") { 
576                         if (optionString != "") { optionString += ", outputdir=" + outputDir; }
577                         else { optionString += "outputdir=" + outputDir; }
578                 }
579                 
580                 //user has opted to redirect input from dir where mothur.exe is located to some other place
581                 if (inputDir != "") { 
582                         if (optionString != "") { optionString += ", inputdir=" + inputDir; }
583                         else { optionString += "inputdir=" + inputDir; }
584                 }
585                 
586                 if(commandName == "cluster")                            {       pipecommand = new ClusterCommand(optionString);                                 }
587                 else if(commandName == "unique.seqs")                   {       pipecommand = new DeconvoluteCommand(optionString);                             }
588                 else if(commandName == "parsimony")                             {       pipecommand = new ParsimonyCommand(optionString);                               }
589                 else if(commandName == "help")                                  {       pipecommand = new HelpCommand(optionString);                                    }
590                 else if(commandName == "quit")                                  {       pipecommand = new QuitCommand(optionString);                                    }
591                 else if(commandName == "collect.single")                {       pipecommand = new CollectCommand(optionString);                                 }
592                 else if(commandName == "collect.shared")                {       pipecommand = new CollectSharedCommand(optionString);                   }
593                 else if(commandName == "rarefaction.single")    {       pipecommand = new RareFactCommand(optionString);                                }
594                 else if(commandName == "rarefaction.shared")    {       pipecommand = new RareFactSharedCommand(optionString);                  }
595                 else if(commandName == "summary.single")                {       pipecommand = new SummaryCommand(optionString);                                 }
596                 else if(commandName == "summary.shared")                {       pipecommand = new SummarySharedCommand(optionString);                   }
597                 else if(commandName == "unifrac.weighted")              {       pipecommand = new UnifracWeightedCommand(optionString);                 }
598                 else if(commandName == "unifrac.unweighted")    {       pipecommand = new UnifracUnweightedCommand(optionString);               }
599                 else if(commandName == "get.group")             {   pipecommand = new GetgroupCommand(optionString);                            }
600                 else if(commandName == "get.label")             {   pipecommand = new GetlabelCommand(optionString);                            }
601                 else if(commandName == "get.sabund")            {   pipecommand = new GetSAbundCommand(optionString);                           }
602                 else if(commandName == "get.rabund")            {   pipecommand = new GetRAbundCommand(optionString);                           }
603                 else if(commandName == "libshuff")              {   pipecommand = new LibShuffCommand(optionString);                            }
604                 else if(commandName == "heatmap.bin")                   {   pipecommand = new HeatMapCommand(optionString);                                     }
605                 else if(commandName == "heatmap.sim")                   {   pipecommand = new HeatMapSimCommand(optionString);                          }
606                 else if(commandName == "filter.seqs")                   {   pipecommand = new FilterSeqsCommand(optionString);                          }
607                 else if(commandName == "venn")                                  {   pipecommand = new VennCommand(optionString);                                        }
608                 else if(commandName == "bin.seqs")                              {   pipecommand = new BinSeqCommand(optionString);                                      }
609                 else if(commandName == "get.oturep")                    {   pipecommand = new GetOTURepCommand(optionString);                           }
610                 else if(commandName == "tree.shared")                   {   pipecommand = new TreeGroupCommand(optionString);                           }
611                 else if(commandName == "dist.shared")                   {   pipecommand = new MatrixOutputCommand(optionString);                        }
612                 else if(commandName == "dist.seqs")                             {   pipecommand = new DistanceCommand(optionString);                            }
613                 else if(commandName == "align.seqs")                    {   pipecommand = new AlignCommand(optionString);                                       }
614                 else if(commandName == "summary.seqs")                  {       pipecommand = new SeqSummaryCommand(optionString);                              }
615                 else if(commandName == "screen.seqs")                   {       pipecommand = new ScreenSeqsCommand(optionString);                              }
616                 else if(commandName == "reverse.seqs")                  {       pipecommand = new ReverseSeqsCommand(optionString);                             }
617                 else if(commandName == "trim.seqs")                             {       pipecommand = new TrimSeqsCommand(optionString);                                }
618                 else if(commandName == "trim.flows")                    {       pipecommand = new TrimFlowsCommand(optionString);                               }
619                 else if(commandName == "shhh.flows")                    {       pipecommand = new ShhherCommand(optionString);                                  }
620                 else if(commandName == "list.seqs")                             {       pipecommand = new ListSeqsCommand(optionString);                                }
621                 else if(commandName == "get.seqs")                              {       pipecommand = new GetSeqsCommand(optionString);                                 }
622                 else if(commandName == "remove.seqs")                   {       pipecommand = new RemoveSeqsCommand(optionString);                              }
623                 else if(commandName == "merge.files")                   {       pipecommand = new MergeFileCommand(optionString);                               }
624                 else if(commandName == "system")                                {       pipecommand = new SystemCommand(optionString);                                  }
625                 else if(commandName == "align.check")                   {       pipecommand = new AlignCheckCommand(optionString);                              }
626                 else if(commandName == "get.sharedseqs")                {       pipecommand = new GetSharedOTUCommand(optionString);                    }
627                 else if(commandName == "get.otulist")                   {       pipecommand = new GetListCountCommand(optionString);                    }
628                 else if(commandName == "hcluster")                              {       pipecommand = new HClusterCommand(optionString);                                }
629                 else if(commandName == "classify.seqs")                 {       pipecommand = new ClassifySeqsCommand(optionString);                    }
630                 else if(commandName == "chimera.ccode")                 {       pipecommand = new ChimeraCcodeCommand(optionString);                    }
631                 else if(commandName == "chimera.check")                 {       pipecommand = new ChimeraCheckCommand(optionString);                    }
632                 else if(commandName == "chimera.uchime")                {       pipecommand = new ChimeraUchimeCommand(optionString);                   }
633                 else if(commandName == "chimera.slayer")                {       pipecommand = new ChimeraSlayerCommand(optionString);                   }
634                 else if(commandName == "chimera.pintail")               {       pipecommand = new ChimeraPintailCommand(optionString);                  }
635                 else if(commandName == "chimera.bellerophon")   {       pipecommand = new ChimeraBellerophonCommand(optionString);              }
636                 else if(commandName == "phylotype")                             {       pipecommand = new PhylotypeCommand(optionString);                               }
637                 else if(commandName == "mgcluster")                             {       pipecommand = new MGClusterCommand(optionString);                               }
638                 else if(commandName == "pre.cluster")                   {       pipecommand = new PreClusterCommand(optionString);                              }
639                 else if(commandName == "pcoa")                                  {       pipecommand = new PCOACommand(optionString);                                    }
640                 else if(commandName == "pca")                                   {       pipecommand = new PCACommand(optionString);                                             }
641                 else if(commandName == "nmds")                                  {       pipecommand = new NMDSCommand(optionString);                                    }
642                 else if(commandName == "otu.hierarchy")                 {       pipecommand = new OtuHierarchyCommand(optionString);                    }
643                 else if(commandName == "set.dir")                               {       pipecommand = new SetDirectoryCommand(optionString);                    }
644                 else if(commandName == "set.logfile")                   {       pipecommand = new SetLogFileCommand(optionString);                              }
645                 else if(commandName == "parse.list")                    {       pipecommand = new ParseListCommand(optionString);                               }
646                 else if(commandName == "phylo.diversity")               {       pipecommand = new PhyloDiversityCommand(optionString);                  }
647                 else if(commandName == "make.group")                    {       pipecommand = new MakeGroupCommand(optionString);                               }
648                 else if(commandName == "chop.seqs")                             {       pipecommand = new ChopSeqsCommand(optionString);                                }
649                 else if(commandName == "clearcut")                              {       pipecommand = new ClearcutCommand(optionString);                                }
650                 else if(commandName == "catchall")                              {       pipecommand = new CatchAllCommand(optionString);                                }
651                 else if(commandName == "split.abund")                   {       pipecommand = new SplitAbundCommand(optionString);                              }
652                 else if(commandName == "cluster.split")                 {       pipecommand = new ClusterSplitCommand(optionString);                    }
653                 else if(commandName == "classify.otu")                  {       pipecommand = new ClassifyOtuCommand(optionString);                             }
654                 else if(commandName == "degap.seqs")                    {       pipecommand = new DegapSeqsCommand(optionString);                               }
655                 else if(commandName == "get.relabund")                  {       pipecommand = new GetRelAbundCommand(optionString);                             }
656                 else if(commandName == "sens.spec")                             {       pipecommand = new SensSpecCommand(optionString);                                }
657                 else if(commandName == "seq.error")                             {       pipecommand = new SeqErrorCommand(optionString);                                }
658                 else if(commandName == "sffinfo")                               {       pipecommand = new SffInfoCommand(optionString);                                 }
659                 else if(commandName == "normalize.shared")              {       pipecommand = new NormalizeSharedCommand(optionString);                 }
660                 else if(commandName == "metastats")                             {       pipecommand = new MetaStatsCommand(optionString);                               }
661                 else if(commandName == "split.groups")                  {       pipecommand = new SplitGroupCommand(optionString);                              }
662                 else if(commandName == "cluster.fragments")             {       pipecommand = new ClusterFragmentsCommand(optionString);                }
663                 else if(commandName == "get.lineage")                   {       pipecommand = new GetLineageCommand(optionString);                              }
664                 else if(commandName == "get.groups")                    {       pipecommand = new GetGroupsCommand(optionString);                               }
665                 else if(commandName == "remove.lineage")                {       pipecommand = new RemoveLineageCommand(optionString);                   }
666                 else if(commandName == "remove.groups")                 {       pipecommand = new RemoveGroupsCommand(optionString);                    }
667                 else if(commandName == "get.otus")                              {       pipecommand = new GetOtusCommand(optionString);                                 }
668                 else if(commandName == "remove.otus")                   {       pipecommand = new RemoveOtusCommand(optionString);                              }
669                 else if(commandName == "fastq.info")                    {       pipecommand = new ParseFastaQCommand(optionString);                             }
670                 else if(commandName == "deunique.seqs")                 {       pipecommand = new DeUniqueSeqsCommand(optionString);                    }
671                 else if(commandName == "pairwise.seqs")                 {       pipecommand = new PairwiseSeqsCommand(optionString);                    }
672                 else if(commandName == "cluster.classic")               {       pipecommand = new ClusterDoturCommand(optionString);                    }
673                 else if(commandName == "sub.sample")                    {       pipecommand = new SubSampleCommand(optionString);                               }
674                 else if(commandName == "indicator")                             {       pipecommand = new IndicatorCommand(optionString);                               }
675                 else if(commandName == "consensus.seqs")                {       pipecommand = new ConsensusSeqsCommand(optionString);                   }
676                 else if(commandName == "corr.axes")                             {       pipecommand = new CorrAxesCommand(optionString);                                }
677                 else if(commandName == "remove.rare")                   {       pipecommand = new RemoveRareCommand(optionString);                              }
678                 else if(commandName == "merge.groups")                  {       pipecommand = new MergeGroupsCommand(optionString);                             }
679                 else if(commandName == "amova")                                 {       pipecommand = new AmovaCommand(optionString);                                   }
680                 else if(commandName == "homova")                                {       pipecommand = new HomovaCommand(optionString);                                  }
681                 else if(commandName == "mantel")                                {       pipecommand = new MantelCommand(optionString);                                  }
682                 else if(commandName == "anosim")                                {       pipecommand = new AnosimCommand(optionString);                                  }
683                 else if(commandName == "make.fastq")                    {       pipecommand = new MakeFastQCommand(optionString);                               }
684                 else if(commandName == "get.current")                   {       pipecommand = new GetCurrentCommand(optionString);                              }
685                 else if(commandName == "set.current")                   {       pipecommand = new SetCurrentCommand(optionString);                              }
686                 else if(commandName == "make.shared")                   {       pipecommand = new SharedCommand(optionString);                                  }
687                 else if(commandName == "get.commandinfo")               {       pipecommand = new GetCommandInfoCommand(optionString);                  }
688                 else if(commandName == "deunique.tree")                 {       pipecommand = new DeuniqueTreeCommand(optionString);                    }
689                 else if((commandName == "count.seqs") || (commandName == "make.table"))                 {       pipecommand = new CountSeqsCommand(optionString);                               }
690                 else if(commandName == "count.groups")                  {       pipecommand = new CountGroupsCommand(optionString);                             }
691                 else if(commandName == "clear.memory")                  {       pipecommand = new ClearMemoryCommand(optionString);                             }
692                 else if(commandName == "summary.tax")                   {       pipecommand = new SummaryTaxCommand(optionString);                              }
693                 else if(commandName == "summary.qual")                  {       pipecommand = new SummaryQualCommand(optionString);                             }
694                 else if(commandName == "chimera.perseus")               {       pipecommand = new ChimeraPerseusCommand(optionString);                  }
695                 else if(commandName == "shhh.seqs")                             {       pipecommand = new ShhhSeqsCommand(optionString);                                }
696                 else if(commandName == "otu.association")               {       pipecommand = new OTUAssociationCommand(optionString);                  }
697         else if(commandName == "sort.seqs")             {       pipecommand = new SortSeqsCommand(optionString);                }
698         else if(commandName == "classify.tree")         {       pipecommand = new ClassifyTreeCommand(optionString);            }
699         else if(commandName == "cooccurrence")          {       pipecommand = new CooccurrenceCommand(optionString);            }
700         else if(commandName == "pcr.seqs")              {       pipecommand = new PcrSeqsCommand(optionString);                 }
701         else if(commandName == "create.database")       {       pipecommand = new CreateDatabaseCommand(optionString);          }
702         else if(commandName == "make.biom")             {       pipecommand = new MakeBiomCommand(optionString);                }
703         else if(commandName == "get.coremicrobiome")    {       pipecommand = new GetCoreMicroBiomeCommand(optionString);       }
704         else if(commandName == "list.otulabels")        {       pipecommand = new ListOtuLabelsCommand(optionString);           }
705         else if(commandName == "get.otulabels")         {       pipecommand = new GetOtuLabelsCommand(optionString);            }
706         else if(commandName == "remove.otulabels")      {       pipecommand = new RemoveOtuLabelsCommand(optionString);         }
707         else if(commandName == "make.contigs")          {       pipecommand = new MakeContigsCommand(optionString);             }
708         else if(commandName == "load.logfile")          {       pipecommand = new LoadLogfileCommand(optionString);             }
709         else if(commandName == "sff.multiple")          {       pipecommand = new SffMultipleCommand(optionString);             }
710         else if(commandName == "classify.rf")           {       pipecommand = new ClassifyRFSharedCommand(optionString);        }
711         else if(commandName == "filter.shared")         {       pipecommand = new FilterSharedCommand(optionString);            }
712         else if(commandName == "primer.design")         {       pipecommand = new PrimerDesignCommand(optionString);            }
713         else if(commandName == "get.dists")             {       pipecommand = new GetDistsCommand(optionString);                }
714         else if(commandName == "remove.dists")          {       pipecommand = new RemoveDistsCommand(optionString);             }
715         else if(commandName == "merge.taxsummary")      {       pipecommand = new MergeTaxSummaryCommand(optionString);         }
716         else if(commandName == "get.communitytype")     {       pipecommand = new GetMetaCommunityCommand(optionString);        }
717         else if(commandName == "sparcc")                {       pipecommand = new SparccCommand(optionString);                  }
718         else if(commandName == "make.lookup")                   {       pipecommand = new MakeLookupCommand(optionString);                              }
719         else if(commandName == "rename.seqs")                   {       pipecommand = new RenameSeqsCommand(optionString);                              }
720         else if(commandName == "make.lefse")                    {       pipecommand = new MakeLefseCommand(optionString);                               }
721         else if(commandName == "lefse")                 {       pipecommand = new LefseCommand(optionString);                   }
722         else if(commandName == "kruskal.wallis")        {       pipecommand = new KruskalWallisCommand(optionString);           }
723         else if(commandName == "sra")                   {       pipecommand = new SRACommand(optionString);                     }
724         else if(commandName == "merge.sfffiles")        {       pipecommand = new MergeSfffilesCommand(optionString);           }
725                 else                                                                                    {       pipecommand = new NoCommand(optionString);                                              }
726
727                 return pipecommand;
728         }
729         catch(exception& e) {
730                 m->errorOut(e, "CommandFactory", "getCommand");
731                 exit(1);
732         }
733 }
734 /***********************************************************/
735
736 /***********************************************************/
737 //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
738 Command* CommandFactory::getCommand(string commandName){
739         try {
740                 delete shellcommand;   //delete the old command
741                 
742                 if(commandName == "cluster")                            {       shellcommand = new ClusterCommand();                            }
743                 else if(commandName == "unique.seqs")                   {       shellcommand = new DeconvoluteCommand();                        }
744                 else if(commandName == "parsimony")                             {       shellcommand = new ParsimonyCommand();                          }
745                 else if(commandName == "help")                                  {       shellcommand = new HelpCommand();                                       }
746                 else if(commandName == "quit")                                  {       shellcommand = new QuitCommand();                                       }
747                 else if(commandName == "collect.single")                {       shellcommand = new CollectCommand();                            }
748                 else if(commandName == "collect.shared")                {       shellcommand = new CollectSharedCommand();                      }
749                 else if(commandName == "rarefaction.single")    {       shellcommand = new RareFactCommand();                           }
750                 else if(commandName == "rarefaction.shared")    {       shellcommand = new RareFactSharedCommand();                     }
751                 else if(commandName == "summary.single")                {       shellcommand = new SummaryCommand();                            }
752                 else if(commandName == "summary.shared")                {       shellcommand = new SummarySharedCommand();                      }
753                 else if(commandName == "unifrac.weighted")              {       shellcommand = new UnifracWeightedCommand();            }
754                 else if(commandName == "unifrac.unweighted")    {       shellcommand = new UnifracUnweightedCommand();          }
755                 else if(commandName == "get.group")             {   shellcommand = new GetgroupCommand();                               }
756                 else if(commandName == "get.label")             {   shellcommand = new GetlabelCommand();                               }
757                 else if(commandName == "get.sabund")            {   shellcommand = new GetSAbundCommand();                              }
758                 else if(commandName == "get.rabund")            {   shellcommand = new GetRAbundCommand();                              }
759                 else if(commandName == "libshuff")              {   shellcommand = new LibShuffCommand();                               }
760                 else if(commandName == "heatmap.bin")                   {   shellcommand = new HeatMapCommand();                                }
761                 else if(commandName == "heatmap.sim")                   {   shellcommand = new HeatMapSimCommand();                             }
762                 else if(commandName == "filter.seqs")                   {   shellcommand = new FilterSeqsCommand();                             }
763                 else if(commandName == "venn")                                  {   shellcommand = new VennCommand();                                   }
764                 else if(commandName == "bin.seqs")                              {   shellcommand = new BinSeqCommand();                                 }
765                 else if(commandName == "get.oturep")                    {   shellcommand = new GetOTURepCommand();                              }
766                 else if(commandName == "tree.shared")                   {   shellcommand = new TreeGroupCommand();                              }
767                 else if(commandName == "dist.shared")                   {   shellcommand = new MatrixOutputCommand();                   }
768                 else if(commandName == "dist.seqs")                             {   shellcommand = new DistanceCommand();                               }
769                 else if(commandName == "align.seqs")                    {   shellcommand = new AlignCommand();                                  }
770                 else if(commandName == "summary.seqs")                  {       shellcommand = new SeqSummaryCommand();                         }
771                 else if(commandName == "screen.seqs")                   {       shellcommand = new ScreenSeqsCommand();                         }
772                 else if(commandName == "reverse.seqs")                  {       shellcommand = new ReverseSeqsCommand();                        }
773                 else if(commandName == "trim.seqs")                             {       shellcommand = new TrimSeqsCommand();                           }
774                 else if(commandName == "trim.flows")                    {       shellcommand = new TrimFlowsCommand();                          }
775                 else if(commandName == "shhh.flows")                    {       shellcommand = new ShhherCommand();                                     }
776                 else if(commandName == "list.seqs")                             {       shellcommand = new ListSeqsCommand();                           }
777                 else if(commandName == "get.seqs")                              {       shellcommand = new GetSeqsCommand();                            }
778                 else if(commandName == "remove.seqs")                   {       shellcommand = new RemoveSeqsCommand();                         }
779                 else if(commandName == "merge.files")                   {       shellcommand = new MergeFileCommand();                          }
780                 else if(commandName == "system")                                {       shellcommand = new SystemCommand();                                     }
781                 else if(commandName == "align.check")                   {       shellcommand = new AlignCheckCommand();                         }
782                 else if(commandName == "get.sharedseqs")                {       shellcommand = new GetSharedOTUCommand();                       }
783                 else if(commandName == "get.otulist")                   {       shellcommand = new GetListCountCommand();                       }
784                 else if(commandName == "hcluster")                              {       shellcommand = new HClusterCommand();                           }
785                 else if(commandName == "classify.seqs")                 {       shellcommand = new ClassifySeqsCommand();                       }
786                 else if(commandName == "chimera.ccode")                 {       shellcommand = new ChimeraCcodeCommand();                       }
787                 else if(commandName == "chimera.check")                 {       shellcommand = new ChimeraCheckCommand();                       }
788                 else if(commandName == "chimera.slayer")                {       shellcommand = new ChimeraSlayerCommand();                      }
789                 else if(commandName == "chimera.uchime")                {       shellcommand = new ChimeraUchimeCommand();                      }
790                 else if(commandName == "chimera.pintail")               {       shellcommand = new ChimeraPintailCommand();                     }
791                 else if(commandName == "chimera.bellerophon")   {       shellcommand = new ChimeraBellerophonCommand();         }
792                 else if(commandName == "phylotype")                             {       shellcommand = new PhylotypeCommand();                          }
793                 else if(commandName == "mgcluster")                             {       shellcommand = new MGClusterCommand();                          }
794                 else if(commandName == "pre.cluster")                   {       shellcommand = new PreClusterCommand();                         }
795                 else if(commandName == "pcoa")                                  {       shellcommand = new PCOACommand();                                       }
796                 else if(commandName == "pca")                                   {       shellcommand = new PCACommand();                                        }
797                 else if(commandName == "nmds")                                  {       shellcommand = new NMDSCommand();                                       }
798                 else if(commandName == "otu.hierarchy")                 {       shellcommand = new OtuHierarchyCommand();                       }
799                 else if(commandName == "set.dir")                               {       shellcommand = new SetDirectoryCommand();                       }
800                 else if(commandName == "set.logfile")                   {       shellcommand = new SetLogFileCommand();                         }
801                 else if(commandName == "parse.list")                    {       shellcommand = new ParseListCommand();                          }
802                 else if(commandName == "phylo.diversity")               {       shellcommand = new PhyloDiversityCommand();                     }
803                 else if(commandName == "make.group")                    {       shellcommand = new MakeGroupCommand();                          }
804                 else if(commandName == "chop.seqs")                             {       shellcommand = new ChopSeqsCommand();                           }
805                 else if(commandName == "clearcut")                              {       shellcommand = new ClearcutCommand();                           }
806                 else if(commandName == "catchall")                              {       shellcommand = new CatchAllCommand();                           }
807                 else if(commandName == "split.abund")                   {       shellcommand = new SplitAbundCommand();                         }
808                 else if(commandName == "cluster.split")                 {       shellcommand = new ClusterSplitCommand();                       }
809                 else if(commandName == "classify.otu")                  {       shellcommand = new ClassifyOtuCommand();                        }
810                 else if(commandName == "degap.seqs")                    {       shellcommand = new DegapSeqsCommand();                          }
811                 else if(commandName == "get.relabund")                  {       shellcommand = new GetRelAbundCommand();                        }
812                 else if(commandName == "sens.spec")                             {       shellcommand = new SensSpecCommand();                           }
813                 else if(commandName == "seq.error")                             {       shellcommand = new SeqErrorCommand();                           }
814                 else if(commandName == "sffinfo")                               {       shellcommand = new SffInfoCommand();                            }
815                 else if(commandName == "normalize.shared")              {       shellcommand = new NormalizeSharedCommand();            }
816                 else if(commandName == "metastats")                             {       shellcommand = new MetaStatsCommand();                          }
817                 else if(commandName == "split.groups")                  {       shellcommand = new SplitGroupCommand();                         }
818                 else if(commandName == "cluster.fragments")             {       shellcommand = new ClusterFragmentsCommand();           }
819                 else if(commandName == "get.lineage")                   {       shellcommand = new GetLineageCommand();                         }
820                 else if(commandName == "remove.lineage")                {       shellcommand = new RemoveLineageCommand();                      }
821                 else if(commandName == "get.groups")                    {       shellcommand = new GetGroupsCommand();                          }
822                 else if(commandName == "remove.groups")                 {       shellcommand = new RemoveGroupsCommand();                       }
823                 else if(commandName == "get.otus")                              {       shellcommand = new GetOtusCommand();                            }
824                 else if(commandName == "remove.otus")                   {       shellcommand = new RemoveOtusCommand();                         }
825                 else if(commandName == "fastq.info")                    {       shellcommand = new ParseFastaQCommand();                        }
826                 else if(commandName == "deunique.seqs")                 {       shellcommand = new DeUniqueSeqsCommand();                       }
827                 else if(commandName == "pairwise.seqs")                 {       shellcommand = new PairwiseSeqsCommand();                       }
828                 else if(commandName == "cluster.classic")               {       shellcommand = new ClusterDoturCommand();                       }
829                 else if(commandName == "sub.sample")                    {       shellcommand = new SubSampleCommand();                          }
830                 else if(commandName == "indicator")                             {       shellcommand = new IndicatorCommand();                          }
831                 else if(commandName == "consensus.seqs")                {       shellcommand = new ConsensusSeqsCommand();                      }
832                 else if(commandName == "corr.axes")                             {       shellcommand = new CorrAxesCommand();                           }
833                 else if(commandName == "remove.rare")                   {       shellcommand = new RemoveRareCommand();                         }
834                 else if(commandName == "merge.groups")                  {       shellcommand = new MergeGroupsCommand();                        }
835                 else if(commandName == "amova")                                 {       shellcommand = new AmovaCommand();                                      }
836                 else if(commandName == "homova")                                {       shellcommand = new HomovaCommand();                                     }
837                 else if(commandName == "mantel")                                {       shellcommand = new MantelCommand();                                     }
838                 else if(commandName == "anosim")                                {       shellcommand = new AnosimCommand();                                     }
839                 else if(commandName == "make.fastq")                    {       shellcommand = new MakeFastQCommand();                          }
840                 else if(commandName == "get.current")                   {       shellcommand = new GetCurrentCommand();                         }
841                 else if(commandName == "set.current")                   {       shellcommand = new SetCurrentCommand();                         }
842                 else if(commandName == "make.shared")                   {       shellcommand = new SharedCommand();                                     }
843                 else if(commandName == "get.commandinfo")               {       shellcommand = new GetCommandInfoCommand();                     }
844                 else if(commandName == "deunique.tree")                 {       shellcommand = new DeuniqueTreeCommand();                       }
845                 else if((commandName == "count.seqs") || (commandName == "make.table"))                 {       shellcommand = new CountSeqsCommand();                          }
846                 else if(commandName == "count.groups")                  {       shellcommand = new CountGroupsCommand();                        }
847                 else if(commandName == "clear.memory")                  {       shellcommand = new ClearMemoryCommand();                        }
848                 else if(commandName == "summary.tax")                   {       shellcommand = new SummaryTaxCommand();                         }
849                 else if(commandName == "summary.qual")                  {       shellcommand = new SummaryQualCommand();                        }
850                 else if(commandName == "chimera.perseus")               {       shellcommand = new ChimeraPerseusCommand();                     }
851                 else if(commandName == "shhh.seqs")                             {       shellcommand = new ShhhSeqsCommand();                           }
852                 else if(commandName == "otu.association")               {       shellcommand = new OTUAssociationCommand();                     }
853         else if(commandName == "sort.seqs")             {       shellcommand = new SortSeqsCommand();               }
854         else if(commandName == "classify.tree")         {       shellcommand = new ClassifyTreeCommand();           }
855         else if(commandName == "cooccurrence")          {       shellcommand = new CooccurrenceCommand();           }
856         else if(commandName == "pcr.seqs")              {       shellcommand = new PcrSeqsCommand();                }
857         else if(commandName == "create.database")       {       shellcommand = new CreateDatabaseCommand();         }
858         else if(commandName == "make.biom")             {       shellcommand = new MakeBiomCommand();               }
859         else if(commandName == "get.coremicrobiome")    {       shellcommand = new GetCoreMicroBiomeCommand();      }
860         else if(commandName == "list.otulabels")        {       shellcommand = new ListOtuLabelsCommand();          }
861         else if(commandName == "get.otulabels")         {       shellcommand = new GetOtuLabelsCommand();           }
862         else if(commandName == "remove.otulabels")      {       shellcommand = new RemoveOtuLabelsCommand();        }
863         else if(commandName == "make.contigs")          {       shellcommand = new MakeContigsCommand();            }
864         else if(commandName == "load.logfile")          {       shellcommand = new LoadLogfileCommand();            }
865         else if(commandName == "sff.multiple")          {       shellcommand = new SffMultipleCommand();            }
866         else if(commandName == "classify.rf")           {       shellcommand = new ClassifyRFSharedCommand();       }
867         else if(commandName == "filter.shared")         {       shellcommand = new FilterSharedCommand();           }
868         else if(commandName == "primer.design")         {       shellcommand = new PrimerDesignCommand();           }
869         else if(commandName == "get.dists")             {       shellcommand = new GetDistsCommand();               }
870         else if(commandName == "remove.dists")          {       shellcommand = new RemoveDistsCommand();            }
871         else if(commandName == "merge.taxsummary")      {       shellcommand = new MergeTaxSummaryCommand();        }
872         else if(commandName == "get.communitytype")     {       shellcommand = new GetMetaCommunityCommand();       }
873         else if(commandName == "sparcc")                {       shellcommand = new SparccCommand();                 }
874         else if(commandName == "make.lookup")                   {       shellcommand = new MakeLookupCommand();                         }
875         else if(commandName == "rename.seqs")                   {       shellcommand = new RenameSeqsCommand();                         }
876         else if(commandName == "make.lefse")                    {       shellcommand = new MakeLefseCommand();                          }
877         else if(commandName == "lefse")                 {       shellcommand = new LefseCommand();                  }
878         else if(commandName == "kruskal.wallis")        {       shellcommand = new KruskalWallisCommand();          }
879         else if(commandName == "sra")                   {       shellcommand = new SRACommand();                    }
880         else if(commandName == "merge.sfffiles")        {       shellcommand = new MergeSfffilesCommand();          }
881                 else                                                                                    {       shellcommand = new NoCommand();                                         }
882
883                 return shellcommand;
884         }
885         catch(exception& e) {
886                 m->errorOut(e, "CommandFactory", "getCommand");
887                 exit(1);
888         }
889 }
890 /***********************************************************
891 //This function is used to interrupt a command
892 Command* CommandFactory::getCommand(){
893         try {
894                 delete command;   //delete the old command
895
896                 string s = "";
897             command = new NoCommand(s);
898         
899                 return command;
900         }
901         catch(exception& e) {
902                 m->errorOut(e, "CommandFactory", "getCommand");
903                 exit(1);
904         }
905 }
906 ***********************************************************************/
907 bool CommandFactory::isValidCommand(string command) {
908         try {   
909         
910                 //is the command in the map
911                 if ((commands.find(command)) != (commands.end())) {
912                         return true;
913                 }else{
914                         m->mothurOut(command + " is not a valid command in Mothur.  Valid commands are ");
915                         for (it = commands.begin(); it != commands.end(); it++) {
916                                 m->mothurOut(it->first + ", ");
917                         }
918                         m->mothurOutEndLine();
919                         return false;
920                 }
921                 
922         }
923         catch(exception& e) {
924                 m->errorOut(e, "CommandFactory", "isValidCommand");
925                 exit(1);
926         }
927 }
928 /***********************************************************************/
929 bool CommandFactory::isValidCommand(string command, string noError) {
930         try {   
931         
932                 //is the command in the map
933                 if ((commands.find(command)) != (commands.end())) {
934                         return true;
935                 }else{
936                         return false;
937                 }
938                 
939         }
940         catch(exception& e) {
941                 m->errorOut(e, "CommandFactory", "isValidCommand");
942                 exit(1);
943         }
944 }
945 /***********************************************************************/
946 void CommandFactory::printCommands(ostream& out) {
947         try {   
948                 out << "Valid commands are: ";
949                 for (it = commands.begin(); it != commands.end(); it++) {
950                         out << it->first << ",";
951                 }
952                 out << endl;
953         }
954         catch(exception& e) {
955                 m->errorOut(e, "CommandFactory", "printCommands");
956                 exit(1);
957         }
958 }
959 /***********************************************************************/
960 void CommandFactory::printCommandsCategories(ostream& out) {
961     try {
962         map<string, string> commands = getListCommands();
963         map<string, string>::iterator it;
964
965         map<string, string> categories;
966         map<string, string>::iterator itCat;
967         //loop through each command outputting info
968         for (it = commands.begin(); it != commands.end(); it++) {
969     
970             Command* thisCommand = getCommand(it->first);
971     
972             //don't add hidden commands
973             if (thisCommand->getCommandCategory() != "Hidden") {
974                 itCat = categories.find(thisCommand->getCommandCategory());
975                 if (itCat == categories.end()) {
976                     categories[thisCommand->getCommandCategory()] = thisCommand->getCommandName();
977                 }else {
978                     categories[thisCommand->getCommandCategory()] += ", " + thisCommand->getCommandName();
979                 }
980             }
981         }
982         
983         for (itCat = categories.begin(); itCat != categories.end(); itCat++) {
984             out << itCat->first << " commmands include: " << itCat->second << endl;
985         }
986
987     }
988         catch(exception& e) {
989                 m->errorOut(e, "CommandFactory", "printCommandsCategories");
990                 exit(1);
991         }
992 }      
993
994 /***********************************************************************/
995
996
997
998