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