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