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