]> git.donarmstrong.com Git - mothur.git/blob - commandfactory.cpp
a3858639a1f78d633e9c1537054978bac4e4d499
[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 "getlinecommand.h"
20 #include "rarefactcommand.h"
21 #include "summarycommand.h"
22 #include "summarysharedcommand.h"
23 #include "rarefactsharedcommand.h"
24 #include "quitcommand.h"
25 #include "helpcommand.h"
26 #include "commandfactory.hpp"
27 #include "deconvolutecommand.h"
28 #include "parsimonycommand.h"
29 #include "unifracunweightedcommand.h"
30 #include "unifracweightedcommand.h"
31 #include "libshuffcommand.h"
32 #include "heatmapcommand.h"
33 #include "heatmapsimcommand.h"
34 #include "filterseqscommand.h"
35 #include "venncommand.h"
36 #include "nocommands.h"
37 #include "binsequencecommand.h"
38 #include "getoturepcommand.h"
39 #include "treegroupscommand.h"
40 #include "bootstrapsharedcommand.h"
41 //#include "consensuscommand.h"
42 #include "distancecommand.h"
43 #include "aligncommand.h"
44 #include "matrixoutputcommand.h"
45 #include "getsabundcommand.h"
46 #include "getrabundcommand.h"
47 #include "seqsummarycommand.h"
48 #include "screenseqscommand.h"
49 #include "reversecommand.h"
50 #include "trimseqscommand.h"
51 #include "mergefilecommand.h"
52 #include "chimeraseqscommand.h"
53 #include "listseqscommand.h"
54 #include "getseqscommand.h"
55 #include "removeseqscommand.h"
56 #include "systemcommand.h"
57 #include "secondarystructurecommand.h"
58 #include "getsharedotucommand.h"
59 #include "getlistcountcommand.h"
60 #include "hclustercommand.h"
61 #include "classifyseqscommand.h"
62 #include "phylotypecommand.h"
63
64 /***********************************************************/
65
66 /***********************************************************/
67 CommandFactory::CommandFactory(){
68         string s = "";
69         command = new NoCommand(s);
70         
71         
72         //initialize list of valid commands
73         commands["read.dist"]                   = "read.dist"; 
74         commands["read.otu"]                    = "read.otu";
75         commands["read.tree"]                   = "read.tree"; 
76         commands["bin.seqs"]                    = "bin.seqs"; 
77         commands["get.oturep"]                  = "get.oturep";
78         commands["cluster"]                             = "cluster"; 
79         commands["unique.seqs"]                 = "unique.seqs"; 
80         commands["dist.seqs"]                   = "dist.seqs";
81         commands["dist.shared"]                 = "dist.shared";
82         commands["collect.single"]              = "collect.single"; 
83         commands["collect.shared"]              = "collect.shared"; 
84         commands["rarefaction.single"]  = "rarefaction.single"; 
85         commands["rarefaction.shared"]  = "rarefaction.shared"; 
86         commands["summary.single"]              = "summary.single"; 
87         commands["summary.shared"]              = "summary.shared"; 
88         commands["parsimony"]                   = "parsimony";
89         commands["unifrac.weighted"]    = "unifrac.weighted"; 
90         commands["unifrac.unweighted"]  = "unifrac.unweighted"; 
91         commands["libshuff"]                    = "libshuff";
92         commands["tree.shared"]                 = "tree.shared";
93         commands["heatmap.bin"]                 = "heatmap.bin";
94         commands["heatmap.sim"]                 = "heatmap.sim";
95         commands["venn"]                                = "venn";
96         commands["get.group"]           = "get.group";
97         commands["get.label"]           = "get.label";
98         commands["get.line"]            = "get.line";
99         commands["get.sabund"]          = "get.sabund";
100         commands["get.rabund"]          = "get.rabund";
101         commands["bootstrap.shared"]    = "bootstrap.shared";
102         //commands["consensus"]                 = "consensus";
103         commands["help"]                                = "help"; 
104         commands["filter.seqs"]                 = "filter.seqs";
105         commands["align.seqs"]                  = "align.seqs";
106         commands["summary.seqs"]                = "summary.seqs";
107         commands["screen.seqs"]                 = "screen.seqs";
108         commands["reverse.seqs"]                = "reverse.seqs";
109         commands["trim.seqs"]                   = "trim.seqs";
110         commands["chimera.seqs"]                = "chimera.seqs";
111         commands["list.seqs"]                   = "list.seqs";
112         commands["get.seqs"]                    = "get.seqs";
113         commands["remove.seqs"]                 = "get.seqs";
114         commands["system"]                              = "system";
115         commands["align.check"]                 = "align.check";
116         commands["get.sharedseqs"]              = "get.sharedseqs";
117         commands["get.otulist"]                 = "get.otulist";
118         commands["quit"]                                = "quit"; 
119         commands["hcluster"]                    = "hcluster"; 
120         commands["classify.seqs"]               = "classify.seqs"; 
121         commands["phylotype"]                   = "phylotype";
122
123 }
124 /***********************************************************/
125
126 /***********************************************************/
127 CommandFactory::~CommandFactory(){
128         delete command;
129 }
130
131 /***********************************************************/
132
133 /***********************************************************/
134 //This function calls the appropriate command fucntions based on user input.
135 Command* CommandFactory::getCommand(string commandName, string optionString){
136         try {
137                 delete command;   //delete the old command
138
139                 if(commandName == "read.dist")                                  {       command = new ReadDistCommand(optionString);                    }
140                 else if(commandName == "read.otu")                              {       command = new ReadOtuCommand(optionString);                             }
141                 else if(commandName == "read.tree")                             {       command = new ReadTreeCommand(optionString);                    }
142                 else if(commandName == "cluster")                               {       command = new ClusterCommand(optionString);                             }
143                 else if(commandName == "unique.seqs")                   {       command = new DeconvoluteCommand(optionString);                 }
144                 else if(commandName == "parsimony")                             {       command = new ParsimonyCommand(optionString);                   }
145                 else if(commandName == "help")                                  {       command = new HelpCommand(optionString);                                }
146                 else if(commandName == "quit")                                  {       command = new QuitCommand(optionString);                                }
147                 else if(commandName == "collect.single")                {       command = new CollectCommand(optionString);                             }
148                 else if(commandName == "collect.shared")                {       command = new CollectSharedCommand(optionString);               }
149                 else if(commandName == "rarefaction.single")    {       command = new RareFactCommand(optionString);                    }
150                 else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand(optionString);              }
151                 else if(commandName == "summary.single")                {       command = new SummaryCommand(optionString);                             }
152                 else if(commandName == "summary.shared")                {       command = new SummarySharedCommand(optionString);               }
153                 else if(commandName == "unifrac.weighted")              {       command = new UnifracWeightedCommand(optionString);             }
154                 else if(commandName == "unifrac.unweighted")    {       command = new UnifracUnweightedCommand(optionString);   }
155                 else if(commandName == "get.group")             {   command = new GetgroupCommand(optionString);                        }
156                 else if(commandName == "get.label")             {   command = new GetlabelCommand(optionString);                        }
157                 else if(commandName == "get.line")              {   command = new GetlineCommand(optionString);                         }
158                 else if(commandName == "get.sabund")            {   command = new GetSAbundCommand(optionString);                       }
159                 else if(commandName == "get.rabund")            {   command = new GetRAbundCommand(optionString);                       }
160                 else if(commandName == "libshuff")              {   command = new LibShuffCommand(optionString);                        }
161                 else if(commandName == "heatmap.bin")                   {   command = new HeatMapCommand(optionString);                         }
162                 else if(commandName == "heatmap.sim")                   {   command = new HeatMapSimCommand(optionString);                      }
163                 else if(commandName == "filter.seqs")                   {   command = new FilterSeqsCommand(optionString);                      }
164                 else if(commandName == "venn")                                  {   command = new VennCommand(optionString);                            }
165                 else if(commandName == "bin.seqs")                              {   command = new BinSeqCommand(optionString);                          }
166                 else if(commandName == "get.oturep")                    {   command = new GetOTURepCommand(optionString);                       }
167                 else if(commandName == "tree.shared")                   {   command = new TreeGroupCommand(optionString);                       }
168                 else if(commandName == "dist.shared")                   {   command = new MatrixOutputCommand(optionString);            }
169                 else if(commandName == "bootstrap.shared")              {   command = new BootSharedCommand(optionString);                      }
170                 //else if(commandName == "consensus")                   {   command = new ConcensusCommand(optionString);                       }
171                 else if(commandName == "dist.seqs")                             {   command = new DistanceCommand(optionString);                        }
172                 else if(commandName == "align.seqs")                    {   command = new AlignCommand(optionString);                           }
173                 else if(commandName == "summary.seqs")                  {       command = new SeqSummaryCommand(optionString);                  }
174                 else if(commandName == "screen.seqs")                   {       command = new ScreenSeqsCommand(optionString);                  }
175                 else if(commandName == "reverse.seqs")                  {       command = new ReverseSeqsCommand(optionString);                 }
176                 else if(commandName == "trim.seqs")                             {       command = new TrimSeqsCommand(optionString);                    }
177                 else if(commandName == "chimera.seqs")                  {       command = new ChimeraSeqsCommand(optionString);                 }
178                 else if(commandName == "list.seqs")                             {       command = new ListSeqsCommand(optionString);                    }
179                 else if(commandName == "get.seqs")                              {       command = new GetSeqsCommand(optionString);                             }
180                 else if(commandName == "remove.seqs")                   {       command = new RemoveSeqsCommand(optionString);                  }
181                 else if(commandName == "merge.files")                   {       command = new MergeFileCommand(optionString);                   }
182                 else if(commandName == "system")                                {       command = new SystemCommand(optionString);                              }
183                 else if(commandName == "align.check")                   {       command = new AlignCheckCommand(optionString);                  }
184                 else if(commandName == "get.sharedseqs")                {       command = new GetSharedOTUCommand(optionString);                }
185                 else if(commandName == "get.otulist")                   {       command = new GetListCountCommand(optionString);                }
186                 else if(commandName == "hcluster")                              {       command = new HClusterCommand(optionString);                    }
187                 else if(commandName == "classify.seqs")                 {       command = new ClassifySeqsCommand(optionString);                }
188                 else if(commandName == "phylotype")                             {       command = new PhylotypeCommand(optionString);                   }
189                 else                                                                                    {       command = new NoCommand(optionString);                                  }
190
191                 return command;
192         }
193         catch(exception& e) {
194                 errorOut(e, "CommandFactory", "getCommand");
195                 exit(1);
196         }
197 }
198 /***********************************************************/
199 //This function is used to interrupt a command
200 Command* CommandFactory::getCommand(){
201         try {
202                 delete command;   //delete the old command
203
204                 string s = "";
205             command = new NoCommand(s);
206         
207                 return command;
208         }
209         catch(exception& e) {
210                 errorOut(e, "CommandFactory", "getCommand");
211                 exit(1);
212         }
213 }
214 /***********************************************************************/
215 bool CommandFactory::isValidCommand(string command) {
216         try {   
217         
218                 //is the command in the map
219                 if ((commands.find(command)) != (commands.end())) {
220                         return true;
221                 }else{
222                         mothurOut(command + " is not a valid command in Mothur.  Valid commands are ");
223                         for (it = commands.begin(); it != commands.end(); it++) {
224                                 mothurOut(it->first + ", ");
225                         }
226                         mothurOutEndLine();
227                         return false;
228                 }
229                 
230         }
231         catch(exception& e) {
232                 errorOut(e, "CommandFactory", "isValidCommand");
233                 exit(1);
234         }
235 }
236
237 /***********************************************************************/
238 void CommandFactory::printCommands(ostream& out) {
239         try {   
240                 out << "Valid commands are ";
241                 for (it = commands.begin(); it != commands.end(); it++) {
242                         out << it->first << ", ";
243                 }
244                 out << endl;
245         }
246         catch(exception& e) {
247                 errorOut(e, "CommandFactory", "printCommands");
248                 exit(1);
249         }
250 }
251 /***********************************************************************/
252
253
254
255