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"
53 /***********************************************************/
55 /***********************************************************/
56 CommandFactory::CommandFactory(){
58 command = new NoCommand(s);
61 //initialize list of valid commands
62 commands["read.dist"] = "read.dist";
63 commands["read.otu"] = "read.otu";
64 commands["read.tree"] = "read.tree";
65 commands["bin.seqs"] = "bin.seqs";
66 commands["get.oturep"] = "get.oturep";
67 commands["cluster"] = "cluster";
68 commands["unique.seqs"] = "unique.seqs";
69 commands["dist.seqs"] = "dist.seqs";
70 commands["dist.shared"] = "dist.shared";
71 commands["collect.single"] = "collect.single";
72 commands["collect.shared"] = "collect.shared";
73 commands["rarefaction.single"] = "rarefaction.single";
74 commands["rarefaction.shared"] = "rarefaction.shared";
75 commands["summary.single"] = "summary.single";
76 commands["summary.shared"] = "summary.shared";
77 commands["parsimony"] = "parsimony";
78 commands["unifrac.weighted"] = "unifrac.weighted";
79 commands["unifrac.unweighted"] = "unifrac.unweighted";
80 commands["libshuff"] = "libshuff";
81 commands["tree.shared"] = "tree.shared";
82 commands["heatmap.bin"] = "heatmap.bin";
83 commands["heatmap.sim"] = "heatmap.sim";
84 commands["venn"] = "venn";
85 commands["get.group"] = "get.group";
86 commands["get.label"] = "get.label";
87 commands["get.line"] = "get.line";
88 commands["get.sabund"] = "get.sabund";
89 commands["get.rabund"] = "get.rabund";
90 commands["bootstrap.shared"] = "bootstrap.shared";
91 //commands["consensus"] = "consensus";
92 commands["help"] = "help";
93 commands["filter.seqs"] = "filter.seqs";
94 commands["align.seqs"] = "align.seqs";
95 commands["summary.seqs"] = "summary.seqs";
96 commands["screen.seqs"] = "screen.seqs";
97 commands["reverse.seqs"] = "reverse.seqs";
98 commands["trim.seqs"] = "trim.seqs";
99 commands["quit"] = "quit";
102 /***********************************************************/
104 /***********************************************************/
105 CommandFactory::~CommandFactory(){
109 /***********************************************************/
111 /***********************************************************/
112 //This function calls the appropriate command fucntions based on user input.
113 Command* CommandFactory::getCommand(string commandName, string optionString){
115 delete command; //delete the old command
117 if(commandName == "read.dist") { command = new ReadDistCommand(optionString); }
118 else if(commandName == "read.otu") { command = new ReadOtuCommand(optionString); }
119 else if(commandName == "read.tree") { command = new ReadTreeCommand(optionString); }
120 else if(commandName == "cluster") { command = new ClusterCommand(optionString); }
121 else if(commandName == "unique.seqs") { command = new DeconvoluteCommand(optionString); }
122 else if(commandName == "parsimony") { command = new ParsimonyCommand(optionString); }
123 else if(commandName == "help") { command = new HelpCommand(optionString); }
124 else if(commandName == "quit") { command = new QuitCommand(optionString); }
125 else if(commandName == "collect.single") { command = new CollectCommand(optionString); }
126 else if(commandName == "collect.shared") { command = new CollectSharedCommand(optionString); }
127 else if(commandName == "rarefaction.single") { command = new RareFactCommand(optionString); }
128 else if(commandName == "rarefaction.shared") { command = new RareFactSharedCommand(optionString); }
129 else if(commandName == "summary.single") { command = new SummaryCommand(optionString); }
130 else if(commandName == "summary.shared") { command = new SummarySharedCommand(optionString); }
131 else if(commandName == "unifrac.weighted") { command = new UnifracWeightedCommand(optionString); }
132 else if(commandName == "unifrac.unweighted") { command = new UnifracUnweightedCommand(optionString); }
133 else if(commandName == "get.group") { command = new GetgroupCommand(optionString); }
134 else if(commandName == "get.label") { command = new GetlabelCommand(optionString); }
135 else if(commandName == "get.line") { command = new GetlineCommand(optionString); }
136 else if(commandName == "get.sabund") { command = new GetSAbundCommand(optionString); }
137 else if(commandName == "get.rabund") { command = new GetRAbundCommand(optionString); }
138 else if(commandName == "libshuff") { command = new LibShuffCommand(optionString); }
139 else if(commandName == "heatmap.bin") { command = new HeatMapCommand(optionString); }
140 else if(commandName == "heatmap.sim") { command = new HeatMapSimCommand(optionString); }
141 else if(commandName == "filter.seqs") { command = new FilterSeqsCommand(optionString); }
142 else if(commandName == "venn") { command = new VennCommand(optionString); }
143 else if(commandName == "bin.seqs") { command = new BinSeqCommand(optionString); }
144 else if(commandName == "get.oturep") { command = new GetOTURepCommand(optionString); }
145 else if(commandName == "tree.shared") { command = new TreeGroupCommand(optionString); }
146 else if(commandName == "dist.shared") { command = new MatrixOutputCommand(optionString); }
147 else if(commandName == "bootstrap.shared") { command = new BootSharedCommand(optionString); }
148 //else if(commandName == "consensus") { command = new ConcensusCommand(optionString); }
149 else if(commandName == "dist.seqs") { command = new DistanceCommand(optionString); }
150 else if(commandName == "align.seqs") { command = new AlignCommand(optionString); }
151 else if(commandName == "summary.seqs") { command = new SeqSummaryCommand(optionString); }
152 else if(commandName == "screen.seqs") { command = new ScreenSeqsCommand(optionString); }
153 else if(commandName == "reverse.seqs") { command = new ReverseSeqsCommand(optionString); }
154 else if(commandName == "trim.seqs") { command = new TrimSeqsCommand(optionString); }
155 else if(commandName == "merge.files") { command = new MergeFileCommand(optionString); }
156 else { command = new NoCommand(optionString); }
160 catch(exception& e) {
161 errorOut(e, "CommandFactory", "getCommand");
166 /***********************************************************************/
167 bool CommandFactory::isValidCommand(string command) {
170 //is the command in the map
171 if ((commands.find(command)) != (commands.end())) {
174 mothurOut(command + " is not a valid command in Mothur. Valid commands are ");
175 for (it = commands.begin(); it != commands.end(); it++) {
176 mothurOut(it->first + ", ");
183 catch(exception& e) {
184 errorOut(e, "CommandFactory", "isValidCommand");
189 /***********************************************************************/
190 void CommandFactory::printCommands(ostream& out) {
192 out << "Valid commands are ";
193 for (it = commands.begin(); it != commands.end(); it++) {
194 out << it->first << ", ";
198 catch(exception& e) {
199 errorOut(e, "CommandFactory", "printCommands");
203 /***********************************************************************/