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