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