5 * Created by Pat Schloss on 10/25/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
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"
65 /*******************************************************/
67 /******************************************************/
68 CommandFactory* CommandFactory::getInstance() {
69 if( _uniqueInstance == 0) {
70 _uniqueInstance = new CommandFactory();
72 return _uniqueInstance;
74 /***********************************************************/
76 /***********************************************************/
77 CommandFactory::CommandFactory(){
80 command = new NoCommand(s);
83 //initialize list of valid commands
84 commands["read.dist"] = "read.dist";
85 commands["read.otu"] = "read.otu";
86 commands["read.tree"] = "read.tree";
87 commands["bin.seqs"] = "bin.seqs";
88 commands["get.oturep"] = "get.oturep";
89 commands["cluster"] = "cluster";
90 commands["unique.seqs"] = "unique.seqs";
91 commands["dist.seqs"] = "dist.seqs";
92 commands["dist.shared"] = "dist.shared";
93 commands["collect.single"] = "collect.single";
94 commands["collect.shared"] = "collect.shared";
95 commands["rarefaction.single"] = "rarefaction.single";
96 commands["rarefaction.shared"] = "rarefaction.shared";
97 commands["summary.single"] = "summary.single";
98 commands["summary.shared"] = "summary.shared";
99 commands["parsimony"] = "parsimony";
100 commands["unifrac.weighted"] = "unifrac.weighted";
101 commands["unifrac.unweighted"] = "unifrac.unweighted";
102 commands["libshuff"] = "libshuff";
103 commands["tree.shared"] = "tree.shared";
104 commands["heatmap.bin"] = "heatmap.bin";
105 commands["heatmap.sim"] = "heatmap.sim";
106 commands["venn"] = "venn";
107 commands["get.group"] = "get.group";
108 commands["get.label"] = "get.label";
109 commands["get.line"] = "get.line";
110 commands["get.sabund"] = "get.sabund";
111 commands["get.rabund"] = "get.rabund";
112 commands["bootstrap.shared"] = "bootstrap.shared";
113 //commands["consensus"] = "consensus";
114 commands["help"] = "help";
115 commands["filter.seqs"] = "filter.seqs";
116 commands["align.seqs"] = "align.seqs";
117 commands["summary.seqs"] = "summary.seqs";
118 commands["screen.seqs"] = "screen.seqs";
119 commands["reverse.seqs"] = "reverse.seqs";
120 commands["trim.seqs"] = "trim.seqs";
121 commands["chimera.seqs"] = "chimera.seqs";
122 commands["list.seqs"] = "list.seqs";
123 commands["get.seqs"] = "get.seqs";
124 commands["remove.seqs"] = "get.seqs";
125 commands["system"] = "system";
126 commands["align.check"] = "align.check";
127 commands["get.sharedseqs"] = "get.sharedseqs";
128 commands["get.otulist"] = "get.otulist";
129 commands["quit"] = "quit";
130 commands["hcluster"] = "hcluster";
131 commands["classify.seqs"] = "classify.seqs";
132 commands["phylotype"] = "phylotype";
133 commands["mgcluster"] = "mgcluster";
136 /***********************************************************/
138 /***********************************************************/
139 CommandFactory::~CommandFactory(){
143 /***********************************************************/
145 /***********************************************************/
146 //This function calls the appropriate command fucntions based on user input.
147 Command* CommandFactory::getCommand(string commandName, string optionString){
149 delete command; //delete the old command
151 if(commandName == "read.dist") { command = new ReadDistCommand(optionString); }
152 else if(commandName == "read.otu") { command = new ReadOtuCommand(optionString); }
153 else if(commandName == "read.tree") { command = new ReadTreeCommand(optionString); }
154 else if(commandName == "cluster") { command = new ClusterCommand(optionString); }
155 else if(commandName == "unique.seqs") { command = new DeconvoluteCommand(optionString); }
156 else if(commandName == "parsimony") { command = new ParsimonyCommand(optionString); }
157 else if(commandName == "help") { command = new HelpCommand(optionString); }
158 else if(commandName == "quit") { command = new QuitCommand(optionString); }
159 else if(commandName == "collect.single") { command = new CollectCommand(optionString); }
160 else if(commandName == "collect.shared") { command = new CollectSharedCommand(optionString); }
161 else if(commandName == "rarefaction.single") { command = new RareFactCommand(optionString); }
162 else if(commandName == "rarefaction.shared") { command = new RareFactSharedCommand(optionString); }
163 else if(commandName == "summary.single") { command = new SummaryCommand(optionString); }
164 else if(commandName == "summary.shared") { command = new SummarySharedCommand(optionString); }
165 else if(commandName == "unifrac.weighted") { command = new UnifracWeightedCommand(optionString); }
166 else if(commandName == "unifrac.unweighted") { command = new UnifracUnweightedCommand(optionString); }
167 else if(commandName == "get.group") { command = new GetgroupCommand(optionString); }
168 else if(commandName == "get.label") { command = new GetlabelCommand(optionString); }
169 else if(commandName == "get.line") { command = new GetlineCommand(optionString); }
170 else if(commandName == "get.sabund") { command = new GetSAbundCommand(optionString); }
171 else if(commandName == "get.rabund") { command = new GetRAbundCommand(optionString); }
172 else if(commandName == "libshuff") { command = new LibShuffCommand(optionString); }
173 else if(commandName == "heatmap.bin") { command = new HeatMapCommand(optionString); }
174 else if(commandName == "heatmap.sim") { command = new HeatMapSimCommand(optionString); }
175 else if(commandName == "filter.seqs") { command = new FilterSeqsCommand(optionString); }
176 else if(commandName == "venn") { command = new VennCommand(optionString); }
177 else if(commandName == "bin.seqs") { command = new BinSeqCommand(optionString); }
178 else if(commandName == "get.oturep") { command = new GetOTURepCommand(optionString); }
179 else if(commandName == "tree.shared") { command = new TreeGroupCommand(optionString); }
180 else if(commandName == "dist.shared") { command = new MatrixOutputCommand(optionString); }
181 else if(commandName == "bootstrap.shared") { command = new BootSharedCommand(optionString); }
182 //else if(commandName == "consensus") { command = new ConcensusCommand(optionString); }
183 else if(commandName == "dist.seqs") { command = new DistanceCommand(optionString); }
184 else if(commandName == "align.seqs") { command = new AlignCommand(optionString); }
185 else if(commandName == "summary.seqs") { command = new SeqSummaryCommand(optionString); }
186 else if(commandName == "screen.seqs") { command = new ScreenSeqsCommand(optionString); }
187 else if(commandName == "reverse.seqs") { command = new ReverseSeqsCommand(optionString); }
188 else if(commandName == "trim.seqs") { command = new TrimSeqsCommand(optionString); }
189 else if(commandName == "chimera.seqs") { command = new ChimeraSeqsCommand(optionString); }
190 else if(commandName == "list.seqs") { command = new ListSeqsCommand(optionString); }
191 else if(commandName == "get.seqs") { command = new GetSeqsCommand(optionString); }
192 else if(commandName == "remove.seqs") { command = new RemoveSeqsCommand(optionString); }
193 else if(commandName == "merge.files") { command = new MergeFileCommand(optionString); }
194 else if(commandName == "system") { command = new SystemCommand(optionString); }
195 else if(commandName == "align.check") { command = new AlignCheckCommand(optionString); }
196 else if(commandName == "get.sharedseqs") { command = new GetSharedOTUCommand(optionString); }
197 else if(commandName == "get.otulist") { command = new GetListCountCommand(optionString); }
198 else if(commandName == "hcluster") { command = new HClusterCommand(optionString); }
199 else if(commandName == "classify.seqs") { command = new ClassifySeqsCommand(optionString); }
200 else if(commandName == "phylotype") { command = new PhylotypeCommand(optionString); }
201 else if(commandName == "mgcluster") { command = new MGClusterCommand(optionString); }
202 else { command = new NoCommand(optionString); }
206 catch(exception& e) {
207 errorOut(e, "CommandFactory", "getCommand");
211 /***********************************************************/
212 //This function is used to interrupt a command
213 Command* CommandFactory::getCommand(){
215 delete command; //delete the old command
218 command = new NoCommand(s);
222 catch(exception& e) {
223 errorOut(e, "CommandFactory", "getCommand");
227 /***********************************************************************/
228 bool CommandFactory::isValidCommand(string command) {
231 //is the command in the map
232 if ((commands.find(command)) != (commands.end())) {
235 mothurOut(command + " is not a valid command in Mothur. Valid commands are ");
236 for (it = commands.begin(); it != commands.end(); it++) {
237 mothurOut(it->first + ", ");
244 catch(exception& e) {
245 errorOut(e, "CommandFactory", "isValidCommand");
250 /***********************************************************************/
251 void CommandFactory::printCommands(ostream& out) {
253 out << "Valid commands are ";
254 for (it = commands.begin(); it != commands.end(); it++) {
255 out << it->first << ", ";
259 catch(exception& e) {
260 errorOut(e, "CommandFactory", "printCommands");
264 /***********************************************************************/