]> git.donarmstrong.com Git - mothur.git/blob - mothur.cpp
adding mothurout.h and .cpp to repo
[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 /***********************************************************************/
22 volatile int ctrlc_pressed = 0;
23 void ctrlc_handler ( int sig ) {
24         MothurOut* m = MothurOut::getInstance();
25     ctrlc_pressed = 1;
26         m->control_pressed = ctrlc_pressed;
27 }
28 /***********************************************************************/
29 int main(int argc, char *argv[]){
30         MothurOut* m = MothurOut::getInstance();
31         try {
32                 
33                 signal(SIGINT, ctrlc_handler );
34                                 
35                 time_t ltime = time(NULL); /* calendar time */  
36                 string logFileName = "mothur." + toString(ltime) + ".logfile";
37                 
38                 m->setFileName(logFileName);
39                 
40                 //version
41                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
42                         system("clear");
43                         #if defined (__APPLE__) || (__MACH__)
44                                 m->mothurOutJustToLog("Mac version");
45                                 m->mothurOutEndLine(); m->mothurOutEndLine();
46                         #else
47                                 m->mothurOutJustToLog("Linux version");
48                                 >m->mothurOutEndLine(); m->mothurOutEndLine();
49                         #endif
50
51                 #else
52                         system("CLS");
53                         m->mothurOutJustToLog("Windows version");
54                         m->mothurOutEndLine(); m->mothurOutEndLine();
55                 #endif          
56                 
57                 #ifdef USE_READLINE
58                         m->mothurOutJustToLog("Using ReadLine");
59                         m->mothurOutEndLine(); m->mothurOutEndLine();
60                 #endif
61                 
62                 //header
63                 m->mothurOut("mothur v.1.8");
64                 m->mothurOutEndLine();          
65                 m->mothurOut("Last updated: 2/02/2010");
66                 m->mothurOutEndLine();  
67                 m->mothurOutEndLine();          
68                 m->mothurOut("by");
69                 m->mothurOutEndLine();          
70                 m->mothurOut("Patrick D. Schloss");
71                 m->mothurOutEndLine();
72                 m->mothurOutEndLine();                  
73                 m->mothurOut("Department of Microbiology & Immunology");
74                 m->mothurOutEndLine();  
75                 m->mothurOut("University of Michigan");
76                 m->mothurOutEndLine();                  
77                 m->mothurOut("pschloss@umich.edu");
78                 m->mothurOutEndLine();          
79                 m->mothurOut("http://www.mothur.org");
80                 m->mothurOutEndLine();
81                 m->mothurOutEndLine();
82                 m->mothurOut("When using, please cite:");
83                 m->mothurOutEndLine();
84                 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.");
85                 m->mothurOutEndLine();  
86                 m->mothurOutEndLine();          
87                 m->mothurOut("Distributed under the GNU General Public License");
88                 m->mothurOutEndLine();
89                 m->mothurOutEndLine();                  
90                 m->mothurOut("Type 'help()' for information on the commands that are available");
91                 m->mothurOutEndLine();
92                 m->mothurOutEndLine();                  
93                 m->mothurOut("Type 'quit()' to exit program");
94                 m->mothurOutEndLine();  
95
96                                 
97                 //srand(54321);
98                 srand( (unsigned)time( NULL ) );
99                 
100                 Engine* mothur;
101                 bool bail = 0;
102                 string input;
103
104                 if(argc>1){
105                         input = argv[1];
106
107                         if (input[0] == '#') {
108                                 m->mothurOutJustToLog("Script Mode");
109                                 m->mothurOutEndLine(); m->mothurOutEndLine();
110
111                                 mothur = new ScriptEngine(argv[0], argv[1]);
112                         }else{
113                                 m->mothurOutJustToLog("Batch Mode");
114                                 m->mothurOutEndLine(); m->mothurOutEndLine();
115                                 
116                                 mothur = new BatchEngine(argv[0], argv[1]);
117                         }
118                 }
119                 else{
120                         m->mothurOutJustToLog("Interactive Mode");
121                         m->mothurOutEndLine(); m->mothurOutEndLine();
122                         
123                         mothur = new InteractEngine(argv[0]);   
124                 }
125                 
126                 while(bail == 0)                {       bail = mothur->getInput();                      }
127                 
128                 string outputDir = mothur->getOutputDir();
129                 string newlogFileName = outputDir + logFileName;
130         
131                 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
132                 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
133                 
134                 delete mothur;
135
136                 return 0;
137         }
138         catch(exception& e) {
139                 m->errorOut(e, "mothur", "main");
140                 exit(1);
141         }
142 }
143
144 /**************************************************************************************************/
145