]> git.donarmstrong.com Git - mothur.git/blob - mothur.cpp
created mothurOut class to handle logfiles
[mothur.git] / mothur.cpp
1 /*
2  *  interface.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 8/14/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9  
10 #include "mothur.h"
11 #include "engine.hpp"
12 #include "globaldata.hpp"
13 #include "mothurout.h"
14
15 /**************************************************************************************************/
16
17 GlobalData* GlobalData::_uniqueInstance = 0;
18 CommandFactory* CommandFactory::_uniqueInstance = 0;
19 MothurOut* MothurOut::_uniqueInstance = 0;
20
21 int main(int argc, char *argv[]){
22         MothurOut* m = MothurOut::getInstance();
23         try {
24                 
25                 //string log = "mothur.logFile";
26                 //remove(log.c_str());
27                 
28                 time_t ltime = time(NULL); /* calendar time */  
29                 string logFileName = "mothur." + toString(ltime) + ".logfile";
30                 
31                 m->setFileName(logFileName);
32                 
33                 //version
34                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
35                         system("clear");
36                         #if defined (__APPLE__) || (__MACH__)
37                                 m->mothurOutJustToLog("Mac version");
38                                 m->mothurOutEndLine(); m->mothurOutEndLine();
39                         #else
40                                 m->mothurOutJustToLog("Linux version");
41                                 >m->mothurOutEndLine(); m->mothurOutEndLine();
42                         #endif
43
44                 #else
45                         system("CLS");
46                         m->mothurOutJustToLog("Windows version");
47                         m->mothurOutEndLine(); m->mothurOutEndLine();
48                 #endif          
49                 
50                 #ifdef USE_READLINE
51                         m->mothurOutJustToLog("Using ReadLine");
52                         m->mothurOutEndLine(); m->mothurOutEndLine();
53                 #endif
54                 
55                 //header
56                 m->mothurOut("mothur v.1.8");
57                 m->mothurOutEndLine();          
58                 m->mothurOut("Last updated: 2/02/2010");
59                 m->mothurOutEndLine();  
60                 m->mothurOutEndLine();          
61                 m->mothurOut("by");
62                 m->mothurOutEndLine();          
63                 m->mothurOut("Patrick D. Schloss");
64                 m->mothurOutEndLine();
65                 m->mothurOutEndLine();                  
66                 m->mothurOut("Department of Microbiology & Immunology");
67                 m->mothurOutEndLine();  
68                 m->mothurOut("University of Michigan");
69                 m->mothurOutEndLine();                  
70                 m->mothurOut("pschloss@umich.edu");
71                 m->mothurOutEndLine();          
72                 m->mothurOut("http://www.mothur.org");
73                 m->mothurOutEndLine();
74                 m->mothurOutEndLine();
75                 m->mothurOut("When using, please cite:");
76                 m->mothurOutEndLine();
77                 m->mothurOut("Schloss, P.D., et al., Introducing mothur: Open-source, platform-independent, community-supported software for describing and comparing microbial communities. Appl Environ Microbiol, 2009. 75(23):7537-41.");
78                 m->mothurOutEndLine();  
79                 m->mothurOutEndLine();          
80                 m->mothurOut("Distributed under the GNU General Public License");
81                 m->mothurOutEndLine();
82                 m->mothurOutEndLine();                  
83                 m->mothurOut("Type 'help()' for information on the commands that are available");
84                 m->mothurOutEndLine();
85                 m->mothurOutEndLine();                  
86                 m->mothurOut("Type 'quit()' to exit program");
87                 m->mothurOutEndLine();  
88
89                                 
90                 //srand(54321);
91                 srand( (unsigned)time( NULL ) );
92                 
93                 Engine* mothur;
94                 bool bail = 0;
95                 string input;
96
97                 if(argc>1){
98                         input = argv[1];
99
100                         if (input[0] == '#') {
101                                 m->mothurOutJustToLog("Script Mode");
102                                 m->mothurOutEndLine(); m->mothurOutEndLine();
103
104                                 mothur = new ScriptEngine(argv[0], argv[1]);
105                         }else{
106                                 m->mothurOutJustToLog("Batch Mode");
107                                 m->mothurOutEndLine(); m->mothurOutEndLine();
108                                 
109                                 mothur = new BatchEngine(argv[0], argv[1]);
110                         }
111                 }
112                 else{
113                         m->mothurOutJustToLog("Interactive Mode");
114                         m->mothurOutEndLine(); m->mothurOutEndLine();
115                         
116                         mothur = new InteractEngine(argv[0]);   
117                 }
118                 
119                 while(bail == 0)                {       bail = mothur->getInput();                      }
120                 
121                 string outputDir = mothur->getOutputDir();
122                 string newlogFileName = outputDir + logFileName;
123         
124                 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
125                 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
126                 
127                 delete mothur;
128
129                 return 0;
130         }
131         catch(exception& e) {
132                 m->errorOut(e, "mothur", "main");
133                 exit(1);
134         }
135 }
136
137 /**************************************************************************************************/
138