]> git.donarmstrong.com Git - mothur.git/blob - commandfactory.cpp
added pca command
[mothur.git] / commandfactory.cpp
1 /*
2  *  commandfactory.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 10/25/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "command.hpp"
11 #include "readdistcommand.h"
12 #include "readtreecommand.h"
13 #include "readotucommand.h"
14 #include "clustercommand.h"
15 #include "collectcommand.h"
16 #include "collectsharedcommand.h"
17 #include "getgroupcommand.h"
18 #include "getlabelcommand.h"
19 #include "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 #include "mgclustercommand.h"
64 #include "preclustercommand.h"
65 #include "pcacommand.h"
66
67 /*******************************************************/
68
69 /******************************************************/
70 CommandFactory* CommandFactory::getInstance() {
71         if( _uniqueInstance == 0) {
72                 _uniqueInstance = new CommandFactory();
73         }
74         return _uniqueInstance;
75 }
76 /***********************************************************/
77
78 /***********************************************************/
79 CommandFactory::CommandFactory(){
80         _uniqueInstance = 0;
81         string s = "";
82         command = new NoCommand(s);
83         
84         
85         //initialize list of valid commands
86         commands["read.dist"]                   = "read.dist"; 
87         commands["read.otu"]                    = "read.otu";
88         commands["read.tree"]                   = "read.tree"; 
89         commands["bin.seqs"]                    = "bin.seqs"; 
90         commands["get.oturep"]                  = "get.oturep";
91         commands["cluster"]                             = "cluster"; 
92         commands["unique.seqs"]                 = "unique.seqs"; 
93         commands["dist.seqs"]                   = "dist.seqs";
94         commands["dist.shared"]                 = "dist.shared";
95         commands["collect.single"]              = "collect.single"; 
96         commands["collect.shared"]              = "collect.shared"; 
97         commands["rarefaction.single"]  = "rarefaction.single"; 
98         commands["rarefaction.shared"]  = "rarefaction.shared"; 
99         commands["summary.single"]              = "summary.single"; 
100         commands["summary.shared"]              = "summary.shared"; 
101         commands["parsimony"]                   = "parsimony";
102         commands["unifrac.weighted"]    = "unifrac.weighted"; 
103         commands["unifrac.unweighted"]  = "unifrac.unweighted"; 
104         commands["libshuff"]                    = "libshuff";
105         commands["tree.shared"]                 = "tree.shared";
106         commands["heatmap.bin"]                 = "heatmap.bin";
107         commands["heatmap.sim"]                 = "heatmap.sim";
108         commands["venn"]                                = "venn";
109         commands["get.group"]           = "get.group";
110         commands["get.label"]           = "get.label";
111         commands["get.line"]            = "get.line";
112         commands["get.sabund"]          = "get.sabund";
113         commands["get.rabund"]          = "get.rabund";
114         commands["bootstrap.shared"]    = "bootstrap.shared";
115         //commands["consensus"]                 = "consensus";
116         commands["help"]                                = "help"; 
117         commands["filter.seqs"]                 = "filter.seqs";
118         commands["align.seqs"]                  = "align.seqs";
119         commands["summary.seqs"]                = "summary.seqs";
120         commands["screen.seqs"]                 = "screen.seqs";
121         commands["reverse.seqs"]                = "reverse.seqs";
122         commands["trim.seqs"]                   = "trim.seqs";
123         commands["chimera.seqs"]                = "chimera.seqs";
124         commands["list.seqs"]                   = "list.seqs";
125         commands["get.seqs"]                    = "get.seqs";
126         commands["remove.seqs"]                 = "get.seqs";
127         commands["system"]                              = "system";
128         commands["align.check"]                 = "align.check";
129         commands["get.sharedseqs"]              = "get.sharedseqs";
130         commands["get.otulist"]                 = "get.otulist";
131         commands["quit"]                                = "quit"; 
132         commands["hcluster"]                    = "hcluster"; 
133         commands["classify.seqs"]               = "classify.seqs"; 
134         commands["phylotype"]                   = "phylotype";
135         commands["mgcluster"]                   = "mgcluster";
136         commands["pre.cluster"]                 = "pre.cluster";
137         commands["pca"]                                 = "pca";
138
139 }
140 /***********************************************************/
141
142 /***********************************************************/
143 CommandFactory::~CommandFactory(){
144         delete command;
145 }
146
147 /***********************************************************/
148
149 /***********************************************************/
150 //This function calls the appropriate command fucntions based on user input.
151 Command* CommandFactory::getCommand(string commandName, string optionString){
152         try {
153                 delete command;   //delete the old command
154
155                 if(commandName == "read.dist")                                  {       command = new ReadDistCommand(optionString);                    }
156                 else if(commandName == "read.otu")                              {       command = new ReadOtuCommand(optionString);                             }
157                 else if(commandName == "read.tree")                             {       command = new ReadTreeCommand(optionString);                    }
158                 else if(commandName == "cluster")                               {       command = new ClusterCommand(optionString);                             }
159                 else if(commandName == "unique.seqs")                   {       command = new DeconvoluteCommand(optionString);                 }
160                 else if(commandName == "parsimony")                             {       command = new ParsimonyCommand(optionString);                   }
161                 else if(commandName == "help")                                  {       command = new HelpCommand(optionString);                                }
162                 else if(commandName == "quit")                                  {       command = new QuitCommand(optionString);                                }
163                 else if(commandName == "collect.single")                {       command = new CollectCommand(optionString);                             }
164                 else if(commandName == "collect.shared")                {       command = new CollectSharedCommand(optionString);               }
165                 else if(commandName == "rarefaction.single")    {       command = new RareFactCommand(optionString);                    }
166                 else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand(optionString);              }
167                 else if(commandName == "summary.single")                {       command = new SummaryCommand(optionString);                             }
168                 else if(commandName == "summary.shared")                {       command = new SummarySharedCommand(optionString);               }
169                 else if(commandName == "unifrac.weighted")              {       command = new UnifracWeightedCommand(optionString);             }
170                 else if(commandName == "unifrac.unweighted")    {       command = new UnifracUnweightedCommand(optionString);   }
171                 else if(commandName == "get.group")             {   command = new GetgroupCommand(optionString);                        }
172                 else if(commandName == "get.label")             {   command = new GetlabelCommand(optionString);                        }
173                 else if(commandName == "get.line")              {   command = new GetlineCommand(optionString);                         }
174                 else if(commandName == "get.sabund")            {   command = new GetSAbundCommand(optionString);                       }
175                 else if(commandName == "get.rabund")            {   command = new GetRAbundCommand(optionString);                       }
176                 else if(commandName == "libshuff")              {   command = new LibShuffCommand(optionString);                        }
177                 else if(commandName == "heatmap.bin")                   {   command = new HeatMapCommand(optionString);                         }
178                 else if(commandName == "heatmap.sim")                   {   command = new HeatMapSimCommand(optionString);                      }
179                 else if(commandName == "filter.seqs")                   {   command = new FilterSeqsCommand(optionString);                      }
180                 else if(commandName == "venn")                                  {   command = new VennCommand(optionString);                            }
181                 else if(commandName == "bin.seqs")                              {   command = new BinSeqCommand(optionString);                          }
182                 else if(commandName == "get.oturep")                    {   command = new GetOTURepCommand(optionString);                       }
183                 else if(commandName == "tree.shared")                   {   command = new TreeGroupCommand(optionString);                       }
184                 else if(commandName == "dist.shared")                   {   command = new MatrixOutputCommand(optionString);            }
185                 else if(commandName == "bootstrap.shared")              {   command = new BootSharedCommand(optionString);                      }
186                 //else if(commandName == "consensus")                   {   command = new ConcensusCommand(optionString);                       }
187                 else if(commandName == "dist.seqs")                             {   command = new DistanceCommand(optionString);                        }
188                 else if(commandName == "align.seqs")                    {   command = new AlignCommand(optionString);                           }
189                 else if(commandName == "summary.seqs")                  {       command = new SeqSummaryCommand(optionString);                  }
190                 else if(commandName == "screen.seqs")                   {       command = new ScreenSeqsCommand(optionString);                  }
191                 else if(commandName == "reverse.seqs")                  {       command = new ReverseSeqsCommand(optionString);                 }
192                 else if(commandName == "trim.seqs")                             {       command = new TrimSeqsCommand(optionString);                    }
193                 else if(commandName == "chimera.seqs")                  {       command = new ChimeraSeqsCommand(optionString);                 }
194                 else if(commandName == "list.seqs")                             {       command = new ListSeqsCommand(optionString);                    }
195                 else if(commandName == "get.seqs")                              {       command = new GetSeqsCommand(optionString);                             }
196                 else if(commandName == "remove.seqs")                   {       command = new RemoveSeqsCommand(optionString);                  }
197                 else if(commandName == "merge.files")                   {       command = new MergeFileCommand(optionString);                   }
198                 else if(commandName == "system")                                {       command = new SystemCommand(optionString);                              }
199                 else if(commandName == "align.check")                   {       command = new AlignCheckCommand(optionString);                  }
200                 else if(commandName == "get.sharedseqs")                {       command = new GetSharedOTUCommand(optionString);                }
201                 else if(commandName == "get.otulist")                   {       command = new GetListCountCommand(optionString);                }
202                 else if(commandName == "hcluster")                              {       command = new HClusterCommand(optionString);                    }
203                 else if(commandName == "classify.seqs")                 {       command = new ClassifySeqsCommand(optionString);                }
204                 else if(commandName == "phylotype")                             {       command = new PhylotypeCommand(optionString);                   }
205                 else if(commandName == "mgcluster")                             {       command = new MGClusterCommand(optionString);                   }
206                 else if(commandName == "pre.cluster")                   {       command = new PreClusterCommand(optionString);                  }
207                 else if(commandName == "pca")                                   {       command = new PCACommand(optionString);                                 }
208                 else                                                                                    {       command = new NoCommand(optionString);                                  }
209
210                 return command;
211         }
212         catch(exception& e) {
213                 errorOut(e, "CommandFactory", "getCommand");
214                 exit(1);
215         }
216 }
217 /***********************************************************/
218 //This function is used to interrupt a command
219 Command* CommandFactory::getCommand(){
220         try {
221                 delete command;   //delete the old command
222
223                 string s = "";
224             command = new NoCommand(s);
225         
226                 return command;
227         }
228         catch(exception& e) {
229                 errorOut(e, "CommandFactory", "getCommand");
230                 exit(1);
231         }
232 }
233 /***********************************************************************/
234 bool CommandFactory::isValidCommand(string command) {
235         try {   
236         
237                 //is the command in the map
238                 if ((commands.find(command)) != (commands.end())) {
239                         return true;
240                 }else{
241                         mothurOut(command + " is not a valid command in Mothur.  Valid commands are ");
242                         for (it = commands.begin(); it != commands.end(); it++) {
243                                 mothurOut(it->first + ", ");
244                         }
245                         mothurOutEndLine();
246                         return false;
247                 }
248                 
249         }
250         catch(exception& e) {
251                 errorOut(e, "CommandFactory", "isValidCommand");
252                 exit(1);
253         }
254 }
255
256 /***********************************************************************/
257 void CommandFactory::printCommands(ostream& out) {
258         try {   
259                 out << "Valid commands are ";
260                 for (it = commands.begin(); it != commands.end(); it++) {
261                         out << it->first << ", ";
262                 }
263                 out << endl;
264         }
265         catch(exception& e) {
266                 errorOut(e, "CommandFactory", "printCommands");
267                 exit(1);
268         }
269 }
270 /***********************************************************************/
271
272
273
274