]> git.donarmstrong.com Git - mothur.git/blob - mothur.cpp
started work on sffinfo command. fixed bug across all paralellized commands if the...
[mothur.git] / mothur.cpp
1 /*\r
2  *  interface.cpp\r
3  *  \r
4  *\r
5  *  Created by Pat Schloss on 8/14/08.\r
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.\r
7  *\r
8  */\r
9  \r
10 #include "mothur.h"\r
11 #include "engine.hpp"\r
12 #include "globaldata.hpp"\r
13 #include "mothurout.h"\r
14 \r
15 \r
16 /**************************************************************************************************/\r
17 \r
18 GlobalData* GlobalData::_uniqueInstance = 0;\r
19 CommandFactory* CommandFactory::_uniqueInstance = 0;\r
20 MothurOut* MothurOut::_uniqueInstance = 0;\r
21 \r
22 /***********************************************************************/\r
23 volatile int ctrlc_pressed = 0;\r
24 void ctrlc_handler ( int sig ) {\r
25         MothurOut* m = MothurOut::getInstance();\r
26     ctrlc_pressed = 1;\r
27         m->control_pressed = ctrlc_pressed;\r
28         \r
29         if (m->executing) { //if mid command quit execution, else quit mothur\r
30                 m->mothurOutEndLine(); m->mothurOut("quitting command...");  m->mothurOutEndLine();\r
31         }else{\r
32                 m->mothurOut("quitting mothur");  m->mothurOutEndLine();\r
33                 exit(1);\r
34         }\r
35 }\r
36 /***********************************************************************/\r
37 int main(int argc, char *argv[]){\r
38         MothurOut* m = MothurOut::getInstance();\r
39         try {\r
40                 \r
41                 signal(SIGINT, ctrlc_handler );\r
42                                 \r
43                 time_t ltime = time(NULL); /* calendar time */  \r
44                 string logFileName = "mothur." + toString(ltime) + ".logfile";\r
45                 \r
46                 #ifdef USE_MPI\r
47                         MPI_Init(&argc, &argv); \r
48                 #endif\r
49 \r
50                 m->setFileName(logFileName);\r
51                 \r
52                                 \r
53                 //version\r
54                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)\r
55                         system("clear");\r
56                         #if defined (__APPLE__) || (__MACH__)\r
57                                 m->mothurOutJustToLog("Mac version");\r
58                                 m->mothurOutEndLine(); m->mothurOutEndLine();\r
59                         #else\r
60                                 m->mothurOutJustToLog("Linux version");\r
61                                 m->mothurOutEndLine(); m->mothurOutEndLine();\r
62                         #endif\r
63 \r
64                 #else\r
65                         system("CLS");\r
66                         m->mothurOutJustToLog("Windows version");\r
67                         m->mothurOutEndLine(); m->mothurOutEndLine();\r
68                 #endif          \r
69                 \r
70                 #ifdef USE_READLINE\r
71                         m->mothurOutJustToLog("Using ReadLine");\r
72                         m->mothurOutEndLine(); m->mothurOutEndLine();\r
73                 #endif\r
74                 \r
75                 #ifdef BIT_VERSION\r
76                         m->mothurOutJustToLog("Running 64Bit Version");\r
77                         m->mothurOutEndLine(); m->mothurOutEndLine();\r
78                 #else\r
79                         m->mothurOutJustToLog("Running 32Bit Version");\r
80                         m->mothurOutEndLine(); m->mothurOutEndLine();\r
81                 #endif\r
82                 \r
83                 //header\r
84                 m->mothurOut("mothur v.1.11.0");\r
85                 m->mothurOutEndLine();          \r
86                 m->mothurOut("Last updated: 6/18/2010");\r
87                 m->mothurOutEndLine();  \r
88                 m->mothurOutEndLine();          \r
89                 m->mothurOut("by");\r
90                 m->mothurOutEndLine();          \r
91                 m->mothurOut("Patrick D. Schloss");\r
92                 m->mothurOutEndLine();\r
93                 m->mothurOutEndLine();                  \r
94                 m->mothurOut("Department of Microbiology & Immunology");\r
95                 m->mothurOutEndLine();  \r
96                 m->mothurOut("University of Michigan");\r
97                 m->mothurOutEndLine();                  \r
98                 m->mothurOut("pschloss@umich.edu");\r
99                 m->mothurOutEndLine();          \r
100                 m->mothurOut("http://www.mothur.org");\r
101                 m->mothurOutEndLine();\r
102                 m->mothurOutEndLine();\r
103                 m->mothurOut("When using, please cite:");\r
104                 m->mothurOutEndLine();\r
105                 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.");\r
106                 m->mothurOutEndLine();  \r
107                 m->mothurOutEndLine();          \r
108                 m->mothurOut("Distributed under the GNU General Public License");\r
109                 m->mothurOutEndLine();\r
110                 m->mothurOutEndLine();                  \r
111                 m->mothurOut("Type 'help()' for information on the commands that are available");\r
112                 m->mothurOutEndLine();\r
113                 m->mothurOutEndLine();                  \r
114                 m->mothurOut("Type 'quit()' to exit program");\r
115                 m->mothurOutEndLine();  \r
116                 \r
117                 #ifdef USE_MPI\r
118                         m->mothurOutJustToLog("Using MPI\tversion ");\r
119                         int version, subversion;\r
120                         MPI_Get_version(&version, &subversion);\r
121                         m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n");\r
122                 #endif\r
123                 \r
124                 //srand(54321);\r
125                 srand( (unsigned)time( NULL ) );\r
126                 \r
127                 Engine* mothur;\r
128                 bool bail = 0;\r
129                 string input;\r
130 \r
131                 if(argc>1){\r
132                         input = argv[1];\r
133 \r
134                         if (input[0] == '#') {\r
135                                 m->mothurOutJustToLog("Script Mode");\r
136                                 m->mothurOutEndLine(); m->mothurOutEndLine();\r
137 \r
138                                 mothur = new ScriptEngine(argv[0], argv[1]);\r
139                         }else{\r
140                                 m->mothurOutJustToLog("Batch Mode");\r
141                                 m->mothurOutEndLine(); m->mothurOutEndLine();\r
142                                 \r
143                                 mothur = new BatchEngine(argv[0], argv[1]);\r
144                         }\r
145                 }\r
146                 else{\r
147                         m->mothurOutJustToLog("Interactive Mode");\r
148                         m->mothurOutEndLine(); m->mothurOutEndLine();\r
149                         \r
150                         mothur = new InteractEngine(argv[0]);   \r
151                 }\r
152                 \r
153                 while(bail == 0)        {       bail = mothur->getInput();      }\r
154                 \r
155                 //closes logfile so we can rename\r
156                 m->closeLog();\r
157                 \r
158                 string outputDir = mothur->getOutputDir();\r
159                 string tempLog = mothur->getLogFileName();\r
160                 bool append = mothur->getAppend();\r
161                 \r
162                 string newlogFileName;\r
163                 if (tempLog != "") {\r
164                         newlogFileName = outputDir + tempLog;\r
165                         \r
166                         if (!append) {  \r
167                                 //need this because m->mothurOut makes the logfile, but doesn't know where to put it\r
168                                 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp\r
169 \r
170                         }else {\r
171                                 ofstream outNewLog;\r
172                                 openOutputFileAppend(newlogFileName, outNewLog);\r
173                                 outNewLog << endl << endl << "*********************************************************************************" << endl << endl;\r
174                                 outNewLog.close();\r
175                                 \r
176                                 appendFiles(logFileName, newlogFileName);\r
177                                 remove(logFileName.c_str());\r
178                         }\r
179                 }else{  \r
180                         newlogFileName = outputDir + logFileName;\r
181                         //need this because m->mothurOut makes the logfile, but doesn't know where to put it\r
182                         rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp\r
183                 }\r
184                 \r
185                                 \r
186                 delete mothur;\r
187                 \r
188                 #ifdef USE_MPI\r
189                         MPI_Finalize();\r
190                 #endif\r
191                 \r
192                 return 0;\r
193         }\r
194         catch(exception& e) {\r
195                 m->errorOut(e, "mothur", "main");\r
196                 exit(1);\r
197         }\r
198 }\r
199 \r
200 /**************************************************************************************************/\r
201 \r