00001 #ifndef MAIN_CPP
00002 #define MAIN_CPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "arg_parser.h"
00038 #include "ClusterMakerFactory.h"
00039 #include "ESTAnalyzerFactory.h"
00040 #include "ClusterMaker.h"
00041 #include "ESTAnalyzer.h"
00042 #include "HeuristicFactory.h"
00043 #include "HeuristicChain.h"
00044 #include "FilterFactory.h"
00045 #include "FilterChain.h"
00046 #include "ParameterSetManager.h"
00047 #include "MPIHelper.h"
00048 #include "InteractiveConsole.h"
00049 #include "EST.h"
00050
00051 #include <string>
00052 #include <sstream>
00053 #include <fstream>
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 static void showUsage(arg_parser& ap,
00081 ESTAnalyzer *analyzer, ClusterMaker *cMaker,
00082 HeuristicChain *hChain,
00083 FilterChain *fChain) {
00084 std::cout << "Usage: PEACE [options]\n"
00085 << "where options are:\n";
00086 std::cout << ap;
00087 std::cout << "Names of EST analyzers available are:\n";
00088 ESTAnalyzerFactory::displayList(std::cerr);
00089 std::cout << "Names of cluster makers available are:\n";
00090 ClusterMakerFactory::displayList(std::cerr);
00091 std::cout << "Names of heuristics available are:\n";
00092 HeuristicFactory::displayList(std::cerr);
00093 std::cout << "Names of filters available are:\n";
00094 FilterFactory::displayList(std::cerr);
00095
00096 if (analyzer != NULL) {
00097 analyzer->showArguments(std::cout);
00098 delete analyzer;
00099 }
00100
00101 if (cMaker != NULL) {
00102 cMaker->showArguments(std::cout);
00103 delete cMaker;
00104 }
00105
00106 if (hChain != NULL) {
00107 hChain->showArguments(std::cout);
00108 delete hChain;
00109 }
00110
00111 if (fChain != NULL) {
00112 fChain->showArguments(std::cout);
00113 delete fChain;
00114 }
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 int applyFilters(ClusterMaker *clusterMaker, FilterChain *chain,
00130 const char* filterPassFileName,
00131 const char *filterFailFileName) {
00132 if (chain == NULL) {
00133
00134 return 0;
00135 }
00136 if (FilterChain::applyFilters(clusterMaker)) {
00137
00138 return 1;
00139 }
00140
00141 if (MPI_GET_RANK() != 0) {
00142
00143 return 0;
00144 }
00145
00146
00147 if (filterPassFileName != NULL) {
00148 std::ofstream outFile(filterPassFileName);
00149 if (!outFile.good()) {
00150 std::cerr << "Unable to open file " << filterPassFileName
00151 << "for writing. Aborting!" << std::endl;
00152 return 2;
00153 }
00154
00155 EST::dumpESTList(outFile, false);
00156 outFile.close();
00157 }
00158
00159 if (filterFailFileName != NULL) {
00160 std::ofstream outFile(filterFailFileName);
00161 if (!outFile.good()) {
00162 std::cerr << "Unable to open file " << filterFailFileName
00163 << "for writing. Aborting!" << std::endl;
00164 return 2;
00165 }
00166
00167 EST::dumpESTList(outFile, true);
00168 outFile.close();
00169 }
00170
00171 return 0;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 int
00188 main(int argc, char* argv[]) {
00189
00190
00191 char emptyString[1] = {'\0'};
00192 char defAnalyzer[] = "twopassD2";
00193 char defClusterMaker[] = "mst";
00194 char defHeuristic[] = "tv";
00195 char defFilters[] = "lengthFilter-lcFilter";
00196
00197 char *analyzerName = defAnalyzer;
00198 char *clusterName = defClusterMaker;
00199 char *heuristicStr = defHeuristic;
00200 char *outputFile = emptyString;
00201 bool showOptions = false;
00202 int refESTidx = 0;
00203 bool interactive = false;
00204
00205
00206 char *filterStr = defFilters;
00207 char *filterPassFile = NULL;
00208 char *filterFailFile = NULL;
00209 bool filterOnly = false;
00210
00211
00212 arg_parser::arg_record arg_list[] = {
00213 {"--clusterMaker", "Name of clustering algorithm to use (null for none)",
00214 &clusterName, arg_parser::STRING},
00215 {"--analyzer", "Name of the EST analyzer to use",
00216 &analyzerName, arg_parser::STRING},
00217 {"--heuristics", "Name(s) of the heuristic(s) to use, in order (null for none)",
00218 &heuristicStr, arg_parser::STRING},
00219 {"--filters", "Name(s) of the filters(s) to use, in order (null for none)",
00220 &filterStr, arg_parser::STRING},
00221 {"--filter-fail", "FASTA file to which ESTs that failed the filter must be written",
00222 &filterFailFile, arg_parser::STRING},
00223 {"--filter-pass", "FASTA file to which ESTs that pass the filter must be written",
00224 &filterPassFile, arg_parser::STRING},
00225 {"--filter-only", "Just do filtering and no other processing (false by default)",
00226 &filterOnly, arg_parser::BOOLEAN},
00227 {"--estIdx", "Index of reference EST in a EST file",
00228 &refESTidx, arg_parser::INTEGER},
00229 {"--output", "File to which output must be written",
00230 &outputFile, arg_parser::STRING},
00231 {"--options", "Lists options for the specified cluster & analyzer",
00232 &showOptions, arg_parser::BOOLEAN},
00233 {"--interactive", "Lauch PEACE interactive console",
00234 &interactive, arg_parser::BOOLEAN},
00235 {NULL, NULL, NULL, arg_parser::BOOLEAN}
00236 };
00237
00238
00239 MPI_INIT(argc, argv);
00240
00241 arg_parser::set_global_args(argc, argv);
00242
00243
00244
00245 arg_parser ap(arg_list);
00246 ap.check_args(argc, argv, false);
00247
00248 if (showOptions) {
00249
00250
00251
00252
00253 refESTidx = 0;
00254 }
00255
00256 ESTAnalyzer *analyzer =
00257 ESTAnalyzerFactory::create(analyzerName, refESTidx,
00258 std::string(outputFile));
00259
00260
00261 if (!strcmp(clusterName, "null")) clusterName = NULL;
00262
00263 ClusterMaker *clusterMaker =
00264 ClusterMakerFactory::create(clusterName, analyzer,
00265 refESTidx, std::string(outputFile));
00266
00267
00268 if (!strcmp(heuristicStr, "null")) {
00269 heuristicStr = NULL;
00270 }
00271
00272 HeuristicChain *heuristicChain =
00273 HeuristicChain::setupChain(heuristicStr, refESTidx, outputFile);
00274
00275
00276 if (!strcmp(filterStr, "null")) {
00277 filterStr = NULL;
00278 }
00279
00280 FilterChain *filterChain = FilterChain::setupChain(filterStr, clusterMaker);
00281
00282
00283 ParameterSetManager::setupParameters();
00284
00285
00286
00287 if ((analyzer == NULL) || (showOptions) ||
00288 (!analyzer->parseArguments(argc, argv))) {
00289 showUsage(ap, analyzer, clusterMaker, heuristicChain, filterChain);
00290 return (showOptions ? 0 : 1);
00291 }
00292
00293
00294 if (clusterName != NULL) {
00295 if ((clusterMaker == NULL) || (showOptions) ||
00296 (!clusterMaker->parseArguments(argc, argv))) {
00297 showUsage(ap, analyzer, clusterMaker, heuristicChain, filterChain);
00298 return (showOptions ? 0 : 2);
00299 }
00300 }
00301
00302
00303 if (heuristicStr != NULL) {
00304 if ((heuristicChain == NULL) || (showOptions) ||
00305 (!heuristicChain->parseArguments(argc, argv))) {
00306 showUsage(ap, analyzer, clusterMaker, heuristicChain, filterChain);
00307 return (showOptions ? 0 : 3);
00308 }
00309 }
00310
00311
00312 if (filterStr != NULL) {
00313 if ((filterChain == NULL) || (showOptions) ||
00314 (!filterChain->parseArguments(argc, argv))) {
00315 showUsage(ap, analyzer, clusterMaker, heuristicChain, filterChain);
00316 return (showOptions ? 0 : 3);
00317 }
00318 }
00319
00320
00321 if (heuristicChain != NULL) {
00322 analyzer->setHeuristicChain(heuristicChain);
00323 }
00324
00325
00326 int result = 0;
00327
00328 if (interactive) {
00329
00330 InteractiveConsole console(analyzer);
00331 console.processCommands();
00332 } else if (clusterMaker != NULL) {
00333
00334 clusterMaker->initialize();
00335
00336 if ((applyFilters(clusterMaker, filterChain, filterPassFile,
00337 filterFailFile) == 0) && (!filterOnly)) {
00338 result = clusterMaker->makeClusters();
00339 }
00340 delete clusterMaker;
00341 } else {
00342
00343 result = analyzer->analyze();
00344 }
00345
00346
00347
00348
00349 if (heuristicChain != NULL) {
00350
00351
00352
00353
00354 std::ostringstream buffer;
00355 heuristicChain->printStats(buffer, MPI_GET_RANK());
00356 std::cout << buffer.str() << std::endl;
00357 }
00358
00359
00360 if (filterChain != NULL) {
00361
00362
00363
00364
00365 std::ostringstream buffer;
00366 filterChain->printStats(buffer, MPI_GET_RANK());
00367 std::cout << buffer.str() << std::endl;
00368 }
00369
00370
00371 delete analyzer;
00372
00373 delete heuristicChain;
00374
00375 delete filterChain;
00376
00377
00378 MPI_FINALIZE();
00379
00380
00381 return result;
00382 }
00383
00384 #endif