]> git.donarmstrong.com Git - mothur.git/blob - commandfactory.cpp
2783aa3acfe56a38d2479af5696e542f2228693b
[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
56 /***********************************************************/
57
58 /***********************************************************/
59 CommandFactory::CommandFactory(){
60         string s = "";
61         command = new NoCommand(s);
62         
63         
64         //initialize list of valid commands
65         commands["read.dist"]                   = "read.dist"; 
66         commands["read.otu"]                    = "read.otu";
67         commands["read.tree"]                   = "read.tree"; 
68         commands["bin.seqs"]                    = "bin.seqs"; 
69         commands["get.oturep"]                  = "get.oturep";
70         commands["cluster"]                             = "cluster"; 
71         commands["unique.seqs"]                 = "unique.seqs"; 
72         commands["dist.seqs"]                   = "dist.seqs";
73         commands["dist.shared"]                 = "dist.shared";
74         commands["collect.single"]              = "collect.single"; 
75         commands["collect.shared"]              = "collect.shared"; 
76         commands["rarefaction.single"]  = "rarefaction.single"; 
77         commands["rarefaction.shared"]  = "rarefaction.shared"; 
78         commands["summary.single"]              = "summary.single"; 
79         commands["summary.shared"]              = "summary.shared"; 
80         commands["parsimony"]                   = "parsimony";
81         commands["unifrac.weighted"]    = "unifrac.weighted"; 
82         commands["unifrac.unweighted"]  = "unifrac.unweighted"; 
83         commands["libshuff"]                    = "libshuff";
84         commands["tree.shared"]                 = "tree.shared";
85         commands["heatmap.bin"]                 = "heatmap.bin";
86         commands["heatmap.sim"]                 = "heatmap.sim";
87         commands["venn"]                                = "venn";
88         commands["get.group"]           = "get.group";
89         commands["get.label"]           = "get.label";
90         commands["get.line"]            = "get.line";
91         commands["get.sabund"]          = "get.sabund";
92         commands["get.rabund"]          = "get.rabund";
93         commands["bootstrap.shared"]    = "bootstrap.shared";
94         //commands["consensus"]                 = "consensus";
95         commands["help"]                                = "help"; 
96         commands["filter.seqs"]                 = "filter.seqs";
97         commands["align.seqs"]                  = "align.seqs";
98         commands["summary.seqs"]                = "summary.seqs";
99         commands["screen.seqs"]                 = "screen.seqs";
100         commands["reverse.seqs"]                = "reverse.seqs";
101         commands["trim.seqs"]                   = "trim.seqs";
102         commands["chimera.seqs"]                = "chimera.seqs";
103         commands["list.seqs"]                   = "list.seqs";
104         commands["get.seqs"]                    = "get.seqs";
105         commands["quit"]                                = "quit"; 
106
107 }
108 /***********************************************************/
109
110 /***********************************************************/
111 CommandFactory::~CommandFactory(){
112         delete command;
113 }
114
115 /***********************************************************/
116
117 /***********************************************************/
118 //This function calls the appropriate command fucntions based on user input.
119 Command* CommandFactory::getCommand(string commandName, string optionString){
120         try {
121                 delete command;   //delete the old command
122
123                 if(commandName == "read.dist")                                  {       command = new ReadDistCommand(optionString);                    }
124                 else if(commandName == "read.otu")                              {       command = new ReadOtuCommand(optionString);                             }
125                 else if(commandName == "read.tree")                             {       command = new ReadTreeCommand(optionString);                    }
126                 else if(commandName == "cluster")                               {       command = new ClusterCommand(optionString);                             }
127                 else if(commandName == "unique.seqs")                   {       command = new DeconvoluteCommand(optionString);                 }
128                 else if(commandName == "parsimony")                             {       command = new ParsimonyCommand(optionString);                   }
129                 else if(commandName == "help")                                  {       command = new HelpCommand(optionString);                                }
130                 else if(commandName == "quit")                                  {       command = new QuitCommand(optionString);                                }
131                 else if(commandName == "collect.single")                {       command = new CollectCommand(optionString);                             }
132                 else if(commandName == "collect.shared")                {       command = new CollectSharedCommand(optionString);               }
133                 else if(commandName == "rarefaction.single")    {       command = new RareFactCommand(optionString);                    }
134                 else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand(optionString);              }
135                 else if(commandName == "summary.single")                {       command = new SummaryCommand(optionString);                             }
136                 else if(commandName == "summary.shared")                {       command = new SummarySharedCommand(optionString);               }
137                 else if(commandName == "unifrac.weighted")              {       command = new UnifracWeightedCommand(optionString);             }
138                 else if(commandName == "unifrac.unweighted")    {       command = new UnifracUnweightedCommand(optionString);   }
139                 else if(commandName == "get.group")             {   command = new GetgroupCommand(optionString);                        }
140                 else if(commandName == "get.label")             {   command = new GetlabelCommand(optionString);                        }
141                 else if(commandName == "get.line")              {   command = new GetlineCommand(optionString);                         }
142                 else if(commandName == "get.sabund")            {   command = new GetSAbundCommand(optionString);                       }
143                 else if(commandName == "get.rabund")            {   command = new GetRAbundCommand(optionString);                       }
144                 else if(commandName == "libshuff")              {   command = new LibShuffCommand(optionString);                        }
145                 else if(commandName == "heatmap.bin")                   {   command = new HeatMapCommand(optionString);                         }
146                 else if(commandName == "heatmap.sim")                   {   command = new HeatMapSimCommand(optionString);                      }
147                 else if(commandName == "filter.seqs")                   {   command = new FilterSeqsCommand(optionString);                      }
148                 else if(commandName == "venn")                                  {   command = new VennCommand(optionString);                            }
149                 else if(commandName == "bin.seqs")                              {   command = new BinSeqCommand(optionString);                          }
150                 else if(commandName == "get.oturep")                    {   command = new GetOTURepCommand(optionString);                       }
151                 else if(commandName == "tree.shared")                   {   command = new TreeGroupCommand(optionString);                       }
152                 else if(commandName == "dist.shared")                   {   command = new MatrixOutputCommand(optionString);            }
153                 else if(commandName == "bootstrap.shared")              {   command = new BootSharedCommand(optionString);                      }
154                 //else if(commandName == "consensus")                   {   command = new ConcensusCommand(optionString);                       }
155                 else if(commandName == "dist.seqs")                             {   command = new DistanceCommand(optionString);                        }
156                 else if(commandName == "align.seqs")                    {   command = new AlignCommand(optionString);                           }
157                 else if(commandName == "summary.seqs")                  {       command = new SeqSummaryCommand(optionString);                  }
158                 else if(commandName == "screen.seqs")                   {       command = new ScreenSeqsCommand(optionString);                  }
159                 else if(commandName == "reverse.seqs")                  {       command = new ReverseSeqsCommand(optionString);                 }
160                 else if(commandName == "trim.seqs")                             {       command = new TrimSeqsCommand(optionString);                    }
161                 else if(commandName == "chimera.seqs")                  {       command = new ChimeraSeqsCommand(optionString);                 }
162                 else if(commandName == "list.seqs")                             {       command = new ListSeqsCommand(optionString);                    }
163                 else if(commandName == "get.seqs")                              {       command = new GetSeqsCommand(optionString);                             }
164                 else if(commandName == "merge.files")                   {       command = new MergeFileCommand(optionString);                   }
165                 else                                                                                    {       command = new NoCommand(optionString);                                  }
166
167                 return command;
168         }
169         catch(exception& e) {
170                 errorOut(e, "CommandFactory", "getCommand");
171                 exit(1);
172         }
173 }
174
175 /***********************************************************************/
176 bool CommandFactory::isValidCommand(string command) {
177         try {   
178         
179                 //is the command in the map
180                 if ((commands.find(command)) != (commands.end())) {
181                         return true;
182                 }else{
183                         mothurOut(command + " is not a valid command in Mothur.  Valid commands are ");
184                         for (it = commands.begin(); it != commands.end(); it++) {
185                                 mothurOut(it->first + ", ");
186                         }
187                         mothurOutEndLine();
188                         return false;
189                 }
190                 
191         }
192         catch(exception& e) {
193                 errorOut(e, "CommandFactory", "isValidCommand");
194                 exit(1);
195         }
196 }
197
198 /***********************************************************************/
199 void CommandFactory::printCommands(ostream& out) {
200         try {   
201                 out << "Valid commands are ";
202                 for (it = commands.begin(); it != commands.end(); it++) {
203                         out << it->first << ", ";
204                 }
205                 out << endl;
206         }
207         catch(exception& e) {
208                 errorOut(e, "CommandFactory", "printCommands");
209                 exit(1);
210         }
211 }
212 /***********************************************************************/
213
214
215
216